예제 #1
0
        public IEnumerator Shuffle(bool f)
        {
            bool force = f;

            List <Move> moves = FindMoves();

            if (moves.Count > 0 && !force)
            {
                yield break;
            }
            if (!isPlaying || !FightControl.Instance.IsFighting)
            {
                yield break;
            }

            isPlaying = false;

            _goSlotCreate = FieldAssistant.Instance._goSlotCreate;

            List <Slot> slots = new List <Slot>(SlotManager.Instance.DicSlotNow.Values);

            Dictionary <Slot, Vector3> positions = new Dictionary <Slot, Vector3> ();

            for (int index = 0; index < slots.Count; index++)
            {
                positions.Add(slots[index], slots[index].transform.position);
            }

            float t = 0;

            while (t < 1)
            {
                t += Time.unscaledDeltaTime * 3;
                _goSlotCreate.transform.localScale  = Vector3.one * Mathf.Lerp(1, 0.6f, EasingFunctions.easeInOutQuad(t));
                _goSlotCreate.transform.eulerAngles = Vector3.forward * Mathf.Lerp(0, Mathf.Sin(Time.unscaledTime * 40) * 3, EasingFunctions.easeInOutQuad(t));

                yield return(0);
            }


            if (f || moves.Count == 0)
            {
                f = false;
                RawShuffle(slots);
            }

            moves = FindMoves();
            List <Solution> solutions = FindSolutions();

            int itrn = 0;
            int targetID;

            if (solutions.Count > 0 || moves.Count == 0)
            {
                while (solutions.Count > 0 || moves.Count == 0)
                {
                    if (itrn > 100)
                    {
                        //ShowLosePopup();
                        _goSlotCreate.transform.localScale  = Vector3.one;
                        _goSlotCreate.transform.eulerAngles = Vector3.zero;
                        FightControl.Instance.ShowMsg(FightDefine.E_NoteMsgType.NoShuffle);
                        yield break;
                    }
                    if (solutions.Count > 0)
                    {
                        for (int s = 0; s < solutions.Count; s++)
                        {
                            targetID = Random.Range(0, slots.Count - 1);
                            if (slots[targetID].GetChip() && slots[targetID].GetChip().chipType != "SugarChip" && slots[targetID].GetChip().id != solutions[s].id)
                            {
                                AnimationControl.Instance.SwapTwoItemNow(solutions[s].chips[Random.Range(0, solutions[s].chips.Count - 1)], slots[targetID].GetChip());
                            }
                        }
                    }
                    else
                    {
                        RawShuffle(slots);
                    }

                    moves     = FindMoves();
                    solutions = FindSolutions();
                    itrn++;
                    _goSlotCreate.transform.eulerAngles = Vector3.forward * Mathf.Sin(Time.unscaledTime * 40) * 3;

                    yield return(0);
                }
            }
//			else
//			{
//				_goSlotCreate.transform.eulerAngles = Vector3.forward * Mathf.Sin(Time.unscaledTime * 40) * 3;
//				yield return 0;
//			}

            t = 0;
//			AudioAssistant.Shot("Shuffle");
            while (t < 1)
            {
                t += Time.unscaledDeltaTime * 3;
                _goSlotCreate.transform.localScale  = Vector3.one * Mathf.Lerp(0.6f, 1, EasingFunctions.easeInOutQuad(t));
                _goSlotCreate.transform.eulerAngles = Vector3.forward * Mathf.Lerp(Mathf.Sin(Time.unscaledTime * 40) * 3, 0, EasingFunctions.easeInOutQuad(t));
                yield return(0);
            }

            _goSlotCreate.transform.localScale  = Vector3.one;
            _goSlotCreate.transform.eulerAngles = Vector3.zero;

            isPlaying = true;
        }
예제 #2
0
        // 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;
        }