// Function immediate swapping 2 chips public void SwapTwoItemNow(Card a, Card b) { if (!a || !b) { return; } if (a == b) { return; } if (a.parentSlot.slot.Block || b.parentSlot.slot.Block) { return; } //Vector3 posA = a.parentSlot.transform.position; //Vector3 posB = b.parentSlot.transform.position; //a.transform.position = posB; //b.transform.position = posA; a.movementID = SessionControl.Instance.GetMovementID(); b.movementID = SessionControl.Instance.GetMovementID(); SlotForCard slotA = a.parentSlot; SlotForCard slotB = b.parentSlot; slotB.SetChip(a); slotA.SetChip(b); }
// public void Reset() // { // // } public void SetChip(Card card) { // Card = card; // Card.transform.SetParent(this.transform,false); //// Card.SetSlot(this); // if (slotForChip) { FieldAssistant.Instance.field.chips[_row, _col] = card.id; FieldAssistant.Instance.field.powerUps[_row, _col] = card.powerId; slotForChip.SetChip(card); } }
// Coroutine swapping 2 chips IEnumerator SwapTwoItemRoutine(Card a, Card b, bool force) { if (!Iteraction) { a.SetBorder(false); b.SetBorder(false); yield break; } // cancellation terms if (swaping) { a.SetBorder(false); b.SetBorder(false); yield break; // If the process is already running } if (!a || !b) { if (a) { a.SetBorder(false); } if (b) { b.SetBorder(false); } yield break; // If one of the chips is missing } if (a.destroying || b.destroying) { a.SetBorder(false); b.SetBorder(false); yield break; } if (a.parentSlot.slot.Block != null || b.parentSlot.slot.Block != null) { a.SetBorder(false); b.SetBorder(false); yield break; // If one of the chips is blocked } if (!SessionControl.Instance.CanIAnimate()) { a.SetBorder(false); b.SetBorder(false); yield break; // If the core prohibits animation } if (SessionControl.Instance.movesCount <= 0) { a.SetBorder(false); b.SetBorder(false); FightControl.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); yield break; // If not enough moves } if (SessionControl.Instance.timeLeft <= 0) { a.SetBorder(false); b.SetBorder(false); yield break; // If not enough time } SessionControl.Mix mix = SessionControl.Instance.mixes.Find(x => x.Compare(a.chipType, b.chipType)); int move = 0; // Number of points movement which will be expend SessionControl.Instance.animate++; swaping = true; Vector3 posA = a.parentSlot.transform.position; Vector3 posB = b.parentSlot.transform.position; float progress = 0; Vector3 normal = a.parentSlot.slot.Row == b.parentSlot.slot.Row ? Vector3.right : Vector3.up; float time = 0; // Animation swapping 2 chips while (progress < swapDuration) { if (a == null || b == null) { SessionControl.Instance.animate--; swaping = false; if (a) { a.SetBorder(false); } if (b) { b.SetBorder(false); } yield break; } time = EasingFunctions.easeInOutQuad(progress / swapDuration); a.transform.position = Vector3.Lerp(posA, posB, time) + normal * Mathf.Sin(3.14f * time) * 0.05f; if (mix == null) { b.transform.position = Vector3.Lerp(posB, posA, time) - normal * Mathf.Sin(3.14f * time) * 0.05f; } progress += Time.deltaTime; yield return(0); } a.transform.position = posB; if (SessionControl.Instance.movesCount <= 0 || mix == null) { b.transform.position = posA; } a.movementID = SessionControl.Instance.GetMovementID(); b.movementID = SessionControl.Instance.GetMovementID(); if (SessionControl.Instance.movesCount > 0 && mix != null) { // Scenario mix effect swaping = false; SessionControl.Instance.MixChips(a, b); a.SetBorder(false); b.SetBorder(false); yield return(new WaitForSeconds(0.3f)); SessionControl.Instance.movesCount--; SessionControl.Instance.animate--; SessionControl.Instance.SuccessMoveCounter(); yield break; } // Scenario the effect of swapping two chips SlotForCard slotA = a.parentSlot; SlotForCard slotB = b.parentSlot; slotB.SetChip(a); slotA.SetChip(b); move++; // searching for solutions of matching int count = 0; SessionControl.Solution solution; //todo yangzj solution = slotA.MatchAnaliz(false); if (solution != null) { count += solution.count; } // solution = slotA.MatchSquareAnaliz(); // if (solution != null) count += solution.count; solution = slotB.MatchAnaliz(false); if (solution != null) { count += solution.count; } // solution = slotB.MatchSquareAnaliz(); // if (solution != null) count += solution.count; // Scenario canceling of changing places of chips if (SessionControl.Instance.movesCount <= 0 || (count == 0 && !force)) { if (SessionControl.Instance.movesCount <= 0) { //显示不能移动提示 FightControl.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoMoves); } // AudioAssistant.Shot("SwapFailed"); while (progress > 0) { time = EasingFunctions.easeInOutQuad(progress / swapDuration); a.transform.position = Vector3.Lerp(posA, posB, time) - normal * Mathf.Sin(3.14f * time) * 0.05f; b.transform.position = Vector3.Lerp(posB, posA, time) + normal * Mathf.Sin(3.14f * time) * 0.05f; progress -= Time.deltaTime; yield return(0); } a.transform.position = posA; b.transform.position = posB; a.movementID = SessionControl.Instance.GetMovementID(); b.movementID = SessionControl.Instance.GetMovementID(); slotB.SetChip(b); slotA.SetChip(a); a.transform.Find("Border").gameObject.SetActive(false); b.transform.Find("Border").gameObject.SetActive(false); move--; } else { // AudioAssistant.Shot("SwapSuccess"); SessionControl.Instance.swapEvent++; SessionControl.Instance.SuccessMoveCounter(); } // SessionControl.Instance.firstChipGeneration = false; SessionControl.Instance.movesCount -= move; SessionControl.Instance.EventCounter(); SessionControl.Instance.animate--; a.SetBorder(false); b.SetBorder(false); swaping = false; }