Exemple #1
0
        private IEnumerator enterCoroutine(PlayerController fsm)
        {
            Time.timeScale = 0f;
            fsm.blockMovement.staticExtrusion = false;
            dir = targetPosition - fsm.PositionWithoutHalo;
            fsm.swapSkill.UseSkill <SwapState>();
            var binding = fsm.swapCharges.GetSwapCharge();

            binding.value = 0;
            fsm.StartCoroutine(binding.redLight.SwapCor(fsm, targetPosition));
            var enemyRedLight = RedLightEnemyController.Create(fsm, targetPosition);

            fsm.StartCoroutine(enemyRedLight.SwapCor());
            EventBus.Notify("PlayerSwapEnter", fsm, fsm.swapProperty.disappearTime);
            float time = dir.magnitude / fsm.swapProperty.speed;

            target.SwapMove(-dir, time, fsm.swapProperty.disappearTime);
            //ApCtrl.DisappearAlpha(fsm.scaleAd, fsm.swapProperty.disappearTime);
            yield return(new WaitForSecondsRealtime(fsm.swapProperty.disappearTime));

            Swapable.SwapMove(dir, time, (pos) => fsm.blockMovement.Position = pos, () => fsm.PositionWithoutHalo, fsm);
            yield return(new WaitForSecondsRealtime(time));

            fsm.blockMovement.staticExtrusion = true;
            EventBus.Notify("PlayerSwapExit", fsm, fsm.swapProperty.disappearTime);
            //ApCtrl.AppearAlpha(fsm.scaleAd, fsm.swapProperty.disappearTime);
            yield return(new WaitForSecondsRealtime(fsm.swapProperty.disappearTime));

            Time.timeScale = 1;
            var v = fsm.blockMovement.Velocity;

            v *= 0;
            fsm.blockMovement.Velocity = v;
            fsm.ChangeState(last);
        }
        public static IEnumerable <Swapable <T> > LexicographicPermutations <T>(Swapable <T> items)
        {
            items.Sort();

            while (true)
            {
                yield return(items);

                //Find the rightmost item which is smaller than its next item. We will call this the "first item"
                int i;
                for (i = items.ElementCount - 2; i >= 0; i--)
                {
                    if (items.Compare(items.ElementAt(i), items.ElementAt(i + 1)) < 0)
                    {
                        break;
                    }
                }

                //If there is no such character, all are sorted which means we just printed the last permutation
                if (i == -1)
                {
                    yield break;
                }
                else
                {
                    //Find the ceil of the "first item" to the right
                    //The ceil is the smallest item greater than it
                    int ceilIndex = findCeil(items, items.ElementAt(i), i + 1, items.ElementCount - 1);
                    items.Swap(i, ceilIndex);
                    reverse(items, i + 1, items.ElementCount - i - 1);
                }
            }
        }
        private static void reverse <T>(Swapable <T> items, int index, int count)
        {
            int indexStop = index + count - 1;

            for (int i = 0; i < count / 2; i++)
            {
                items.Swap(index + i, indexStop - i);
            }
        }
Exemple #4
0
 private IEnumerator checkClosest(Swapable swapable)
 {
     while (true)
     {
         if (swapable != closestSwapable || !swapSkill.SkillValid || !swapCharges.SwapValid)
         {
             swapable.SelectedUIActive = false;
             yield break;
         }
         yield return(null);
     }
 }
        //Probably inefficient way to move items but we will keep it for now
        private static void Bubble <T>(Swapable <T> items, int index, int targetIndex)
        {
            while (index > targetIndex)
            {
                items.Swap(index, index - 1);
                index--;
            }

            while (index < targetIndex)
            {
                items.Swap(index, index + 1);
                index++;
            }
        }
        private static int PermutateN <T>(Swapable <T> items, int n, int factorial, int depth)
        {
            factorial *= depth;
            if (depth + 1 < items.ElementCount)
            {
                // Subtract the returned offset
                n = PermutateN(items, n, factorial, depth + 1);
            }

            int index       = n / factorial;
            int targetIndex = items.ElementCount - depth - 1;

            Bubble(items, targetIndex + index, targetIndex);

            return(n % factorial); // The n offset for the previous depth
        }
        // Find the index of the smalled element which is greater than 'current' and is present in the range [L..H]
        private static int findCeil <T>(Swapable <T> items, T current, int L, int H)
        {
            int ceilIndex   = L;
            T   ceilElement = items.ElementAt(L);

            for (int i = L + 1; i <= H; i++)
            {
                T element = items.ElementAt(i);
                if (items.Compare(element, current) > 0 && items.Compare(element, ceilElement) < 0)
                {
                    ceilIndex   = i;
                    ceilElement = element;
                }
            }

            return(ceilIndex);
        }
        private static IEnumerable <Swapable <T> > Permutate <T>(Swapable <T> items, int depth)
        {
            if (depth == 1)
            {
                yield return(items);
            }
            else
            {
                foreach (Swapable <T> perm in Permutate(items, depth - 1))
                {
                    yield return(perm);
                }

                for (int i = 0; i < depth - 1; i++)
                {
                    items.Swap((depth % 2 == 0) ? i : 0, depth - 1);
                    foreach (Swapable <T> perm in Permutate(items, depth - 1))
                    {
                        yield return(perm);
                    }
                }
            }
        }
Exemple #9
0
    private void SwapProcess()
    {
        if (swapView.InRangeGosCount == 0)
        {
            return;
        }
        var swapables = Algorithm.GetMonos <Swapable>(swapView.InRangeGos);
        Func <Swapable, GameObject> getGo    = (sa) => sa.gameObject;
        Func <GameObject, float>    getGoDis = (g) => (VectorUtils.V32(g.transform.position) - blockMovement.Position).magnitude;

        closestSwapable = Algorithm.GetMin(swapables, (sa) => getGoDis(getGo(sa)));
        if (closestSwapable != null && swapSkill.SkillValid && swapCharges.SwapValid)
        {
            if (!closestSwapable.SelectedUIActive)
            {
                closestSwapable.SelectedUIActive = true;
                closestSwapable.StartCoroutine(checkClosest(closestSwapable));
            }
            if (swapSkill.SkillPressed)
            {
                ChangeState <SwapState>(new SwapState(closestSwapable, current));
            }
        }
    }
Exemple #10
0
 public SwapState(Swapable target, IState last)
 {
     this.target = target;
     this.last   = last;
 }
 public static Swapable <T> LexicographicPermutationN <T>(Swapable <T> items, int n)
 {
     items.Sort();
     PermutateN(items, n, 1, 1);
     return(items);
 }
 public static IEnumerable <Swapable <T> > Permutations <T>(Swapable <T> items)
 {
     return(Permutate(items, items.ElementCount));
 }