//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, May 23, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
|
using System;
|
using System.Collections.Generic;
|
using LitJson;
|
|
namespace vnxbqy.UI
|
{
|
|
|
public class FirstTimeRechargeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
|
public bool IsOk = false;
|
|
public int CumulativeTime;//获取累计时间
|
public int FirstGoldTimeOut = 0;
|
public static event Action<string, bool> FirstTimeRechargeTiime;
|
public static event Action FirstTimeRecharEffect;
|
public bool IsPlayEffect = false;
|
private bool IsStageLoadFinish = false;
|
public bool IsTipShow = false;
|
public bool IsShowOnce = false; //倒计时上线点击后不再显示,最后一分钟必显
|
DateTime GetDateTime;
|
|
//--------------------获取首冲试用数据
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public int IsTryOut = 0;//0-不可试用,1-可试用,2-已使用
|
public Dictionary<int, int> TryOutDic = new Dictionary<int, int>();
|
public int TryOutLv = 0;
|
public static event Action<int> TryOutEvent;
|
public event Action IsTipShowEvent;
|
public int firstRechargeCTGID;
|
public int firstRechargeMornCTGID;
|
public int firstRechargeBetterCTGID;
|
public override void Init()
|
{
|
string str = FuncConfigConfig.Get("FirstGoldTimeOut").Numerical1;
|
FirstGoldTimeOut = int.Parse(str);
|
|
var FirstGoldTryItem = FuncConfigConfig.Get("FirstGoldTryItem");
|
TryOutDic.Clear();
|
TryOutDic = ConfigParse.GetDic<int, int>(FirstGoldTryItem.Numerical1);
|
TryOutLv = int.Parse(FirstGoldTryItem.Numerical4);
|
|
int[] firstCTGIDs = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("FirstGold").Numerical4);
|
firstRechargeCTGID = firstCTGIDs[0];
|
firstRechargeBetterCTGID = firstCTGIDs[1];
|
firstRechargeMornCTGID = firstCTGIDs[2];
|
}
|
|
private void PlayerDataRefreshEvent(PlayerDataType dataType)
|
{
|
if (dataType != PlayerDataType.LV)
|
return;
|
|
if (PlayerDatas.Instance.baseData.LV > 150)
|
return;
|
if (PlayerDatas.Instance.baseData.LV % 30 == 0)
|
//到达等级强制再显示一次
|
IsShowOnce = false;
|
}
|
|
|
public override void UnInit()
|
{
|
}
|
|
private void windowBeforeClose(Window _window)
|
{
|
if (_window is MainInterfaceWin)
|
{
|
if (WindowCenter.Instance.IsOpen("FirstTimeRechargeWin"))
|
{
|
WindowCenter.Instance.CloseImmediately("FirstTimeRechargeWin");
|
}
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
IsTipShow = false;
|
IsStageLoadFinish = false;
|
IsOk = false;
|
IsTryOut = 0;
|
CumulativeTime = 0;
|
IsPlayEffect = false;
|
needFirstRechargeMore = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
IsOk = true;
|
if (!LocalSave.GetBool("FirstTimeRechargeBool", false))
|
{
|
LocalSave.SetBool("FirstTimeRechargeBool", true);
|
}
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
|
GlobalTimeEvent.Instance.secondEvent -= secondEvent;
|
GlobalTimeEvent.Instance.secondEvent += secondEvent;
|
WindowCenter.Instance.windowBeforeCloseEvent -= windowBeforeClose;
|
WindowCenter.Instance.windowBeforeCloseEvent += windowBeforeClose;
|
WindowCenter.Instance.windowBeforeOpenEvent -= windowBeforeOpenEvent;
|
WindowCenter.Instance.windowBeforeOpenEvent += windowBeforeOpenEvent;
|
StageLoad.Instance.onStageLoadFinish -= onStageLoadFinish;
|
StageLoad.Instance.onStageLoadFinish += onStageLoadFinish;
|
ItemOverdueModel.FirstGoldWPOver -= FirstGoldWPOver;
|
ItemOverdueModel.FirstGoldWPOver += FirstGoldWPOver;
|
FirstGoldWPOver();
|
}
|
|
private void FirstGoldWPOver()
|
{
|
bool IsExist = NewBieCenter.Instance.completeGuidesBuf.Contains(200);
|
if (!IsExist && IsTryOut == 2 && PlayerDatas.Instance.baseData.coinTotal <= 0)
|
{
|
bool IsOver = false;
|
|
int _weaponId = 0;
|
if (ModelCenter.Instance.GetModel<PackModel>().GetSinglePack(PackType.Item) != null)
|
{
|
var job = PlayerDatas.Instance.baseData.Job;
|
if (TryOutDic.ContainsKey(job))
|
{
|
var itemConfig = ItemConfig.Get(TryOutDic[job]);
|
_weaponId = itemConfig.EffectValueA1;
|
}
|
|
var list = packModel.GetSinglePack(PackType.Item).GetItemsById(_weaponId);
|
if (list != null && list.Count > 0)
|
{
|
for (int k = 0; k < list.Count; k++)
|
{
|
bool isOverdue = ItemLogicUtility.Instance.IsOverdue(list[k].guid);
|
if (isOverdue)
|
{
|
IsOver = isOverdue;
|
}
|
}
|
}
|
}
|
if (IsOver)
|
{
|
var SendInfo = new CA222_tagCMSetGuideOK();
|
SendInfo.GuideIndex = 200;
|
SendInfo.IsOK = 1;
|
GameNetSystem.Instance.SendInfo(SendInfo);
|
IsTipShow = true;
|
if (IsTipShowEvent != null)
|
{
|
IsTipShowEvent();
|
}
|
}
|
}
|
}
|
|
private void onStageLoadFinish()
|
{
|
var inDungeon = IsDungeon();
|
if (IsStageLoadFinish && !inDungeon)
|
{
|
OpenFirstChargeTrialWin();
|
IsStageLoadFinish = false;
|
}
|
|
}
|
|
private void windowBeforeOpenEvent(Window obj)
|
{
|
if ((!WindowCenter.Instance.IsOpen<MainInterfaceWin>() && WindowCenter.Instance.ExistAnyFullScreenOrMaskWin()) || obj is ChatWin)
|
{
|
if (WindowCenter.Instance.IsOpen("FirstTimeRechargeWin"))
|
{
|
WindowCenter.Instance.CloseImmediately("FirstTimeRechargeWin");
|
}
|
}
|
}
|
|
public void GetFirstTimeRecharge(HAA08_tagMCFirstGoldTime info)
|
{
|
CumulativeTime = (int)info.FirstGoldRemainTime;
|
GetDateTime = DateTime.Now;
|
}
|
|
public void WhetherToTry(HAA02_tagMCFirstGoldInfo info)
|
{
|
|
IsTryOut = info.FirstGoldTry;
|
var inDungeon = IsDungeon();
|
if (inDungeon)
|
{
|
IsStageLoadFinish = true;
|
}
|
if (IsOk && IsTryOut == 1 && !inDungeon)
|
{
|
OpenFirstChargeTrialWin();
|
}
|
else if (IsOk && IsTryOut == 2)
|
{
|
if (WindowCenter.Instance.IsOpen<FirstChargeTrialWin>())
|
{
|
WindowCenter.Instance.Close<FirstChargeTrialWin>();
|
}
|
}
|
if (TryOutEvent != null)
|
{
|
TryOutEvent(IsTryOut);
|
}
|
}
|
|
public bool IsShowTime()
|
{
|
TimeSpan ts = DateTime.Now - GetDateTime;
|
int second = (int)ts.TotalSeconds;
|
if (CumulativeTime != 0 && CumulativeTime > second)
|
return true;
|
|
return false;
|
}
|
|
public bool IsDungeon()
|
{
|
var isDungeon = MapUtility.IsDungeon(PlayerDatas.Instance.baseData.MapID);
|
if (ClientDungeonStageUtility.isClientDungeon)
|
{
|
isDungeon = true;
|
}
|
return isDungeon;
|
}
|
|
|
|
private void secondEvent()
|
{
|
//var inDungeon = IsDungeon();
|
TimeSpan ts = DateTime.Now - GetDateTime;
|
int second = (int)ts.TotalSeconds;
|
if (CumulativeTime != 0 && PlayerDatas.Instance.baseData.LV <= FirstGoldTimeOut && PlayerDatas.Instance.baseData.coinTotal <= 0 && second > 0 /*&& !inDungeon*/ && CumulativeTime - second > 0)
|
{
|
if (WindowCenter.Instance.IsOpen<MainInterfaceWin>() && !WindowCenter.Instance.ExistAnyFullScreenOrMaskWin() && !WindowCenter.Instance.IsOpen<ChatWin>())
|
{
|
int Residue = CumulativeTime - second;
|
if (!WindowCenter.Instance.IsOpen("FirstTimeRechargeWin"))
|
{
|
if (!IsShowOnce && Residue > 0 && !IsDungeon())
|
WindowCenter.Instance.Open<FirstTimeRechargeWin>();
|
}
|
|
string strTime = string.Empty;
|
bool isRed = false;
|
if (Residue / 60 > 0)
|
{
|
strTime = Residue / 60 + Language.Get("Minute") + Residue % 60 + Language.Get("RealmWin_Bewrite_35");
|
}
|
else
|
{
|
strTime = Residue % 60 + Language.Get("RealmWin_Bewrite_35");
|
}
|
if ((Residue / 60) < 5 && FirstTimeRecharEffect != null)
|
{
|
IsPlayEffect = true;
|
FirstTimeRecharEffect();
|
isRed = true;
|
|
}
|
|
if (FirstTimeRechargeTiime != null)
|
{
|
FirstTimeRechargeTiime(strTime, isRed);
|
}
|
}
|
else
|
{
|
if (WindowCenter.Instance.IsOpen("FirstTimeRechargeWin"))
|
{
|
WindowCenter.Instance.CloseImmediately("FirstTimeRechargeWin");
|
}
|
}
|
}
|
else
|
{
|
if (WindowCenter.Instance.IsOpen("FirstTimeRechargeWin"))
|
{
|
WindowCenter.Instance.CloseImmediately("FirstTimeRechargeWin");
|
}
|
}
|
}
|
|
public void TryOutSend()//首冲试用
|
{
|
var sendInfo = new CA511_tagCMTryFirstGoldItem();
|
GameNetSystem.Instance.SendInfo(sendInfo);
|
}
|
|
public void OpenFirstChargeTrialWin()
|
{
|
if (NewBieCenter.Instance.inGuiding || ModelCenter.Instance.GetModel<TreasureModel>().newGotShowing)
|
{
|
return;
|
}
|
if (!WindowCenter.Instance.IsOpen<FirstChargeTrialWin>() && IsTryOut == 1)
|
{
|
WindowCenter.Instance.Open<FirstChargeTrialWin>();
|
}
|
|
}
|
|
public bool needFirstRechargeMore = false; //已经充值过低档位首充的玩家,想要高级首充的方法
|
public void AskFirstRechargeMore(string text)
|
{
|
if (text == Language.Get("FirstRecharge6"))
|
{
|
if (PlayerDatas.Instance.baseData.LV < 10)
|
return;
|
|
VipModel.RechargeCount rechargeCount;
|
vipModel.TryGetRechargeCount(firstRechargeMornCTGID, out rechargeCount);
|
if (rechargeCount.totalCount > 0)
|
return;
|
needFirstRechargeMore = true;
|
WindowCenter.Instance.Open<FirstRechargeWin>();
|
}
|
}
|
|
}
|
|
}
|
|
|
|