320 lines
12 KiB
C#
320 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Area;
|
|
using Gameplay.Character;
|
|
using Gameplay.Common;
|
|
using Gameplay.Effect;
|
|
using Gameplay.Level;
|
|
using Gameplay.Pool;
|
|
using Gameplay.Skill;
|
|
using Gameplay.Summon;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Vehicle.Impl;
|
|
using LTGame;
|
|
using PhxhSDK;
|
|
using UnityEngine;
|
|
namespace Gameplay.Vehicle.State
|
|
{
|
|
public class VehicleStateSkill: BaseVehicleState
|
|
{
|
|
|
|
private readonly List<InnerSkillAction> _skillActions;
|
|
private SkillHandle _skillHandle;
|
|
|
|
public VehicleStateSkill(NormalVehicle owner): base(owner, EVehicleState.Skill)
|
|
{
|
|
_skillActions = new List<InnerSkillAction>();
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnEnter(exitState, param);
|
|
|
|
owner.statusData.isInSkilling = true;
|
|
|
|
// 只有己方单位使用技能需要暂停
|
|
if (owner.commonData.troopId == ETroopsId.Self)
|
|
{
|
|
owner.statusData.needSkillPaused = true;
|
|
|
|
// 将自己添加进全屏效果
|
|
SkillManager.instance.screenEffect.AttachObj(owner.Node.GameObject);
|
|
|
|
EffectManager.instance.forceSetLayer = LayerDefine.Skill;
|
|
}
|
|
|
|
//TODO: 播放技能动作
|
|
|
|
// 根据逻辑序列进行处理
|
|
_skillActions.Clear();
|
|
var skillUnit = SkillManager.instance.GetUnitSkillManager(owner);
|
|
_skillHandle = skillUnit.positiveSkill;
|
|
var logicData = _skillHandle.runtimeData.logicData;
|
|
if (logicData == null) return;
|
|
for (var i = 0; i < logicData.actionList.Count; ++i)
|
|
{
|
|
var actionData = logicData.actionList[i];
|
|
var action = new InnerSkillAction();
|
|
action.logicData = actionData;
|
|
action.skill = this;
|
|
action.triggerTime = actionData.triggerTime;
|
|
|
|
if (action.logicData.actionType == ESkillActionType.EMIT_BULLET)
|
|
{
|
|
// 转接id
|
|
var idIndex = action.logicData.id;
|
|
if (idIndex >= _skillHandle.runtimeData.configData.ReferIds.Count)
|
|
{
|
|
idIndex = _skillHandle.runtimeData.configData.ReferIds.Count - 1;
|
|
}
|
|
action.logicData.id = _skillHandle.runtimeData.configData.ReferIds[idIndex];
|
|
}
|
|
|
|
_skillActions.Add(action);
|
|
}
|
|
|
|
_RotateToTargetCell();
|
|
}
|
|
|
|
private void _RotateToTargetCell()
|
|
{
|
|
var targetCellIndex = owner.controlData.skillCellIndex;
|
|
if (targetCellIndex == owner.transData.cellIndex)
|
|
{
|
|
// 同一个格子,不做处理
|
|
return;
|
|
}
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
var targetPos = map.TGSCellIndex2WorldPosition(targetCellIndex);
|
|
var selfPos = owner.transData.pos;
|
|
var toTarget = targetPos - selfPos;
|
|
toTarget.y = 0;
|
|
var angle = Vector3.SignedAngle(Vector3.forward, toTarget, Vector3.up);
|
|
owner.transData.yaw = angle;
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
for (var i = 0; i < _skillActions.Count; ++i)
|
|
{
|
|
var action = _skillActions[i];
|
|
action.LogicUpdate(passTime);
|
|
if (action.isTriggered)
|
|
{
|
|
_skillActions.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void _OnExit(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnExit(exitState, param);
|
|
owner.statusData.isInSkilling = false;
|
|
_skillActions.Clear();
|
|
owner.statusData.needSkillPaused = false;
|
|
EffectManager.instance.forceSetLayer = -1;
|
|
|
|
}
|
|
|
|
private class InnerSkillAction
|
|
{
|
|
public bool isTriggered = false;
|
|
public float triggerTime;
|
|
public VehicleStateSkill skill;
|
|
public SkillLogicActionData logicData;
|
|
private List<int> _selectCellIndexs;
|
|
|
|
public void LogicUpdate(float currentPassTime)
|
|
{
|
|
// 外部保证
|
|
// if (isTriggered) return;
|
|
if (currentPassTime < triggerTime)
|
|
{
|
|
return;
|
|
}
|
|
isTriggered = true;
|
|
|
|
// 触发技能
|
|
_Trigger();
|
|
|
|
}
|
|
|
|
private void _Trigger()
|
|
{
|
|
switch (logicData.actionType)
|
|
{
|
|
case ESkillActionType.EMIT_BULLET:
|
|
_EmitBullet();
|
|
break;
|
|
case ESkillActionType.CREATE_SUMMON:
|
|
_CreateSummon();
|
|
break;
|
|
case ESkillActionType.PLAY_AUDIO:
|
|
_ = AudioManager.Instance.PlayAudio(logicData.id, skill.owner.transData.pos);
|
|
break;
|
|
case ESkillActionType.PLAY_EFFECT:
|
|
_PlayEffect();
|
|
break;
|
|
case ESkillActionType.SKILL_END:
|
|
skill.isFinished = true;
|
|
skill.nextState = EFullState.Empty;
|
|
break;
|
|
case ESkillActionType.PAUSE_END:
|
|
skill.owner.statusData.needSkillPaused = false;
|
|
EffectManager.instance.forceSetLayer = -1;
|
|
break;
|
|
default:
|
|
DebugUtil.LogError("暂未支持的ActionType:{0}", logicData.actionType);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void _PlayEffect()
|
|
{
|
|
var subId = logicData.subId;
|
|
switch (subId)
|
|
{
|
|
case ESkillEffectPosType.SelfLocal:
|
|
_PlayLocalEffect();
|
|
break;
|
|
case ESkillEffectPosType.TargetLocal:
|
|
_PlayTargetEffect();
|
|
break;
|
|
case ESkillEffectPosType.WeaponFire:
|
|
_PlayWeaponFireEffect();
|
|
break;
|
|
case ESkillEffectPosType.WeaponFireFly2Target:
|
|
_PlayWeaponFireFly2TargetEffect();
|
|
break;
|
|
default:
|
|
DebugUtil.LogError("无效的subId:{0}", subId);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void _PlayWeaponFireFly2TargetEffect()
|
|
{
|
|
var effectId = logicData.id;
|
|
if (effectId > 0)
|
|
{
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
// 获取area的cellIndexs
|
|
var releaseCellIndex = skill.owner.controlData.skillCellIndex;
|
|
var configData = skill._skillHandle.runtimeData.configData;
|
|
var areaId = configData.InfluenceAreaId;
|
|
_selectCellIndexs = AreaManager.instance.GetCellIndexs(releaseCellIndex, areaId);
|
|
|
|
for (var i = 0; i < _selectCellIndexs.Count; ++i)
|
|
{
|
|
var trans = skill.owner.Node.GameObject.transform;
|
|
var weapon = skill.owner.battery;
|
|
var startPos = weapon.fireTrans.position;
|
|
var effectData = EffectManager.instance.PlayEffectById(effectId, startPos, trans.rotation);
|
|
var targetCellIndex = _selectCellIndexs[i];
|
|
var targetPos = map.TGSCellIndex2WorldPosition(targetCellIndex);
|
|
if (DebugUtil.LogEnable)
|
|
DebugUtil.Log("startPos:{0}, targetPos:{1}, targetIndex:{2}",startPos, targetPos, targetCellIndex);
|
|
var flyLogic = ObjPoolManager.instance.Get<BulletFlyLogic>();
|
|
flyLogic.Ctor(startPos, targetPos, logicData.floatParam1);
|
|
effectData.AddLogic(flyLogic);
|
|
|
|
effectData.owner = skill.owner;
|
|
if (skill.owner.statusData.needSkillPaused)
|
|
{
|
|
SkillManager.instance.screenEffect.AttachObj(effectData.rootObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _PlayTargetEffect()
|
|
{
|
|
var map = LevelManager.Instance.CurrentLevel.Map;
|
|
var effectId = logicData.id;
|
|
if (effectId > 0)
|
|
{
|
|
// 获取area的cellIndexs
|
|
var releaseCellIndex = skill.owner.controlData.skillCellIndex;
|
|
var configData = skill._skillHandle.runtimeData.configData;
|
|
var areaId = configData.InfluenceAreaId;
|
|
_selectCellIndexs = AreaManager.instance.GetCellIndexs(releaseCellIndex, areaId);
|
|
|
|
for (var i = 0; i < _selectCellIndexs.Count; ++i)
|
|
{
|
|
var cellIndex = _selectCellIndexs[i];
|
|
var worldPos = map.TGSCellIndex2WorldPosition(cellIndex);
|
|
var effectData = EffectManager.instance.PlayEffectById(effectId, worldPos, Quaternion.identity);
|
|
|
|
effectData.owner = skill.owner;
|
|
if (skill.owner.statusData.needSkillPaused)
|
|
{
|
|
SkillManager.instance.screenEffect.AttachObj(effectData.rootObj);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _PlayWeaponFireEffect()
|
|
{
|
|
var effectId = logicData.id;
|
|
if (effectId > 0)
|
|
{
|
|
var trans = skill.owner.Node.GameObject.transform;
|
|
var weapon = skill.owner.battery;
|
|
var effectData = EffectManager.instance.PlayEffectById(effectId, weapon.fireTrans.position, trans.rotation, weapon.fireTrans);
|
|
effectData.owner = skill.owner;
|
|
if (skill.owner.statusData.needSkillPaused)
|
|
{
|
|
SkillManager.instance.screenEffect.AttachObj(effectData.rootObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _PlayLocalEffect()
|
|
{
|
|
var effectId = logicData.id;
|
|
if (effectId > 0)
|
|
{
|
|
var trans = skill.owner.Node.GameObject.transform;
|
|
var effectData = EffectManager.instance.PlayEffectById(effectId, trans.position, trans.rotation, trans);
|
|
effectData.owner = skill.owner;
|
|
if (skill.owner.statusData.needSkillPaused)
|
|
{
|
|
SkillManager.instance.screenEffect.AttachObj(effectData.rootObj);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void _CreateSummon()
|
|
{
|
|
var summonId = logicData.id;
|
|
var createCellIndex = skill.owner.controlData.skillCellIndex;
|
|
var createSummon = GameUnitManager.instance.summonManager.CreateSummon(summonId, createCellIndex, skill.owner);
|
|
if (skill.owner.statusData.needSkillPaused)
|
|
{
|
|
SkillManager.instance.screenEffect.AttachObj(createSummon.Node.GameObject);
|
|
}
|
|
}
|
|
|
|
private void _EmitBullet()
|
|
{
|
|
var bulletId = logicData.id;
|
|
|
|
// 获取area的cellIndexs
|
|
var releaseCellIndex = skill.owner.controlData.skillCellIndex;
|
|
var configData = skill._skillHandle.runtimeData.configData;
|
|
var areaId = configData.InfluenceAreaId;
|
|
_selectCellIndexs = AreaManager.instance.GetCellIndexs(releaseCellIndex, areaId);
|
|
|
|
skill.owner.EmitSkillBullets(bulletId, _selectCellIndexs, skill._skillHandle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|