//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 06, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using System; namespace vnxbqy.UI { public class MapModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk, IMapInitOk { Dictionary worldMapAreas = new Dictionary(); Dictionary worldMapUnLockStates = new Dictionary(); Dictionary> localMapEventPoints = new Dictionary>(); Dictionary> mapFunctionNPCsToRefreshID = new Dictionary>(); Dictionary> mapCollectNPCsToRefreshID = new Dictionary>(); Dictionary> allMapLines = new Dictionary>(); List sortedMapEventPoints = new List(); List sortedHangUpPoints = new List(); List sortedMaps = new List(); TaskModel taskModel { get { return ModelCenter.Instance.GetModel(); } } int m_NewUnlockedMap = 0; public int newUnlockedMap { get { return m_NewUnlockedMap; } set { m_NewUnlockedMap = value; } } public int newUnlockMapTip { get { return LocalSave.GetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "NewUnLockMapsTip")); } set { LocalSave.SetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "NewUnLockMapsTip"), value); } } int m_SelectedMapEventPoint; public int selectedMapEventPoint { get { return this.m_SelectedMapEventPoint; } set { if (m_SelectedMapEventPoint != value) { m_SelectedMapEventPoint = value; if (selectMapEventPointEvent != null) { selectMapEventPointEvent(this.m_SelectedMapEventPoint); } } } } public int wannaLookLocalMap { get; set; } int mapUnLockIndex = 0; public event Action selectMapEventPointEvent; public event Action mapLinesUpdateEvent; public override void Init() { ParseWorldMaps(); ParseLocalMaps(); PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataChange; TaskModel.Event_TaskInformation += OnMainLineTaskInfoUpdate; } public override void UnInit() { PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataChange; TaskModel.Event_TaskInformation -= OnMainLineTaskInfoUpdate; } public void OnBeforePlayerDataInitialize() { mapUnLockIndex = 0; newUnlockedMap = 0; } public void OnAfterPlayerDataInitialize() { } public void OnPlayerLoginOk() { UpdateMapsUnlockedState(); newUnlockedMap = 0; } public void OnMapInitOk() { if (newUnlockMapTip == PlayerDatas.Instance.baseData.MapID) { newUnlockMapTip = 0; } } public void RequestMapTransport(int _mapId, int _lineId = 255) { if (PlayerDatas.Instance.extersion.pkState == 1) { SysNotifyMgr.Instance.ShowTip("PK_Leave"); return; } var currentMapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID); if (currentMapConfig.MapFBType != 0) { SysNotifyMgr.Instance.ShowTip("DungeonNoGO"); return; } if (!worldMapUnLockStates.ContainsKey(_mapId)) { return; } if (!worldMapUnLockStates[_mapId]) { SysNotifyMgr.Instance.ShowTip("Map_Delivery"); return; } InGameDownLoad.Instance.UnRegisterMapAssetDownLoadOk(); var map = MapConfig.Get(_mapId); var position = new Vector3(map.BornPoints[0].x, 0, map.BornPoints[0].y); MapTransferUtility.Send_WorldTransfer(_mapId, position, MapTransferType.WorldTransport, (byte)_lineId, 0); } public void RequestSelectedLine(int _lineId) { var hero = PlayerDatas.Instance.hero; if (hero != null) { hero.Behaviour.StopHandupAI(); hero.Behaviour.StopKillUntilDieAI(); } if (PlayerDatas.Instance.baseData.FBID != _lineId) { var sendInfo = new C010B_tagCChangeLine(); sendInfo.Line = (short)_lineId; GameNetSystem.Instance.SendInfo(sendInfo); } } public void RequestQueryMapLineState(int _mapId, byte[] _lineIds = null, bool _isAllLine = true) { var config = MapConfig.Get(_mapId); if (config.MapFBType == (int)MapType.OpenCountry) { var lineState = new CA003_tagPyGetLineState(); lineState.MapID = (uint)_mapId; GameNetSystem.Instance.SendInfo(lineState); } else { var lineState = new CA004_tagCGGetFBLinePlayerCnt(); lineState.MapID = (uint)_mapId; lineState.LineCount = (byte)(_isAllLine ? 0 : _lineIds.Length); if (_isAllLine) { lineState.LineIDList = new byte[0]; } GameNetSystem.Instance.SendInfo(lineState); } } public List GetMapLines(int _mapId) { var mapLines = new List(); if (allMapLines.ContainsKey(_mapId)) { mapLines.AddRange(allMapLines[_mapId]); //CheckActivityLine(_mapId, mapLines); mapLines.Sort(SortMaplines); return mapLines; } else { return null; } } public void UpdateMapLines(HA006_tagGCPyServerMapState _serverInfo) { for (int i = 0; i < _serverInfo.MapCount; i++) { var mapState = _serverInfo.MapStateList[i]; var mapId = (int)mapState.MapID; var lines = allMapLines[mapId] = new List(); for (int j = 0; j < mapState.LineCnt; j++) { var playerCount = (int)mapState.LineCurPlayerCntList[j]; var playerMaxCount = (int)mapState.LineMaxPlayerCntList[j]; lines.Add(new MapLine(mapId, j + 1, playerCount, playerMaxCount)); } if (mapLinesUpdateEvent != null) { mapLinesUpdateEvent(mapId); } } } public void UpdateDungeonMapLines(HA007_tagGCFBLinePlayerCnt _serverInfo) { var mapId = (int)_serverInfo.MapID; var lines = allMapLines[mapId] = new List(); for (int i = 0; i < _serverInfo.Count; i++) { var mapState = _serverInfo.FBLineInfoList[i]; lines.Add(new MapLine(mapId, mapState.FBLineID, mapState.PlayerCnt)); } if (mapLinesUpdateEvent != null) { mapLinesUpdateEvent(mapId); } } public bool TryGetWorldMapArea(int _id, out WorldMapArea _area) { return worldMapAreas.TryGetValue(_id, out _area); } public List GetWorldMapAreas() { return new List(worldMapAreas.Keys); } public List GetMapEventPoints(int dataMapId, int lineId) { var key = dataMapId * 100 + lineId; if (!localMapEventPoints.ContainsKey(key)) { key = dataMapId * 100; } if (localMapEventPoints.ContainsKey(key)) { return localMapEventPoints[key]; } else { return null; } } public List GetMapNPCRefreshIds(int _mapId) { if (mapFunctionNPCsToRefreshID.ContainsKey(_mapId)) { return mapFunctionNPCsToRefreshID[_mapId]; } return null; } public List GetMapCollectNPCRefreshIds(int _mapId) { if (mapCollectNPCsToRefreshID.ContainsKey(_mapId)) { return mapCollectNPCsToRefreshID[_mapId]; } return null; } public bool CanOpenLocalMapWin(int mapId) { var dataMapId = MapUtility.GetDataMapId(mapId); var lineId = MapUtility.GetLineId(); var mapResConfig = MapResourcesConfig.GetConfig(dataMapId, lineId); var config = MapConfig.Get(mapId); if (string.IsNullOrEmpty(mapResConfig.BigMap) || mapId == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON) { return false; } else { return true; } } //简单改为等级最近的点 public int GetRecommendHangPoint(int _mapId, int lineId) { var eventPoints = new List(GetMapEventPoints(_mapId, lineId)); for (int i = eventPoints.Count - 1; i >= 0; i--) { var config = MapEventPointConfig.Get(eventPoints[i]); if (config.IsShowInfo == 0) { eventPoints.RemoveAt(i); } } eventPoints.Sort((int a, int b) => { var configA = MapEventPointConfig.Get(a); var configB = MapEventPointConfig.Get(b); return configA.LowLV < configB.LowLV ? -1 : 1; }); var playerLevel = PlayerDatas.Instance.baseData.LV; var eventPointsPool = new List(); var levelMatchPointIndex = 0; for (int i = eventPoints.Count - 1; i >= 0; i--) { var config = MapEventPointConfig.Get(eventPoints[i]); if (playerLevel >= config.LowLV) { levelMatchPointIndex = i; break; } } return MapEventPointConfig.Get(eventPoints[levelMatchPointIndex]).Key; //if (levelMatchPointIndex < eventPoints.Count - 1) //{ // eventPointsPool.Add(eventPoints[levelMatchPointIndex + 1]); //} //eventPointsPool.Add(eventPoints[levelMatchPointIndex]); //if (levelMatchPointIndex > 0) //{ // eventPointsPool.Add(eventPoints[levelMatchPointIndex - 1]); //} //var recommendPoint = 0; //if (eventPointsPool.Count > 0) //{ // recommendPoint = eventPointsPool[eventPointsPool.Count - 1]; // for (int i = 0; i < eventPointsPool.Count; i++) // { // var config = MapEventPointConfig.Get(eventPointsPool[i]); // if (PlayerDatas.Instance.extersion.DEF >= config.Defense) // { // recommendPoint = eventPointsPool[i]; // break; // } // } //} //else //{ // var lowest = MapEventPointConfig.Get(eventPoints[0]); // if (playerLevel < lowest.LowLV) // { // recommendPoint = lowest.Key; // } // else // { // var hightest = MapEventPointConfig.Get(eventPoints[eventPoints.Count - 1]); // recommendPoint = hightest.Key; // } //} //return recommendPoint; } public int GetRecommendHangPoint() { var unLockedHangeUpPoints = new List(); for (int i = 0; i < sortedHangUpPoints.Count; i++) { var config = MapEventPointConfig.Get(sortedHangUpPoints[i]); if (IsMapUnlocked(MapUtility.GetMapId(config.DataMapID, config.LineId))) { unLockedHangeUpPoints.Add(sortedHangUpPoints[i]); } } var playerLevel = PlayerDatas.Instance.baseData.LV; var eventPointsPool = new List(); var levelMatchPointIndex = 0; for (int i = unLockedHangeUpPoints.Count - 1; i >= 0; i--) { var config = MapEventPointConfig.Get(unLockedHangeUpPoints[i]); if (playerLevel >= config.LowLV) { levelMatchPointIndex = i; break; } } if (levelMatchPointIndex < unLockedHangeUpPoints.Count - 1) { eventPointsPool.Add(unLockedHangeUpPoints[levelMatchPointIndex + 1]); } eventPointsPool.Add(unLockedHangeUpPoints[levelMatchPointIndex]); if (levelMatchPointIndex > 0) { eventPointsPool.Add(unLockedHangeUpPoints[levelMatchPointIndex - 1]); } var recommendPoint = 0; if (eventPointsPool.Count > 0) { recommendPoint = eventPointsPool[eventPointsPool.Count - 1]; for (int i = 0; i < eventPointsPool.Count; i++) { var config = MapEventPointConfig.Get(eventPointsPool[i]); if (PlayerDatas.Instance.extersion.DEF >= config.Defense) { recommendPoint = eventPointsPool[i]; break; } } } else { var lowest = MapEventPointConfig.Get(unLockedHangeUpPoints[0]); if (playerLevel < lowest.LowLV) { recommendPoint = lowest.Key; } else { var count = unLockedHangeUpPoints.Count; var hightest = MapEventPointConfig.Get(unLockedHangeUpPoints[count - 1]); recommendPoint = hightest.Key; } } return recommendPoint; } public bool IsMapUnlocked(int _mapId) { if (worldMapUnLockStates.ContainsKey(_mapId)) { return worldMapUnLockStates[_mapId]; } else { return false; } } private void UpdateMapsUnlockedState() { foreach (var mapId in worldMapAreas.Keys) { var canUnlock = CanMapUnlock(mapId); if (worldMapUnLockStates.ContainsKey(mapId) && !worldMapUnLockStates[mapId] && canUnlock && mapId != 10010 && !GeneralDefine.neutralBossMaps.Contains(mapId)) { newUnlockedMap = mapId; newUnlockMapTip = mapId; } worldMapUnLockStates[mapId] = canUnlock; } } private bool CanMapUnlock(int _mapId) { var config = MapConfig.Get(_mapId); if (config.LV != 0 && PlayerDatas.Instance.baseData.LV < config.LV) { return false; } if (config.MainTaskID != 0 && mapUnLockIndex < config.MainTaskID) { return false; } if (config.realmLevel != 0 && PlayerDatas.Instance.baseData.realmLevel < config.realmLevel) { return false; } return true; } private void OnPlayerDataChange(PlayerDataType refreshType) { switch (refreshType) { case PlayerDataType.LV: case PlayerDataType.RealmLevel: UpdateMapsUnlockedState(); break; } } private void OnMainLineTaskInfoUpdate(int _id, Dictionary> _Dic) { if (_id == 1) { if (taskModel._DicTaskInformation.ContainsKey(1) && taskModel._DicTaskInformation[1].ContainsKey("OpenMap")) { int.TryParse(taskModel._DicTaskInformation[1]["OpenMap"], out mapUnLockIndex); } else { mapUnLockIndex = 0; } UpdateMapsUnlockedState(); } } private void ParseWorldMaps() { var mapConfigs = MapConfig.GetValues(); foreach (var mapConfig in mapConfigs) { if (mapConfig.MapFBType == 0) { worldMapAreas.Add(mapConfig.MapID, new WorldMapArea(mapConfig.MapID, true)); sortedMaps.Add(mapConfig.MapID); } } sortedMaps.Sort( (int a, int b) => { var configA = MapConfig.Get(a); var configB = MapConfig.Get(b); return configA.LV > configB.LV ? -1 : 1; } ); } private void ParseLocalMaps() { var mapEventConfigs = MapEventPointConfig.GetValues(); foreach (var config in mapEventConfigs) { var mapId = MapUtility.GetMapId(config.DataMapID, config.LineId); var key = config.DataMapID * 100 + config.LineId; List eventPointIds = null; if (!localMapEventPoints.ContainsKey(key)) { localMapEventPoints[key] = eventPointIds = new List(); } else { eventPointIds = localMapEventPoints[key]; } eventPointIds.Add(config.Key); if (config.IsShowInfo == 1 && GeneralDefine.autoOnHookMap.Contains(mapId)) { sortedMapEventPoints.Add(config.Key); } } sortedMapEventPoints.Sort((int a, int b) => { var configA = MapEventPointConfig.Get(a); var configB = MapEventPointConfig.Get(b); return configA.LowLV < configB.LowLV ? -1 : 1; }); for (int i = 0; i < sortedMapEventPoints.Count; i++) { var eventPoint = sortedMapEventPoints[i]; var config = MapEventPointConfig.Get(eventPoint); var mapId = MapUtility.GetMapId(config.DataMapID, config.LineId); if (GeneralDefine.autoOnHookMap.Contains(mapId)) { sortedHangUpPoints.Add(eventPoint); } } var mapNpcConfigs = mapnpcConfig.GetValues(); foreach (var config in mapNpcConfigs) { var mapId = config.MapID; if (config.NPCID != 0) { if (config.NPCType == (int)E_NpcType.Func) { List npcRefreshIs; if (!mapFunctionNPCsToRefreshID.ContainsKey(mapId)) { mapFunctionNPCsToRefreshID[mapId] = npcRefreshIs = new List(); } else { npcRefreshIs = mapFunctionNPCsToRefreshID[mapId]; } npcRefreshIs.Add(config.RefreshID.ToString()); } else if (config.NPCType == (int)E_NpcType.Flag) { List npcRefreshIs; if (!mapCollectNPCsToRefreshID.ContainsKey(mapId)) { mapCollectNPCsToRefreshID[mapId] = npcRefreshIs = new List(); } else { npcRefreshIs = mapCollectNPCsToRefreshID[mapId]; } npcRefreshIs.Add(config.RefreshID.ToString()); } } } } int SortMaplines(MapLine x, MapLine y) { return x.lineIndex.CompareTo(y.lineIndex); } } public struct WorldMapArea { public int id; public bool unLocked; public WorldMapArea(int _id, bool _unLocked) { this.id = _id; this.unLocked = _unLocked; } } public struct MapLine { public int mapId; public int lineIndex; public int playerCount; public int playerMaxCount; public MapLine(int _mapId, int _lineIndex, int _playerCount, int _playerMaxCount) { this.mapId = _mapId; this.lineIndex = _lineIndex; this.playerCount = _playerCount; this.playerMaxCount = _playerMaxCount; } public MapLine(int _mapId, int _lineId, int _playerCount) { this.mapId = _mapId; this.lineIndex = _lineId; this.playerCount = _playerCount; this.playerMaxCount = 99999; } } }