using LitJson;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace vnxbqy.UI
|
{
|
public class YunShiXBActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action<int> onStateUpdate;
|
public Redpoint redPoint = new Redpoint(MainRedDot.YunShiRepoint);
|
public Redpoint redPointTab = new Redpoint(MainRedDot.YunShiRepoint, MainRedDot.YunShiRepoint * 10 + 1); //¿ÉÄܹҶà¸ö¸¸ºìµã
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.YunShiXBAct;
|
public static Operation operaType = Operation.default48;
|
|
//<Ѱ±¦ÀàÐÍ£¬<¸ñ×Ó±àºÅ£¬¸ñ×Ó±³¾°±àºÅ>>
|
public Dictionary<int, Dictionary<int, int>> itemBgDict = new Dictionary<int, Dictionary<int, int>>();
|
|
//ĬÈϸñ×Ó±³¾° Ë÷Òý0ÊÇÓÐÏÞÁ¿¸ñ×ӵı³¾° Ë÷Òý1ÊÇÆÕͨ¸ñ×ӵı³¾°
|
public List<int> defaultBgList = new List<int>();
|
|
//<Ѱ±¦ÀàÐÍ£¬<ÎïÆ·id£¬¸ñ×Ó±³¾°±àºÅ>>
|
public Dictionary<int, Dictionary<int, int>> itemIdBgDict = new Dictionary<int, Dictionary<int, int>>();
|
|
//<Ѱ±¦ÀàÐÍ,¹¦ÄÜID>
|
public Dictionary<int, int> funcIDDict = new Dictionary<int, int>();
|
public int actNum = 10; //¶ÔÓ¦½çÃæ
|
public event Action<bool> UpdateMissionEvent;
|
public readonly int AwardCellCount = 5;
|
|
//ͬ²½²¥·Å°Ú¶¯¶¯»
|
public Action PlayAnimationSync;
|
|
private bool isPlayAnimation = false;
|
public bool IsPlayAnimation
|
{
|
get
|
{
|
return isPlayAnimation;
|
}
|
set
|
{
|
isPlayAnimation = value;
|
if (isPlayAnimation)
|
{
|
PlayAnimationSync?.Invoke();
|
}
|
isPlayAnimation = false;
|
}
|
}
|
public bool isSkipXB { get; set; }
|
|
HappyXBModel happyXBModel { get { return ModelCenter.Instance.GetModelEx<HappyXBModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
happyXBModel.RefreshXBTypeInfoAct += OnRefreshXBTypeInfoAct;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent += OnOperationTimeUpdateEvent;
|
packModel.refreshItemCountEvent += OnRefreshItemCountEvent;
|
GlobalTimeEvent.Instance.secondEvent += CheckRedPoint;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
|
var jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("YunShi").Numerical1);
|
var keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
int type = int.Parse(keyList[i]);
|
if (!itemBgDict.ContainsKey(type))
|
itemBgDict[type] = new Dictionary<int, int>();
|
if (!itemIdBgDict.ContainsKey(type))
|
itemIdBgDict[type] = new Dictionary<int, int>();
|
|
var arr = JsonMapper.ToObject<int[][]>(jsonData[keyList[i]].ToJson());
|
if (type == 0)
|
{
|
defaultBgList.Add(arr[0][0]);
|
defaultBgList.Add(arr[0][1]);
|
}
|
else
|
{
|
for (int j = 0; j < arr.Length; j++)
|
{
|
itemBgDict[type][arr[j][0]] = arr[j][1];
|
}
|
}
|
}
|
jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("YunShi").Numerical2);
|
keyList = jsonData.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
int type = int.Parse(keyList[i]);
|
int funcId = int.Parse(jsonData[keyList[i]].ToJson());
|
funcIDDict[type] = funcId;
|
}
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
WindowCenter.Instance.uiRoot.eventSystem.enabled = true;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
happyXBModel.RefreshXBTypeInfoAct -= OnRefreshXBTypeInfoAct;
|
OperationTimeHepler.Instance.operationTimeUpdateEvent -= OnOperationTimeUpdateEvent;
|
packModel.refreshItemCountEvent -= OnRefreshItemCountEvent;
|
GlobalTimeEvent.Instance.secondEvent -= CheckRedPoint;
|
}
|
|
private void OnRefreshItemCountEvent(PackType type, int arg2, int arg3)
|
{
|
m_CheckRedPoint = true;
|
}
|
|
bool m_CheckRedPoint = false;
|
void CheckRedPoint()
|
{
|
if (m_CheckRedPoint)
|
{
|
UpdateRedPoint();
|
m_CheckRedPoint = false;
|
}
|
}
|
|
private void OnOperationTimeUpdateEvent(Operation operation)
|
{
|
|
if (operation == Operation.default48)
|
{
|
if (WindowCenter.Instance.IsOpen<YunShiWin>())
|
{
|
WindowCenter.Instance.Close<YunShiWin>();
|
}
|
UpdateRedPoint();
|
}
|
}
|
|
private void OnRefreshXBTypeInfoAct()
|
{
|
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);
|
}
|
UpdateRedPoint();
|
if (WindowCenter.Instance.IsOpen<YunShiWin>())
|
{
|
WindowCenter.Instance.Close<YunShiWin>();
|
}
|
WindowCenter.Instance.uiRoot.eventSystem.enabled = true;
|
}
|
}
|
|
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);
|
}
|
}
|
}
|
|
private void UpdateRedPoint()
|
{
|
redPointTab.state = RedPointState.None;
|
|
OperationYunShi act;
|
OperationTimeHepler.Instance.TryGetOperation(YunShiXBActModel.operaType, out act);
|
if (act == null)
|
return;
|
|
int type = act.treasureType;
|
var xbInfo = happyXBModel.GetXBInfoByType(type);
|
if (xbInfo == null)
|
return;
|
|
var award = TreasureCntAwardConfig.GetAwardIndexDict(type);
|
if (award == null)
|
return;
|
|
var list = award.Keys.ToList();
|
list.Sort();
|
if (list == null)
|
return;
|
|
if (happyXBModel.IsHaveOneXBTool(type) || (happyXBModel.IsHaveManyXBTool(type, out int toolCnt, out int needToolCnt) && toolCnt >= needToolCnt))
|
redPointTab.state = RedPointState.Simple;
|
|
//Óн±ÀøÎ´ÁìÈ¡
|
for (int i = 0; i < AwardCellCount; i++)
|
{
|
if (i < list.Count)
|
{
|
int id = award[list[i]];
|
if (!TreasureCntAwardConfig.Has(id))
|
continue;
|
TreasureCntAwardConfig config = TreasureCntAwardConfig.Get(id);
|
int state = GetAwardState(xbInfo.treasureCount, config.NeedTreasureCnt, xbInfo.treasureCntAward, config.AwardIndex);
|
if (state == 1)
|
{
|
redPointTab.state = RedPointState.Simple;
|
}
|
}
|
}
|
}
|
|
public bool TryGetItemBG(int type, int gridIndex, bool isLimit, out string str)
|
{
|
str = string.Empty;
|
if (!itemBgDict.TryGetValue(type, out var dict))
|
return false;
|
if (!dict.TryGetValue(gridIndex, out var num))
|
{
|
if (defaultBgList == null)
|
return false;
|
str = StringUtility.Contact("YunShiXBItemBG_", isLimit ? defaultBgList[0] : defaultBgList[1]);
|
return true;
|
}
|
else
|
{
|
str = StringUtility.Contact("YunShiXBItemBG_", num);
|
return true;
|
}
|
}
|
|
Dictionary<int, int> xbLimitMaxCountDict = new Dictionary<int, int>();
|
|
public Dictionary<int, int> GetXbLimitMaxCountDict(string GridNumMaxLimitInfo)
|
{
|
if (xbLimitMaxCountDict.IsNullOrEmpty())
|
{
|
var jsonData = JsonMapper.ToObject(GridNumMaxLimitInfo);
|
var keyList = jsonData.Keys.ToList();
|
for (int j = 0; j < keyList.Count; j++)
|
{
|
string key = keyList[j];
|
int value = int.Parse(jsonData[key].ToJson());
|
xbLimitMaxCountDict[int.Parse(key)] = value;
|
}
|
}
|
return xbLimitMaxCountDict;
|
}
|
|
//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
public int GetAwardState(int nowCnt, int needCnt, int treasureCntAward, int index)
|
{
|
if (nowCnt < needCnt)
|
return 0;
|
return ((int)Math.Pow(2, index) & treasureCntAward) == 0 ? 1 : 2;
|
}
|
|
public bool IsFuncOpen()
|
{
|
OperationYunShi act;
|
OperationTimeHepler.Instance.TryGetOperation(YunShiXBActModel.operaType, out act);
|
if (act == null)
|
return false;
|
|
int type = act.treasureType;
|
var xbInfo = happyXBModel.GetXBInfoByType(type);
|
if (xbInfo == null)
|
return false;
|
|
if (!funcIDDict.TryGetValue(type, out var funcId))
|
return false;
|
return FuncOpen.Instance.IsFuncOpen(funcId);
|
}
|
|
public void SendGetAward(int type, int count)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 77;
|
getReward.DataEx = (uint)type;
|
getReward.DataExStr = count.ToString();
|
getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
}
|
}
|