214 lines
7.0 KiB
C#
214 lines
7.0 KiB
C#
using BehaviorDesigner.Runtime;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using DragonLi.Core;
|
|
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];
|
|
|
|
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;
|
|
// }
|
|
// }
|
|
|
|
// 指向电力核心(4)
|
|
// if (target == null)
|
|
// {
|
|
// GameManager.Ins.TowerList.TryGetValue(1, out Tower powerCore);
|
|
// if (powerCore != null)
|
|
// {
|
|
// target = powerCore.gameObject;
|
|
// }
|
|
// }
|
|
|
|
target = GameManager.Ins.GetPlayer();
|
|
|
|
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;
|
|
self.ai.isStopped = false;
|
|
self.ai.destination = self.target.transform.position.ReflectVectorXOZ();
|
|
// EnemyInfo enemyInfo = GameManager.Ins.EnemyInfos[self.type];
|
|
// Vector3 x0zSelf = self.transform.position.ReflectVectorXOZ();
|
|
// Vector3 x0zTarget = self.target.transform.position.ReflectVectorXOZ();
|
|
// float dis = Vector3.Distance(x0zTarget, x0zSelf);
|
|
// float maxAtkArea = Random.Range(enemyInfo.MinAtkArea, enemyInfo.MaxAtkArea);
|
|
// if (dis <= maxAtkArea)
|
|
// {
|
|
// self.ai.isStopped = true;
|
|
//
|
|
// }
|
|
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];
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
public class CheckPlayerAiState : Conditional
|
|
{
|
|
public SharedInt state;
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
PlayerAI playerAi = transform.GetComponent<PlayerAI>();
|
|
if (playerAi == null) return TaskStatus.Failure;
|
|
if (playerAi.state == (PlayerAIState)state.Value)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
else
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CheckEnemyCount : Conditional
|
|
{
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
return GameManager.Ins.IsHaveEnemy()? TaskStatus.Success : TaskStatus.Failure;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 击杀敌人倒计时
|
|
/// </summary>
|
|
public class CheckKillEnemyCountdownTime: Conditional
|
|
{
|
|
public SharedFloat CountdownTime;
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
return CountdownTime.Value<=0? TaskStatus.Success : TaskStatus.Failure;
|
|
}
|
|
}
|
|
}
|