Implement statuses, GolemCharge, GolemBerserk, stun
This commit is contained in:
parent
caf782c884
commit
ef9ec43c8a
16 changed files with 260 additions and 38 deletions
|
|
@ -3,43 +3,63 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
|
||||
public class AIUtils {
|
||||
public static BattleHero GetNearestHero(MonsterViewpoint monsterViewpoint,
|
||||
public static BattleHero GetNearestHero(MonsterViewpoint viewpoint,
|
||||
BattleParticipant owner) {
|
||||
int ownerPosition = GetMonsterPosition(monsterViewpoint, owner);
|
||||
int ownerPosition = GetMonsterPosition(viewpoint, owner);
|
||||
|
||||
int nearestHeroIndex = -1;
|
||||
int nearestDistance = int.MaxValue;
|
||||
for (int i = 0; i < monsterViewpoint.Heroes.Length; i++) {
|
||||
if (!monsterViewpoint.Heroes[i].IsAlive()) continue;
|
||||
for (int i = 0; i < viewpoint.Heroes.Length; i++) {
|
||||
if (!viewpoint.Heroes[i].IsAlive()) continue;
|
||||
int distance = System.Math.Abs(i - ownerPosition);
|
||||
if (distance < nearestDistance) {
|
||||
nearestHeroIndex = i;
|
||||
nearestDistance = distance;
|
||||
}
|
||||
}
|
||||
if (nearestHeroIndex == -1) return null;
|
||||
return monsterViewpoint.Heroes[nearestHeroIndex];
|
||||
return HeroAtIndex(nearestHeroIndex, viewpoint);
|
||||
}
|
||||
|
||||
public static int GetMonsterPosition(MonsterViewpoint monsterViewpoint, BattleParticipant monster) {
|
||||
for (int i = 0; i < monsterViewpoint.Monsters.Length; i++) {
|
||||
if (monsterViewpoint.Monsters[i] == monster) return i;
|
||||
public static BattleHero GetFarthestHero(MonsterViewpoint viewpoint,
|
||||
BattleParticipant owner) {
|
||||
int ownerPosition = GetMonsterPosition(viewpoint, owner);
|
||||
|
||||
int farthestHeroIndex = -1;
|
||||
int farthestDistance = -1;
|
||||
for (int i = 0; i < viewpoint.Heroes.Length; i++) {
|
||||
if (!viewpoint.Heroes[i].IsAlive()) continue;
|
||||
int distance = System.Math.Abs(i - ownerPosition);
|
||||
if (distance > farthestDistance) {
|
||||
farthestHeroIndex = i;
|
||||
farthestDistance = distance;
|
||||
}
|
||||
}
|
||||
return HeroAtIndex(farthestHeroIndex, viewpoint);
|
||||
}
|
||||
|
||||
private static int GetMonsterPosition(MonsterViewpoint viewpoint, BattleParticipant monster) {
|
||||
for (int i = 0; i < viewpoint.Monsters.Length; i++) {
|
||||
if (viewpoint.Monsters[i] == monster) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static BattleHero GetHeroWithHighestHP(MonsterViewpoint monsterViewpoint) {
|
||||
public static BattleHero GetHeroWithHighestHP(MonsterViewpoint viewpoint) {
|
||||
int highestHPHeroIndex = -1;
|
||||
int highestHP = -1;
|
||||
for (int i = 0; i < monsterViewpoint.Heroes.Length; i++) {
|
||||
if (!monsterViewpoint.Heroes[i].IsAlive()) continue;
|
||||
int heroHP = monsterViewpoint.Heroes[i].GetHP();
|
||||
for (int i = 0; i < viewpoint.Heroes.Length; i++) {
|
||||
if (!viewpoint.Heroes[i].IsAlive()) continue;
|
||||
int heroHP = viewpoint.Heroes[i].GetHP();
|
||||
if (heroHP > highestHP) {
|
||||
highestHPHeroIndex = i;
|
||||
highestHP = heroHP;
|
||||
}
|
||||
}
|
||||
if (highestHPHeroIndex == -1) return null;
|
||||
return monsterViewpoint.Heroes[highestHPHeroIndex];
|
||||
return HeroAtIndex(highestHPHeroIndex, viewpoint);
|
||||
}
|
||||
|
||||
private static BattleHero HeroAtIndex(int index, MonsterViewpoint viewpoint) {
|
||||
if (index == -1) return null;
|
||||
return viewpoint.Heroes[index];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue