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)); }
protected FDCreature LookForAggressiveTarget() { List <FDCreature> candidates = this.GameAction.GetOppositeCreatures(this.Creature); int candidateIndex = 0; while (candidateIndex < candidates.Count && !this.Creature.IsAbleToAttack(candidates[candidateIndex])) { candidateIndex++; } if (candidateIndex >= candidates.Count) { candidateIndex = 0; } FDCreature terminateCreature = candidates[candidateIndex]; DistanceResolver disResolver = new DistanceResolver(this.GameAction.GetField()); disResolver.ResolveDistanceFrom(this.Creature.Position, terminateCreature.Position); float minDistance = 999; FDCreature finalTarget = terminateCreature; foreach (FDCreature c in candidates) { float distance = disResolver.GetDistanceTo(c.Position); if (distance < minDistance && this.Creature.IsAbleToAttack(c)) { minDistance = distance; finalTarget = c; } } return(finalTarget); }