NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Character/Character.Action.cs

133 lines
3.7 KiB
C#
Raw Normal View History

2023-12-14 14:42:27 +08:00
using Cysharp.Threading.Tasks;
2023-08-22 19:08:45 +08:00
using Gameplay.Bullet;
using Gameplay.Level;
using Gameplay.Skill;
using Gameplay.AI;
using Gameplay.BT.Variables;
2023-12-14 14:42:27 +08:00
using Gameplay.Buff;
2023-12-19 15:01:19 +08:00
using Gameplay.PlayerSkill.Data;
2023-12-13 16:20:41 +08:00
using Gameplay.Unit;
using Gameplay.Unit.Data;
2023-08-22 19:08:45 +08:00
using Gameplay.Vehicle.Impl;
namespace Gameplay.Character
{
public partial class Character
{
private const string AIBehavior = "AIBehavior";
2023-12-14 14:42:27 +08:00
2023-12-14 15:38:17 +08:00
protected override async UniTask _OnPrepare()
2023-08-22 19:08:45 +08:00
{
_InitFsm();
2023-12-14 14:42:27 +08:00
await SkillManager.instance.InitCharacter(this);
2023-08-22 19:08:45 +08:00
}
2023-12-14 15:38:17 +08:00
protected override void _OnReady()
{
}
2023-12-14 14:42:27 +08:00
protected override void _OnEnterBattle()
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
isReady = true;
2023-12-14 14:42:27 +08:00
_SetAIStart();
2023-12-15 16:05:57 +08:00
BuffManager.instance.InitCharacter(this);
SkillManager.instance.AutoAddPassiveBuffs(this);
2023-12-14 14:42:27 +08:00
buffManager.TriggerEnterBattle();
}
2023-08-22 19:08:45 +08:00
2023-12-14 14:42:27 +08:00
private async void _SetAIStart()
{
if (troopId == ETroopsId.Self)
2023-08-22 19:08:45 +08:00
{
2023-12-14 14:42:27 +08:00
return;
2023-08-22 19:08:45 +08:00
}
2023-12-14 19:10:53 +08:00
2023-12-14 14:42:27 +08:00
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,
}
});
2023-12-25 19:00:08 +08:00
statusData.isAIControll = true;
2023-08-22 19:08:45 +08:00
}
2023-12-14 14:42:27 +08:00
protected override void _OnExitBattle()
2023-08-22 19:08:45 +08:00
{
2023-12-20 14:32:55 +08:00
isReady = false;
buffManager?.TriggerExitBattle();
2023-08-22 19:08:45 +08:00
if (troopId != ETroopsId.Self)
{
AIManager.Instance.UnRegisterAI(Node.GameObject);
}
2023-12-14 19:10:53 +08:00
BuffManager.instance?.RemoveCharacter(this);
2023-12-19 14:06:02 +08:00
// SkillManager.instance?.RemoveCharacter(this);
2023-08-22 19:08:45 +08:00
}
2023-12-15 16:05:57 +08:00
protected override void _OnBackPrepare()
{
if (LevelManager.Instance.CurrentLevel.isInBattle)
{
// 在战斗中
2023-12-19 14:06:02 +08:00
// 重置所有状态
ResetToPrepare();
2023-12-15 16:05:57 +08:00
}
}
2023-10-19 15:00:19 +08:00
protected override void _OnUseSkill(int cellIndex,
SkillHandle skillHandle)
2023-08-22 19:08:45 +08:00
{
if (cellIndex == -1)
{
cellIndex = transData.cellIndex;
}
2023-10-19 15:00:19 +08:00
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;
}
2023-08-22 19:08:45 +08:00
}
public void NormalShoot(GameUnit enemy)
{
commonData.lastInFightSeconds = LevelManager.Instance.CurrentLevel.LevelTime;
2023-10-19 15:00:19 +08:00
BulletManager.instance.DoNormalShoot(this, enemy);
2023-08-22 19:08:45 +08:00
}
public void UpVehicle(NormalVehicle vehicle)
{
runtimeData.belongVehicle = vehicle;
}
2023-10-19 15:00:19 +08:00
public void DownVehicle()
{
if (runtimeData.belongVehicle != null)
runtimeData.belongVehicle.MarkRemove(this);
runtimeData.belongVehicle = null;
}
2023-12-19 15:01:19 +08:00
public void Revive(UnitReviveData reviveData)
{
2023-12-19 18:27:27 +08:00
needRemove = false;
2023-12-19 15:01:19 +08:00
ResetToPrepare();
aliveData.Revive(reviveData);
}
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
}