XmdsPlayerCache.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Instance;
  4. using CommonLang;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using XmdsCommonServer.XLS.Data;
  11. namespace XmdsCommonSkill.Plugin.Skills
  12. {
  13. public class XmdsPlayerCache
  14. {
  15. private static HashMap<string, PlayerCacheBase> mGlobalPlayerCache = new HashMap<string, PlayerCacheBase>();
  16. private static HashMap<string, PlayerCacheBase> mGlobalMonsterCache = new HashMap<string, PlayerCacheBase>();
  17. public static PlayerCacheBase PlayerTalnetInit(XmdsUnitPro unitPro, InstanceUnit unit, int maxValue, IntIntIntData refreshRule = null, IntIntData[] talnetData = null)
  18. {
  19. if(unit.PlayerUUID == null || unit.PlayerUUID.Length <= 0)
  20. {
  21. string uniqueID = GetMonsterUniqueID(unit);
  22. PlayerCacheBase oldData = mGlobalMonsterCache.Get(uniqueID);
  23. if (oldData == null)
  24. {
  25. oldData = GetNewData(unitPro, unit, maxValue, refreshRule, talnetData);
  26. mGlobalMonsterCache.Put(uniqueID, oldData);
  27. }
  28. oldData.ReInit(unit, maxValue, refreshRule, talnetData);
  29. return oldData;
  30. }
  31. else
  32. {
  33. PlayerCacheBase oldData = mGlobalPlayerCache.Get(unit.PlayerUUID);
  34. if (oldData == null)
  35. {
  36. oldData = GetNewData(unitPro, unit, maxValue, refreshRule, talnetData);
  37. mGlobalPlayerCache.Put(unit.PlayerUUID, oldData);
  38. }
  39. oldData.ReInit(unit, maxValue, refreshRule, talnetData);
  40. return oldData;
  41. }
  42. }
  43. private static PlayerCacheBase GetNewData(XmdsUnitPro unitPro, InstanceUnit unit, int maxValue, IntIntIntData refreshRule = null, IntIntData[] talnetData = null)
  44. {
  45. switch (unitPro)
  46. {
  47. case XmdsUnitPro.Magic:
  48. return new PlayerCache_Magic(unit, talnetData, refreshRule);
  49. case XmdsUnitPro.Sword:
  50. return new PlayerCache_Warrior(unit, maxValue, refreshRule);
  51. case XmdsUnitPro.Priest:
  52. return new PlayerCache_Remedy(unit, refreshRule.value1, refreshRule.value2);
  53. }
  54. return null;
  55. }
  56. public static void PlayerTalnetDestory(InstanceUnit unit)
  57. {
  58. if (unit.PlayerUUID == null || unit.PlayerUUID.Length <= 0)
  59. {
  60. mGlobalMonsterCache.Remove(GetMonsterUniqueID(unit));
  61. }
  62. else
  63. {
  64. PlayerCacheBase oldData = mGlobalPlayerCache.Get(unit.PlayerUUID);
  65. if (oldData != null)
  66. {
  67. oldData.MarkValid(false);
  68. }
  69. }
  70. }
  71. private static string GetMonsterUniqueID(InstanceUnit unit)
  72. {
  73. return (unit.Info.ID + "_" + unit.ID);
  74. }
  75. //public static void UpdateTalnetInfo()
  76. //{
  77. // foreach(PlayerCacheData data in mGlobalPlayerCache.Values)
  78. // {
  79. // if (!data.IsValid())
  80. // {
  81. // continue;
  82. // }
  83. // }
  84. //}
  85. }
  86. }