133 lines
3.7 KiB
C#
133 lines
3.7 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Level;
|
|
using Gameplay.Skill;
|
|
using Gameplay.AI;
|
|
using Gameplay.BT.Variables;
|
|
using Gameplay.Buff;
|
|
using Gameplay.PlayerSkill.Data;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using Gameplay.Vehicle.Impl;
|
|
|
|
namespace Gameplay.Character
|
|
{
|
|
public partial class Character
|
|
{
|
|
private const string AIBehavior = "AIBehavior";
|
|
|
|
protected override async UniTask _OnPrepare()
|
|
{
|
|
_InitFsm();
|
|
await SkillManager.instance.InitCharacter(this);
|
|
}
|
|
|
|
protected override void _OnReady()
|
|
{
|
|
}
|
|
|
|
protected override void _OnEnterBattle()
|
|
{
|
|
isReady = true;
|
|
_SetAIStart();
|
|
BuffManager.instance.InitCharacter(this);
|
|
SkillManager.instance.AutoAddPassiveBuffs(this);
|
|
buffManager.TriggerEnterBattle();
|
|
}
|
|
|
|
private async void _SetAIStart()
|
|
{
|
|
if (troopId == ETroopsId.Self)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var bt = await AIManager.Instance.RegisterAI(Node.GameObject, AIBehavior);
|
|
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
|
{
|
|
Value = new BattleInfo()
|
|
{
|
|
ownerId = GetID(),
|
|
AIName = runtimeData.characterLevelData.AIName,
|
|
AttachAIName = runtimeData.characterLevelData.AttachAIName,
|
|
PatrolInfos = runtimeData.characterLevelData.PatrolInfos,
|
|
}
|
|
});
|
|
statusData.isAIControll = true;
|
|
}
|
|
|
|
protected override void _OnExitBattle()
|
|
{
|
|
isReady = false;
|
|
buffManager?.TriggerExitBattle();
|
|
if (troopId != ETroopsId.Self)
|
|
{
|
|
AIManager.Instance.UnRegisterAI(Node.GameObject);
|
|
}
|
|
|
|
BuffManager.instance?.RemoveCharacter(this);
|
|
// SkillManager.instance?.RemoveCharacter(this);
|
|
}
|
|
|
|
protected override void _OnBackPrepare()
|
|
{
|
|
if (LevelManager.Instance.CurrentLevel.isInBattle)
|
|
{
|
|
// 在战斗中
|
|
// 重置所有状态
|
|
|
|
ResetToPrepare();
|
|
}
|
|
}
|
|
|
|
protected override void _OnUseSkill(int cellIndex,
|
|
SkillHandle skillHandle)
|
|
{
|
|
if (cellIndex == -1)
|
|
{
|
|
cellIndex = transData.cellIndex;
|
|
}
|
|
controlData.skillCellIndex = cellIndex;
|
|
var skillConfig = skillHandle.runtimeData.configData;
|
|
switch (skillConfig.SkillActionId)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
_fullFSM.ChangeState(EFullState.Skill);
|
|
break;
|
|
default:
|
|
DebugUtil.LogError("暂未支持的技能类型:{0}", skillConfig.SkillActionId);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void NormalShoot(GameUnit enemy)
|
|
{
|
|
commonData.lastInFightSeconds = LevelManager.Instance.CurrentLevel.LevelTime;
|
|
|
|
BulletManager.instance.DoNormalShoot(this, enemy);
|
|
|
|
}
|
|
|
|
public void UpVehicle(NormalVehicle vehicle)
|
|
{
|
|
runtimeData.belongVehicle = vehicle;
|
|
}
|
|
|
|
public void DownVehicle()
|
|
{
|
|
if (runtimeData.belongVehicle != null)
|
|
runtimeData.belongVehicle.MarkRemove(this);
|
|
runtimeData.belongVehicle = null;
|
|
}
|
|
|
|
public void Revive(UnitReviveData reviveData)
|
|
{
|
|
needRemove = false;
|
|
ResetToPrepare();
|
|
aliveData.Revive(reviveData);
|
|
}
|
|
|
|
}
|
|
}
|