JSGMountainKingModule.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. }
  47. /** 怪物复活,判断是否山大王 */
  48. public static void OnMonsterRefreshNotify(string gameSrvId, List<KingRefreshData> refreshList)
  49. {
  50. if(string.IsNullOrEmpty(gameSrvId) || refreshList.Count <= 0)
  51. {
  52. return;
  53. }
  54. HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(gameSrvId);
  55. if (srvMountain == null)
  56. {
  57. string extData = "";
  58. foreach(KingRefreshData temp in refreshList)
  59. {
  60. extData += (temp.monsterId + ", " + temp.nextRefreshTime + "; ");
  61. }
  62. log.Warn("IsKingAlive没有找到服务器数据:" + gameSrvId + ", " + extData);
  63. return;
  64. }
  65. foreach(KingRefreshData data in refreshList)
  66. {
  67. MountainKingData kingData = srvMountain.Get(data.monsterId);
  68. if (data == null || kingData == null)
  69. {
  70. log.Warn("OnMonsterRefreshNotify找不到对应山大王:" + gameSrvId + ", " + data.monsterId + ", " + data.nextRefreshTime);
  71. return;
  72. }
  73. kingData.nextRefreshTime = data.nextRefreshTime;
  74. }
  75. }
  76. /** 是否存在山大王 */
  77. public static bool IsKingAlive(InstanceZone zone, int monsterId)
  78. {
  79. if(zone == null || monsterId <= 0)
  80. {
  81. return false;
  82. }
  83. string srvId = zone.GetBindGameSrvID();
  84. HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(srvId);
  85. if (srvMountain == null)
  86. {
  87. log.Warn("IsKingAlive没有找到服务器数据:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
  88. return false;
  89. }
  90. MountainKingData data = srvMountain.Get(monsterId);
  91. if(data == null)
  92. {
  93. log.Warn("IsKingAlive找不到对应山大王:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
  94. return false;
  95. }
  96. if(data.nextRefreshTime != 0)
  97. {
  98. return false;
  99. }
  100. return true;
  101. }
  102. }