BattleActor.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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]
  11. public class LaunchSkillEventHandler : BEvent<LaunchSkillEvent>
  12. {
  13. protected override async ETTask 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. await ETTask.CompletedTask;
  33. }
  34. }
  35. public class BattleActor : BattlePlayer
  36. {
  37. private bool isSkillInited = false;
  38. public bool IsSkillOk { get { return isSkillInited; } }
  39. private HashMap<int, SkillKeyStruct> SkillLisst = new();
  40. public SkillKeyStruct GetSkill(int index)
  41. {
  42. return SkillLisst[index];
  43. }
  44. public override void OnAwake(ZoneObject zo)
  45. {
  46. base.OnAwake(zo);
  47. ZoneActor za = zo as ZoneActor;
  48. za.IsFollow = false;
  49. za.OnStartPickObject += OnStartPickObject;
  50. za.OnStopPickObject += OnStopPickObject;
  51. za.OnSkillChanged += OnSkillChanged;
  52. za.OnClickSkillSimulationEvent += OnClickSkillSimulationEvent;
  53. var uProp = za.Info.Properties as XmdsUnitProperties;
  54. Log.Debug($"pkMode: {uProp.ServerData.UnitPKInfo.CurPKMode}");
  55. }
  56. private void OnSkillChanged(ZoneUnit.SkillOption op, ZoneUnit unit, int baseSkillID, params int[] skills)
  57. {
  58. //Log.Debug("OnSkillChanged> {0}, base:{1},skills:{2}", op, baseSkillID, skills != null ? skills.Length : 0);
  59. //SkillOption.Init的不用管,SkillBar.InitSkill直接从UserData读
  60. //SkillOpetion.Active不明意义,未处理
  61. if (op == ZoneUnit.SkillOption.Reset)
  62. {
  63. if(baseSkillID != 0)
  64. {
  65. if(skills.Length > 0)
  66. {
  67. skills[0] = baseSkillID;
  68. }
  69. else
  70. {
  71. skills = new int[] { baseSkillID };
  72. }
  73. }
  74. InitSkill(skills);
  75. }
  76. else if (op == ZoneUnit.SkillOption.Add || op == ZoneUnit.SkillOption.Remove)
  77. {
  78. Log.Error($"not implements skill option: {op}");
  79. }
  80. }
  81. public void InitSkill(params int[] skills)
  82. {
  83. isSkillInited = true;
  84. SkillLisst.Clear();
  85. var CFG = UnitMgr.Instance.Actor.ZUnit.Templates;
  86. for (int i = 0; i < skills.Length; i++)
  87. {
  88. int skid = skills[i];
  89. if (skid != 0)
  90. {
  91. SkillTemplate skt = CFG.getSkill(skid);
  92. SkillLisst[i] = new SkillKeyStruct()
  93. {
  94. keyPos = i,
  95. baseSkillId = skid,
  96. icon = skt.IconName
  97. };
  98. }
  99. }
  100. EventSystem.Instance.Publish<SkillChangeEvent>();
  101. }
  102. private void OnStopPickObject(ZoneUnit unit, CommonAI.Zone.UnitStopPickObjectEvent stop)
  103. {
  104. Log.Error("unhande event: OnStopPickObject");
  105. }
  106. private void OnStartPickObject(ZoneUnit unit, CommonLang.TimeExpire<CommonAI.Zone.UnitStartPickObjectEvent> start)
  107. {
  108. Log.Error("unhande event: OnStartPickObject");
  109. }
  110. private void OnClickSkillSimulationEvent(ZoneUnit unit, CommonAI.Zone.Helper.SimulationSkillEnum type)
  111. {
  112. Log.Error("unhande event: OnClickSkillSimulationEvent");
  113. }
  114. }