BuffEffectMgr.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. //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);
  67. }
  68. private async ETTask AddBuff(CommonAI.ZoneClient.ZoneUnit.BuffState buff, UnitRenderComponet unitRender, BattleUnit unit)
  69. {
  70. BuffTemplate bt = buff.Data;
  71. //优先判断是否有叠层效果.
  72. LaunchEffect le = null;
  73. string key = bt.TemplateID.ToString();
  74. string effectName = "";
  75. if (bt.OverlayBindingEffect != null && bt.OverlayBindingEffect.Count > 0)
  76. {
  77. if (buff.BuffExtendData > 0)
  78. {
  79. le = bt.OverlayBindingEffect[buff.OverlayLevel];
  80. if (le.RType != LaunchEffect.RunType.Cycle_BindName) return;
  81. /*/超出最大层数,把最早的给移除掉
  82. if (WordRainRecorderQueue.Count > 0 && WordRainRecorderQueue.Count >= me.Data.MaxOverlay)
  83. {
  84. string effectKey = WordRainRecorderQueue.Dequeue();
  85. int effectStop;
  86. if (BuffEffects.TryGetValue(effectKey, out effectStop))
  87. {
  88. BuffEffects.RemoveByKey(effectKey);
  89. StopEffect(effectStop);
  90. }
  91. }
  92. if (le.CricleMode != null)
  93. {
  94. WordRainRecorder += 1;
  95. key = bt.TemplateID.ToString() + "_" + me.BuffExtendData.ToString() + "_" + WordRainRecorder.ToString();
  96. WordRainRecorderQueue.Enqueue(key);
  97. if (le.CricleMode.EffectName != null && le.CricleMode.EffectName.Length > me.BuffExtendDataIndex - 1 && me.BuffExtendDataIndex > 0)
  98. {
  99. effectName = le.CricleMode.EffectName[me.BuffExtendDataIndex - 1];
  100. }
  101. }*/
  102. }
  103. else
  104. {
  105. le = bt.OverlayBindingEffect[buff.OverlayLevel];
  106. }
  107. }
  108. else
  109. {
  110. le = bt.BindingEffect;
  111. }
  112. if (le != null)
  113. {
  114. if (!unitRender.BuffEffects.ContainsKey(key))
  115. {
  116. uint id = await EffectMgr.Instance.PlayEffect(le, unit.Id, Vector3.zero);
  117. unitRender.BuffEffects.Add(key, id);
  118. }
  119. else
  120. {
  121. EffectMgr.Instance.ResetEffect(unit.Id);
  122. }
  123. }
  124. if (bt.BindingEffectList.Count > 0)
  125. {
  126. System.Action<LaunchEffect, byte, byte, int, int> PlayBindingEffect = async (buff, overLayer, maxOverLayer, templateID, index) =>
  127. {
  128. string _bkey = string.Format("{0}_{1}", templateID, index);
  129. if (buff == null || unitRender.BuffEffects.ContainsKey(_bkey)) return;
  130. //uint id = PlayEffect(buff, false, -1, "", overLayer, maxOverLayer);
  131. uint id = await EffectMgr.Instance.PlayEffect(buff, unit.Id, Vector3.zero);
  132. unitRender.BuffEffects.Add(_bkey, id);
  133. };
  134. if (bt.PlayType == BuffTemplate.BindingPlayType.All)
  135. {
  136. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  137. {
  138. le = bt.BindingEffectList[i];
  139. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
  140. }
  141. }
  142. else if (bt.PlayType == BuffTemplate.BindingPlayType.AppointOverLayer)
  143. {
  144. if (buff.OverlayLevel >= bt.BindingEffectList.Count) return;
  145. le = bt.BindingEffectList[buff.OverlayLevel];
  146. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, buff.OverlayLevel);
  147. }
  148. else if (bt.PlayType == BuffTemplate.BindingPlayType.IncludeOverLayer)
  149. {
  150. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  151. {
  152. if (buff.OverlayLevel >= i)
  153. {
  154. le = bt.BindingEffectList[i];
  155. PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
  156. }
  157. else
  158. {
  159. break;
  160. }
  161. }
  162. }
  163. }
  164. }
  165. private void RemoveBuff(BuffTemplate bt, UnitRenderComponet unitRender)
  166. {
  167. var BuffEffects = unitRender.BuffEffects;
  168. if (BuffEffects != null)
  169. {
  170. uint effectStop = 0;
  171. string key = bt.ID.ToString();
  172. if (BuffEffects.TryGetValue(key, out effectStop))
  173. {
  174. BuffEffects.RemoveByKey(key);
  175. EffectMgr.Instance.RemoveEffect(effectStop);
  176. }
  177. if (bt.BindingEffectList.Count > 0)
  178. {
  179. string key2 = null;
  180. for (int i = 0; i < bt.BindingEffectList.Count; i++)
  181. {
  182. key2 = string.Format("{0}_{1}", key, i);
  183. if (BuffEffects.TryGetValue(key2, out effectStop))
  184. {
  185. BuffEffects.RemoveByKey(key2);
  186. EffectMgr.Instance.RemoveEffect(effectStop);
  187. }
  188. }
  189. }
  190. }
  191. }
  192. private void MergeBuffStatus(BattleUnit unit)
  193. {
  194. bool bFrozen = false;
  195. bool bStealth = false;
  196. bool bNothingess = false;
  197. var list = unit.ZUnit.AllBuffs;
  198. list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>
  199. {
  200. var ablist = (buff.Data.Properties as XmdsBuffProperties).BuffAbilityList;
  201. if (ablist != null)
  202. {
  203. foreach (var ab in ablist)
  204. {
  205. //TODO: 支持BUFF的冰冻、草丛、虚无效果
  206. if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.FROZEN ||
  207. ab.ability == XmdsBuffProperties.XmdsBuffAbility.Fridge)
  208. {
  209. bFrozen = true;
  210. //SetFrozenStatus(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. //SetFrozenStatus(true);
  232. }
  233. else
  234. {
  235. //SetFrozenStatus(false);
  236. if (bStealth)
  237. {
  238. }
  239. else
  240. {
  241. if (bNothingess)
  242. {
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }