using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class HazyGrassModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, List<HazyGrassNpcInfo>> mapNpcs = new Dictionary<int, List<HazyGrassNpcInfo>>();
|
Dictionary<int, int> m_MapNpcCount = new Dictionary<int, int>();
|
|
public const int ReikiGrassMapId = 32040;
|
public const int FairyGrassMapId = 32050;
|
public const int Client_ReikiGrassMapID = 3240;
|
public const int Client_FairyGrassMapID = 3250;
|
|
public bool IsInDungeon { get; private set; }
|
|
public event Action onMapNpcCountRefresh;
|
|
HazyRegionModel hazyRegionModel { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
}
|
|
void ParseConfig()
|
{
|
var mapNpcConfigs = MapNpcRefreshConfig.GetValues();
|
foreach (var config in mapNpcConfigs)
|
{
|
if (config.MapID == ReikiGrassMapId
|
|| config.MapID == FairyGrassMapId)
|
{
|
List<HazyGrassNpcInfo> _npcs = null;
|
if (!mapNpcs.TryGetValue(config.MapID, out _npcs))
|
{
|
_npcs = new List<HazyGrassNpcInfo>();
|
mapNpcs.Add(config.MapID, _npcs);
|
}
|
for (int i = 0; i < config.NPCIDList.Length; i++)
|
{
|
_npcs.Add(new HazyGrassNpcInfo()
|
{
|
npcId = config.NPCIDList[i],
|
refreshMinute = config.RefreshPerMinutes,
|
});
|
}
|
}
|
}
|
}
|
|
private void OnStageLoadFinish()
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
|
m_MapNpcCount.Clear();
|
|
IsInDungeon = false;
|
if (IsInGrassDungeon(mapId))
|
{
|
IsInDungeon = true;
|
}
|
}
|
|
public bool IsInGrassDungeon(int mapId)
|
{
|
if (mapId == Client_ReikiGrassMapID
|
|| mapId == Client_FairyGrassMapID)
|
{
|
return true;
|
}
|
|
var configs = HazyRegionConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if ((config.incidentType == (int)HazyRegionIncidentType.FairyGrass
|
|| config.incidentType == (int)HazyRegionIncidentType.ReikiGrass)
|
&& config.dungeonId == mapId)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public int GetClientMapId(int incidentId)
|
{
|
var config = HazyRegionConfig.Get(incidentId);
|
switch ((HazyRegionIncidentType)config.incidentType)
|
{
|
case HazyRegionIncidentType.FairyGrass:
|
return Client_FairyGrassMapID;
|
case HazyRegionIncidentType.ReikiGrass:
|
return Client_ReikiGrassMapID;
|
}
|
return 0;
|
}
|
|
public int GetGrassMapId(int incidentId)
|
{
|
var config = HazyRegionConfig.Get(incidentId);
|
if (config != null)
|
{
|
return config.dungeonId;
|
}
|
return 0;
|
}
|
|
public List<HazyGrassNpcInfo> GetGrassNpcInfos(int mapId)
|
{
|
if (mapNpcs.ContainsKey(mapId))
|
{
|
return mapNpcs[mapId];
|
}
|
return null;
|
}
|
|
public int GetMapNpcCount(int npcId)
|
{
|
if (m_MapNpcCount.ContainsKey(npcId))
|
{
|
return m_MapNpcCount[npcId];
|
}
|
return 0;
|
}
|
|
public bool CanCollectClientNpc(int npcId)
|
{
|
if (ClientDungeonStageUtility.isClientDungeon
|
&& ClientDungeonStageUtility.clientMapId == Client_ReikiGrassMapID)
|
{
|
var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
|
if (config != null)
|
{
|
var collectCount = dungeonModel.GetDugneonNpcCollectCount(npcId);
|
var hintId = dungeonModel.GetDungeonHintId(config.dungeonId, config.lineId);
|
var hintConfig = DungeonHintConfig.Get(hintId);
|
if (hintConfig.NPC1ID.Length > 0 && hintConfig.NPC1ID[0] == npcId)
|
{
|
return collectCount < hintConfig.targetValue1[0];
|
}
|
else if (hintConfig.NPC2ID.Length > 0 && hintConfig.NPC2ID[0] == npcId)
|
{
|
return collectCount < hintConfig.targetValue2[0];
|
}
|
}
|
}
|
return true;
|
}
|
|
public void DisplayCollectErrorTip()
|
{
|
SysNotifyMgr.Instance.ShowTip("HazyGrassCollectError");
|
}
|
|
public void ReceivePackage(HA714_tagMCNPCCntList package)
|
{
|
if (package.MapID != ReikiGrassMapId
|
&& package.MapID != FairyGrassMapId)
|
{
|
return;
|
}
|
for (int i = 0; i < package.NPCInfoCnt; i++)
|
{
|
var data = package.NPCInfoList[i];
|
m_MapNpcCount[(int)data.NPCID] = (int)data.Cnt;
|
}
|
if (onMapNpcCountRefresh != null)
|
{
|
onMapNpcCountRefresh();
|
}
|
}
|
|
public void RefreshMapNpcCount(int npcId, int count)
|
{
|
m_MapNpcCount[npcId] = count;
|
if (onMapNpcCountRefresh != null)
|
{
|
onMapNpcCountRefresh();
|
}
|
}
|
|
public void RequestEnterClientDungeon()
|
{
|
var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
|
|
var mapId = GetClientMapId(hazyRegionModel.processingIncidentId);
|
|
MapTransferUtility.Instance.Clear();
|
ClientDungeonStageUtility.SetClientDungeon(true, (ushort)mapId);
|
ClientDungeonStageUtility.RequestStartClientDungeon(config.dungeonId, config.lineId);
|
CrossServerLogin.Instance.SetWaitForLoginCrossServerState(false);
|
StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
|
{
|
toMapId = mapId,
|
toLineId = 0,
|
needEmpty = true,
|
needLoadResource = true,
|
serverType = ServerType.Main,
|
isClientLoadMap = true
|
});
|
|
PlayerDatas.Instance.baseData.mainServerMapIdRecord = PlayerDatas.Instance.baseData.MapID;
|
PlayerDatas.Instance.baseData.MapID = (ushort)mapId;
|
var attackMode = new C030A_tagCChangeAttackMode();
|
attackMode.Mode = (byte)E_AttackMode.Peace;
|
GameNetSystem.Instance.PushPackage(attackMode, ServerType.Main);
|
}
|
|
public void RequestExitClientDungeon()
|
{
|
ClientDungeonStageUtility.SetClientDungeon(false, 0);
|
ClientDungeonStageUtility.RequestExitClientDungeon();
|
PlayerDatas.Instance.extersion.pkState = 0;
|
ModelCenter.Instance.GetModel<DungeonModel>().ResetBufData();
|
|
PlayerDatas.Instance.baseData.MapID = PlayerDatas.Instance.baseData.mainServerMapIdRecord;
|
StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
|
{
|
toMapId = PlayerDatas.Instance.baseData.MapID,
|
toLineId = 0,
|
needEmpty = true,
|
needLoadResource = true,
|
serverType = ServerType.Main,
|
isClientLoadMap = true
|
});
|
}
|
}
|
|
public struct HazyGrassNpcInfo
|
{
|
public int npcId;
|
public int refreshMinute;
|
}
|
}
|