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;
///
/// 山大王处理模块
///
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> mMountainKings = new HashMap>();
public static void Init(string gameSrvId)
{
HashMap srvMountain = mMountainKings.Get(gameSrvId);
if(srvMountain != null)
{
log.Warn("多次初始化山大王数据,跳过:" + gameSrvId);
return;
}
srvMountain = new HashMap();
mMountainKings.Put(gameSrvId, srvMountain);
HashSet 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 refreshList)
{
if(string.IsNullOrEmpty(gameSrvId) || refreshList.Count <= 0)
{
return;
}
HashMap 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 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;
}
}