Implement GolemFist

This commit is contained in:
henriquenakashima 2020-09-20 15:45:59 -04:00
parent 4ca7b7537a
commit d1af817bc6
11 changed files with 106 additions and 19 deletions

View file

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AIUtils {
public static BattleHero GetNearestHero(MonsterViewpoint monsterViewpoint,
BattleParticipant owner) {
int ownerPosition = GetMonsterPosition(monsterViewpoint, owner);
int nearestHeroIndex = -1;
int nearestDistance = int.MaxValue;
for (int i = 0; i < monsterViewpoint.Heroes.Length; i++) {
if (!monsterViewpoint.Heroes[i].IsAlive()) continue;
int distance = System.Math.Abs(i - ownerPosition);
if (distance < nearestDistance) {
nearestHeroIndex = i;
nearestDistance = distance;
}
}
return monsterViewpoint.Heroes[nearestHeroIndex];
}
public static int GetMonsterPosition(MonsterViewpoint monsterViewpoint, BattleParticipant monster) {
for (int i = 0; i < monsterViewpoint.Monsters.Length; i++) {
if (monsterViewpoint.Monsters[i] == monster) return i;
}
return -1;
}
public static BattleHero GetHeroWithHighestHP(MonsterViewpoint monsterViewpoint) {
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();
if (heroHP > highestHP) {
highestHPHeroIndex = i;
highestHP = heroHP;
}
}
return monsterViewpoint.Heroes[highestHPHeroIndex];
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 69cce7f2fac935f429b1a72da0b465bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface MonsterViewpoint {
BattleHero[] Heroes {get;}
BattleMonster[] Monsters {get;}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c235e6491d6458a4ab8dbb587ebd8866
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: