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

195 lines
5.8 KiB
C#
Raw Normal View History

2023-12-14 14:42:27 +08:00
using Cysharp.Threading.Tasks;
using Framework;
2023-08-22 19:08:45 +08:00
using Gameplay.Bullet;
using Gameplay.Level;
using Gameplay.Skill;
using Gameplay.AI;
2024-05-17 15:06:34 +08:00
using Gameplay.Area;
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;
2023-08-22 19:08:45 +08:00
using Gameplay.Vehicle.Impl;
namespace Gameplay.Character
{
public partial class Character
{
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()
{
2024-04-11 17:45:07 +08:00
cAnim.ResetFloats();
2023-12-14 15:38:17 +08:00
}
2023-12-14 14:42:27 +08:00
protected override void _OnEnterBattle()
2023-08-22 19:08:45 +08:00
{
2024-09-29 13:38:26 +08:00
base._OnEnterBattle();
_CreateRoadLine();
2024-07-12 13:51:06 +08:00
ActiveCharacter();
2024-09-29 13:38:26 +08:00
isReady = true;
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
2024-07-12 13:51:06 +08:00
private void ActiveCharacter()
2023-12-14 14:42:27 +08:00
{
if (troopId == ETroopsId.Self)
2023-08-22 19:08:45 +08:00
{
2024-07-03 19:26:02 +08:00
statusData.isAttackActive = 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
// 重置所有状态
2024-03-08 14:20:40 +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;
// TODO: 目前看来所有的技能都是切SKILL
_fullFSM.ChangeState(EFullState.Skill);
// 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;
// }
2023-08-22 19:08:45 +08:00
}
public void NormalShoot(GameUnit enemy)
{
commonData.lastInFightSeconds = LevelManager.Instance.CurrentLevel.LevelTime;
2024-05-17 15:06:34 +08:00
switch (fightData.specialAttakcLogicId)
{
case 1:
// 近战,打扇形范围的三个目标
_AttackCloseArea1(enemy);
break;
default:
BulletManager.instance.DoNormalShoot(this, enemy);
break;
}
}
2023-08-22 19:08:45 +08:00
2024-05-17 15:06:34 +08:00
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;
}
2024-07-12 17:06:39 +08:00
if (!judgeUnit.statusData.CheckCanBeTarget(this))
2024-05-17 15:06:34 +08:00
{
continue;
}
if (judgeUnit.commonData.troopId == enemy.commonData.troopId)
{
// 发射子弹
BulletManager.instance.DoNormalShoot(this, judgeUnit);
}
}
}
2023-08-22 19:08:45 +08:00
}
public void UpVehicle(NormalVehicle vehicle)
{
runtimeData.belongVehicle = vehicle;
2024-10-18 14:53:50 +08:00
controlData.markVehicle = null;
if (debugShowInfo.cacheConfigId != 0)
{
EventManager.Instance.Send(EventManager.EventName.INFIGHT_AUDIO_UP_VEHICLE, debugShowInfo.cacheConfigId);
}
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
public void DownVehicle()
{
if (_fullFSM.currentState.id != EFullState.OnVehicle
&& _fullFSM.currentState.id != EFullState.UpVehicle)
2024-04-12 20:36:22 +08:00
{
return;
}
2023-10-19 15:00:19 +08:00
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);
}
2023-10-19 15:00:19 +08:00
}
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);
}
2024-01-23 14:57:06 +08:00
public void ForceDead()
{
// hp直接归0
aliveData.currentHp = 0;
}
2024-03-08 14:20:40 +08:00
2023-08-22 19:08:45 +08:00
}
2023-10-19 15:00:19 +08:00
}