using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
public class LevelGiftModel : Model,IBeforePlayerDataInitialize,IPlayerLoginOk
|
{
|
public override void Init()
|
{
|
ParseConfig();
|
//DTCA003_tagUniversalGameRecInfo.onGetUniversalGameInfo += onGetUniversalGameInfo;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
}
|
|
public override void UnInit()
|
{
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
giftGetRecord = 0;
|
vipGiftGetRecord = 0;
|
//limitGiftCntDict.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType _type)
|
{
|
if (_type == PlayerDataType.LV)
|
{
|
UpdateRedpoint();
|
}
|
else if (_type == PlayerDataType.VIPLv)
|
{
|
UpdateRedpoint();
|
}
|
}
|
#region 配置
|
public Dictionary<int, ImpactRankModel.RankAwardItem> levelGiftItemDict { get; private set; }
|
public Dictionary<int, VIPAward> m_VipItemDict { get; private set; }
|
void ParseConfig()
|
{
|
levelGiftItemDict = new Dictionary<int, ImpactRankModel.RankAwardItem>();
|
m_VipItemDict = new Dictionary<int, VIPAward>();
|
var _cfgs = LVAawrdConfig.GetValues();
|
for (int i = 0; i < _cfgs.Count; i++)
|
{
|
var _json = LitJson.JsonMapper.ToObject(_cfgs[i].Reward);
|
var _award = new ImpactRankModel.RankAwardItem();
|
foreach (var _key in _json.Keys)
|
{
|
var _job = int.Parse(_key);
|
var _array = LitJson.JsonMapper.ToObject<int[][]>(_json[_key].ToJson());
|
for (int j = 0; j < _array.Length; j++)
|
{
|
_award.Add(_job, new Item(_array[j][0], _array[j][1]));
|
}
|
}
|
levelGiftItemDict.Add(_cfgs[i].RewardID, _award);
|
|
var intarray = LitJson.JsonMapper.ToObject<int[][]>(_cfgs[i].VIPAward);
|
VIPAward vipAward = new VIPAward()
|
{
|
item = new Item(intarray[0][0], intarray[0][1]),
|
vipLv = _cfgs[i].VIPLimit,
|
};
|
m_VipItemDict.Add(_cfgs[i].RewardID, vipAward);
|
}
|
}
|
#endregion
|
private int giftGetRecord = 0;
|
private int vipGiftGetRecord = 0;
|
public event Action OnGetGiftUpdateEvent;
|
public void UpdateGetGift(HA30B_tagMCPlayerLVAwardGetRecord _package)
|
{
|
giftGetRecord = (int)_package.LVAwardGetRecord;
|
vipGiftGetRecord = (int)_package.VIPAwardRecord;
|
UpdateRedpoint();
|
if (OnGetGiftUpdateEvent != null)
|
{
|
OnGetGiftUpdateEvent();
|
}
|
}
|
|
public bool IsGet(int _id)
|
{
|
var _cfgs = LVAawrdConfig.GetValues();
|
var _index = _cfgs.FindIndex((x) =>
|
{
|
return x.RewardID == _id;
|
});
|
if (_index == -1)
|
{
|
return true;
|
}
|
return (giftGetRecord & (1 << _index)) != 0;
|
}
|
|
public bool IsVipGet(int _id)
|
{
|
var _cfgs = LVAawrdConfig.GetValues();
|
var _index = _cfgs.FindIndex((x) =>
|
{
|
return x.RewardID == _id;
|
});
|
if (_index == -1)
|
{
|
return true;
|
}
|
return (vipGiftGetRecord & (1 << _index)) != 0;
|
}
|
|
//private Dictionary<int, int> limitGiftCntDict = new Dictionary<int, int>();
|
//public event Action OnLimitGiftUpdateEvent;
|
//private void onGetUniversalGameInfo(HA003_tagUniversalGameRecInfo _package)
|
//{
|
// if (_package.Type == 3)
|
// {
|
// for (int i = 0; i < _package.Count; i++)
|
// {
|
// var _data = _package.UniversalGameRec[i];
|
// //limitGiftCntDict[(int)_data.Value1] = (int)_data.Value2;
|
// }
|
// UpdateRedpoint();
|
// if (OnLimitGiftUpdateEvent != null)
|
// {
|
// OnLimitGiftUpdateEvent();
|
// }
|
// }
|
//}
|
|
//public int LimitGiftGetCount(int _id)
|
//{
|
// if (limitGiftCntDict.ContainsKey(_id))
|
// {
|
// return limitGiftCntDict[_id];
|
// }
|
// return 0;
|
//}
|
|
public void TryGetLevelGift(out int _index)
|
{
|
_index = 0;
|
var _cfgs = LVAawrdConfig.GetValues();
|
for (int i = 0; i < _cfgs.Count; i++)
|
{
|
var _cfg = _cfgs[i];
|
bool _got = IsGet(_cfg.RewardID);
|
bool _vipGot = IsVipGet(_cfg.RewardID);
|
if (_vipGot && _got)
|
{
|
continue;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= _cfg.LV && !_got)
|
{
|
_index = i;
|
return;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= _cfg.LV &&
|
PlayerDatas.Instance.baseData.VIPLv >= _cfg.VIPLimit && !_vipGot)
|
{
|
_index = i;
|
return;
|
}
|
}
|
for (int i = 0; i < _cfgs.Count; i++)
|
{
|
var _cfg = _cfgs[i];
|
bool _got = IsGet(_cfg.RewardID);
|
if (_got)
|
{
|
continue;
|
}
|
_index = i;
|
return;
|
}
|
}
|
|
#region 红点
|
public Redpoint redpoint = new Redpoint(201, 20107);
|
public void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
var _cfgs = LVAawrdConfig.GetValues();
|
for (int i = 0; i < _cfgs.Count; i++)
|
{
|
var _cfg = _cfgs[i];
|
bool _got = IsGet(_cfg.RewardID);
|
bool _vipGot = IsVipGet(_cfg.RewardID);
|
if (_got && _vipGot)
|
{
|
continue;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= _cfg.LV && !_got)
|
{
|
redpoint.state = RedPointState.GetReward;
|
break;
|
}
|
if (PlayerDatas.Instance.baseData.LV >= _cfg.LV &&
|
PlayerDatas.Instance.baseData.VIPLv >= _cfg.VIPLimit && !_vipGot)
|
{
|
redpoint.state = RedPointState.GetReward;
|
break;
|
}
|
}
|
}
|
#endregion
|
|
public struct VIPAward
|
{
|
public Item item;
|
public int vipLv;
|
}
|
}
|
}
|
|