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

214 lines
6.4 KiB
C#

using Code.Scripts.Gameplay.PlaneShadow;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Bullet;
using Gameplay.Level;
using Gameplay.Skill;
using Gameplay.AI;
using Gameplay.Area;
using Gameplay.Buff;
using Gameplay.PlayerSkill.Data;
using Gameplay.Summon;
using Gameplay.Unit;
using Gameplay.Unit.Data;
using Gameplay.Vehicle.Impl;
namespace Gameplay.Character
{
public partial class Character
{
protected override async UniTask _OnPrepare()
{
_InitFsm();
await SkillManager.instance.InitCharacter(this);
}
protected override void _OnReady()
{
cAnim.ResetFloats();
}
protected override void _OnEnterBattle()
{
base._OnEnterBattle();
_CreateRoadLine();
isReady = true;
BuffManager.instance.InitCharacter(this);
SkillManager.instance.AutoAddPassiveBuffs(this);
buffManager.TriggerEnterBattle();
// 默认添加防御缩放
runtimeData.AddStandDefenceScale();
}
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;
// TODO: 目前看来所有的技能都是切SKILL
_fullFSM.ChangeState(EFullState.Skill);
}
public void NormalShoot(GameUnit enemy)
{
weapon.OpenFire(enemy);
commonData.lastInFightSeconds = LevelManager.Instance.CurrentLevel.LevelTime;
switch (fightData.specialAttakcLogicId)
{
case 1:
// 近战,打扇形范围的三个目标
_AttackCloseArea1(enemy);
break;
default:
BulletManager.instance.DoNormalShoot(this, enemy, false);
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(this))
{
continue;
}
if (judgeUnit.commonData.troopId == enemy.commonData.troopId)
{
// 发射子弹
BulletManager.instance.DoNormalShoot(this, judgeUnit, true);
}
}
}
}
public void EnterBuilding(BaseSummon buildSummon)
{
if (buildSummon.subUnitType != EGameUnitType.Building)
{
DebugUtil.LogError("非建筑召唤物");
return;
}
runtimeData.belongBuilding = buildSummon;
}
public void UpVehicle(NormalVehicle vehicle)
{
runtimeData.belongVehicle = vehicle;
controlData.markVehicle = null;
if (debugShowInfo.cacheConfigId != 0)
{
EventManager.Instance.Send(EventManager.EventName.INFIGHT_AUDIO_UP_VEHICLE, debugShowInfo.cacheConfigId);
}
}
public void DownVehicle()
{
if (_fullFSM.currentState.id != EFullState.OnVehicle
&& _fullFSM.currentState.id != EFullState.UpVehicle)
{
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;
}
protected override void _OnRecordAnim()
{
base._OnRecordAnim();
if (cAnim == null) return;
fightStoryData.cacheAnim1 = cAnim.targetFullAnim;
fightStoryData.cacheAnim2 = cAnim.targetDownAnim;
}
protected override void _OnForcePlayAnim(string animName)
{
base._OnForcePlayAnim(animName);
if (cAnim == null) return;
cAnim.targetFullAnim = animName;
cAnim.targetDownAnim = EAnimDownState.EMPTY;
}
protected override void _OnRestoreAnim()
{
base._OnRestoreAnim();
if (cAnim == null) return;
cAnim.targetFullAnim = fightStoryData.cacheAnim1;
cAnim.targetDownAnim = fightStoryData.cacheAnim2;
}
}
}