Implement GolemFist
This commit is contained in:
parent
4ca7b7537a
commit
d1af817bc6
11 changed files with 106 additions and 19 deletions
43
Assets/Battle/MonsterAI/AIUtils.cs
Normal file
43
Assets/Battle/MonsterAI/AIUtils.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/MonsterAI/AIUtils.cs.meta
Normal file
11
Assets/Battle/MonsterAI/AIUtils.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 69cce7f2fac935f429b1a72da0b465bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Battle/MonsterAI/MonsterViewpoint.cs
Normal file
8
Assets/Battle/MonsterAI/MonsterViewpoint.cs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface MonsterViewpoint {
|
||||
BattleHero[] Heroes {get;}
|
||||
BattleMonster[] Monsters {get;}
|
||||
}
|
||||
11
Assets/Battle/MonsterAI/MonsterViewpoint.cs.meta
Normal file
11
Assets/Battle/MonsterAI/MonsterViewpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c235e6491d6458a4ab8dbb587ebd8866
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue