//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, September 06, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using TableConfig; using System; namespace Snxxz.UI { public class MapModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk, IMapInitOk { int m_SelectedLocalMapEventPoint; public int selectedLocalMapEventPoint { get { return this.m_SelectedLocalMapEventPoint; } set { if (m_SelectedLocalMapEventPoint != value) { m_SelectedLocalMapEventPoint = value; if (selectLocalMapEventPointEvent != null) { selectLocalMapEventPointEvent(this.m_SelectedLocalMapEventPoint); } } } } Dictionary worldMapAreas = new Dictionary(); Dictionary worldMapUnLockStates = new Dictionary(); Dictionary> localMapEventPoints = new Dictionary>(); Dictionary> mapFunctionNPCsToRefreshID = new Dictionary>(); Dictionary> mapCollectNPCsToRefreshID = new Dictionary>(); Dictionary> mapLines = new Dictionary>(); List sortedMapEventPoints = new List(); List sortedHangUpPoints = new List(); List sortedMaps = new List(); int m_NewUnLockedMap = 0; public int newUnLockedMap { get { return m_NewUnLockedMap; } set { m_NewUnLockedMap = value; } } public int newUnLockMapsTip { get { return LocalSave.GetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "NewUnLockMapsTip")); } set { LocalSave.SetInt(StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "NewUnLockMapsTip"), value); } } public int wannaLookLocalMap { get; set; } int mapUnLockIndex = 0; PlayerTaskDatas taskModel { get { return ModelCenter.Instance.GetModel(); } } public event Action selectLocalMapEventPointEvent; public event Action mapLinesUpdateEvent; public override void Init() { ParseWorldMaps(); ParseLocalMaps(); PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnPlayerLevelChange; PlayerTaskDatas.Event_TaskInformation += OnMainLineTaskInfoUpdate; } public override void UnInit() { PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnPlayerLevelChange; PlayerTaskDatas.Event_TaskInformation -= OnMainLineTaskInfoUpdate; } public void OnBeforePlayerDataInitialize() { mapUnLockIndex = 0; newUnLockedMap = 0; } public void OnAfterPlayerDataInitialize() { } public void OnPlayerLoginOk() { UpdateMapsUnLockedState(); newUnLockedMap = 0; } public void OnMapInitOk() { if (newUnLockMapsTip == PlayerDatas.Instance.baseData.MapID) { newUnLockMapsTip = 0; } } public void RequestMapTransport(int _mapId, int _lineId = 255) { if (PlayerDatas.Instance.extersion.pkState == 1) { SysNotifyMgr.Instance.ShowTip("PK_Leave"); return; } var currentMapConfig = ConfigManager.Instance.GetTemplate(PlayerDatas.Instance.baseData.MapID); if (currentMapConfig.MapFBType != 0) { SysNotifyMgr.Instance.ShowTip("DungeonNoGO"); return; } if (worldMapUnLockStates.ContainsKey(_mapId)) { if (!worldMapUnLockStates[_mapId]) { SysNotifyMgr.Instance.ShowTip("Map_Delivery"); return; } } else { //未知的地图 return; } var map = ConfigManager.Instance.GetTemplate(_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 RequestFlyToEventPoint(int _eventPoint) { GA_Hero _hero = PlayerDatas.Instance.hero; if (_hero != null) { _hero.Behaviour.StopHandupAI(); _hero.Behaviour.StopKillUntilDieAI(); } var mapNPCConfig = ConfigManager.Instance.GetTemplate(_eventPoint); MapTransferUtility.Instance.MissionFlyTo(wannaLookLocalMap, mapNPCConfig.NPCID); } public void RequestSelectedLine(int _lineId) { GA_Hero _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, int _lineId = 0, bool _isAllLine = true) { var config = ConfigManager.Instance.GetTemplate(_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.IsAllLine = (byte)(_isAllLine ? 1 : 0); if (_isAllLine) { lineState.FBLineID = (byte)_lineId; } GameNetSystem.Instance.SendInfo(lineState); } } public List GetMapLines(int _mapId) { if (mapLines.ContainsKey(_mapId)) { return mapLines[_mapId]; } 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 = mapLines[mapId] = new List(); for (int j = 0; j < mapState.LineCnt; j++) { lines.Add(new MapLine(mapId, j + 1, (int)mapState.LineCurPlayerCntList[j], (int)mapState.LineMaxPlayerCntList[j])); } if (mapLinesUpdateEvent != null) { mapLinesUpdateEvent(mapId); } } } public void UpdateDungeonMapLines(HA007_tagGCFBLinePlayerCnt _serverInfo) { var mapId = (int)_serverInfo.MapID; var lines = mapLines[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 _mapId) { if (localMapEventPoints.ContainsKey(_mapId)) { return localMapEventPoints[_mapId]; } 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 int GetNextMap(int _mapId) { for (int i = sortedMaps.Count - 1; i >= 0; i--) { int mapId = sortedMaps[i]; if (_mapId == mapId) { var nextMap = sortedMaps[Mathf.Clamp(i - 1, 0, sortedMaps.Count - 1)]; return nextMap; } } return -1; } public int GetLatestUnLockHangUpMap() { for (int i = 0; i < sortedMaps.Count; i++) { int mapId = sortedMaps[i]; if (GeneralConfig.Instance.autoOnHookMap.Contains(mapId) && IsMapUnLocked(mapId)) { return mapId; } } return GeneralConfig.Instance.autoOnHookMap[GeneralConfig.Instance.autoOnHookMap.Count - 1]; } public int GetRecommendHangPoint(int _mapId) { var eventPoints = new List(GetMapEventPoints(_mapId)); for (int i = eventPoints.Count - 1; i >= 0; i--) { var config = ConfigManager.Instance.GetTemplate(eventPoints[i]); if (config.IsShowInfo == 0) { eventPoints.RemoveAt(i); } } eventPoints.Sort((int a, int b) => { var configA = ConfigManager.Instance.GetTemplate(a); var configB = ConfigManager.Instance.GetTemplate(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 = ConfigManager.Instance.GetTemplate(eventPoints[i]); if (playerLevel >= config.LowLV) { levelMatchPointIndex = i; break; } } 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 = ConfigManager.Instance.GetTemplate(eventPointsPool[i]); if (PlayerDatas.Instance.extersion.DEF >= config.Defense) { recommendPoint = eventPointsPool[i]; break; } } } else { var lowest = ConfigManager.Instance.GetTemplate(eventPoints[0]); if (playerLevel < lowest.LowLV) { recommendPoint = lowest.Key; } else { var hightest = ConfigManager.Instance.GetTemplate(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 = ConfigManager.Instance.GetTemplate(sortedHangUpPoints[i]); if (IsMapUnLocked(config.MapID)) { 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 = ConfigManager.Instance.GetTemplate(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 = ConfigManager.Instance.GetTemplate(eventPointsPool[i]); if (PlayerDatas.Instance.extersion.DEF >= config.Defense) { recommendPoint = eventPointsPool[i]; break; } } } else { var lowest = ConfigManager.Instance.GetTemplate(unLockedHangeUpPoints[0]); if (playerLevel < lowest.LowLV) { recommendPoint = lowest.Key; } else { var count = unLockedHangeUpPoints.Count; var hightest = ConfigManager.Instance.GetTemplate(unLockedHangeUpPoints[count - 1]); recommendPoint = hightest.Key; } } return recommendPoint; } public void ConfirmNewMap(int _mapId) { } 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 unLocked = CheckMapUnLocked(mapId); if (worldMapUnLockStates.ContainsKey(mapId) && !worldMapUnLockStates[mapId] && unLocked && mapId != 10010) { newUnLockedMap = mapId; newUnLockMapsTip = mapId; } worldMapUnLockStates[mapId] = unLocked; } } private bool CheckMapUnLocked(int _mapId) { var config = ConfigManager.Instance.GetTemplate(_mapId); var playerLevel = PlayerDatas.Instance.baseData.LV; if (playerLevel >= config.LV) { if (config.MainTaskID > 0) { return mapUnLockIndex >= config.MainTaskID; } else { return true; } } else { return false; } } private void OnPlayerLevelChange(PlayerDataRefresh refreshType) { switch (refreshType) { case PlayerDataRefresh.LV: 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 = ConfigManager.Instance.GetAllValues(); foreach (var mapConfig in mapConfigs) { if (mapConfig.MapFBType == 0) { worldMapAreas.Add(mapConfig.MapID, new WorldMapArea(mapConfig.MapID, true, WorldMapCamp.Neutral)); sortedMaps.Add(mapConfig.MapID); } } sortedMaps.Sort( (int a, int b) => { var configA = ConfigManager.Instance.GetTemplate(a); var configB = ConfigManager.Instance.GetTemplate(b); return configA.LV > configB.LV ? -1 : 1; } ); } private void ParseLocalMaps() { var mapEventConfigs = ConfigManager.Instance.GetAllValues(); foreach (var config in mapEventConfigs) { var mapId = config.MapID; List eventPointIds = null; if (!localMapEventPoints.ContainsKey(mapId)) { localMapEventPoints[mapId] = eventPointIds = new List(); } else { eventPointIds = localMapEventPoints[mapId]; } eventPointIds.Add(config.Key); if (config.IsShowInfo == 1 && GeneralConfig.Instance.autoOnHookMap.Contains(config.MapID)) { sortedMapEventPoints.Add(config.Key); } } sortedMapEventPoints.Sort((int a, int b) => { var configA = ConfigManager.Instance.GetTemplate(a); var configB = ConfigManager.Instance.GetTemplate(b); return configA.LowLV < configB.LowLV ? -1 : 1; }); for (int i = 0; i < sortedMapEventPoints.Count; i++) { var eventPoint = sortedMapEventPoints[i]; var config = ConfigManager.Instance.GetTemplate(eventPoint); if (GeneralConfig.Instance.autoOnHookMap.Contains(config.MapID)) { sortedHangUpPoints.Add(eventPoint); } } var mapNpcConfigs = ConfigManager.Instance.GetAllValues(); foreach (var config in mapNpcConfigs) { var mapId = config.MapID; 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()); } } } } public struct WorldMapArea { public int id; public bool unLocked; public WorldMapCamp camp; public WorldMapArea(int _id, bool _unLocked, WorldMapCamp _camp) { this.id = _id; this.unLocked = _unLocked; this.camp = _camp; } } 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; } } }