|  |  |  |  | using Entitas; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using Game; | 
					
						
							|  |  |  |  | using Articy.Touhou.Templates; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /// <summary> | 
					
						
							|  |  |  |  | /// buff和元素触发在此管理 | 
					
						
							|  |  |  |  | /// </summary> | 
					
						
							|  |  |  |  | public class BuffData | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public string BuffId; | 
					
						
							|  |  |  |  |     public EState State; | 
					
						
							|  |  |  |  |     public BuffTemplate BuffCfg; | 
					
						
							|  |  |  |  |     public float TimeMax; | 
					
						
							|  |  |  |  |     public float TimePast; | 
					
						
							|  |  |  |  |     public MetaData<int> Level = new MetaData<int>(); | 
					
						
							|  |  |  |  |     public MetaData<float> TimeLeft = new MetaData<float>(); | 
					
						
							|  |  |  |  |     public int Owner; | 
					
						
							|  |  |  |  |     public int Target; | 
					
						
							|  |  |  |  |     public bool IsShow;//是否在ui中显示 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | [Game] | 
					
						
							|  |  |  |  | public class BuffComponent : IComponent | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public MetaDictionary<string, BuffData> BuffMap = new MetaDictionary<string, BuffData>(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | namespace Game | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public abstract partial class Util | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         public static void AddBuff(int owner, int target, string buffId, float timeS = 0, int level = 1, bool isShowInfo = true) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             var e = Util.GetEntity(target); | 
					
						
							|  |  |  |  |             if (e == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (!UtilBuff.BuffPreCheck(owner, target, buffId)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (isShowInfo) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 UtilBuff.SendHitBuff(target, buffId); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             var buff = e.buff; | 
					
						
							|  |  |  |  |             var buffCfgData = Util.GetBuffConfigData(buffId); | 
					
						
							|  |  |  |  |             var buffCfg = Util.GetBuffConfig(buffId); | 
					
						
							|  |  |  |  |             var isNew = false; | 
					
						
							|  |  |  |  |             if (buffCfg.Buff.IsAliveForever) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 timeS = -1; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (!buff.BuffMap.ContainsKey(buffId)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 //新建buff TODO 池化 | 
					
						
							|  |  |  |  |                 buff.BuffMap[buffId] = new BuffData | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     BuffId = buffCfgData.TechnicalName, | 
					
						
							|  |  |  |  |                     State = EState.Enter, | 
					
						
							|  |  |  |  |                     BuffCfg = buffCfg, | 
					
						
							|  |  |  |  |                     Owner = owner, | 
					
						
							|  |  |  |  |                     Target = target, | 
					
						
							|  |  |  |  |                     IsShow = !GameConst.BuffUnShowed.Contains(buffId), | 
					
						
							|  |  |  |  |                 }; | 
					
						
							|  |  |  |  |                 isNew = true; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             // Util.Print("AddBuff", buffCfg.Buff.Name); | 
					
						
							|  |  |  |  |             var buffData = buff.BuffMap[buffId]; | 
					
						
							|  |  |  |  |             var timeLeft = (timeS == 0 ? buffCfg.Buff.AliveTime : timeS); | 
					
						
							|  |  |  |  |             var levelMax = buffCfg.Buff.LevelMax; | 
					
						
							|  |  |  |  |             buffData.TimeLeft.Value = timeLeft; | 
					
						
							|  |  |  |  |             buffData.TimeMax = timeLeft; | 
					
						
							|  |  |  |  |             buffData.Level.Value += level; | 
					
						
							|  |  |  |  |             buffData.Level.Value = Mathf.Min(buffData.Level.Value, levelMax); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             if (isNew) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 UtilBuff.BuffEffect(buffData, EBuffEffectTimingType.Enter); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (buffData.Level.Value == levelMax) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 UtilBuff.BuffEffect(buffData, EBuffEffectTimingType.LevelFull); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void RemoveBuff(int entity, string buffId) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             var e = Util.GetEntity(entity); | 
					
						
							|  |  |  |  |             if (e == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             var buff = e.buff; | 
					
						
							|  |  |  |  |             if (!buff.BuffMap.ContainsKey(buffId)) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             var buffData = buff.BuffMap[buffId]; | 
					
						
							|  |  |  |  |             buff.BuffMap.Remove(buffId); | 
					
						
							|  |  |  |  |             UtilBuff.BuffEffect(buffData, EBuffEffectTimingType.Leave); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void AddStaggerBuff(int entity, float timeS) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //硬直buff特殊计算,包含浮空 | 
					
						
							|  |  |  |  |             AddBuff(entity, entity, GameConst.BuffStagger, timeS, 1, false); | 
					
						
							|  |  |  |  |             Util.EntityStopMove(entity); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void AddSetSpeedBuff(int entity, float timeS) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //设置速度buff | 
					
						
							|  |  |  |  |             AddBuff(entity, entity, GameConst.BuffSetSpeed, timeS, 1, false); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void AddHitDownBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //击落buff 落地时反弹 | 
					
						
							|  |  |  |  |             AddBuff(entity, entity, GameConst.BuffHitdown, -1, 1, false); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void RemoveSetSpeedBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //清除设置速度buff | 
					
						
							|  |  |  |  |             RemoveBuff(entity, GameConst.BuffSetSpeed); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void RemoveHitDownBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //清除击落buff | 
					
						
							|  |  |  |  |             RemoveBuff(entity, GameConst.BuffHitdown); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void RemoveControlBuffAll(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             //清除所有控制buff | 
					
						
							|  |  |  |  |             RemoveBuff(entity, GameConst.BuffStagger); | 
					
						
							|  |  |  |  |             RemoveBuff(entity, GameConst.BuffSetSpeed); | 
					
						
							|  |  |  |  |             RemoveBuff(entity, GameConst.BuffHitdown); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static bool HasHitDownBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return HasBuff(entity, GameConst.BuffHitdown); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static bool HasSetSpeedBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return HasBuff(entity, GameConst.BuffSetSpeed); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static bool HasStunBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return HasBuff(entity, GameConst.BuffStun); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void AddStunBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             AddBuff(entity, entity, GameConst.BuffStun, 0, 1, false); | 
					
						
							|  |  |  |  |             Util.EntityStopMove(entity); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void AddExecuteBuff(int entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             AddBuff(entity, entity, GameConst.BuffExecute, 0, 1, false); | 
					
						
							|  |  |  |  |             Util.EntityStopMove(entity); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static bool HasBuff(int entity, string buffId) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             var e = Util.GetEntity(entity); | 
					
						
							|  |  |  |  |             if (e == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             if (!e.hasBuff) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return false; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             var buff = e.buff; | 
					
						
							|  |  |  |  |             return buff.BuffMap.ContainsKey(buffId); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         public static void ClearBuff(GameEntity entity) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             var buff = entity.buff; | 
					
						
							|  |  |  |  |             buff.BuffMap.Clear(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |