BuffEffectMgr.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. 
  2. using CommonAI.Zone;
  3. using System.Collections.Generic;
  4. using XmdsCommon.Plugin;
  5. using UnityEngine;
  6. namespace ET.Client
  7. {
  8. [Event]
  9. [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
  10. public class BuffChangeEventHandler : BEvent<EventType.BuffChangeEvent>
  11. {
  12. protected override async ETTask OnEvent(EventType.BuffChangeEvent args)
  13. {
  14. BattleUnit unit = UnitMgr.Instance.GetUnit(args.ObjectId) as BattleUnit;
  15. if (unit == null)
  16. {
  17. Log.Error($"buff unit not exist: {args.ObjectId}");
  18. return;
  19. }
  20. var unitRender = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(args.ObjectId);
  21. if (unitRender == null)
  22. {
  23. Log.Debug($"buff unitrender not exist: {args.ObjectId}");
  24. return;
  25. }
  26. //Log.Debug($"Buff({args.Buff?.BuffID}) event {args.Type} @{unit.ZUnit.TemplateID}");
  27. if (args.Type == BuffChangeType.Add)
  28. {
  29. BuffTemplate bt = args.Buff.Data;
  30. if (bt.MakeAvatar)
  31. {
  32. //TODO: 支持BUFF变身
  33. Log.Error("Not implements MakeAvatar");
  34. }
  35. AddBuff(args.Buff, unitRender, unit).Coroutine();
  36. }
  37. else if (args.Type == BuffChangeType.Remove)
  38. {
  39. BuffTemplate bt = args.Buff.Data;
  40. RemoveBuff(bt, unitRender);
  41. }
  42. else if (args.Type == BuffChangeType.Change)
  43. {
  44. BuffTemplate bt = args.Buff.Data;
  45. //随BUFF状态变更,表现特效不同时.
  46. if ((bt.BindingEffectList != null && bt.BindingEffectList.Count > 0) ||
  47. (bt.OverlayBindingEffect != null && bt.OverlayBindingEffect.Count > 0))
  48. {
  49. var buff = args.Buff;
  50. if ((buff.OverlayLevel >= 0 && buff.OverlayLevel < bt.BindingEffectList.Count) ||
  51. (buff.BuffExtendData > 0 && buff.OverlayLevel < bt.OverlayBindingEffect.Count))
  52. {
  53. RemoveBuff(bt, unitRender);
  54. AddBuff(buff, unitRender, unit).Coroutine();
  55. }
  56. }
  57. }
  58. else if (args.Type == BuffChangeType.Reload)
  59. {
  60. var list = unit.ZUnit.AllBuffs;
  61. list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>
  62. {
  63. AddBuff(buff, unitRender, unit).Coroutine();
  64. });
  65. }
  66. MergeBuffStatus(unit, unitRender);
  67. await ETTask.CompletedTask;
  68. }
  69. private async ETTask AddBuff(CommonAI.ZoneClient.ZoneUnit.BuffState buff, UnitRenderComponet unitRender, BattleUnit unit)
  70. {
  71. BuffTemplate bt = buff.Data;
  72. //优先判断是否有叠层效果.
  73. LaunchEffect le = null;
  74. string key = bt.TemplateID.ToString();
  75. string effectName = "";
  76. if (bt.OverlayBindingEffect != null && bt.OverlayBindingEffect.Count > 0)
  77. {
  78. if (buff.BuffExtendData > 0)
  79. {
  80. le = bt.OverlayBindingEffect[buff.OverlayLevel];
  81. if (le.RType != LaunchEffect.RunType.Cycle_BindName) return;
  82. /*/超出最大层数,把最早的给移除掉
  83. if (WordRainRecorderQueue.Count > 0 && WordRainRecorderQueue.Count >= me.Data.MaxOverlay)
  84. {
  85. string effectKey = WordRainRecorderQueue.Dequeue();
  86. int effectStop;
  87. if (BuffEffects.TryGetValue(effectKey, out effectStop))
  88. {
  89. BuffEffects.RemoveByKey(effectKey);
  90. StopEffect(effectStop);
  91. }
  92. }
  93. if (le.CricleMode != null)
  94. {
  95. WordRainRecorder += 1;
  96. key = bt.TemplateID.ToString() + "_" + me.BuffExtendData.ToString() + "_" + WordRainRecorder.ToString();
  97. WordRainRecorderQueue.Enqueue(key);
  98. if (le.CricleMode.EffectName != null && le.CricleMode.EffectName.Length > me.BuffExtendDataIndex - 1 && me.BuffExtendDataIndex > 0)
  99. {
  100. effectName = le.CricleMode.EffectName[me.BuffExtendDataIndex - 1];
  101. }
  102. }*/
  103. }
  104. else
  105. {
  106. le = bt.OverlayBindingEffect[buff.OverlayLevel];
  107. }
  108. }
  109. else
  110. {
  111. le = bt.BindingEffect;
  112. }
  113. if (le != null)
  114. {
  115. if (!unitRender.BuffEffects.ContainsKey(key))
  116. {
  117. uint id = await EffectMgr.Instance.PlayEffect(le, unit.Id, Vector3.zero);
  118. unitRender.BuffEffects.Add(key, id);
  119. }
  120. else
  121. {
  122. EffectMgr.Instance.ResetEffect(unit.Id);
  123. }
  124. }
  125. if (bt.BindingEffectList.Count > 0)
  126. {
  127. System.Action<LaunchEffect, byte, byte, int, int> PlayBindingEffect = async (buff, overLayer, maxOverLayer, templateID, index) =>
  128. {
  129. string _bkey = string.Format("{0}_{1}", templateID, index);
  130. if (buff == null || unitRender.BuffEffects.ContainsKey(_bkey)) return;
  131. //uint id = PlayEffect(buff, false, -1, "", overLayer, maxOverLayer);
  132. uint id = await EffectMgr.Instance.PlayEffect(buff, unit.Id, Vector3.zero);
  133. unitRender.BuffEffects.Add(_bkey, id);
  134. };
  135. if (bt.PlayType == BuffTemplate.BindingPlayType.All)
  136. {
  137. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  138. {
  139. le = bt.BindingEffectList[i];
  140. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
  141. }
  142. }
  143. else if (bt.PlayType == BuffTemplate.BindingPlayType.AppointOverLayer)
  144. {
  145. if (buff.OverlayLevel >= bt.BindingEffectList.Count) return;
  146. le = bt.BindingEffectList[buff.OverlayLevel];
  147. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, buff.OverlayLevel);
  148. }
  149. else if (bt.PlayType == BuffTemplate.BindingPlayType.IncludeOverLayer)
  150. {
  151. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  152. {
  153. if (buff.OverlayLevel >= i)
  154. {
  155. le = bt.BindingEffectList[i];
  156. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
  157. }
  158. else
  159. {
  160. break;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. private void RemoveBuff(BuffTemplate bt, UnitRenderComponet unitRender)
  167. {
  168. var BuffEffects = unitRender.BuffEffects;
  169. if (BuffEffects != null)
  170. {
  171. uint effectStop = 0;
  172. string key = bt.ID.ToString();
  173. if (BuffEffects.TryGetValue(key, out effectStop))
  174. {
  175. BuffEffects.RemoveByKey(key);
  176. EffectMgr.Instance.RemoveEffect(effectStop);
  177. }
  178. if (bt.BindingEffectList.Count > 0)
  179. {
  180. string key2 = null;
  181. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  182. {
  183. key2 = string.Format("{0}_{1}", key, i);
  184. if (BuffEffects.TryGetValue(key2, out effectStop))
  185. {
  186. BuffEffects.RemoveByKey(key2);
  187. EffectMgr.Instance.RemoveEffect(effectStop);
  188. }
  189. }
  190. }
  191. }
  192. }
  193. private void MergeBuffStatus(BattleUnit unit, UnitRenderComponet unitRender)
  194. {
  195. bool bFrozen = false;
  196. bool bStealth = false;
  197. bool bNothingess = false;
  198. var list = unit.ZUnit.AllBuffs;
  199. list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>
  200. {
  201. var ablist = (buff.Data.Properties as XmdsBuffProperties).BuffAbilityList;
  202. if (ablist != null)
  203. {
  204. foreach (var ab in ablist)
  205. {
  206. //TODO: 支持BUFF的冰冻、草丛、虚无效果
  207. if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.FROZEN ||
  208. ab.ability == XmdsBuffProperties.XmdsBuffAbility.Fridge)
  209. {
  210. bFrozen = true;
  211. }
  212. else if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.Stealth)
  213. {
  214. bStealth = true;
  215. //判断是不是在墙角,在墙角只更新currentMat,否则修改材质和currentMat
  216. /*foreach (var item in this.GameObject.GetComponentsInChildren<MaterialManager>())
  217. {
  218. item.AddMatState(StateMaterial.HIDDING);
  219. }*/
  220. }
  221. else if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.Nothingness)
  222. {
  223. bNothingess = true;
  224. //this.HideSelf(true);
  225. }
  226. }
  227. }
  228. });
  229. if (bFrozen)
  230. {
  231. unitRender.PauseAnimation();
  232. unitRender.SetFrozen();
  233. }
  234. else
  235. {
  236. unitRender.ResumeAnimation();
  237. unitRender.ClearFrozen();
  238. if (bStealth)
  239. {
  240. }
  241. else
  242. {
  243. if (bNothingess)
  244. {
  245. }
  246. }
  247. }
  248. }
  249. }
  250. }