//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Thursday, December 21, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
public class DemonJarWin : Window
|
{
|
public static bool guideChallenge = false;
|
|
[SerializeField] CyclicScroll m_Bosses;
|
[SerializeField] Text m_RewardDescription;
|
[SerializeField] BossIntroduceBehaviour m_BossIntroduce;
|
[SerializeField] Button m_KillRecord;
|
[SerializeField] Text m_Times;
|
[SerializeField] Button m_BuyTimes;
|
[SerializeField] TimerBehaviour m_CountRemainTime;
|
[SerializeField] Button m_Goto;
|
[SerializeField] Transform m_SurpassLevel;
|
[SerializeField] RectTransform m_NoDamageTip;
|
[SerializeField] ToggleButton m_Subscribe;
|
|
[SerializeField] RectTransform m_ContainerDouble;
|
[SerializeField] Button m_BtnAutoAndDouble;
|
[SerializeField] Text m_Count;
|
[SerializeField] Text m_CountOver;
|
|
DemonJarModel model { get { return ModelCenter.Instance.GetModel<DemonJarModel>(); } }
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
MapModel mapModel { get { return ModelCenter.Instance.GetModel<MapModel>(); } }
|
|
int enterTimes = 0;
|
int totalTimes = 0;
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
m_Goto.AddListener(GotoKillBoss);
|
m_KillRecord.AddListener(ShowSkillRecord);
|
m_Subscribe.AddListener(SwitchSubscribeBoss);
|
m_BuyTimes.AddListener(BuyTimes);
|
m_BtnAutoAndDouble.AddListener(OpenAutoDuoubleSettingWin);
|
}
|
|
protected override void OnPreOpen()
|
{
|
totalTimes = dungeonModel.GetTotalTimes(DemonJarModel.DATA_MAPID);
|
enterTimes = dungeonModel.GetEnterTimes(DemonJarModel.DATA_MAPID);
|
m_Times.text = StringUtility.Contact(totalTimes - enterTimes, "/", DemonJarModel.TOTALTIME_LIMIT);
|
m_Times.color = totalTimes - enterTimes == 0 ? UIHelper.GetUIColor(TextColType.Red) : UIHelper.GetUIColor(TextColType.DarkGreen);
|
OnRemaintimeUpdate(DemonJarModel.DATA_MAPID);
|
//mapModel.RequestQueryMapLineState(DemonJarModel.DATA_MAPID);
|
}
|
|
protected override void OnAfterOpen()
|
{
|
model.bossSelectedEvent += OnBossSelected;
|
findPreciousModel.bossSubscribeChangeEvent += OnSubscribeBoss;
|
dungeonModel.dungeonRecordChangeEvent += OnRemaintimeUpdate;
|
dungeonModel.countRemainTimeChangeEvent += OnRemaintimeUpdate;
|
dungeonModel.updateDungeonBuyCnt += OnBuyTimesOk;
|
}
|
|
protected override void OnPreClose()
|
{
|
guideChallenge = false;
|
model.bossSelectedEvent -= OnBossSelected;
|
findPreciousModel.bossSubscribeChangeEvent -= OnSubscribeBoss;
|
dungeonModel.dungeonRecordChangeEvent -= OnRemaintimeUpdate;
|
dungeonModel.countRemainTimeChangeEvent -= OnRemaintimeUpdate;
|
dungeonModel.updateDungeonBuyCnt -= OnBuyTimesOk;
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
ShowBosses();
|
model.lockSelectedBoss = false;
|
|
CheckTaskGuide();
|
CheckAchievementGuideByTimes();
|
CheckAchievementGuideKillBoss();
|
}
|
#endregion
|
|
private void ShowBosses()
|
{
|
var bosses = new List<int>();
|
bosses.AddRange(model.GetDemonJarBosses());
|
|
if (!model.lockSelectedBoss)
|
{
|
var targetBoss = model.GetRecommendBoss();
|
model.selectedBoss = targetBoss;
|
}
|
|
DemonJarBossData bossData;
|
model.TryGetBossData(model.selectedBoss, out bossData);
|
|
m_BossIntroduce.Display(model.selectedBoss, true);
|
m_Bosses.Init(bosses);
|
m_Bosses.MoveToCenter(bosses.IndexOf(model.selectedBoss));
|
|
DisplayGotoKillButton(model.selectedBoss);
|
DisplaySubscribe(model.selectedBoss);
|
DisplayTip(model.selectedBoss);
|
}
|
|
private void ShowSkillRecord()
|
{
|
findPreciousModel.ViewKillRecordsBoss = model.selectedBoss;
|
WindowCenter.Instance.Open<DemonJarKillRecordWin>();
|
}
|
|
private void BuyTimes()
|
{
|
if ((totalTimes - enterTimes) >= DemonJarModel.TOTALTIME_LIMIT)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("DemonJar18"));
|
}
|
else
|
{
|
dungeonModel.currentDungeon = new Dungeon(DemonJarModel.DATA_MAPID, 0);
|
WindowCenter.Instance.Open<DungeonBuyTimesWin>();
|
}
|
}
|
|
private void SwitchSubscribeBoss()
|
{
|
if (findPreciousModel.IsBossSubscribed(model.selectedBoss))
|
{
|
findPreciousModel.RequestDeSubscribeBoss(model.selectedBoss);
|
}
|
else
|
{
|
findPreciousModel.RequestSubscribeBoss(model.selectedBoss, false);
|
}
|
}
|
|
private void OnSubscribeBoss(int _bossId)
|
{
|
m_Subscribe.isOn = findPreciousModel.IsBossSubscribed(model.selectedBoss);
|
}
|
|
private void OpenAutoDuoubleSettingWin()
|
{
|
var dataMapId = dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID);
|
if (dataMapId == DemonJarModel.DATA_MAPID)
|
{
|
SysNotifyMgr.Instance.ShowTip("CantChangeInDemon");
|
}
|
else
|
{
|
WindowCenter.Instance.Open<DemonJarAutoDoubleSettingWin>();
|
}
|
}
|
|
private void GotoKillBoss()
|
{
|
var error = 0;
|
if (TestEnterDungeon(out error))
|
{
|
var config = DemonJarConfig.Get(model.selectedBoss);
|
//if (config.CanEnterTimes == 1)
|
//{
|
// ClientDungeonStageUtility.GotoNormalClientDungeon(
|
// DemonJarModel.SINGLEMAPID,
|
// DemonJarModel.SINGLEMAPID,
|
// config.LineID);
|
//}
|
//else
|
//{
|
dungeonModel.SingleChallenge(DemonJarModel.DATA_MAPID, config.LineID);
|
|
var mapId = MapUtility.GetMapId(DemonJarModel.DATA_MAPID, config.LineID);
|
LoadingWin.targetMapResId = MapUtility.GetMapResourceId(mapId, config.LineID);
|
WindowCenter.Instance.Open<LoadingWin>();
|
Clock.AlarmAfter(5f, () =>
|
{
|
if (!StageLoad.Instance.isLoading)
|
{
|
WindowCenter.Instance.Close<LoadingWin>();
|
}
|
});
|
//}
|
}
|
else
|
{
|
|
switch (error)
|
{
|
case 1:
|
var npcConfig = NPCConfig.Get(model.selectedBoss);
|
SysNotifyMgr.Instance.ShowTip("BossRealmHint3", npcConfig.NPCLV);
|
break;
|
case 2:
|
dungeonModel.currentDungeon = new Dungeon(DemonJarModel.DATA_MAPID, 0);
|
WindowCenter.Instance.Open<DungeonBuyTimesWin>();
|
break;
|
case 3:
|
SysNotifyMgr.Instance.ShowTip("DemonJar_Text1");
|
break;
|
case 4:
|
dungeonModel.currentDungeon = new Dungeon(DemonJarModel.DATA_MAPID, 0);
|
WindowCenter.Instance.Open<DungeonBuyTimesWin>();
|
break;
|
case 5:
|
ConfirmCancel.ToggleConfirmCancel(
|
Language.Get("Mail101"),
|
Language.Get("DemonJarDoubleTip"),
|
Language.Get("DontRemindAgain"),
|
(bool _ok, bool _toggle) =>
|
{
|
if (_ok)
|
{
|
var demonJarConfig = DemonJarConfig.Get(model.selectedBoss);
|
dungeonModel.SingleChallenge(DemonJarModel.DATA_MAPID, demonJarConfig.LineID);
|
}
|
|
if (_toggle)
|
{
|
model.doubleToKillLowerBossHint = false;
|
}
|
});
|
break;
|
case 6:
|
SysNotifyMgr.Instance.ShowTip("BossRealmHint2", RealmConfig.Get(NPCConfig.Get(model.selectedBoss).Realm).LvLarge);
|
break;
|
case 7:
|
SysNotifyMgr.Instance.ShowTip("DungeonNoGO");
|
break;
|
}
|
}
|
|
}
|
|
private void OnRemaintimeUpdate(int _mapId)
|
{
|
if (DemonJarModel.DATA_MAPID != _mapId)
|
{
|
return;
|
}
|
|
totalTimes = dungeonModel.GetTotalTimes(DemonJarModel.DATA_MAPID);
|
enterTimes = dungeonModel.GetEnterTimes(DemonJarModel.DATA_MAPID);
|
|
m_Times.text = StringUtility.Contact(totalTimes - enterTimes, "/", DemonJarModel.TOTALTIME_LIMIT);
|
m_Times.color = totalTimes - enterTimes == 0 ? UIHelper.GetUIColor(TextColType.Red) : UIHelper.GetUIColor(TextColType.DarkGreen);
|
if ((totalTimes - enterTimes) < DemonJarModel.TOTALTIME_LIMIT)
|
{
|
DateTime endTime;
|
if (dungeonModel.TryGetCountRemainTime(DemonJarModel.DATA_MAPID, out endTime))
|
{
|
m_CountRemainTime.SetActive(true);
|
m_CountRemainTime.Begin((int)(endTime - TimeUtility.ServerNow).TotalSeconds);
|
m_Count.text = Language.Get("FindPrecious_7", dungeonModel.GetCoverCount(DemonJarModel.DATA_MAPID));
|
}
|
else
|
{
|
m_CountRemainTime.SetActive(false);
|
}
|
}
|
else
|
{
|
m_CountRemainTime.SetActive(false);
|
}
|
m_CountOver.SetActive(false);//(dungeonModel.GetCoverCount(DemonJarModel.DATA_MAPID) == 0);
|
|
}
|
|
private void OnBuyTimesOk()
|
{
|
totalTimes = dungeonModel.GetTotalTimes(DemonJarModel.DATA_MAPID);
|
enterTimes = dungeonModel.GetEnterTimes(DemonJarModel.DATA_MAPID);
|
|
m_Times.text = StringUtility.Contact(totalTimes - enterTimes, "/", DemonJarModel.TOTALTIME_LIMIT);
|
m_Times.color = totalTimes - enterTimes == 0 ? UIHelper.GetUIColor(TextColType.Red) : UIHelper.GetUIColor(TextColType.DarkGreen);
|
if (totalTimes - enterTimes >= DemonJarModel.TOTALTIME_LIMIT)
|
{
|
m_CountRemainTime.SetActive(false);
|
}
|
}
|
|
private bool TestEnterDungeon(out int _error)
|
{
|
if (!model.IsBossUnlock(model.selectedBoss))
|
{
|
if (!model.IsPlayerRealmEnough(model.selectedBoss))
|
{
|
_error = 6;
|
return false;
|
}
|
|
if (!model.IsPlayerLevelEnough(model.selectedBoss))
|
{
|
_error = 1;
|
return false;
|
}
|
}
|
|
if (enterTimes >= totalTimes)
|
{
|
_error = 2;
|
return false;
|
}
|
|
if (!findPreciousModel.IsBossAlive(model.selectedBoss))
|
{
|
_error = 3;
|
return false;
|
}
|
|
var config = DemonJarConfig.Get(model.selectedBoss);
|
if (config.CanEnterTimes == 0 && model.isDoubleAward && totalTimes - enterTimes < 2)
|
{
|
_error = 4;
|
return false;
|
}
|
|
if (model.doubleToKillLowerBossHint && model.isDoubleAward
|
&& model.selectedBoss != model.GetRecommendBoss() && config.CanEnterTimes == 0)
|
{
|
_error = 5;
|
return false;
|
}
|
|
var mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
|
if (mapConfig.MapFBType != (int)MapType.OpenCountry && PlayerDatas.Instance.baseData.MapID != 31020)
|
{
|
_error = 7;
|
return false;
|
}
|
|
_error = 0;
|
return true;
|
}
|
|
private void OnBossSelected(int bossId)
|
{
|
m_BossIntroduce.Display(bossId, false);
|
|
DemonJarBossData bossData;
|
model.TryGetBossData(bossId, out bossData);
|
|
var config = DemonJarConfig.Get(model.selectedBoss);
|
m_RewardDescription.text = Language.Get(config.RewardDescription);
|
|
DisplayGotoKillButton(model.selectedBoss);
|
DisplaySubscribe(model.selectedBoss);
|
DisplayTip(bossId);
|
}
|
|
private void CheckAchievementGuideByTimes()
|
{
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
var config = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
var condition = config.Type == 99 && config.Condition[0] == DemonJarModel.DATA_MAPID;
|
|
if (condition)
|
{
|
var guideEffect = AchievementGuideEffectPool.Require(3);
|
guideEffect.transform.SetParentEx(m_BuyTimes.transform, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
}
|
}
|
|
private void CheckAchievementGuideKillBoss()
|
{
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
var config = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
var condition = config.Type == 36 && config.Condition[0] == model.selectedBoss;
|
condition = condition || config.Type == 81;
|
|
if (condition)
|
{
|
var guideEffect = AchievementGuideEffectPool.Require(1);
|
guideEffect.transform.SetParentEx(m_Goto.transform, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
}
|
}
|
|
private void CheckTaskGuide()
|
{
|
if (guideChallenge)
|
{
|
var guideEffect = AchievementGuideEffectPool.Require(1);
|
guideEffect.transform.SetParentEx(m_Goto.transform, Vector3.zero, Vector3.zero, Vector3.one);
|
}
|
}
|
|
private void DisplayTip(int bossId)
|
{
|
if (!findPreciousModel.IsBossUnlock(bossId))
|
{
|
m_NoDamageTip.SetActive(true);
|
m_SurpassLevel.SetActive(false);
|
}
|
else
|
{
|
m_NoDamageTip.SetActive(false);
|
var dropConfig = NPCDropItemConfig.Get(bossId);
|
var noDrop = dropConfig == null || (dropConfig.MaxLV != 0 && PlayerDatas.Instance.baseData.LV > dropConfig.MaxLV);
|
m_SurpassLevel.SetActive(noDrop);
|
}
|
}
|
|
private void DisplayGotoKillButton(int bossId)
|
{
|
}
|
|
private void DisplaySubscribe(int bossId)
|
{
|
var isUnLocked = findPreciousModel.IsBossUnlock(bossId);
|
m_Subscribe.SetActive(isUnLocked);
|
if (isUnLocked)
|
{
|
m_Subscribe.isOn = findPreciousModel.IsBossSubscribed(bossId);
|
}
|
}
|
|
}
|
|
}
|
|
|
|
|