예제 #1
0
        protected FDMovePath DecidePositionAndPath(FDPosition targetPos)
        {
            DistanceResolver disResolver = new DistanceResolver(this.GameAction.GetField());

            disResolver.ResolveDistanceFrom(targetPos, this.Creature.Position);

            FDPosition originalPos = this.Creature.Position;

            float bestDistance       = 999;
            int   bestDistanceInUnit = -1;
            bool  inAttackScope      = false;

            MoveRangeFinder finder    = new MoveRangeFinder(this.GameAction, this.Creature);
            FDMoveRange     moveRange = finder.CalculateMoveRange();

            FDSpan     span     = null;
            FDPosition finalPos = originalPos;

            if (this.GameAction.GetCreatureAt(targetPos) != null)
            {
                span = Creature.Data.GetAttackItem()?.AttackScope;
            }
            else
            {
                span = new FDSpan(0, 0);
            }

            foreach (FDPosition movePos in moveRange.Positions)
            {
                int distanceToTarget = GetDirectDistance(targetPos, movePos);
                if (span.ContainsValue(distanceToTarget))
                {
                    inAttackScope = true;
                    if (distanceToTarget > bestDistanceInUnit)
                    {
                        bestDistanceInUnit = distanceToTarget;
                        finalPos           = movePos;
                    }
                }

                if (!inAttackScope)
                {
                    float distance = disResolver.GetDistanceTo(movePos);
                    if (distance < bestDistance)
                    {
                        bestDistance = distance;
                        finalPos     = movePos;
                    }
                }
            }

            return(moveRange.GetPath(finalPos));
        }
예제 #2
0
        public override void OnEnter()
        {
            base.OnEnter();

            // Calculcate the moving scopes and save it in cache
            if (moveRange == null)
            {
                MoveRangeFinder finder = new MoveRangeFinder(gameAction, this.creature);
                moveRange = finder.CalculateMoveRange();
            }

            // If the creature has moved, reset the creature position
            this.creature.ResetPosition();
            CreatureRefreshPack reset = new CreatureRefreshPack(this.creature.Clone());

            SendPack(reset);

            ShowRangePack showRange = new ShowRangePack(moveRange);

            SendPack(showRange);
        }