185 lines
6.2 KiB
C#
185 lines
6.2 KiB
C#
using BehaviorDesigner.Runtime;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using UnityEngine;
|
|
|
|
public class Conditionals
|
|
{
|
|
public class CheckEnemyState : Conditional
|
|
{
|
|
public SharedInt state;
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy enemy = transform.GetComponent<Enemy>();
|
|
if (enemy == null) return TaskStatus.Failure;
|
|
if (enemy.state == (EnemyState)state.Value)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
else
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class EnemyHaveTarget : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy enemy = transform.GetComponent<Enemy>();
|
|
if (enemy == null) return TaskStatus.Failure;
|
|
return enemy.target == null ? TaskStatus.Failure : TaskStatus.Success;
|
|
}
|
|
}
|
|
|
|
public class EnemySearchTarget : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy self = transform.GetComponent<Enemy>();
|
|
if (self == null) return TaskStatus.Failure;
|
|
|
|
GameObject target = null;
|
|
EnemyInfo enemyInfo = GameManager.Ins.EnemyInfos[self.type][1];
|
|
|
|
// 指向玩家
|
|
// target = GameLocal.Ins.self.gameObject;
|
|
target = GameManager.Ins.standPos.gameObject;
|
|
|
|
// float minPriorityDis = 9999f;
|
|
// GameObject priorityTarget = null;
|
|
// float minAreaDis = 9999f;
|
|
// GameObject areaTarget = null;
|
|
// float minDis = 9999f;
|
|
// GameObject minDisTarget = null;
|
|
|
|
// foreach (Tower tower in GameManager.Ins.TowerList.Values)
|
|
// {
|
|
// float dis = UnityEngine.Vector3.Distance(tower.transform.position, self.transform.position);
|
|
// // 战术目标搜索(1)
|
|
// if (
|
|
// enemyInfo.Priority != TowerType.NULL &&
|
|
// enemyInfo.Priority == tower.type &&
|
|
// dis < minPriorityDis &&
|
|
// tower.state == TowerState.Normal
|
|
// )
|
|
// {
|
|
// minPriorityDis = dis;
|
|
// priorityTarget = tower.gameObject;
|
|
// }
|
|
|
|
// // 范围搜索(2)
|
|
// if (
|
|
// dis < minAreaDis &&
|
|
// dis <= enemyInfo.MaxAtkArea &&
|
|
// tower.state == TowerState.Normal
|
|
// )
|
|
// {
|
|
// minAreaDis = dis;
|
|
// areaTarget = tower.gameObject;
|
|
// }
|
|
|
|
// // 就近选择(3)
|
|
// if (
|
|
// dis < minDis &&
|
|
// tower.state == TowerState.Normal
|
|
// )
|
|
// {
|
|
// minDis = dis;
|
|
// minDisTarget = tower.gameObject;
|
|
// }
|
|
// }
|
|
|
|
// if (priorityTarget != null)
|
|
// {
|
|
// target = priorityTarget;
|
|
// }
|
|
// else if (areaTarget != null)
|
|
// {
|
|
// target = areaTarget;
|
|
// }
|
|
// else if (minDisTarget != null)
|
|
// {
|
|
// target = minDisTarget;
|
|
// }
|
|
|
|
// // 指向电力核心(4)
|
|
// if (target == null)
|
|
// {
|
|
// GameManager.Ins.TowerList.TryGetValue(1, out Tower powerCore);
|
|
// if (powerCore != null)
|
|
// {
|
|
// target = powerCore.gameObject;
|
|
// }
|
|
// }
|
|
|
|
if (target != null)
|
|
{
|
|
self.target = target;
|
|
Owner.SetVariable("target", (SharedGameObject)self.target);
|
|
}
|
|
else
|
|
{
|
|
self.target = null;
|
|
SharedGameObject targetShared = new SharedGameObject();
|
|
targetShared.Value = null;
|
|
Owner.SetVariable("target", targetShared);
|
|
}
|
|
|
|
return target != null ? TaskStatus.Success : TaskStatus.Failure;
|
|
}
|
|
}
|
|
|
|
public class EnemyInMaxAtkArea : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy self = transform.GetComponent<Enemy>();
|
|
if (self == null) return TaskStatus.Failure;
|
|
if (self.target == null) return TaskStatus.Failure;
|
|
TaskStatus res = TaskStatus.Failure;
|
|
EnemyInfo enemyInfo = GameManager.Ins.EnemyInfos[self.type][1];
|
|
UnityEngine.Vector3 x0zSelf = new UnityEngine.Vector3(self.transform.position.x, 0, self.transform.position.z);
|
|
UnityEngine.Vector3 x0zTarget = new UnityEngine.Vector3(self.target.transform.position.x, 0, self.target.transform.position.z);
|
|
float dis = UnityEngine.Vector3.Distance(x0zTarget, x0zSelf);
|
|
if (dis <= enemyInfo.MaxAtkArea)
|
|
{
|
|
res = TaskStatus.Success;
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
public class EnemyInMinAtkArea : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy self = transform.GetComponent<Enemy>();
|
|
if (self == null) return TaskStatus.Failure;
|
|
if (self.target == null) return TaskStatus.Failure;
|
|
TaskStatus res = TaskStatus.Failure;
|
|
EnemyInfo enemyInfo = GameManager.Ins.EnemyInfos[self.type][1];
|
|
float dis = UnityEngine.Vector3.Distance(self.target.transform.position, self.transform.position);
|
|
if (dis <= enemyInfo.MinAtkArea)
|
|
{
|
|
res = TaskStatus.Success;
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
public class EnemyCheckTargetAlive : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
Enemy self = transform.GetComponent<Enemy>();
|
|
if (self == null) return TaskStatus.Failure;
|
|
if (self.target == null) return TaskStatus.Failure;
|
|
// return self.target.GetComponent<Tower>().state == TowerState.Normal ? TaskStatus.Success : TaskStatus.Failure;
|
|
// return
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
}
|