123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using CommonAI.Data;
- using CommonAI.Zone;
- using CommonAI.Zone.Instance;
- using CommonLang;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsCommonServer.XLS.Data;
- namespace XmdsCommonSkill.Plugin.Skills
- {
- public class XmdsPlayerCache
- {
- private static HashMap<string, PlayerCacheBase> mGlobalPlayerCache = new HashMap<string, PlayerCacheBase>();
- private static HashMap<string, PlayerCacheBase> mGlobalMonsterCache = new HashMap<string, PlayerCacheBase>();
- public static PlayerCacheBase PlayerTalnetInit(XmdsUnitPro unitPro, InstanceUnit unit, int maxValue, IntIntIntData refreshRule = null, IntIntData[] talnetData = null)
- {
- if(unit.PlayerUUID == null || unit.PlayerUUID.Length <= 0)
- {
- string uniqueID = GetMonsterUniqueID(unit);
- PlayerCacheBase oldData = mGlobalMonsterCache.Get(uniqueID);
- if (oldData == null)
- {
- oldData = GetNewData(unitPro, unit, maxValue, refreshRule, talnetData);
- mGlobalMonsterCache.Put(uniqueID, oldData);
- }
- oldData.ReInit(unit, maxValue, refreshRule, talnetData);
- return oldData;
- }
- else
- {
- PlayerCacheBase oldData = mGlobalPlayerCache.Get(unit.PlayerUUID);
- if (oldData == null)
- {
- oldData = GetNewData(unitPro, unit, maxValue, refreshRule, talnetData);
- mGlobalPlayerCache.Put(unit.PlayerUUID, oldData);
- }
- oldData.ReInit(unit, maxValue, refreshRule, talnetData);
- return oldData;
- }
- }
- private static PlayerCacheBase GetNewData(XmdsUnitPro unitPro, InstanceUnit unit, int maxValue, IntIntIntData refreshRule = null, IntIntData[] talnetData = null)
- {
- switch (unitPro)
- {
- case XmdsUnitPro.Magic:
- return new PlayerCache_Magic(unit, talnetData, refreshRule);
- case XmdsUnitPro.Sword:
- return new PlayerCache_Warrior(unit, maxValue, refreshRule);
- case XmdsUnitPro.Priest:
- return new PlayerCache_Remedy(unit, refreshRule.value1, refreshRule.value2);
- }
- return null;
- }
- public static void PlayerTalnetDestory(InstanceUnit unit)
- {
- if (unit.PlayerUUID == null || unit.PlayerUUID.Length <= 0)
- {
- mGlobalMonsterCache.Remove(GetMonsterUniqueID(unit));
- }
- else
- {
- PlayerCacheBase oldData = mGlobalPlayerCache.Get(unit.PlayerUUID);
- if (oldData != null)
- {
- oldData.MarkValid(false);
- }
- }
- }
- private static string GetMonsterUniqueID(InstanceUnit unit)
- {
- return (unit.Info.ID + "_" + unit.ID);
- }
- //public static void UpdateTalnetInfo()
- //{
- // foreach(PlayerCacheData data in mGlobalPlayerCache.Values)
- // {
- // if (!data.IsValid())
- // {
- // continue;
- // }
- // }
- //}
- }
- }
|