Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Creature FindBestTarget(List<Creature> targets)
- {
- Creature topKillTarget = null;
- Creature topAlmostKill = null;
- int maxDamageTarget = 0;
- int closestToDeath = int.MaxValue;
- List<Creature> equalHealthTarget = new List<Creature>();
- foreach (var currentTarget in targets)
- {
- if ((currentTarget.HealthPoints - CalculateActualDamage(currentTarget) <= 0) && currentTarget.Damage > maxDamageTarget)
- {
- maxDamageTarget = currentTarget.Damage;
- topKillTarget = currentTarget;
- }
- else if (currentTarget.HealthPoints - CalculateActualDamage(currentTarget) <= closestToDeath)
- {
- //topAlmostKill = currentTarget;
- if(currentTarget.HealthPoints - CalculateActualDamage(currentTarget) == closestToDeath)
- {
- equalHealthTarget.Add(currentTarget);
- }
- else
- {
- equalHealthTarget.Clear();
- equalHealthTarget.Add(currentTarget);
- closestToDeath = currentTarget.HealthPoints - CalculateActualDamage(currentTarget);
- }
- }
- }
- int maxDamageEqualTarget = 0;
- foreach(var healthTarget in equalHealthTarget)
- {
- if (healthTarget.damage > maxDamageEqualTarget)
- {
- maxDamageEqualTarget = healthTarget.damage;
- topAlmostKill = healthTarget;
- }
- }
- if (topKillTarget != null)
- {
- return topKillTarget;
- }
- else
- {
- return topAlmostKill;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement