/* * Algorithm used by the Pere Fwetar to know who to attack */ public override int GetAttackIndex(List <MonsterData> monsters) { //Creates another list with only the monsters that are ALIVE and that arent us List <MonsterData> monstersToAttack = new List <MonsterData>(); //we create a dummy NPC temporary until we determine which npc is the most efficient to attack MonsterData toAttack = new MonsterData(" ", " ", 1, 1); //Makes sure there are any monsters left if (monsters.Count > 0) { foreach (MonsterData monster in monsters) { //if the hp is more than 0, that means the monster is alive if (monster.hp > 0) { //If its ourself, do not add it to the list, cause we dont want to attack ourself (prevent suicide) string ourType = GetType().Name; if (monster.type != ourType) { monstersToAttack.Add(monster); } } } } //Create another list with the npcs that we can kill this turn List <MonsterData> canKill = new List <MonsterData>(); //Make sure there are atleast 1 enemy to attack if (monstersToAttack.Count > 0) { foreach (MonsterData monster in monstersToAttack) { //If you can kill the NPC, focus that NPC if (monster.hp <= DAMAGE) { canKill.Add(monster); } //Checks for the NPC with the highest hp if (toAttack.hp < monster.hp) { toAttack = monster; } } } //Checks if we have atleast 1 npc that we can kill this turn if (canKill.Count > 0) { //Checks for the best npc that we can kill this turn and choose that one foreach (MonsterData monster in canKill) { //we focus the monster that is the highest level, since we steal the stats of that npc if we kill it if (monster.level > toAttack.level) { toAttack = monster; } } } return(monsters.IndexOf(toAttack)); }
public override int GetAttackIndex(List <MonsterData> monsters) { int target = 0; List <MonsterData> PotentialTargets = new List <MonsterData>(monsters.Count); for (int i = 0; i < monsters.Count; i++) { if (monsters[i].name != GetData().name&& monsters[i].hp > 0) { if (monsters[i].hp <= GetDamage()) { PotentialTargets.Add(monsters[i]); } } } if (PotentialTargets.Count > 1) { for (int j = 0; j < 3; j++) { for (int i = 0; i < PotentialTargets.Count - 1; i++) { if (PotentialTargets[i].hp < PotentialTargets[i + 1].hp) { MonsterData temp = PotentialTargets[i + 1]; PotentialTargets[i + 1] = PotentialTargets[i]; PotentialTargets[i] = temp; } } } for (int i = 0; i < monsters.Count; i++) { if (monsters[i].type == PotentialTargets[0].type) { target = i; break; ; } } } else { for (int i = 0; i < monsters.Count; i++) { if (monsters[i].name != GetData().name&& monsters[i].hp > 0 && monsters[i].hp / 2 < GetDamage()) { target = i; break; } else { for (int j = 0; j < monsters.Count; j++) { if (monsters[j].name != GetData().name&& monsters[j].hp > 0) { target = j; break; } } } } } return(target); }
public override int GetAttackIndex(List <MonsterData> monsters) { System.Console.WriteLine("Prepaire to die!"); List <MonsterData> possibleTargets = new List <MonsterData>(); List <MonsterData> goodTarget = new List <MonsterData>(); List <MonsterData> betterTarget = new List <MonsterData>(); MonsterData bestTarget = monsters[0]; foreach (MonsterData md in monsters) { if (md.hp > 0 && md.type != this.GetData().type) { possibleTargets.Add(md); } } foreach (MonsterData md in possibleTargets) { if (md.hp <= this.GetDamage()) { goodTarget.Add(md); } } int GetBestLevel(List <MonsterData> targets) { int lvl = 0; foreach (MonsterData md in targets) { if (md.level > lvl) { lvl = md.level; } } return(lvl); } foreach (MonsterData md in goodTarget) { if (md.level == GetBestLevel(possibleTargets)) { betterTarget.Add(md); } } int GetLowestHp(List <MonsterData> targets) { int Hp = 1000000; foreach (MonsterData md in targets) { if (md.hp < Hp) { Hp = md.hp; } } return(Hp); } foreach (MonsterData md in betterTarget) { if (md.hp == GetLowestHp(betterTarget)) { bestTarget = md; } } return(monsters.IndexOf(bestTarget)); }