using vnxbqy.UI;
|
using System;
|
|
using LitJson;
|
using UnityEngine;
|
using System.Collections.Generic;
|
|
|
public class TaiChiModel : Model,IBeforePlayerDataInitialize
|
{
|
//日常活动
|
DailyQuestModel _dailyQuestModel;
|
public DailyQuestModel dailyQuestModel
|
{
|
get { return _dailyQuestModel ?? (_dailyQuestModel = ModelCenter.Instance.GetModel<DailyQuestModel>()); }
|
}
|
|
public readonly int TaiChiDailyTaskID = 12;
|
|
private FuncConfigConfig diceFreeNumFunc;
|
private FuncConfigConfig diceRewardFunc;
|
private DailyQuestOpenTimeConfig dailyTask;
|
public int sumFreeNum { get; private set; }
|
public int sumPlayNum { get; private set; }
|
|
private Dictionary<int, DiceReward> diceRewardDict = new Dictionary<int, DiceReward>();
|
|
public override void Init()
|
{
|
diceRewardDict.Clear();
|
diceFreeNumFunc = FuncConfigConfig.Get("DiceFreeNum");
|
sumFreeNum = int.Parse(diceFreeNumFunc.Numerical1);
|
diceRewardFunc = FuncConfigConfig.Get("DiceReward");
|
dailyTask = DailyQuestOpenTimeConfig.Get(7);
|
sumPlayNum = dailyTask.DayTimes;
|
JsonData jsonData = JsonMapper.ToObject(diceRewardFunc.Numerical1);
|
foreach(var key in jsonData.Keys)
|
{
|
DiceReward diceReward = new DiceReward(int.Parse(key));
|
diceRewardDict.Add(diceReward.taiChiNum,diceReward);
|
foreach (var key1 in jsonData[key].Keys)
|
{
|
switch (key1)
|
{
|
case "exp":
|
diceReward.SetExpModel(jsonData[key][key1].ToString(),2103);
|
break;
|
case "gold":
|
diceReward.SetGoldModel((int)jsonData[key][key1],2100);
|
break;
|
case "item":
|
if(jsonData[key][key1].IsArray)
|
{
|
if(jsonData[key][key1].Count >= 2)
|
{
|
diceReward.SetItemModel((int)jsonData[key][key1][0], (int)jsonData[key][key1][1]);
|
}
|
}
|
break;
|
}
|
}
|
}
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState += RefreshDailyQuestState;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
diceType = -1;
|
useFreeCnt = 0;
|
taiChiNum = 0;
|
taiChiResultNum = "0";
|
}
|
|
public override void UnInit()
|
{
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
|
}
|
|
|
private void RefreshDailyQuestState()
|
{
|
var state = dailyQuestModel.GetQuestState(TaiChiDailyTaskID);
|
if (state == DailyQuestModel.DailyQuestState.Normal) return;
|
|
WindowCenter.Instance.Close<WytjGameWin>();
|
WindowCenter.Instance.Close<WytjRulesWin>();
|
}
|
|
public string taiChiResultNum { get; private set; }
|
public int diceType { get; private set; }
|
public int useFreeCnt { get; private set; }
|
public int taiChiNum { get; private set; }
|
public List<int> resultNumlist = new List<int>();
|
public event Action RefreshTaiChiModel;
|
public void SetTaiChiModel(HAB22_tagMCDiceExResult result)
|
{
|
taiChiResultNum = result.ResultNum.ToString();
|
diceType = result.DiceType;
|
useFreeCnt = result.UseFreeCnt;
|
taiChiNum = 0;
|
resultNumlist.Clear();
|
for (int i = 0; i <taiChiResultNum.Length; i++)
|
{
|
int point = int.Parse(taiChiResultNum.Substring(i,1));
|
resultNumlist.Add(point);
|
if(point == 6)
|
{
|
taiChiNum += 1;
|
}
|
}
|
|
if(RefreshTaiChiModel != null)
|
{
|
RefreshTaiChiModel();
|
}
|
//ModelCenter.Instance.GetModel<DungeonModel>().GetDungeonTotalTimes();
|
//ModelCenter.Instance.GetModel<DungeonModel>().GetDungeonEnterTimes();
|
//ModelCenter.Instance.GetModel<DailyQuestModel>().TryGetOpenTime();
|
}
|
|
public event Action GetResultEvent;
|
public int getResultNum { get; private set; }
|
public void GetTaichiResult(int taichiNum)
|
{
|
getResultNum = taichiNum;
|
if(GetResultEvent != null)
|
{
|
GetResultEvent();
|
}
|
}
|
|
public void SendQuest(int type)
|
{
|
CAB0C_tagCMDiceEx tagCMDiceEx = new CAB0C_tagCMDiceEx();
|
tagCMDiceEx.Type = (byte)type;
|
GameNetSystem.Instance.SendInfo(tagCMDiceEx);
|
}
|
|
public DiceReward GetDiceReward(int taiChiNum)
|
{
|
DiceReward diceReward = null;
|
diceRewardDict.TryGetValue(taiChiNum, out diceReward);
|
return diceReward;
|
}
|
|
public long GetDiceRewardExp(string exp)
|
{
|
Equation.Instance.Clear();
|
PlayerLVConfig playerLVConfig = PlayerLVConfig.Get(PlayerDatas.Instance.baseData.LV);
|
int reExp = 0;
|
if(playerLVConfig != null)
|
{
|
reExp = playerLVConfig.ReExp;
|
}
|
Equation.Instance.AddKeyValue("reExp",reExp);
|
return Equation.Instance.Eval<long>(exp);
|
}
|
|
public bool CheckEnterError(out int error)
|
{
|
int playerLv = PlayerDatas.Instance.baseData.LV;
|
var config = DailyQuestConfig.Get(TaiChiDailyTaskID);
|
FuncOpenLVConfig openLVConfig = FuncOpenLVConfig.Get(config.UnLockFuncID);
|
int limitLv = openLVConfig.LimitLV;
|
var completedTimes = dailyQuestModel.GetDailyQuestCompletedTimes(TaiChiDailyTaskID);
|
var totalTimes = dailyQuestModel.GetDailyQuestTotalTimes(TaiChiDailyTaskID);
|
error = 0;
|
if (playerLv < limitLv)
|
{
|
error = 1;
|
return true;
|
}
|
else if(completedTimes >= totalTimes)
|
{
|
error = 2;
|
return true;
|
}
|
|
return false;
|
}
|
}
|
|
public class DiceReward
|
{
|
public int taiChiNum { get; private set; }
|
public int expId { get; private set; }
|
public string exp { get; private set; }
|
public int goldId { get; private set; }
|
public int gold { get; private set; }
|
public int itemID { get; private set; }
|
public int itemCount { get; private set; }
|
public ItemConfig itemConfig { get; private set; }
|
public DiceReward(int taiChiNum)
|
{
|
this.taiChiNum = taiChiNum;
|
}
|
|
public void SetExpModel(string exp,int expId)
|
{
|
this.exp = exp;
|
this.expId = expId;
|
}
|
|
public void SetGoldModel(int gold,int goldId)
|
{
|
this.gold = gold;
|
this.goldId = goldId;
|
}
|
|
public void SetItemModel(int itemId, int itemCount)
|
{
|
this.itemID = itemId;
|
this.itemCount = itemCount;
|
itemConfig = ItemConfig.Get(itemId);
|
}
|
}
|