BuffEffectMgr.cs 10 KB

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