191 lines
7.3 KiB
C#
Executable File
191 lines
7.3 KiB
C#
Executable File
using Cal.DataTable;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
public class GoodsEffectComponentAwakeystem : AwakeSystem<GoodsEffectComponent>
|
|
{
|
|
public override void Awake(GoodsEffectComponent self)
|
|
{
|
|
GoodsEffectComponent.Instance = self;
|
|
}
|
|
}
|
|
public class GoodsEffectComponentUpdateSystem : UpdateSystem<GoodsEffectComponent>
|
|
{
|
|
public override void Update(GoodsEffectComponent self)
|
|
{
|
|
self.Update();
|
|
}
|
|
}
|
|
public static class GoodsEffectComponentSystem
|
|
{
|
|
public static string AcquireGoodsEffect(this GoodsEffectComponent self, Unit unit, GoodsBase goodsBase, bool isLock)
|
|
{
|
|
try
|
|
{
|
|
GoodsEffectType effect = (GoodsEffectType)goodsBase.EffectType;
|
|
|
|
Type tempType = self.GetEffectType(effect);
|
|
|
|
if (self._goodsEffectPoolDic.TryGetValue(tempType, out Queue<GoodsEffect> buffBase))
|
|
{
|
|
if (buffBase.Count > 0)
|
|
{
|
|
GoodsEffect tempBuffBase = buffBase.Dequeue();
|
|
return tempBuffBase.Init(unit, goodsBase, isLock);
|
|
}
|
|
}
|
|
GoodsEffect temp = (GoodsEffect)Activator.CreateInstance(tempType);
|
|
return temp.Init(unit, goodsBase, isLock);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
return string.Empty;
|
|
}
|
|
//!断线重连时调用
|
|
public static void ReAcquireGoodsEffect(this GoodsEffectComponent self, Unit unit, GoodsBase goodsBase, long endTime)
|
|
{
|
|
try
|
|
{
|
|
GoodsEffectType effect = (GoodsEffectType)goodsBase.EffectType;
|
|
|
|
Type tempType = self.GetEffectType(effect);
|
|
|
|
if (self._goodsEffectPoolDic.TryGetValue(tempType, out Queue<GoodsEffect> buffBase))
|
|
{
|
|
if (buffBase.Count > 0)
|
|
{
|
|
GoodsEffect tempBuffBase = buffBase.Dequeue();
|
|
tempBuffBase.ReInit(unit, goodsBase, endTime);
|
|
return;
|
|
}
|
|
}
|
|
GoodsEffect temp = (GoodsEffect)Activator.CreateInstance(tempType);
|
|
temp.ReInit(unit, goodsBase, endTime);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
private static Type GetEffectType(this GoodsEffectComponent self, GoodsEffectType effectType) => effectType switch
|
|
{
|
|
GoodsEffectType.AddHpOrMp => typeof(AddHpOrMpGoodsEffect),
|
|
GoodsEffectType.AddHp => typeof(AddHpGoodsEffect),
|
|
GoodsEffectType.AddMp => typeof(AddMpGoodsEffect),
|
|
GoodsEffectType.AddGoods => typeof(AddGoodsEffect),
|
|
GoodsEffectType.AddEquipOrMaterialBySpecial => typeof(AddEquipOrMaterialBySpecialEffect),
|
|
GoodsEffectType.AddSpecialGoods => typeof(AddSpecialGoodsEffect),
|
|
GoodsEffectType.BackHome => typeof(BackHomeGoodsEffect),
|
|
GoodsEffectType.AddHpBuff => typeof(AddHpBuffGoodsEffect),
|
|
GoodsEffectType.AddMpBuff => typeof(AddMpBuffGoodsEffect),
|
|
GoodsEffectType.AddBattleExpSpeed => typeof(AddBattleExpSpeedGoodsEffect),
|
|
GoodsEffectType.AddIdleExpSpeed => typeof(AddIdleExpSpeedGoodsEffect),
|
|
|
|
GoodsEffectType.ChatHorn => throw new NotImplementedException(),
|
|
GoodsEffectType.AddPet =>typeof(AddPetGoodsEffect),
|
|
GoodsEffectType.AddPetExpSpeed => throw new NotImplementedException(),
|
|
// GoodsEffectType.AddPetIntimacy => typeof(AddPetIntimacyGoodsEffect),
|
|
GoodsEffectType.LearnSkill => typeof(LearnSkillGoodsEffect),
|
|
GoodsEffectType.AddEnergy => typeof(AddEnergyGoodsEffect),
|
|
GoodsEffectType.AddMainAITime => typeof(AddMainAITimeGoodsEffect),
|
|
GoodsEffectType.AddMainVIPAITime => typeof(AddMainVIPAITimeGoodsEffect),
|
|
GoodsEffectType.StrengthEquipToL17 => typeof(StrengthEquipToL17GoodsEffect),
|
|
GoodsEffectType.OpenMainStoryBossChest => typeof(OpenMainStoryBossChestGoodsEffect),
|
|
_ => throw new Exception("Goods 类型名错误,检查表格"),
|
|
};
|
|
|
|
public static void AddGoodsBuff(this GoodsEffectComponent self, long id, GoodsEffectType type, GoodsEffect goodsEffect)
|
|
{
|
|
try
|
|
{
|
|
if (!self._goodsEffectBuffDic.TryGetValue(id, out Dictionary<int, GoodsEffect> dic))
|
|
{
|
|
dic = self._goodsEffectBuffDic[id] = new Dictionary<int, GoodsEffect>();
|
|
}
|
|
dic[(int)type] = goodsEffect;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
|
|
public static GoodsEffect GetGoodsBuffType(this GoodsEffectComponent self, long id, GoodsEffectType type)
|
|
{
|
|
try
|
|
{
|
|
if (self._goodsEffectBuffDic.TryGetValue(id, out Dictionary<int, GoodsEffect> dic))
|
|
{
|
|
if (dic.TryGetValue((int)type, out GoodsEffect goodsEffect))
|
|
{
|
|
return goodsEffect;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
return null;
|
|
}
|
|
public static IEnumerable<GoodsEffect> GetAllEffect(this GoodsEffectComponent self, long id)
|
|
{
|
|
if (self._goodsEffectBuffDic.TryGetValue(id, out Dictionary<int, GoodsEffect> dic))
|
|
{
|
|
return dic.Values;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private static List<ValueTuple<long, int>> _needRemoveList = new List<ValueTuple<long, int>>();
|
|
internal static void Update(this GoodsEffectComponent self)
|
|
{
|
|
try
|
|
{
|
|
foreach (KeyValuePair<long, Dictionary<int, GoodsEffect>> kv in self._goodsEffectBuffDic)
|
|
{
|
|
Dictionary<int, GoodsEffect> dic = kv.Value;
|
|
foreach (KeyValuePair<int, GoodsEffect> _kv in dic)
|
|
{
|
|
GoodsEffect effect = _kv.Value;
|
|
switch (effect.BuffState)
|
|
{
|
|
case BuffState.Running:
|
|
effect.Execute();
|
|
break;
|
|
case BuffState.Finished:
|
|
_needRemoveList.Add((kv.Key, _kv.Key));
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (_needRemoveList.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach ((long id, int type) in _needRemoveList)
|
|
{
|
|
self._goodsEffectBuffDic[id].Remove(type);
|
|
if (self._goodsEffectBuffDic[id].Count == 0)
|
|
{
|
|
self._goodsEffectBuffDic.Remove(type);
|
|
}
|
|
}
|
|
_needRemoveList.Clear();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|