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 readonly List<HazyRegionIncidentType> incidentTypesSort = new List<HazyRegionIncidentType>()
|
{
|
HazyRegionIncidentType.Adventure,
|
HazyRegionIncidentType.Precious,
|
HazyRegionIncidentType.FairyGrass,
|
HazyRegionIncidentType.ReikiGrass,
|
HazyRegionIncidentType.DemonKing,
|
};
|
|
public readonly List<IncidentState> incidentSelectSort = new List<IncidentState>()
|
{
|
IncidentState.Processing,
|
IncidentState.UnStart,
|
IncidentState.Complete,
|
};
|
|
public const int PRECIOUS_CLIENTDATAMAP = 31190;
|
|
public int limitPoint { get; private set; }
|
public int point { get; private set; }
|
|
public int processingIncidentId
|
{
|
get
|
{
|
return LocalSave.GetInt(StringUtility.Contact("HazyIncidentId", PlayerDatas.Instance.PlayerId));
|
}
|
private set
|
{
|
LocalSave.SetInt(StringUtility.Contact("HazyIncidentId", PlayerDatas.Instance.PlayerId), value);
|
}
|
}
|
|
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; }
|
public bool incidentDirty { get; set; }
|
public bool auto;
|
public int openActviePoint { get; private set; }
|
public int autoOpenLimitLevel { get; private set; }
|
int autoOpenLimitTimes = 0;
|
public int autoOpenLimitLV = 0;
|
|
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 !FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HazyRegion);
|
}
|
}
|
|
public readonly Redpoint redpointBase = new Redpoint(39);
|
public readonly Redpoint redpoint = new Redpoint(39, 3901);
|
readonly Redpoint entranceRedpoint = new Redpoint(3901, 390101);
|
readonly Redpoint incidentRedpoint = new Redpoint(3901, 390102);
|
|
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>(); } }
|
TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
CrossServerOneVsOneModel crossServerOneVsOneModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
AdventureStage.Instance.onLoadAdventureStage += OnLoadAdventureStage;
|
AdventureStage.Instance.onExitAdventureStage += OnExitAdventureStage;
|
findPreciousModel.bossInfoUpdateEvent += BossInfoUpdateEvent;
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState += RefreshDailyQuestState;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
isServerPrepare = false;
|
point = 0;
|
playing = false;
|
hazyRegionOpenTimes = 0;
|
m_Incidents.Clear();
|
m_AdventureInfos.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
auto = false;//LocalSave.GetBool("HazyRegionAutoSetting" + PlayerDatas.Instance.PlayerId, false);
|
isServerPrepare = true;
|
|
if (AdventureStage.Instance.IsInAdventureStage)
|
{
|
ClientDungeonStageUtility.RequestStartClientDungeon(0, 0, (dungeonInfo, isOk) =>
|
{
|
if (!isOk)
|
{
|
AdventureStage.Instance.Exit();
|
}
|
});
|
}
|
|
UpdateRedpoint();
|
}
|
|
public override void UnInit()
|
{
|
StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish;
|
AdventureStage.Instance.onExitAdventureStage -= OnExitAdventureStage;
|
AdventureStage.Instance.onLoadAdventureStage -= OnLoadAdventureStage;
|
findPreciousModel.bossInfoUpdateEvent -= BossInfoUpdateEvent;
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
|
}
|
|
private void OnLoadAdventureStage()
|
{
|
//WindowCenter.Instance.Open<HazyAdventureHintWin>();
|
var dialogueConfig = AdventureDialogueConfig.Get(adventureDialogueId);
|
BossShowModel.Instance.Start(0, dialogueConfig.npcId);
|
}
|
|
private void OnExitAdventureStage()
|
{
|
if (PlayerDatas.Instance.baseData.LV > autoOpenLimitLevel)
|
{
|
if (hazyRegionOpenTimes > autoOpenLimitTimes || !IsAllIncidentComplete())
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_TryOpenHazyRegionWin());
|
}
|
}
|
//WindowCenter.Instance.Close<HazyAdventureHintWin>();
|
//taskModel.AutomaticTripToTask(taskModel.currentMission);
|
}
|
|
private void OnStageLoadFinish()
|
{
|
if (!(StageLoad.Instance.currentStage is DungeonStage))
|
{
|
cacheMapId = 0;
|
}
|
else
|
{
|
var mapId = PlayerDatas.Instance.baseData.MapID;
|
if (!MapUtility.IsDungeon(mapId))
|
{
|
if (PlayerDatas.Instance.baseData.LV > autoOpenLimitLevel
|
&& IsIncidentDungeon(cacheMapId))
|
{
|
if (hazyRegionOpenTimes > autoOpenLimitTimes || !IsAllIncidentComplete())
|
{
|
SnxxzGame.Instance.StartCoroutine(Co_TryOpenHazyRegionWin());
|
}
|
}
|
}
|
cacheMapId = mapId;
|
}
|
}
|
|
private void BossInfoUpdateEvent(int obj)
|
{
|
if (isServerPrepare)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void RefreshDailyQuestState()
|
{
|
if (isServerPrepare)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
|
|
IEnumerator Co_TryOpenHazyRegionWin()
|
{
|
yield return WaitingForSecondConst.WaitMS1000;
|
if (NewBieCenter.Instance.inGuiding ||
|
ModelCenter.Instance.GetModel<TreasureModel>().newGotShowing ||
|
InFakeHazyRegion)
|
{
|
yield break;
|
}
|
if (WindowCenter.Instance.IsOpen<MainInterfaceWin>())
|
{
|
WindowCenter.Instance.Open<HazyRegionFrameWin>();
|
}
|
}
|
|
void ParseConfig()
|
{
|
var funcConfig = FuncConfigConfig.Get("ImmortalDomainStrength");
|
limitPoint = int.Parse(funcConfig.Numerical1);
|
|
funcConfig = FuncConfigConfig.Get("FakeImmortalCount");
|
fakeOpenTimes = int.Parse(funcConfig.Numerical1);
|
|
funcConfig = FuncConfigConfig.Get("ImmortalDomainActivePoint");
|
openActviePoint = int.Parse(funcConfig.Numerical2);
|
|
funcConfig = FuncConfigConfig.Get("HazyRegionAutoOpen");
|
autoOpenLimitLevel = int.Parse(funcConfig.Numerical1);
|
int.TryParse(funcConfig.Numerical2, out autoOpenLimitTimes);
|
int.TryParse(funcConfig.Numerical3, out autoOpenLimitLV);
|
|
|
}
|
|
public bool TryGetIncident(int id, out Incident incident)
|
{
|
return m_Incidents.TryGetValue(id, out incident);
|
}
|
|
public bool TryGotoIncident(int id, bool careDungeon, out int error)
|
{
|
error = 0;
|
var config = HazyRegionConfig.Get(id);
|
if (config == null)
|
{
|
return false;
|
}
|
var questState = dailyQuestModel.GetQuestState((int)DailyQuestType.HazyRegion);
|
if (questState == DailyQuestModel.DailyQuestState.OutTime)
|
{
|
error = 6;
|
return false;
|
}
|
if (careDungeon && !TryGotoDungeon(id, out error))
|
{
|
return false;
|
}
|
if (PlayerDatas.Instance.extersion.bossState == 1)
|
{
|
error = 7;
|
return false;
|
}
|
Incident incident;
|
if (TryGetIncident(id, out incident))
|
{
|
switch ((HazyRegionIncidentType)config.incidentType)
|
{
|
case HazyRegionIncidentType.DemonKing:
|
if (config.dungeonType != 0 && !findPreciousModel.IsBossAlive(config.npcId))
|
{
|
error = 5;
|
return false;
|
}
|
break;
|
}
|
|
if (incident.state != IncidentState.Processing)
|
{
|
switch (incident.state)
|
{
|
case IncidentState.UnStart:
|
//if (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;
|
}
|
if (crossServerOneVsOneModel.IsMatching)
|
{
|
error = 8;
|
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.CLIENTDATAMAP
|
|| mapId == HazyGrassModel.FAIRY_CLIENTDATAMAP
|
|| mapId == HazyGrassModel.REIKI_CLIENTDATAMAP)
|
{
|
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 bool HasIncidentByMapID(int MapID)
|
{
|
foreach (var id in m_Incidents.Keys)
|
{
|
if (HazyRegionConfig.Get(id).dungeonId == MapID)
|
{
|
|
Incident incident;
|
TryGetIncident(id, out incident);
|
if (incident.state != IncidentState.Complete)
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsAllIncidentComplete()
|
{
|
var allComplete = true;
|
foreach (var id in m_Incidents.Keys)
|
{
|
Incident incident;
|
if (TryGetIncident(id, out incident))
|
{
|
if (incident.state != IncidentState.Complete)
|
{
|
allComplete = false;
|
break;
|
}
|
}
|
}
|
return allComplete;
|
}
|
|
public void DisplayErrorRemind(int error)
|
{
|
switch (error)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowTip("CrossMap10");
|
break;
|
case 2:
|
SysNotifyMgr.Instance.ShowTip("InDungeon_CantGo");
|
break;
|
case 3:
|
SysNotifyMgr.Instance.ShowTip("EnterHazyIncidentError_3");
|
break;
|
case 4:
|
SysNotifyMgr.Instance.ShowTip("EnterHazyIncidentError_4");
|
break;
|
case 5:
|
SysNotifyMgr.Instance.ShowTip("EnterHazyIncidentError_5");
|
break;
|
case 6:
|
DailyQuestOpenTime dailyQuestOpenTime;
|
if (dailyQuestModel.TryGetOpenTime((int)DailyQuestType.HazyRegion, out dailyQuestOpenTime))
|
{
|
HourMinute hourMinute;
|
if (dailyQuestOpenTime.TryGetTodayNearestOpenTime(out hourMinute))
|
{
|
SysNotifyMgr.Instance.ShowTip("OpenHazyRegionError_1",
|
hourMinute.hourBegin.ToString("D2"),
|
hourMinute.hourEnd.ToString("D2"));
|
}
|
}
|
break;
|
case 7:
|
SysNotifyMgr.Instance.ShowTip("Boss_Leave");
|
break;
|
case 8:
|
SysNotifyMgr.Instance.ShowTip("CrossOneVsOneMatching");
|
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 >= (ulong)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:
|
ClientDungeonStageUtility.RequestStartClientDungeon(0, 0, (dungeonInfo, isOk) =>
|
{
|
InitializeAdventure();
|
|
WindowJumpMgr.Instance.ClearJumpData();
|
WindowCenter.Instance.CloseAll(WindowCenter.CloseAllIgnoreType.BaseAndCustom);
|
|
var hero = PlayerDatas.Instance.hero;
|
if (hero != null)
|
{
|
hero.StopAll();
|
}
|
|
AdventureStage.Instance.Enter();
|
Incident incident;
|
if (TryGetIncident(id, out incident))
|
{
|
if (incident.state == IncidentState.UnStart)
|
{
|
SendSwitchAdventureState(id, 2);
|
}
|
}
|
});
|
break;
|
case HazyRegionIncidentType.DemonKing:
|
if (config.dungeonType == 0)
|
{
|
hazyDemonKingModel.RequestEnterClientDungeon();
|
}
|
else
|
{
|
SendGotoIncidentDungeon(config);
|
}
|
break;
|
case HazyRegionIncidentType.FairyGrass:
|
case HazyRegionIncidentType.ReikiGrass:
|
if (config.dungeonType == 0)
|
{
|
hazyGrassModel.RequestEnterClientDungeon();
|
}
|
else
|
{
|
SendGotoIncidentDungeon(config);
|
}
|
break;
|
case HazyRegionIncidentType.Precious:
|
//BossShowModel.Instance.reqDungeonLineId = 0;
|
//ClientDungeonStageUtility.GotoNormalClientDungeon(config.dungeonId, config.dungeonId, config.lineId);
|
break;
|
}
|
}
|
|
void SendGotoIncidentDungeon(HazyRegionConfig config)
|
{
|
if (config.dungeonType == 2)
|
{
|
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;
|
if (playing)
|
{
|
GA_Hero.startAutoHazyRegion = true;
|
}
|
satisfyFakeOpen = package.State == 2;
|
|
hazyRegionOpenTimes = (int)package.VisitCnt;
|
|
point = package.Energy;
|
|
if (package.IsAll == 1)
|
{
|
m_Incidents.Clear();
|
}
|
|
if (package.State != 1)
|
{
|
hazyGrassModel.DeleteLocalSaveKey();
|
}
|
|
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);
|
}
|
}
|
|
if (isServerPrepare)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
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,
|
};
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
var satisfyEntrance = false;
|
var satisfyIncident = false;
|
if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HazyRegion))
|
{
|
var totalTimes = dailyQuestModel.GetDailyQuestTotalTimes((int)DailyQuestType.HazyRegion);
|
var completedTimes = dailyQuestModel.GetDailyQuestCompletedTimes((int)DailyQuestType.HazyRegion);
|
satisfyEntrance = totalTimes > completedTimes;
|
|
if (playing)
|
{
|
var error = 0;
|
foreach (var id in m_Incidents.Keys)
|
{
|
if (TryGotoIncident(id, false, out error))
|
{
|
satisfyIncident = true;
|
break;
|
}
|
}
|
}
|
}
|
|
entranceRedpoint.state = satisfyEntrance ? RedPointState.Simple : RedPointState.None;
|
incidentRedpoint.state = satisfyIncident ? RedPointState.Simple : RedPointState.None;
|
}
|
|
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,
|
}
|
}
|
|