JSGMountainKingModule.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using CommonAI.Zone.Instance;
  2. using CommonLang;
  3. using CommonLang.Log;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using XmdsCommonServer.Plugin;
  10. /// <summary>
  11. /// 山大王处理模块
  12. /// </summary>
  13. public class JSGMountainKingModule
  14. {
  15. protected static Logger log = LoggerFactory.GetLogger(typeof(JSGMountainKingModule).Name);
  16. public class MountainKingData
  17. {
  18. public int nextRefreshTime;
  19. }
  20. public class KingRefreshData
  21. {
  22. public int monsterId;
  23. public int nextRefreshTime;
  24. public KingRefreshData(int monsterId, int refreshTime)
  25. {
  26. this.monsterId = monsterId;
  27. this.nextRefreshTime = refreshTime;
  28. }
  29. }
  30. private static HashMap<string, HashMap<int, MountainKingData>> mMountainKings = new HashMap<string, HashMap<int, MountainKingData>>();
  31. public static void Init(string gameSrvId)
  32. {
  33. HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(gameSrvId);
  34. if(srvMountain != null)
  35. {
  36. log.Warn("多次初始化山大王数据,跳过:" + gameSrvId);
  37. return;
  38. }
  39. srvMountain = new HashMap<int, MountainKingData>();
  40. mMountainKings.Put(gameSrvId, srvMountain);
  41. HashSet<int> kings = XmdsDataMgr.GetInstance().GetMountainKings();
  42. foreach (int kingId in kings)
  43. {
  44. srvMountain.Put(kingId, new MountainKingData());
  45. }
  46. log.Warn("初始化山大王信息:" + gameSrvId + ", " + kings.Count);
  47. }
  48. /** 怪物复活,判断是否山大王 */
  49. public static void OnMonsterRefreshNotify(string gameSrvId, List<KingRefreshData> refreshList)
  50. {
  51. if(string.IsNullOrEmpty(gameSrvId) || refreshList.Count <= 0)
  52. {
  53. return;
  54. }
  55. HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(gameSrvId);
  56. if (srvMountain == null)
  57. {
  58. string extData = "";
  59. foreach(KingRefreshData temp in refreshList)
  60. {
  61. extData += (temp.monsterId + ", " + temp.nextRefreshTime + "; ");
  62. }
  63. log.Warn("IsKingAlive没有找到服务器数据:" + gameSrvId + ", " + extData);
  64. return;
  65. }
  66. foreach(KingRefreshData data in refreshList)
  67. {
  68. MountainKingData kingData = srvMountain.Get(data.monsterId);
  69. if (data == null || kingData == null)
  70. {
  71. log.Warn("OnMonsterRefreshNotify找不到对应山大王:" + gameSrvId + ", " + data.monsterId + ", " + data.nextRefreshTime);
  72. return;
  73. }
  74. kingData.nextRefreshTime = data.nextRefreshTime;
  75. }
  76. }
  77. /** 是否存在山大王 */
  78. public static bool IsKingAlive(InstanceZone zone, int monsterId)
  79. {
  80. if(zone == null || monsterId <= 0)
  81. {
  82. return false;
  83. }
  84. string srvId = zone.GetBindGameSrvID();
  85. HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(srvId);
  86. if (srvMountain == null)
  87. {
  88. log.Warn("IsKingAlive没有找到服务器数据:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
  89. return false;
  90. }
  91. MountainKingData data = srvMountain.Get(monsterId);
  92. if(data == null)
  93. {
  94. log.Warn("IsKingAlive找不到对应山大王:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
  95. return false;
  96. }
  97. if(data.nextRefreshTime != 0)
  98. {
  99. return false;
  100. }
  101. return true;
  102. }
  103. }