123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
-
- using CommonAI.Zone;
- using System.Collections.Generic;
- using XmdsCommon.Plugin;
- using UnityEngine;
- namespace ET.Client
- {
- [Event(SceneType.None)]
- [FriendOfAttribute(typeof(ET.Client.UnitRenderComponet))]
- public class BuffChangeEventHandler : BEvent<EventType.BuffChangeEvent>
- {
- public override void OnEvent(EventType.BuffChangeEvent args)
- {
- BattleUnit unit = UnitMgr.Instance.GetUnit(args.ObjectId) as BattleUnit;
- if (unit == null)
- {
- Log.Error($"buff unit not exist: {args.ObjectId}");
- return;
- }
- var unitRender = ModelViewComponent.Instance.GetChild<UnitRenderComponet>(args.ObjectId);
- if (unitRender == null)
- {
- Log.Debug($"buff unitrender not exist: {args.ObjectId}");
- return;
- }
- if (args.Type == BuffChangeType.Add)
- {
- BuffTemplate bt = args.Buff.Data;
- if (bt.MakeAvatar)
- {
- //TODO: 支持BUFF变身
- Log.Error("Not implements MakeAvatar");
- }
- AddBuff(args.Buff, unitRender, unit).Coroutine();
- }
- else if (args.Type == BuffChangeType.Remove)
- {
- BuffTemplate bt = args.Buff.Data;
- RemoveBuff(bt, unitRender);
- }
- else if (args.Type == BuffChangeType.Change)
- {
- BuffTemplate bt = args.Buff.Data;
- //随BUFF状态变更,表现特效不同时.
- if ((bt.BindingEffectList != null && bt.BindingEffectList.Count > 0) ||
- (bt.OverlayBindingEffect != null && bt.OverlayBindingEffect.Count > 0))
- {
- var buff = args.Buff;
- if ((buff.OverlayLevel >= 0 && buff.OverlayLevel < bt.BindingEffectList.Count) ||
- (buff.BuffExtendData > 0 && buff.OverlayLevel < bt.OverlayBindingEffect.Count))
- {
- RemoveBuff(bt, unitRender);
- AddBuff(buff, unitRender, unit).Coroutine();
- }
- }
- }
- else if (args.Type == BuffChangeType.Reload)
- {
- var list = unit.ZUnit.AllBuffs;
- list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>
- {
- AddBuff(buff, unitRender, unit).Coroutine();
- });
- }
- MergeBuffStatus(unit);
- }
- private async ETTask AddBuff(CommonAI.ZoneClient.ZoneUnit.BuffState buff, UnitRenderComponet unitRender, BattleUnit unit)
- {
- BuffTemplate bt = buff.Data;
- //优先判断是否有叠层效果.
- LaunchEffect le = null;
- string key = bt.TemplateID.ToString();
- string effectName = "";
- if (bt.OverlayBindingEffect != null && bt.OverlayBindingEffect.Count > 0)
- {
- if (buff.BuffExtendData > 0)
- {
- le = bt.OverlayBindingEffect[buff.OverlayLevel];
- if (le.RType != LaunchEffect.RunType.Cycle_BindName) return;
- /*/超出最大层数,把最早的给移除掉
- if (WordRainRecorderQueue.Count > 0 && WordRainRecorderQueue.Count >= me.Data.MaxOverlay)
- {
- string effectKey = WordRainRecorderQueue.Dequeue();
- int effectStop;
- if (BuffEffects.TryGetValue(effectKey, out effectStop))
- {
- BuffEffects.RemoveByKey(effectKey);
- StopEffect(effectStop);
- }
- }
- if (le.CricleMode != null)
- {
- WordRainRecorder += 1;
- key = bt.TemplateID.ToString() + "_" + me.BuffExtendData.ToString() + "_" + WordRainRecorder.ToString();
- WordRainRecorderQueue.Enqueue(key);
- if (le.CricleMode.EffectName != null && le.CricleMode.EffectName.Length > me.BuffExtendDataIndex - 1 && me.BuffExtendDataIndex > 0)
- {
- effectName = le.CricleMode.EffectName[me.BuffExtendDataIndex - 1];
- }
- }*/
- }
- else
- {
- le = bt.OverlayBindingEffect[buff.OverlayLevel];
- }
- }
- else
- {
- le = bt.BindingEffect;
- }
- if (le != null)
- {
- if (!unitRender.BuffEffects.ContainsKey(key))
- {
- uint id = await EffectMgr.Instance.PlayEffect(le, unit.Id, Vector3.zero);
- unitRender.BuffEffects.Add(key, id);
- }
- else
- {
- EffectMgr.Instance.ResetEffect(unit.Id);
- }
- }
- if (bt.BindingEffectList.Count > 0)
- {
- System.Action<LaunchEffect, byte, byte, int, int> PlayBindingEffect = async (buff, overLayer, maxOverLayer, templateID, index) =>
- {
- string _bkey = string.Format("{0}_{1}", templateID, index);
- if (buff == null || unitRender.BuffEffects.ContainsKey(_bkey)) return;
- //uint id = PlayEffect(buff, false, -1, "", overLayer, maxOverLayer);
- uint id = await EffectMgr.Instance.PlayEffect(buff, unit.Id, Vector3.zero);
- unitRender.BuffEffects.Add(_bkey, id);
- };
- if (bt.PlayType == BuffTemplate.BindingPlayType.All)
- {
- for (int i = 0; i < bt.BindingEffectList.Count; i++)
- {
- le = bt.BindingEffectList[i];
- PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
- }
- }
- else if (bt.PlayType == BuffTemplate.BindingPlayType.AppointOverLayer)
- {
- if (buff.OverlayLevel >= bt.BindingEffectList.Count) return;
- le = bt.BindingEffectList[buff.OverlayLevel];
- PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, buff.OverlayLevel);
- }
- else if (bt.PlayType == BuffTemplate.BindingPlayType.IncludeOverLayer)
- {
- for (int i = 0; i < bt.BindingEffectList.Count; i++)
- {
- if (buff.OverlayLevel >= i)
- {
- le = bt.BindingEffectList[i];
- PlayBindingEffect(le, buff.OverlayLevel, bt.MaxOverlay, bt.TemplateID, i);
- }
- else
- {
- break;
- }
- }
- }
- }
- }
- private void RemoveBuff(BuffTemplate bt, UnitRenderComponet unitRender)
- {
- var BuffEffects = unitRender.BuffEffects;
- if (BuffEffects != null)
- {
- uint effectStop = 0;
- string key = bt.ID.ToString();
- if (BuffEffects.TryGetValue(key, out effectStop))
- {
- BuffEffects.RemoveByKey(key);
- EffectMgr.Instance.RemoveEffect(effectStop);
- }
- if (bt.BindingEffectList.Count > 0)
- {
- string key2 = null;
- for (int i = 0; i < bt.BindingEffectList.Count; i++)
- {
- key2 = string.Format("{0}_{1}", key, i);
- if (BuffEffects.TryGetValue(key2, out effectStop))
- {
- BuffEffects.RemoveByKey(key2);
- EffectMgr.Instance.RemoveEffect(effectStop);
- }
- }
- }
- }
- }
- private void MergeBuffStatus(BattleUnit unit)
- {
- bool bFrozen = false;
- bool bStealth = false;
- bool bNothingess = false;
- var list = unit.ZUnit.AllBuffs;
- list.ForEach((CommonAI.ZoneClient.ZoneUnit.BuffState buff) =>
- {
- var ablist = (buff.Data.Properties as XmdsBuffProperties).BuffAbilityList;
- if (ablist != null)
- {
- foreach (var ab in ablist)
- {
- //TODO: 支持BUFF的冰冻、草丛、虚无效果
- if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.FROZEN ||
- ab.ability == XmdsBuffProperties.XmdsBuffAbility.Fridge)
- {
- bFrozen = true;
- //SetFrozenStatus(true);
- }
- else if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.Stealth)
- {
- bStealth = true;
- //判断是不是在墙角,在墙角只更新currentMat,否则修改材质和currentMat
- /*foreach (var item in this.GameObject.GetComponentsInChildren<MaterialManager>())
- {
- item.AddMatState(StateMaterial.HIDDING);
- }*/
- }
- else if (ab.ability == XmdsBuffProperties.XmdsBuffAbility.Nothingness)
- {
- bNothingess = true;
- //this.HideSelf(true);
- }
- }
- }
- });
- if (bFrozen)
- {
- //SetFrozenStatus(true);
- }
- else
- {
- //SetFrozenStatus(false);
- if (bStealth)
- {
- }
- else
- {
- if (bNothingess)
- {
- }
- }
- }
- }
- }
- }
|