100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using Framework;
|
|
using Framework.Wrapper;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Common;
|
|
using Gameplay.Level;
|
|
using Gameplay.Skill;
|
|
using System.Collections.Generic;
|
|
using Cysharp.Threading.Tasks;
|
|
using Gameplay.AI;
|
|
using Gameplay.BT.Variables;
|
|
using Gameplay.Vehicle.Impl;
|
|
using UnityEngine;
|
|
|
|
namespace Gameplay.Character
|
|
{
|
|
public partial class Character
|
|
{
|
|
private const string AIBehavior = "AIBehavior";
|
|
public void PrepareReady()
|
|
{
|
|
_InitFsm();
|
|
EventManager.Instance.Send(EventManager.EventName.LevelUnitBorn, this);
|
|
}
|
|
|
|
public async UniTask EnterBattle()
|
|
{
|
|
isReady = true;
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UNIT_READY, this);
|
|
|
|
if (troopId != ETroopsId.Self)
|
|
{
|
|
var bt = await AIManager.Instance.RegisterAI(Node.GameObject, AIBehavior);
|
|
|
|
DebugUtil.LogG($"BT set variable: {bt.ExternalBehavior?.name}");
|
|
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
|
{
|
|
Value = new BattleInfo()
|
|
{
|
|
ownerId = this.GetID(),
|
|
AIName = this.runtimeData.characterLevelData.AIName,
|
|
AttachAIName = this.runtimeData.characterLevelData.AttachAIName,
|
|
PatrolInfos = this.runtimeData.characterLevelData.PatrolInfos,
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
public void LeaveBattle()
|
|
{
|
|
if (troopId != ETroopsId.Self)
|
|
{
|
|
AIManager.Instance.UnRegisterAI(Node.GameObject);
|
|
}
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_UNIT_REMOVE, this);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|