190 lines
5.6 KiB
C#
190 lines
5.6 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using Framework;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Level;
|
|
using Gameplay.Skill;
|
|
using Gameplay.AI;
|
|
using Gameplay.Area;
|
|
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()
|
|
{
|
|
cAnim.ResetFloats();
|
|
}
|
|
|
|
protected override void _OnEnterBattle()
|
|
{
|
|
isReady = true;
|
|
ActiveCharacter();
|
|
BuffManager.instance.InitCharacter(this);
|
|
SkillManager.instance.AutoAddPassiveBuffs(this);
|
|
buffManager.TriggerEnterBattle();
|
|
}
|
|
|
|
private void ActiveCharacter()
|
|
{
|
|
if (troopId == ETroopsId.Self)
|
|
{
|
|
statusData.isAttackActive = 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:
|
|
case 3:
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
case 7:
|
|
_fullFSM.ChangeState(EFullState.Skill);
|
|
break;
|
|
default:
|
|
DebugUtil.LogError("暂未支持的技能类型:{0}", skillConfig.SkillActionId);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void NormalShoot(GameUnit enemy)
|
|
{
|
|
commonData.lastInFightSeconds = LevelManager.Instance.CurrentLevel.LevelTime;
|
|
|
|
switch (fightData.specialAttakcLogicId)
|
|
{
|
|
case 1:
|
|
// 近战,打扇形范围的三个目标
|
|
_AttackCloseArea1(enemy);
|
|
break;
|
|
default:
|
|
BulletManager.instance.DoNormalShoot(this, enemy);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void _AttackCloseArea1(GameUnit enemy)
|
|
{
|
|
// 找到敌人周边一圈的范围
|
|
var centerCellIndex = enemy.transData.cellIndex;
|
|
var aroundCells = AreaManager.instance.GetCellIndexsAround(centerCellIndex, 1);
|
|
for (int i = 0; i < aroundCells.Count; i++)
|
|
{
|
|
var cellIndex = aroundCells[i];
|
|
var distance = AreaManager.instance.GetDistance(cellIndex, transData.cellIndex);
|
|
var getUnits = AreaManager.instance.GetUnitsByCellIndex(cellIndex);
|
|
if (distance > fightData.attackDistance)
|
|
{
|
|
continue;
|
|
}
|
|
for (int j = 0; j < getUnits.Count; j++)
|
|
{
|
|
var judgeUnit = getUnits[j];
|
|
if (judgeUnit == null)
|
|
{
|
|
continue;
|
|
}
|
|
if (!judgeUnit.statusData.CheckCanBeTarget())
|
|
{
|
|
continue;
|
|
}
|
|
if (judgeUnit.commonData.troopId == enemy.commonData.troopId)
|
|
{
|
|
// 发射子弹
|
|
BulletManager.instance.DoNormalShoot(this, judgeUnit);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpVehicle(NormalVehicle vehicle)
|
|
{
|
|
runtimeData.belongVehicle = vehicle;
|
|
|
|
if (debugShowInfo.cacheConfigId != 0)
|
|
{
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_AUDIO_UP_VEHICLE, debugShowInfo.cacheConfigId);
|
|
}
|
|
}
|
|
|
|
public void DownVehicle()
|
|
{
|
|
if (_fullFSM.currentState.id != EFullState.OnVehicle)
|
|
{
|
|
return;
|
|
}
|
|
if (runtimeData.belongVehicle != null)
|
|
runtimeData.belongVehicle.MarkRemove(this);
|
|
runtimeData.belongVehicle = null;
|
|
|
|
if (debugShowInfo.cacheConfigId != 0)
|
|
{
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_AUDIO_DOWN_VEHICLE, debugShowInfo.cacheConfigId);
|
|
}
|
|
}
|
|
|
|
public void Revive(UnitReviveData reviveData)
|
|
{
|
|
needRemove = false;
|
|
ResetToPrepare();
|
|
aliveData.Revive(reviveData);
|
|
}
|
|
|
|
public void ForceDead()
|
|
{
|
|
// hp直接归0
|
|
aliveData.currentHp = 0;
|
|
}
|
|
|
|
}
|
|
}
|