using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class HazyRegionModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, Incident> m_Incidents = new Dictionary<int, Incident>();
|
Dictionary<int, AdventureInfo> m_AdventureInfos = new Dictionary<int, AdventureInfo>();
|
|
public int limitPoint { get; private set; }
|
public int point { get; private set; }
|
public int processingIncidentId { get; private set; }
|
public int adventureDialogueId { get; private set; }
|
public bool playing { get; private set; }
|
public bool satisfyFakeOpen { get; private set; }
|
public int hazyRegionOpenTimes { get; private set; }
|
public int fakeOpenTimes { get; private set; }
|
public bool isServerPrepare { get; private set; }
|
public bool requireIncidentAnimation { get; set; }
|
|
int m_SelectIncident;
|
public int selectIncident
|
{
|
get { return m_SelectIncident; }
|
set
|
{
|
if (m_SelectIncident != value)
|
{
|
m_SelectIncident = value;
|
if (selectIncidentRefresh != null)
|
{
|
selectIncidentRefresh();
|
}
|
}
|
}
|
}
|
|
public bool InFakeHazyRegion
|
{
|
get { return hazyRegionOpenTimes <= fakeOpenTimes; }
|
}
|
|
int cacheMapId = 0;
|
|
public event Action selectIncidentRefresh;
|
public event Action<int> onHazyRegionStateRefresh; //0-结束拜访 1-开始拜访 2-强制刷新
|
public event Action onHazyRegionIncidentRefresh;
|
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
HazyDemonKingModel hazyDemonKingModel { get { return ModelCenter.Instance.GetModel<HazyDemonKingModel>(); } }
|
HazyGrassModel hazyGrassModel { get { return ModelCenter.Instance.GetModel<HazyGrassModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
AdventureStage.Instance.onLoadAdventureStage += OnLoadAdventureStage;
|
AdventureStage.Instance.onExitAdventureStage += OnExitAdventureStage;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
isServerPrepare = false;
|
point = 0;
|
playing = false;
|
hazyRegionOpenTimes = 0;
|
m_Incidents.Clear();
|
m_AdventureInfos.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
isServerPrepare = true;
|
}
|
|
public override void UnInit()
|
{
|
StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
AdventureStage.Instance.onExitAdventureStage -= OnExitAdventureStage;
|
AdventureStage.Instance.onLoadAdventureStage -= OnLoadAdventureStage;
|
}
|
|
private void OnLoadAdventureStage()
|
{
|
WindowCenter.Instance.Open<HazyAdventureHintWin>();
|
}
|
|
private void OnExitAdventureStage()
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_TryOpenHazyRegionWin());
|
WindowCenter.Instance.Close<HazyAdventureHintWin>();
|
}
|
|
private void OnStageLoadFinish()
|
{
|
if (!(StageLoad.Instance.currentStage is DungeonStage))
|
{
|
cacheMapId = 0;
|
}
|
else
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
if (!MapUtility.IsDungeon(mapId))
|
{
|
if (IsIncidentDungeon(cacheMapId))
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_TryOpenHazyRegionWin());
|
}
|
}
|
cacheMapId = mapId;
|
}
|
}
|
|
IEnumerator Co_TryOpenHazyRegionWin()
|
{
|
yield return WaitingForSecondConst.WaitMS1000;
|
if (NewBieCenter.Instance.inGuiding ||
|
ModelCenter.Instance.GetModel<TreasureModel>().newGotShowing)
|
{
|
yield break;
|
}
|
if (WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<CrossServerWin>(false, 2);
|
}
|
}
|
|
void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("ImmortalDomainStrength");
|
limitPoint = int.Parse(funcConfig.Numerical1);
|
|
funcConfig = FuncConfigConfig.Get("FakeImmortalCount");
|
fakeOpenTimes = int.Parse(funcConfig.Numerical1);
|
}
|
|
public bool TryGetIncident(int id, out Incident incident)
|
{
|
return m_Incidents.TryGetValue(id, out incident);
|
}
|
|
public bool TryGotoIncident(int id, out int error)
|
{
|
error = 0;
|
var config = HazyRegionConfig.Get(id);
|
if (config == null)
|
{
|
return false;
|
}
|
if (!TryGotoDungeon(id, out error))
|
{
|
return false;
|
}
|
Incident incident;
|
if (TryGetIncident(id, out incident))
|
{
|
if (incident.state != IncidentState.Processing)
|
{
|
switch (incident.state)
|
{
|
case IncidentState.UnStart:
|
if (!InFakeHazyRegion && point < config.point)
|
{
|
error = 3;
|
return false;
|
}
|
break;
|
case IncidentState.Complete:
|
error = 4;
|
return false;
|
}
|
}
|
}
|
return true;
|
}
|
|
public bool TryGotoDungeon(int id, out int error)
|
{
|
error = 0;
|
if (CrossServerUtility.IsCrossServer())
|
{
|
error = 1;
|
return false;
|
}
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
if (MapUtility.IsDungeon(mapId))
|
{
|
error = 2;
|
return false;
|
}
|
if (AdventureStage.Instance.IsInAdventureStage)
|
{
|
error = 2;
|
return false;
|
}
|
return true;
|
}
|
|
public bool TryAddTimes()
|
{
|
var config = DailyQuestConfig.Get((int)DailyQuestType.HazyRegion);
|
var dailyQuestOpenTime = DailyQuestOpenTimeConfig.Get(config.RelatedID);
|
var limitTimes = dailyQuestOpenTime.DayTimes;
|
|
var totalTimes = dailyQuestModel.GetDailyQuestTotalTimes((int)DailyQuestType.HazyRegion);
|
var completedTimes = dailyQuestModel.GetDailyQuestCompletedTimes((int)DailyQuestType.HazyRegion);
|
var times = Mathf.Clamp(totalTimes - completedTimes, 0, limitTimes);
|
|
if (times >= limitTimes)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
public bool TryGetAdventureInfo(int id, out AdventureInfo adventureInfo)
|
{
|
return m_AdventureInfos.TryGetValue(id, out adventureInfo);
|
}
|
|
public ICollection<int> GetAllIncidents()
|
{
|
return m_Incidents.Keys;
|
}
|
|
public int GetIncidentId(int mapId, int lineId)
|
{
|
var configs = HazyRegionConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (config.dungeonId == mapId && config.lineId == lineId)
|
{
|
return config.id;
|
}
|
}
|
return 0;
|
}
|
|
public int GetAdventureNpcId()
|
{
|
var dialogueConfig = AdventureDialogueConfig.Get(adventureDialogueId);
|
if (dialogueConfig != null)
|
{
|
return dialogueConfig.npcId;
|
}
|
return 0;
|
}
|
|
public bool IsIncidentDungeon(int mapId)
|
{
|
if (mapId == 0)
|
{
|
return false;
|
}
|
if (mapId == HazyDemonKingModel.Client_MapID
|
|| mapId == HazyGrassModel.Client_FairyGrassMapID
|
|| mapId == HazyGrassModel.Client_ReikiGrassMapID)
|
{
|
return true;
|
}
|
var configs = HazyRegionConfig.GetValues();
|
foreach (var config in configs)
|
{
|
if (config.dungeonId == mapId)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsIncidentDungeon()
|
{
|
if (AdventureStage.Instance.IsInAdventureStage)
|
{
|
return true;
|
}
|
if (IsIncidentDungeon(PlayerDatas.Instance.baseData.MapID))
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public void DisplayErrorRemind(int error)
|
{
|
switch (error)
|
{
|
default:
|
break;
|
}
|
}
|
|
public void StartAdventureDialogue()
|
{
|
WindowCenter.Instance.Close<MainInterfaceWin>();
|
HazyRegionDialogueWin.adventureDialogueId = adventureDialogueId;
|
WindowCenter.Instance.Open<HazyRegionDialogueWin>();
|
}
|
|
void InitializeAdventure()
|
{
|
var config = HazyRegionConfig.Get(processingIncidentId);
|
if (config != null)
|
{
|
var gear = 0;
|
AdventureInfo adventureInfo;
|
if (TryGetAdventureInfo(processingIncidentId, out adventureInfo))
|
{
|
switch (config.lineId)
|
{
|
case 1:
|
gear = PlayerDatas.Instance.baseData.LV >= adventureInfo.condition ? adventureInfo.gear : 0;
|
break;
|
case 2:
|
gear = PlayerDatas.Instance.baseData.realmLevel >= adventureInfo.condition ? adventureInfo.gear : 0;
|
break;
|
case 3:
|
gear = PlayerDatas.Instance.baseData.FightPoint >= adventureInfo.condition ? adventureInfo.gear : 0;
|
break;
|
case 4:
|
gear = PlayerDatas.Instance.extersion.luckValue >= adventureInfo.condition ? adventureInfo.gear : 0;
|
break;
|
}
|
}
|
var dialogueConfig = AdventureDialogueConfig.Get(config.lineId, gear);
|
if (dialogueConfig != null)
|
{
|
adventureDialogueId = dialogueConfig.id;
|
}
|
}
|
}
|
|
public void SendGotoIncident(int id)
|
{
|
processingIncidentId = id;
|
|
var config = HazyRegionConfig.Get(id);
|
switch ((HazyRegionIncidentType)config.incidentType)
|
{
|
case HazyRegionIncidentType.Adventure:
|
InitializeAdventure();
|
|
WindowCenter.Instance.CloseAll(WindowCenter.CloseAllIgnoreType.BaseAndCustom);
|
|
AdventureStage.Instance.Enter();
|
|
Incident incident;
|
if(TryGetIncident(id,out incident))
|
{
|
if (incident.state == IncidentState.UnStart)
|
{
|
SendSwitchAdventureState(id, 2);
|
}
|
}
|
break;
|
case HazyRegionIncidentType.DemonKing:
|
if (InFakeHazyRegion)
|
{
|
hazyDemonKingModel.RequestEnterClientDungeon();
|
}
|
else
|
{
|
SendGotoIncidentDungeon(config);
|
}
|
break;
|
case HazyRegionIncidentType.FairyGrass:
|
case HazyRegionIncidentType.ReikiGrass:
|
if (InFakeHazyRegion)
|
{
|
hazyGrassModel.RequestEnterClientDungeon();
|
}
|
else
|
{
|
SendGotoIncidentDungeon(config);
|
}
|
break;
|
case HazyRegionIncidentType.Precious:
|
SendGotoIncidentDungeon(config);
|
break;
|
}
|
}
|
|
void SendGotoIncidentDungeon(HazyRegionConfig config)
|
{
|
if (config.crossServer == 1)
|
{
|
var pak = new CC105_tagCMEnterCrossServer();
|
pak.DataMapID = (uint)config.dungeonId;
|
pak.LineID = (ushort)config.lineId;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
else
|
{
|
dungeonModel.SingleChallenge(config.dungeonId, config.lineId);
|
}
|
}
|
|
public void SendBackHazyRegion()
|
{
|
var pak = new CA526_tagCMVisitFairyDomain();
|
pak.Type = 1;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void SendOpenHazyRegion()
|
{
|
var pak = new CA526_tagCMVisitFairyDomain();
|
pak.Type = 0;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void SendSwitchAdventureState(int id, int state)
|
{
|
var pak = new CA504_tagCMPlayerGetReward();
|
pak.RewardType = (byte)GotServerRewardType.Def_RewardType_FairyAdventuresAward;
|
pak.DataEx = (uint)id;
|
pak.DataExStr = state.ToString();
|
pak.DataExStrLen = (byte)Encoding.UTF8.GetBytes(pak.DataExStr).Length;
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public void ReceivePackage(HA306_tagMCFairyDomainInfo package)
|
{
|
var preplaying = playing;
|
|
playing = package.State == 1;
|
|
satisfyFakeOpen = package.State == 2;
|
|
hazyRegionOpenTimes = (int)package.VisitCnt;
|
|
point = package.Energy;
|
|
if (package.IsAll == 1)
|
{
|
m_Incidents.Clear();
|
}
|
|
for (int i = 0; i < package.Count; i++)
|
{
|
var data = package.InfoList[i];
|
m_Incidents[data.EventID] = new Incident()
|
{
|
id = data.EventID,
|
state = (IncidentState)data.EventState,
|
};
|
}
|
|
if (onHazyRegionIncidentRefresh != null)
|
{
|
onHazyRegionIncidentRefresh();
|
}
|
|
if (isServerPrepare)
|
{
|
if (preplaying != playing)
|
{
|
if (onHazyRegionStateRefresh != null)
|
{
|
onHazyRegionStateRefresh(playing ? 1 : 0);
|
}
|
}
|
}
|
else
|
{
|
if (onHazyRegionStateRefresh != null)
|
{
|
onHazyRegionStateRefresh(2);
|
}
|
}
|
}
|
|
public void ReceivePackage(HA307_tagMCFairyAdventuresInfo package)
|
{
|
m_AdventureInfos.Clear();
|
for (int i = 0; i < package.Cnt; i++)
|
{
|
var data = package.InfoList[i];
|
|
m_AdventureInfos[data.EventID] = new AdventureInfo()
|
{
|
gear = data.Gear,
|
condition = (int)data.Condition,
|
};
|
}
|
}
|
|
public enum IncidentState
|
{
|
UnStart = 1,
|
Processing = 2,
|
Complete = 3,
|
}
|
|
public struct Incident
|
{
|
public int id;
|
public IncidentState state;
|
}
|
|
public struct AdventureInfo
|
{
|
public int gear;
|
public int condition;
|
}
|
}
|
|
public enum HazyRegionIncidentType
|
{
|
Adventure,
|
Precious,
|
FairyGrass,
|
DemonKing,
|
ReikiGrass,
|
}
|
}
|