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 mGlobalPlayerCache = new HashMap(); private static HashMap mGlobalMonsterCache = new HashMap(); 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); 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); 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, maxValue); } 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; // } // } //} } }