using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using TableConfig;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class TrialDungeonModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
Dictionary<int, List<TrialExchangeConfig>> trialTokenExchangeDict = new Dictionary<int, List<TrialExchangeConfig>>();
|
Dictionary<int, int> lineToTokenClassDict;
|
Dictionary<int, Dictionary<int, Item[]>> trialRewardDict = new Dictionary<int, Dictionary<int, Item[]>>();
|
public Dictionary<int, List<int>> trialClassTokens = new Dictionary<int, List<int>>();
|
public List<int> trialTokens = new List<int>();
|
PlayerPackModel packModel { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
|
public event Action SelectEquipClassEvent;
|
|
bool serverInited = false;
|
|
public const int TRIALEXCHANGE_GUIDE = 91;
|
|
int m_TrialExchangeRemindLevel = 250;
|
public int trialExchangeRemindLevel
|
{
|
get { return m_TrialExchangeRemindLevel; }
|
}
|
public override void Init()
|
{
|
ParseConfig();
|
packModel.RefreshItemCountAct += RefreshItemCountAct;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
dungeonModel.dungeonRecordChangeEvent += DungeonRecordChangeEvent;
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
}
|
|
private void DungeonRecordChangeEvent(int _dungeonId)
|
{
|
if (_dungeonId == 60010)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
serverInited = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
serverInited = true;
|
UpdateRedpoint();
|
}
|
|
void ParseConfig()
|
{
|
var configs = Config.Instance.GetAllValues<TrialExchangeConfig>();
|
for (int i = 0; i < configs.Count; i++)
|
{
|
List<TrialExchangeConfig> list;
|
var itemConfig = Config.Instance.Get<ItemConfig>(configs[i].tokenId);
|
if (!trialTokenExchangeDict.TryGetValue(itemConfig.LV, out list))
|
{
|
list = new List<TrialExchangeConfig>();
|
trialTokenExchangeDict.Add(itemConfig.LV, list);
|
}
|
list.Add(configs[i]);
|
if (!trialTokens.Contains(configs[i].tokenId))
|
{
|
trialTokens.Add(configs[i].tokenId);
|
List<int> _tokens;
|
if (!trialClassTokens.TryGetValue(itemConfig.LV, out _tokens))
|
{
|
_tokens = new List<int>();
|
trialClassTokens.Add(itemConfig.LV, _tokens);
|
}
|
if (!_tokens.Contains(configs[i].tokenId))
|
{
|
_tokens.Add(configs[i].tokenId);
|
}
|
}
|
}
|
var funcConfig = Config.Instance.Get<FuncConfigConfig>("LineToItemStage");
|
lineToTokenClassDict = ConfigParse.GetDic<int, int>(funcConfig.Numerical1);
|
|
var trialRewards = Config.Instance.GetAllValues<TrialRewardsConfig>();
|
for (int i = 0; i < trialRewards.Count; i++)
|
{
|
Dictionary<int, Item[]> dict = null;
|
if (!trialRewardDict.TryGetValue(trialRewards[i].lineId, out dict))
|
{
|
dict = new Dictionary<int, Item[]>();
|
trialRewardDict.Add(trialRewards[i].lineId, dict);
|
}
|
var itemsArray = LitJson.JsonMapper.ToObject<int[][]>(trialRewards[i].rewards);
|
if (itemsArray != null && itemsArray.Length > 0)
|
{
|
Item[] items = new Item[itemsArray.Length];
|
for (int k = 0; k < itemsArray.Length; k++)
|
{
|
items[k] = new Item()
|
{
|
id = itemsArray[k][0],
|
count = itemsArray[k][1],
|
bind = itemsArray[k][2] == 1
|
};
|
}
|
dict.Add(trialRewards[i].grade, items);
|
}
|
}
|
|
funcConfig = Config.Instance.Get<FuncConfigConfig>("MunekadoRedPoint");
|
if (funcConfig != null)
|
{
|
m_TrialExchangeRemindLevel = int.Parse(funcConfig.Numerical1);
|
}
|
}
|
|
public override void UnInit()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent;
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataRefresh refreshType)
|
{
|
if (refreshType == PlayerDataRefresh.LV ||
|
refreshType == PlayerDataRefresh.LV2 ||
|
refreshType == PlayerDataRefresh.LVEx)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void RefreshItemCountAct(PackType packType, int arg2, int itemId)
|
{
|
var config = Config.Instance.Get<ItemConfig>(itemId);
|
if (config == null)
|
{
|
return;
|
}
|
if (packType == PackType.rptItem)
|
{
|
if (trialTokens.Contains(itemId) || config.EquipPlace > 0)
|
{
|
UpdateRedpoint();
|
}
|
}
|
else if (packType == PackType.rptEquip)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
private void OnFuncStateChangeEvent(int _id)
|
{
|
if (_id == 88)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
int m_SelectEquipClass = 0;//1-全部阶数
|
public int selectEquipClass
|
{
|
get { return m_SelectEquipClass; }
|
set
|
{
|
if (m_SelectEquipClass != value && SelectEquipClassEvent != null)
|
{
|
m_SelectEquipClass = value;
|
SelectEquipClassEvent();
|
}
|
m_SelectEquipClass = value;
|
}
|
}
|
|
public int GetTrialTokenCount(int itemId)
|
{
|
var count = 0;
|
count += packModel.GetSinglePackModel(PackType.rptItem).GetItemCountByID(itemId);
|
return count;
|
}
|
|
public int LineToTokenClass(int line)
|
{
|
if (lineToTokenClassDict != null && lineToTokenClassDict.ContainsKey(line))
|
{
|
return lineToTokenClassDict[line];
|
}
|
return lineToTokenClassDict != null ? lineToTokenClassDict.Values.Last() : 0;
|
}
|
|
public bool TryGetTrialExchanges(int lv, out List<TrialExchangeConfig> list)
|
{
|
return trialTokenExchangeDict.TryGetValue(lv, out list);
|
}
|
|
public bool TryGetTrialRewards(int lineId, int grade, out Item[] rewards)
|
{
|
rewards = null;
|
if (trialRewardDict.ContainsKey(lineId))
|
{
|
if (trialRewardDict[lineId].ContainsKey(grade))
|
{
|
rewards = trialRewardDict[lineId][grade];
|
return rewards != null && rewards.Length > 0;
|
}
|
}
|
return false;
|
}
|
|
public List<int> GetTotalClass()
|
{
|
return trialTokenExchangeDict.Keys.ToList();
|
}
|
|
public bool TrialSendExchange(int _id, out int error)
|
{
|
error = 0;
|
if (!FuncOpen.Instance.IsFuncOpen(88))
|
{
|
error = 2;
|
return false;
|
}
|
var config = Config.Instance.Get<TrialExchangeConfig>(_id);
|
if (config == null)
|
{
|
return false;
|
}
|
var count = GetTrialTokenCount(config.tokenId);
|
if (count < config.tokenCount)
|
{
|
error = 1;
|
return false;
|
}
|
if (!NewBieCenter.Instance.completeGuidesBuf.Contains(TRIALEXCHANGE_GUIDE))
|
{
|
NewBieCenter.Instance.RemoveNewBieGuide(TRIALEXCHANGE_GUIDE);
|
}
|
//var tokenConfig = Config.Instance.Get<ItemConfig>(config.tokenId);
|
//ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
// Language.Get("TokenUseConfirm", config.tokenCount, tokenConfig.ItemName, config.description), (bool isOk) =>
|
// {
|
// if (isOk)
|
// {
|
CA32F_tagCMTrialExchange pak = new CA32F_tagCMTrialExchange();
|
pak.ID = (uint)_id;
|
GameNetSystem.Instance.SendInfo(pak);
|
// }
|
// });
|
return true;
|
}
|
|
public void ProcessTrialError(int error)
|
{
|
switch (error)
|
{
|
case 1:
|
SysNotifyMgr.Instance.ShowTip("TrialTokenCountError");
|
break;
|
case 2:
|
FuncOpen.Instance.ProcessorFuncErrorTip(88);
|
break;
|
}
|
}
|
|
public bool CompleteTrialFloor(int _lineId)
|
{
|
DungeonRecord dungeonRecord;
|
if (dungeonModel.TryGetRecord(60010, out dungeonRecord))
|
{
|
if (dungeonRecord.lineGrades != null
|
&& dungeonRecord.lineGrades.ContainsKey(_lineId))
|
{
|
return dungeonRecord.lineGrades[_lineId] > 0;
|
}
|
}
|
return false;
|
}
|
|
public void ProcessOpenTrialExchangeError()
|
{
|
SysNotifyMgr.Instance.ShowTip("TrialExchangeLimit");
|
}
|
|
public int EquipCompare(int _itemId)
|
{
|
var config = Config.Instance.Get<ItemConfig>(_itemId);
|
var equipPlace = config.EquipPlace;
|
if (equipPlace == 0)
|
{
|
return 0;
|
}
|
var singlepack = packModel.GetSinglePackModel(PackType.rptItem);
|
if (singlepack != null)
|
{
|
var dict = singlepack.GetPackModelIndexDict();
|
if (dict != null)
|
{
|
var badCompare = 1;
|
foreach (var itemModel in dict.Values)
|
{
|
if (itemModel.chinItemModel.EquipPlace == config.EquipPlace
|
&& (itemModel.chinItemModel.JobLimit / 100 == PlayerDatas.Instance.baseData.Job
|
|| itemModel.chinItemModel.JobLimit == 0)
|
&& !ModelCenter.Instance.GetModel<PackModelInterface>().IsOverdue(itemModel.itemInfo.ItemGUID, itemModel.itemId, itemModel.useDataDict))
|
{
|
var compare = EquipCompare(itemModel, config);
|
if (compare == 0)
|
{
|
badCompare = compare;
|
}
|
if (compare == -1)
|
{
|
return compare;
|
}
|
}
|
}
|
if (badCompare == 0)
|
{
|
return badCompare;
|
}
|
}
|
}
|
singlepack = packModel.GetSinglePackModel(PackType.rptEquip);
|
if (singlepack == null)
|
{
|
return 1;
|
}
|
var equipItem = singlepack.GetItemModelByIndex(equipPlace);
|
if (equipItem == null)
|
{
|
return 1;
|
}
|
return EquipCompare(equipItem, config);
|
}
|
|
int EquipCompare(ItemModel compareItem, ItemConfig config)
|
{
|
var compareConfig = Config.Instance.Get<ItemConfig>(compareItem.itemId);
|
if (compareConfig == null)
|
{
|
return 1;
|
}
|
if (compareConfig.ItemColor != config.ItemColor)
|
{
|
return compareConfig.ItemColor > config.ItemColor ? -1 : 1;
|
}
|
if (compareConfig.StarLevel != config.StarLevel)
|
{
|
return compareConfig.StarLevel > config.StarLevel ? -1 : 1;
|
}
|
if (compareConfig.LV != config.LV)
|
{
|
return compareConfig.LV > config.LV ? -1 : 1;
|
}
|
return 0;
|
}
|
|
public int GetExchangeItemByJob(TrialExchangeConfig config)
|
{
|
if (config == null)
|
{
|
return 0;
|
}
|
if (config.exchangeItemID.Length == 1)
|
{
|
return config.exchangeItemID[0];
|
}
|
var job = PlayerDatas.Instance.baseData.Job;
|
if (job - 1 < config.exchangeItemID.Length && job - 1 >= 0)
|
{
|
return config.exchangeItemID[job - 1];
|
}
|
return config.exchangeItemID[0];
|
}
|
|
#region 红点
|
void UpdateRedpoint()
|
{
|
dailyQuestModel.trialExchangeRedpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen(88) ||
|
PlayerDatas.Instance.baseData.LV >= trialExchangeRemindLevel)
|
{
|
return;
|
}
|
var maxClass = 0;
|
if (TryGetSatisfyExchange(out maxClass))
|
{
|
dailyQuestModel.trialExchangeRedpoint.state = RedPointState.Simple;
|
}
|
}
|
|
public bool TryGetSatisfyExchange(out int maxClass)
|
{
|
maxClass = 0;
|
foreach (var _class in trialTokenExchangeDict.Keys)
|
{
|
List<TrialExchangeConfig> list;
|
if (TryGetTrialExchanges(_class, out list))
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
if (SatisfyExchangeBetter(list[i].id))
|
{
|
var itemConfig = Config.Instance.Get<ItemConfig>(list[i].tokenId);
|
if (itemConfig.LV > maxClass)
|
{
|
maxClass = itemConfig.LV;
|
}
|
break;
|
}
|
}
|
}
|
}
|
return maxClass != 0;
|
}
|
|
public bool SatisfyExchangeBetter(int _id)
|
{
|
if (!CompleteTrialFloor(0))
|
{
|
return false;
|
}
|
var config = Config.Instance.Get<TrialExchangeConfig>(_id);
|
if (config == null)
|
{
|
return false;
|
}
|
var count = GetTrialTokenCount(config.tokenId);
|
if (count < config.tokenCount)
|
{
|
return false;
|
}
|
var exchangeItemConfig = Config.Instance.Get<ItemConfig>(GetExchangeItemByJob(config));
|
if (exchangeItemConfig.EquipPlace == 0)
|
{
|
return true;
|
}
|
if (EquipCompare(GetExchangeItemByJob(config)) == 1)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
public bool IsAnySatisfyExchangeBetterEquip(int _class, out int _id)
|
{
|
_id = -1;
|
List<TrialExchangeConfig> list;
|
if (TryGetTrialExchanges(_class, out list))
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
var itemConfig = Config.Instance.Get<ItemConfig>(GetExchangeItemByJob(list[i]));
|
if (SatisfyExchangeBetter(list[i].id) && itemConfig.EquipPlace != 0)
|
{
|
_id = list[i].id;
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool IsAnySatisfyExchangeBetter(int _itemId)
|
{
|
if (PlayerDatas.Instance.baseData.LV >= trialExchangeRemindLevel)
|
{
|
return false;
|
}
|
if (!trialTokens.Contains(_itemId))
|
{
|
return false;
|
}
|
var config = Config.Instance.Get<ItemConfig>(_itemId);
|
List<TrialExchangeConfig> list;
|
if (TryGetTrialExchanges(config.LV, out list))
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
if (list[i].tokenId == _itemId && SatisfyExchangeBetter(list[i].id))
|
{
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
#endregion
|
}
|
}
|