Exemplo n.º 1
0
        public IPromise Move(Vector2Int target)
        {
            List <Vector2Int> path         = gridNavigator.GetPath(this, target, MaxWalkDistance);
            Deferred          moveDeferred = Deferred.GetFromPool();

            if (path != null)
            {
                Vector2Int oldPosition = GridPosition;

                for (int stepIdx = 0; stepIdx < path.Count; stepIdx++)
                {
                    Vector2Int newPosition = path[stepIdx];
                    OnStep(newPosition, stepIdx, stepDuration);
                }

                Timers.Instance.Wait(path.Count * stepDuration)
                .Done(() =>
                {
                    GridPosition = path[path.Count - 1];
                    OnMovementFinished(this, oldPosition, GridPosition);
                    moveDeferred.Resolve();
                });
                return(moveDeferred);
            }
            else
            {
                return(moveDeferred.Resolve());
            }
        }
Exemplo n.º 2
0
        public IPromise MakeAITurn()
        {
            EntityFaction opposingFaction = Faction == EntityFaction.Player ? EntityFaction.Enemy : EntityFaction.Player;
            bool          attackSuccess   = TryAttackFractionInRange(opposingFaction);

            if (attackSuccess == false)
            {
                Entity closestPlayerCharacter = levelService.GetClosestCharacter(GridPosition, opposingFaction);
                if (closestPlayerCharacter != null)
                {
                    List <Vector2Int> path        = gridNavigator.GetPath(this, closestPlayerCharacter.GridPosition, MaxWalkDistance, closestPlayerCharacter);
                    Vector2Int        moveTarget  = path.Last() == closestPlayerCharacter.GridPosition ? path[path.Count - 2] : path[path.Count - 1];
                    IPromise          movePromise = Move(moveTarget);
                    movePromise.Done(() => TryAttackFractionInRange(opposingFaction));
                    return(movePromise);
                }
            }
            return(Deferred.GetFromPool().Resolve());
        }
Exemplo n.º 3
0
    public IPromise AttachBubble(Bubble newBubble, int x, int y, bool shotFromGun, uint mergesInTurn = 0)
    {
        Deferred attachDeferred = Deferred.GetFromPool();

        SetBubbleGridIndeces(newBubble, x, y);
        newBubble.transform.position = IndecesToPosition(x, y);

        bubblesActionSet.Clear();

        CheckMatches(newBubble);

        if (bubblesActionSet.Count > 1)
        {
            List <Bubble> bubblesMatched  = new List <Bubble>(bubblesActionSet);
            int           afterMergePower = bubblesMatched[0].Power + bubblesMatched.Count - 1;
            bubblesMatched = bubblesMatched
                             .OrderByDescending((b) => DoesBubbleHaveNeighbourWithPower(b, afterMergePower))
                             .ThenByDescending(b => b.transform.position.y)
                             .ToList();


            Bubble targetMergeBubble = bubblesMatched[0];

            Sequence mergeSequence = DOTween.Sequence();
            //Merge bubbles & destroy all except first
            for (int bIndex = bubblesMatched.Count - 1; bIndex >= 1; bIndex--)
            {
                Bubble mergingBubble   = bubblesMatched[bIndex];
                float  mergeDuration   = animationCfg.bubbleMergeDuration + animationCfg.bubbleMergeDelay * bIndex;
                Tween  mergeScaleTween = mergingBubble.transform.DOScale(animationCfg.bubbleMergeTargetScale, mergeDuration)
                                         .SetEase(animationCfg.bubbleMergeEase);
                Tween mergeMoveTween = mergingBubble.transform.DOMove(targetMergeBubble.transform.position, mergeDuration)
                                       .SetEase(animationCfg.bubbleMergeEase);
                mergeMoveTween.OnComplete(() => DestroyBubble(mergingBubble, Bubble.BubbleDeathType.EXPLOSION));
                mergeSequence.Insert(0, mergeMoveTween);
                mergeSequence.Insert(0, mergeScaleTween);
            }
            mergeSequence.OnComplete(() =>
            {
                OnBubblesMerged(afterMergePower);
                targetMergeBubble.Upgrade(afterMergePower);

                if (targetMergeBubble.Power >= bubblesConfig.explosionThresholdPower)
                {
                    Explode(targetMergeBubble);
                    FinishTurn(mergesInTurn + 1);
                    attachDeferred.Resolve();
                }
                else
                {
                    AttachBubble(targetMergeBubble, targetMergeBubble.X, targetMergeBubble.Y, false, mergesInTurn + 1)
                    .Done(() => attachDeferred.Resolve());
                }
            });
        }
        else
        {
            if (shotFromGun)
            {
                foreach (var neighbour in NeighbourBubbles(newBubble))
                {
                    neighbour.OnGunBubbleAttached(newBubble.X, newBubble.Y);
                }

                OnNothingMergedTurn();
            }
            FinishTurn(mergesInTurn);
            attachDeferred.Resolve();
        }

        return(attachDeferred);
    }