using LitJson;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class PrayForDurgModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
BlastFurnaceModel blastModel { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
|
PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
Dictionary<int, int> prayDrugDict = new Dictionary<int, int>(); //丹药id 特效id
|
public string prayDrugRecordKey;
|
|
public override void Init()
|
{
|
SetPrayDrugCondi();
|
SetPrayDrugDict();
|
SetPrayVipLimit();
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
|
FuncOpen.Instance.OnFuncStateChangeEvent -= UpdateFuncState;
|
blastModel.RefreshStoveModelEvent -= UpdateBlastLv;
|
playerPack.RefreshItemSumUseCntAct -= RefreshItemUsce;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= UpdateVipLV;
|
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += UpdateVipLV;
|
FuncOpen.Instance.OnFuncStateChangeEvent += UpdateFuncState;
|
blastModel.RefreshStoveModelEvent += UpdateBlastLv;
|
playerPack.RefreshItemSumUseCntAct += RefreshItemUsce;
|
SetPrayPrivilegeByVipLv();
|
prayDrugRecordKey = StringUtility.Contact(PlayerDatas.Instance.baseData.PlayerID, "PrayDrugRecord");
|
SetIsNewDay();
|
UpdatePrayDanRedpoint();
|
}
|
|
private void UpdateVipLV(PlayerDataRefresh type)
|
{
|
if (type != PlayerDataRefresh.VIPLv) return;
|
|
SetPrayPrivilegeByVipLv();
|
UpdatePrayDanRedpoint();
|
}
|
|
private void RefreshItemUsce(int id)
|
{
|
if (!playerPack.CheckIsDrugById(id)) return;
|
|
AttrFruitConfig fruitConfig = AttrFruitConfig.Get(id);
|
if (!playerPack.IsReachMaxUseDrug(fruitConfig)) return;
|
|
UpdatePrayDanRedpoint();
|
}
|
|
private void UpdateBlastLv()
|
{
|
if (!blastModel.StoveIsUpGrade) return;
|
|
UpdatePrayDanRedpoint();
|
}
|
|
private void UpdateFuncState(int funcId)
|
{
|
if (funcId != (int)FuncOpenEnum.BlastFurnace) return;
|
|
UpdatePrayDanRedpoint();
|
}
|
|
public bool CheckPrayDrugIsOpen()
|
{
|
if(!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.BlastFurnace))
|
{
|
return false;
|
}
|
else if (blastModel.StoveLV < prayPushLv)
|
{
|
SysNotifyMgr.Instance.ShowTip("PrayforDrug102",prayPushLv);
|
return false;
|
}
|
else if (GetPrayDruglist().Count < 1)
|
{
|
SysNotifyMgr.Instance.ShowTip("PrayforDrug101");
|
return false;
|
}
|
|
return true;
|
}
|
|
#region 读取本地配置
|
public int costMoney { get; private set; }
|
public int prayPushLv { get; private set;}
|
private void SetPrayDrugCondi()
|
{
|
FuncConfigConfig func = FuncConfigConfig.Get("GodAlchemy");
|
costMoney = int.Parse(func.Numerical2);
|
func = FuncConfigConfig.Get("GodAlchemyShow");
|
prayPushLv = int.Parse(func.Numerical2);
|
}
|
/// <summary>
|
/// 得到所有祈求丹药数据
|
/// </summary>
|
private Dictionary<int, int> SetPrayDrugDict()
|
{
|
FuncConfigConfig funcConfig = FuncConfigConfig.Get("GodAlchemyShow");
|
JsonData jsonData = JsonMapper.ToObject(funcConfig.Numerical1);
|
prayDrugDict.Clear();
|
if (jsonData.IsArray)
|
{
|
for (int i = 0; i < jsonData.Count; i++)
|
{
|
if (jsonData[i].IsArray)
|
{
|
int itemId = int.Parse(jsonData[i][0].ToString());
|
if (jsonData[i].Count > 1)
|
{
|
int effectId = int.Parse(jsonData[i][1].ToString());
|
prayDrugDict.Add(itemId, effectId);
|
}
|
else
|
{
|
prayDrugDict.Add(itemId, 0);
|
}
|
}
|
}
|
}
|
return prayDrugDict;
|
}
|
|
public bool IsNewDay { get; private set; }
|
public void SetIsNewDay()
|
{
|
if (IsNewDay) return;
|
|
if (PlayerPrefs.HasKey(prayDrugRecordKey))
|
{
|
int day = LocalSave.GetInt(prayDrugRecordKey);
|
if (day != TimeUtility.ServerNow.Day)
|
{
|
IsNewDay = true;
|
if (CheckIsPray())
|
{
|
LocalSave.SetInt(prayDrugRecordKey, TimeUtility.ServerNow.Day);
|
}
|
}
|
else
|
{
|
IsNewDay = false;
|
}
|
}
|
else
|
{
|
IsNewDay = true;
|
if(CheckIsPray())
|
{
|
LocalSave.SetInt(prayDrugRecordKey, TimeUtility.ServerNow.Day);
|
}
|
}
|
}
|
|
public int everyDayNum { get; private set; }
|
public int minVipLvLimit { get; private set; }
|
public void SetPrayPrivilegeByVipLv()
|
{
|
int vipLv = PlayerDatas.Instance.baseData.VIPLv;
|
everyDayNum = VipPrivilegeConfig.GetVipPrivilegeData(VipPrivilegeType.PrayForDrug,vipLv);
|
}
|
|
public void SetPrayVipLimit()
|
{
|
for (int i = 0; i < 16; i++)
|
{
|
int prayNum = VipPrivilegeConfig.GetVipPrivilegeData(VipPrivilegeType.PrayForDrug, i);
|
if(prayNum != 0)
|
{
|
minVipLvLimit = i;
|
break;
|
}
|
}
|
}
|
|
public bool CheckIsPrayByVip()
|
{
|
return PlayerDatas.Instance.baseData.VIPLv >= minVipLvLimit ? true : false;
|
}
|
#endregion
|
|
#region 协议
|
public int itemId { get; private set; }
|
public int alreadyPrayNum { get; private set;}
|
public event Action RefreshPrayEvent;
|
public void SetPrayResult(HA321_tagMCPrayElixirResult elixirResult)
|
{
|
itemId = (int)elixirResult.ItemID;
|
alreadyPrayNum = elixirResult.PrayCnt;
|
if(itemId != 0)
|
{
|
WindowCenter.Instance.Open<PrayforDrugGetItemWin>();
|
}
|
UpdatePrayDanRedpoint();
|
if(RefreshPrayEvent != null)
|
{
|
RefreshPrayEvent();
|
}
|
}
|
|
public void SendPrayElixir()
|
{
|
CA514_tagCMPrayElixir prayElixir = new CA514_tagCMPrayElixir();
|
GameNetSystem.Instance.SendInfo(prayElixir);
|
}
|
#endregion
|
|
List<int> prayIdlist = new List<int>();
|
public List<int> GetPrayDruglist()
|
{
|
prayIdlist.Clear();
|
List<AlchemyConfig> configs = blastModel.alchemyModellist;
|
foreach(var key in prayDrugDict.Keys)
|
{
|
for (int i = 0; i < configs.Count; i++)
|
{
|
if (blastModel.StoveLV >= configs[i].BlastFurnaceLV)
|
{
|
List<int> idlist = blastModel.GetPreviewIdlist(configs[i]);
|
if(idlist.Contains(key))
|
{
|
AttrFruitConfig fruitConfig = AttrFruitConfig.Get(key);
|
if (!playerPack.IsReachMaxUseDrug(fruitConfig))
|
{
|
prayIdlist.Add(key);
|
}
|
break;
|
}
|
}
|
}
|
}
|
return prayIdlist;
|
}
|
|
public int GetEffectIdById(int drugId)
|
{
|
int effectId = 0;
|
prayDrugDict.TryGetValue(drugId,out effectId);
|
return effectId;
|
}
|
|
#region 红点
|
|
public bool CheckIsPray()
|
{
|
if (blastModel.StoveLV < prayPushLv
|
|| alreadyPrayNum >= everyDayNum
|
|| GetPrayDruglist().Count < 1)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
public const int PRAYDRUGREDPOINT_KEY = 110011001;
|
private Redpoint prayRedpoint = new Redpoint(BlastFurnaceModel.LINGDANREDPOINT_KEY, PRAYDRUGREDPOINT_KEY);
|
public void UpdatePrayDanRedpoint()
|
{
|
if ( !CheckIsPray() || !IsNewDay)
|
{
|
prayRedpoint.state = RedPointState.None;
|
return;
|
}
|
|
prayRedpoint.state = RedPointState.Simple;
|
}
|
|
|
public void ClearPrayRedpoint()
|
{
|
if(prayRedpoint.state != RedPointState.None)
|
{
|
prayRedpoint.state = RedPointState.None;
|
LocalSave.SetInt(prayDrugRecordKey, TimeUtility.ServerNow.Day);
|
IsNewDay = false;
|
}
|
}
|
#endregion
|
}
|
}
|