123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using CommonAI.Zone.Instance;
- using CommonLang;
- using CommonLang.Log;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsCommonServer.Plugin;
- /// <summary>
- /// 山大王处理模块
- /// </summary>
- public class JSGMountainKingModule
- {
- protected static Logger log = LoggerFactory.GetLogger(typeof(JSGMountainKingModule).Name);
- public class MountainKingData
- {
- public int nextRefreshTime;
- }
- public class KingRefreshData
- {
- public int monsterId;
- public int nextRefreshTime;
- public KingRefreshData(int monsterId, int refreshTime)
- {
- this.monsterId = monsterId;
- this.nextRefreshTime = refreshTime;
- }
- }
- private static HashMap<string, HashMap<int, MountainKingData>> mMountainKings = new HashMap<string, HashMap<int, MountainKingData>>();
- public static void Init(string gameSrvId)
- {
- HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(gameSrvId);
- if(srvMountain != null)
- {
- log.Warn("多次初始化山大王数据,跳过:" + gameSrvId);
- return;
- }
- srvMountain = new HashMap<int, MountainKingData>();
- mMountainKings.Put(gameSrvId, srvMountain);
- HashSet<int> kings = XmdsDataMgr.GetInstance().GetMountainKings();
- foreach (int kingId in kings)
- {
- srvMountain.Put(kingId, new MountainKingData());
- }
- log.Warn("初始化山大王信息:" + gameSrvId + ", " + kings.Count);
- }
- /** 怪物复活,判断是否山大王 */
- public static void OnMonsterRefreshNotify(string gameSrvId, List<KingRefreshData> refreshList)
- {
- if(string.IsNullOrEmpty(gameSrvId) || refreshList.Count <= 0)
- {
- return;
- }
- HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(gameSrvId);
- if (srvMountain == null)
- {
- string extData = "";
- foreach(KingRefreshData temp in refreshList)
- {
- extData += (temp.monsterId + ", " + temp.nextRefreshTime + "; ");
- }
- log.Warn("IsKingAlive没有找到服务器数据:" + gameSrvId + ", " + extData);
- return;
- }
- foreach(KingRefreshData data in refreshList)
- {
- MountainKingData kingData = srvMountain.Get(data.monsterId);
- if (data == null || kingData == null)
- {
- log.Warn("OnMonsterRefreshNotify找不到对应山大王:" + gameSrvId + ", " + data.monsterId + ", " + data.nextRefreshTime);
- return;
- }
- kingData.nextRefreshTime = data.nextRefreshTime;
- }
- }
- /** 是否存在山大王 */
- public static bool IsKingAlive(InstanceZone zone, int monsterId)
- {
- if(zone == null || monsterId <= 0)
- {
- return false;
- }
- string srvId = zone.GetBindGameSrvID();
- HashMap<int, MountainKingData> srvMountain = mMountainKings.Get(srvId);
- if (srvMountain == null)
- {
- log.Warn("IsKingAlive没有找到服务器数据:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
- return false;
- }
- MountainKingData data = srvMountain.Get(monsterId);
- if(data == null)
- {
- log.Warn("IsKingAlive找不到对应山大王:" + srvId + ", " + zone.GetSceneID() + ", " + monsterId);
- return false;
- }
- if(data.nextRefreshTime != 0)
- {
- return false;
- }
- return true;
- }
- }
|