少年修仙传客户端代码仓库
client_linchunjie
2019-04-16 6dde220aad8d90ef32128c5de178db8c3d9c3e26
System/HazyRegion/HazyGrassModel.cs
@@ -6,6 +6,9 @@
{
    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;
@@ -13,11 +16,10 @@
        public bool IsInDungeon { get; private set; }
        public int grassRefreshSeconds { get; private set; }
        public DateTime grassBornTime { 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()
        {
@@ -41,12 +43,35 @@
        void ParseConfig()
        {
            grassRefreshSeconds = 20;
            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))
@@ -89,14 +114,83 @@
            return 0;
        }
        public void RefreshGrassBornTime()
        public int GetGrassMapId(int incidentId)
        {
            var config = HazyRegionConfig.Get(incidentId);
            if (config != null)
            {
                return config.dungeonId;
            }
            return 0;
        }
        public void RefreshGrassBornTime(DateTime _time)
        public List<HazyGrassNpcInfo> GetGrassNpcInfos(int mapId)
        {
            grassBornTime = _time;
            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 CanCollectNpc(int npcId)
        {
            var collectCount = dungeonModel.GetDugneonNpcCollectCount(npcId);
            if (ClientDungeonStageUtility.isClientDungeon
                && ClientDungeonStageUtility.clientMapId == Client_ReikiGrassMapID)
            {
                var config = HazyRegionConfig.Get(hazyRegionModel.processingIncidentId);
                if (config != null)
                {
                    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 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()
@@ -145,5 +239,11 @@
            });
        }
    }
    public struct HazyGrassNpcInfo
    {
        public int npcId;
        public int refreshMinute;
    }
}