using LitJson;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace vnxbqy.UI
|
{
|
public class CycleHallActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
private int m_NowTabId;
|
public int nowTabId
|
{
|
get { return m_NowTabId; }
|
set
|
{
|
if (m_NowTabId != value)
|
m_NowTabId = value;
|
UpdateRedpoint();
|
onNowTabIdUpdate?.Invoke();
|
}
|
}
|
|
//ͬ²½²¥·Å°Ú¶¯¶¯»
|
public Action PlayAnimationSync;
|
|
private bool isPlayAnimation = false;
|
public bool IsPlayAnimation
|
{
|
get
|
{
|
return isPlayAnimation;
|
}
|
set
|
{
|
isPlayAnimation = value;
|
if (isPlayAnimation)
|
{
|
PlayAnimationSync?.Invoke();
|
}
|
isPlayAnimation = false;
|
}
|
}
|
public Dictionary<int, HAA89_tagMCActLunhuidianPlayerInfo> playerInfoDict = new Dictionary<int, HAA89_tagMCActLunhuidianPlayerInfo>();
|
public event Action<int> onStateUpdate;
|
public event Action onNowTabIdUpdate;
|
public Redpoint redPoint = new Redpoint(MainRedDot.CycleHallRepoint);
|
|
//<Ë÷Òý£¬ºìµã>
|
public Dictionary<int, Redpoint> redPointDict = new Dictionary<int, Redpoint>();
|
|
//<ÂÖ»ØÀàÐÍ,½çÃæID>
|
public Dictionary<int, int> windowIDDict = new Dictionary<int, int>();
|
|
//<ÂÖ»ØÀàÐÍ,¹¦ÄÜID>
|
public Dictionary<int, int> funcIdDict = new Dictionary<int, int>();
|
|
// <ÂÖ»ØÀàÐÍ,ÉÏ´ÎµÄ CurRound>
|
public Dictionary<int, int> lastCurRoundDict = new Dictionary<int, int>();
|
|
// <ÂÖ»ØÀàÐÍ,ÉÏ´ÎµÄ CurValue>
|
public Dictionary<int, int> lastCurValueDict = new Dictionary<int, int>();
|
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.CycleHallAct;
|
public static Operation operaType = Operation.default47;
|
|
public int actNum = 10; //¶ÔÓ¦½çÃæ
|
public event Action UpdatePlayerInfoAction;
|
|
public int newRoundType;
|
public int newAwardType;
|
public int newAwardTypeValue;
|
public int newAwardIndex;
|
public event Action UpdateNewAwardHave;
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
LoadTable();
|
}
|
|
private void LoadTable()
|
{
|
var jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("CycleHall").Numerical1);
|
List<string> keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
windowIDDict.Add(int.Parse(keyList[i]), int.Parse(jsonData[keyList[i]].ToJson()));
|
}
|
|
jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("CycleHall").Numerical2);
|
keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
funcIdDict.Add(int.Parse(keyList[i]), int.Parse(jsonData[keyList[i]].ToJson()));
|
}
|
}
|
|
public OperationCycleHall GetOperationInfo()
|
{
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out OperationCycleHall cycleHallAct);
|
return cycleHallAct;
|
}
|
|
public List<int> GetTabIDList()
|
{
|
OperationCycleHall act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
if (act == null)
|
return new List<int>();
|
var list = CycleHallConfig.GetTabList();
|
if (list.IsNullOrEmpty())
|
return new List<int>();
|
List<int> resList = new List<int>();
|
for (int i = 0; i < list.Count; i++)
|
{
|
int id = list[i];
|
if (!CycleHallConfig.Has(id))
|
continue;
|
CycleHallConfig config = CycleHallConfig.Get(id);
|
if (act.TryGetRound(config.RoundType, out var info) && funcIdDict.TryGetValue(config.RoundType, out var funcId) && FuncOpen.Instance.IsFuncOpen(funcId))
|
{
|
if (!resList.Contains(id))
|
{
|
resList.Add(id);
|
}
|
}
|
}
|
return resList;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
playerInfoDict.Clear();
|
lastCurRoundDict.Clear();
|
lastCurValueDict.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
UpdateRedpoint();
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return redPoint.state == RedPointState.Simple;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
|
}
|
}
|
|
private void OperationEndEvent(Operation type, int state)
|
{
|
if (type == operaType)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
WindowCenter.Instance.Close<CycleHallWin>();
|
UpdateRedpoint();
|
}
|
}
|
|
private void OperationAdvanceEvent(Operation type)
|
{
|
if (type == operaType)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
private void OperationStartEvent(Operation type, int state)
|
{
|
if (type == operaType && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
public int GetAwardState(int roundType, int awardIndex)
|
{
|
if (playerInfoDict == null || !playerInfoDict.TryGetValue((byte)roundType, out var playerInfo) || playerInfo == null)
|
return 0;
|
OperationCycleHall act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex))
|
return 0;
|
|
if (playerInfo.CurValue >= awardInfo.NeedValue)
|
{
|
return (playerInfo.AwardRecord & (1 << awardIndex)) != 0 ? 2 : 1;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
|
//ÁìÈ¡¸ÃroundTypeÀàÐÍËùÓпÉÁìÈ¡µÄ½±Àø
|
public void HaveAllMissionAward(int roundType)
|
{
|
var act = GetOperationInfo();
|
if (act == null || !act.TryGetRound(roundType, out var round) || round.AwardList == null)
|
return;
|
if (playerInfoDict == null || !playerInfoDict.TryGetValue((byte)roundType, out var playerInfo) || playerInfo == null)
|
return;
|
|
for (int i = 0; i < round.AwardList.Length; i++)
|
{
|
var award = round.AwardList[i];
|
int state = GetAwardState(roundType, award.AwardIndex);//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
if (state == 1)
|
{
|
SendGetAward(roundType, (int)award.NeedValue);
|
}
|
}
|
}
|
|
public void UpdateRedpoint()
|
{
|
redPoint.state = RedPointState.None;
|
if (redPointDict != null)
|
{
|
var redPointList = redPointDict.Keys.ToList();
|
for (int i = 0; i < redPointList.Count; i++)
|
{
|
int redPointId = redPointList[i];
|
redPointDict[redPointId].state = RedPointState.None;
|
}
|
}
|
|
if (!IsOpen) return;
|
|
var act = GetOperationInfo();
|
if (act == null || act.roundInfoDict == null)
|
return;
|
var roundTypeList = act.roundInfoDict.Keys.ToList();
|
for (int i = 0; i < roundTypeList.Count; i++)
|
{
|
int roundType = roundTypeList[i];
|
if (!act.roundInfoDict.ContainsKey(roundType))
|
continue;
|
int id = CycleHallConfig.GetIndex(roundType, 1);
|
if (id <= 0)
|
continue;
|
if (!redPointDict.ContainsKey(id))
|
redPointDict[id] = new Redpoint(MainRedDot.CycleHallRepoint, MainRedDot.CycleHallRepoint * 1000 + id);
|
|
//ÓпÉÁìÈ¡µÄÈÎÎñ½±Àø
|
if (!act.TryGetRound(roundType, out var round) || round.AwardList == null)
|
return;
|
for (int j = 0; j < round.AwardList.Length; j++)
|
{
|
var award = round.AwardList[j];
|
int index = award.AwardIndex;
|
|
int state = GetAwardState(roundType, index);//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
if (state == 1)
|
redPointDict[id].state = RedPointState.Simple;
|
}
|
|
//É̵êÃâ·Ñ
|
id = CycleHallConfig.GetIndex(roundType, 2);
|
if (id <= 0)
|
continue;
|
if (!redPointDict.ContainsKey(id))
|
redPointDict[id] = new Redpoint(MainRedDot.CycleHallRepoint, MainRedDot.CycleHallRepoint * 1000 + id);
|
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(round.ShopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int k = 0; k < storeCnt; k++)
|
{
|
if (_list[k].MoneyNumber == 0)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[k], out remainNum);
|
if (remainNum > 0)
|
redPointDict[id].state = RedPointState.Simple;
|
}
|
}
|
}
|
}
|
|
public void CheckNewAwardHave(int roundType, int curRound, int curValue)
|
{
|
if (lastCurRoundDict.ContainsKey(roundType) && lastCurValueDict.ContainsKey(roundType))
|
{
|
int lastCurRound = lastCurRoundDict[roundType];
|
int lastCurValue = lastCurValueDict[roundType];
|
if (lastCurRound < curRound)
|
{
|
lastCurValueDict[roundType] = 0;
|
}
|
|
lastCurValue = lastCurValueDict[roundType];
|
if (lastCurValue < curValue)
|
{
|
var act = GetOperationInfo();
|
if (act != null && act.TryGetRound(roundType, out var round) && round.AwardList != null)
|
{
|
for (int i = 0; i < round.AwardList.Length; i++)
|
{
|
var Award = round.AwardList[i];
|
int state = GetAwardState(roundType, Award.AwardIndex);
|
if (Award.NeedValue > lastCurValue && Award.NeedValue <= curValue && state == 1)
|
{
|
newRoundType = roundType;
|
newAwardType = round.AwardType;
|
newAwardTypeValue = (int)round.AwardTypeValue;
|
newAwardIndex = Award.AwardIndex;
|
if (!DTC0403_tagPlayerLoginLoadOK.neverLoginOk && !WindowCenter.Instance.IsOpen<CycleHallAchievementTipWin>())
|
{
|
WindowCenter.Instance.Open<CycleHallAchievementTipWin>();
|
}
|
UpdateNewAwardHave?.Invoke();
|
}
|
}
|
}
|
}
|
}
|
lastCurRoundDict[roundType] = curRound;
|
lastCurValueDict[roundType] = curValue;
|
}
|
|
public void UpdatePlayerInfo(HAA89_tagMCActLunhuidianPlayerInfo netPack)
|
{
|
if (actNum != netPack.ActNum)
|
return;
|
if (!playerInfoDict.ContainsKey(netPack.RoundType))
|
playerInfoDict[netPack.RoundType] = new HAA89_tagMCActLunhuidianPlayerInfo();
|
playerInfoDict[netPack.RoundType].RoundType = netPack.RoundType;
|
playerInfoDict[netPack.RoundType].CurRound = netPack.CurRound;
|
playerInfoDict[netPack.RoundType].CurValue = netPack.CurValue;
|
playerInfoDict[netPack.RoundType].AwardRecord = netPack.AwardRecord;
|
CheckNewAwardHave(netPack.RoundType, (int)netPack.CurRound, (int)netPack.CurValue);
|
UpdatePlayerInfoAction?.Invoke();
|
UpdateRedpoint();
|
}
|
|
public void SendGetAward(int roundType, int needValue)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 78;
|
getReward.DataEx = (uint)actNum;
|
getReward.DataExStr = StringUtility.Contact(roundType, "|", needValue);
|
getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
}
|
}
|