using UnityEngine;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
#if UNITY_EDITOR
|
public enum SkillCastEnum
|
{
|
MainSkill,
|
SubSkill,
|
}
|
|
#endif
|
|
public class SkillRecordAction : RecordAction
|
{
|
#if UNITY_EDITOR
|
public
|
#else
|
protected
|
#endif
|
|
|
SkillBase skillBase;
|
|
#if UNITY_EDITOR
|
public SkillCastEnum skillCastEnum = SkillCastEnum.MainSkill;
|
#endif
|
|
public HB427_tagSCUseSkill hB427_TagSCUseSkill;
|
|
private bool isCast = false;
|
|
public SkillBase fromSkill = null;
|
|
public SkillRecordAction(BattleField _battleField, BattleObject _caster, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> packList)
|
: base(RecordActionType.Skill, _battleField, _caster)
|
{
|
// Debug.LogError("_caster == null : " + (_caster == null));
|
|
skillBase = SkillFactory.CreateSkill(_caster, vNetData, packList, _battleField);
|
hB427_TagSCUseSkill = vNetData;
|
if (null == skillBase)
|
{
|
BattleUtility.ForceFinishBattlePackList(battleField, packList);
|
}
|
else
|
{
|
// 让SkillBase知道自己的RecordAction
|
skillBase.SetParentRecordAction(this);
|
}
|
}
|
|
public override void AfterAddToQueue()
|
{
|
base.AfterAddToQueue();
|
skillBase?.AfterAddToQueue();
|
}
|
|
public override bool IsNeedWaiting()
|
{
|
if (skillBase == null)
|
{
|
return false;
|
}
|
return !string.IsNullOrEmpty(skillBase.skillConfig.SkillMotionName);
|
}
|
|
|
public override bool IsFinished()
|
{
|
if (null == skillBase)
|
{
|
return true;
|
}
|
return skillBase.IsFinished();
|
}
|
|
// 检查自身动作是否完成(不包括子节点)
|
public override bool IsActionCompleted()
|
{
|
if (null == skillBase)
|
{
|
return true;
|
}
|
return skillBase.IsActionCompleted();
|
}
|
|
|
public override void ForceFinish()
|
{
|
// 设置结束flag 记得清空motionBase里的事件
|
if (null != skillBase)
|
{
|
skillBase.ForceFinished();
|
}
|
|
#if UNITY_EDITOR
|
// 标记包执行完成
|
if (tracePackUID != 0 && !string.IsNullOrEmpty(GetBattleFieldGuid()))
|
{
|
try
|
{
|
var editorAssembly = System.AppDomain.CurrentDomain.GetAssemblies()
|
.FirstOrDefault(a => a.GetName().Name == "Assembly-CSharp-Editor");
|
if (editorAssembly != null)
|
{
|
var checkerType = editorAssembly.GetType("BattleReportChecker");
|
if (checkerType != null)
|
{
|
var method = checkerType.GetMethod("MarkPackageExecuted",
|
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
if (method != null)
|
{
|
method.Invoke(null, new object[] { GetBattleFieldGuid(), tracePackUID });
|
}
|
}
|
}
|
}
|
catch { }
|
}
|
#endif
|
|
base.ForceFinish();
|
}
|
|
public override bool CanStartExecution()
|
{
|
if (null == skillBase)
|
{
|
return false;
|
}
|
|
if (!skillBase.CanStartExecution())
|
{
|
return false;
|
}
|
|
|
return base.CanStartExecution();
|
}
|
|
public override void Run()
|
{
|
base.Run();
|
|
#if UNITY_EDITOR
|
// 标记包开始执行
|
if (tracePackUID != 0 && !string.IsNullOrEmpty(GetBattleFieldGuid()))
|
{
|
try
|
{
|
var editorAssembly = System.AppDomain.CurrentDomain.GetAssemblies()
|
.FirstOrDefault(a => a.GetName().Name == "Assembly-CSharp-Editor");
|
if (editorAssembly != null)
|
{
|
var checkerType = editorAssembly.GetType("BattleReportChecker");
|
if (checkerType != null)
|
{
|
var method = checkerType.GetMethod("MarkPackageExecuting",
|
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
if (method != null)
|
{
|
method.Invoke(null, new object[] { GetBattleFieldGuid(), tracePackUID });
|
}
|
}
|
}
|
}
|
catch { }
|
}
|
#endif
|
|
if (null == skillBase)
|
{
|
return;
|
}
|
|
if (isCast && !skillBase.IsFinished())
|
{
|
skillBase.Run();
|
}
|
|
if (isCast)
|
return;
|
|
if (skillBase.caster.motionBase.CanCastSkill(skillBase.skillConfig))
|
{
|
// Debug.LogError("cast skill id is " + skillBase.skillConfig.SkillID);
|
|
skillBase.fromSkill = fromSkill;
|
|
skillBase.Cast();
|
|
isCast = true;
|
}
|
}
|
|
#if UNITY_EDITOR
|
/// <summary>
|
/// 首次运行时打印日志(仅编辑器)
|
/// 打印施法者名字、技能ID和技能名字
|
/// </summary>
|
protected override void PrintFirstRunLog()
|
{
|
if (skillBase != null && skillBase.caster != null)
|
{
|
string casterName = skillBase.caster.teamHero?.name ?? "Unknown";
|
int skillId = skillBase.skillConfig?.SkillID ?? 0;
|
string skillName = skillBase.skillConfig?.SkillName ?? "Unknown";
|
Debug.LogError($"[SkillRecordAction首次Run] 施法者:{casterName} 技能ID:{skillId} 技能名:{skillName}");
|
}
|
else
|
{
|
base.PrintFirstRunLog();
|
}
|
}
|
#endif
|
}
|