BattleActor.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using CommonAI.Zone;
  2. using CommonAI.ZoneClient;
  3. using CommonLang;
  4. using ET;
  5. using ET.Client;
  6. using ET.EventType;
  7. using ProtoBuf;
  8. using System.ComponentModel;
  9. using XmdsCommon.Plugin;
  10. [Event(SceneType.None)]
  11. public class LaunchSkillEventHandler : BEvent<LaunchSkillEvent>
  12. {
  13. public override void OnEvent(LaunchSkillEvent a)
  14. {
  15. var actor = UnitMgr.Instance.Actor;
  16. if(actor != null )
  17. {
  18. var skillinfo = actor.GetSkill(a.index);
  19. if (skillinfo != null)
  20. {
  21. SkillMgr.Instance.LanchSkill(skillinfo.baseSkillId);
  22. }
  23. else
  24. {
  25. Log.Error($"skill info not exist @index: {a.index}");
  26. }
  27. }
  28. else
  29. {
  30. Log.Warning("actor not exist");
  31. }
  32. }
  33. }
  34. public class BattleActor : BattlePlayer
  35. {
  36. private bool isSkillInited = false;
  37. public bool IsSkillOk { get { return isSkillInited; } }
  38. private HashMap<int, SkillKeyStruct> SkillLisst = new();
  39. public SkillKeyStruct GetSkill(int index)
  40. {
  41. return SkillLisst[index];
  42. }
  43. public override void OnAwake(ZoneObject zo)
  44. {
  45. base.OnAwake(zo);
  46. ZoneActor za = zo as ZoneActor;
  47. za.IsFollow = false;
  48. za.OnStartPickObject += OnStartPickObject;
  49. za.OnStopPickObject += OnStopPickObject;
  50. za.OnSkillChanged += OnSkillChanged;
  51. za.OnClickSkillSimulationEvent += OnClickSkillSimulationEvent;
  52. var uProp = za.Info.Properties as XmdsUnitProperties;
  53. Log.Debug($"pkMode: {uProp.ServerData.UnitPKInfo.CurPKMode}");
  54. }
  55. private void OnSkillChanged(ZoneUnit.SkillOption op, ZoneUnit unit, int baseSkillID, params int[] skills)
  56. {
  57. //Log.Debug("OnSkillChanged> {0}, base:{1},skills:{2}", op, baseSkillID, skills != null ? skills.Length : 0);
  58. //SkillOption.Init的不用管,SkillBar.InitSkill直接从UserData读
  59. //SkillOpetion.Active不明意义,未处理
  60. if (op == ZoneUnit.SkillOption.Reset)
  61. {
  62. if(baseSkillID != 0)
  63. {
  64. if(skills.Length > 0)
  65. {
  66. skills[0] = baseSkillID;
  67. }
  68. else
  69. {
  70. skills = new int[] { baseSkillID };
  71. }
  72. }
  73. InitSkill(skills);
  74. }
  75. else if (op == ZoneUnit.SkillOption.Add || op == ZoneUnit.SkillOption.Remove)
  76. {
  77. Log.Error($"not implements skill option: {op}");
  78. }
  79. }
  80. public void InitSkill(params int[] skills)
  81. {
  82. isSkillInited = true;
  83. SkillLisst.Clear();
  84. var CFG = UnitMgr.Instance.Actor.ZUnit.Templates;
  85. for (int i = 0; i < skills.Length; i++)
  86. {
  87. int skid = skills[i];
  88. if (skid != 0)
  89. {
  90. SkillTemplate skt = CFG.getSkill(skid);
  91. SkillLisst[i] = new SkillKeyStruct()
  92. {
  93. keyPos = i,
  94. baseSkillId = skid,
  95. icon = skt.IconName
  96. };
  97. }
  98. }
  99. EventSystem.Instance.Publish<SkillChangeEvent>();
  100. }
  101. private void OnStopPickObject(ZoneUnit unit, CommonAI.Zone.UnitStopPickObjectEvent stop)
  102. {
  103. Log.Error("unhande event: OnStopPickObject");
  104. }
  105. private void OnStartPickObject(ZoneUnit unit, CommonLang.TimeExpire<CommonAI.Zone.UnitStartPickObjectEvent> start)
  106. {
  107. Log.Error("unhande event: OnStartPickObject");
  108. }
  109. private void OnClickSkillSimulationEvent(ZoneUnit unit, CommonAI.Zone.Helper.SimulationSkillEnum type)
  110. {
  111. Log.Error("unhande event: OnClickSkillSimulationEvent");
  112. }
  113. }