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)); }
public override StateOperationResult OnSelectPosition(FDPosition position) { // If position is in range if (moveRange.Contains(position)) { ClearRangePack clear = new ClearRangePack(); SendPack(clear); FDMovePath movePath = moveRange.GetPath(position); gameAction.CreatureWalk(new SingleWalkAction(creature.CreatureId, movePath)); var nextState = new MenuActionState(gameAction, creature.CreatureId, position); return(new StateOperationResult(StateOperationResult.ResultType.Push, nextState)); } else { // Cancel return(new StateOperationResult(StateOperationResult.ResultType.Pop)); } }