using LitJson;
|
using System;
|
using System.Collections.Generic;
|
|
namespace vnxbqy.UI
|
{
|
public class FairySiegeHelpModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action<int> onStateUpdate;
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.FairySiegeHelpAct;
|
public static Operation operaType = Operation.default54;
|
|
public int actNum = 32; //对应界面
|
public int m_AwardRecord;
|
public event Action UpdateAwardEvent;
|
|
public List<int> rechargePlayerIDs = new List<int>(); //充值玩家ID
|
public Dictionary<int, int> getAwardPlayerNums = new Dictionary<int, int>(); //领取奖励人数
|
public Dictionary<int, List<int>> getAwardMembers = new Dictionary<int, List<int>>(); //领取奖励的玩家ID
|
|
public int nowIndex;
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
FairyModel fairyModel { get { return ModelCenter.Instance.GetModel<FairyModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
FairySiegeActModel fairySiegeActModel { get { return ModelCenter.Instance.GetModel<FairySiegeActModel>(); } }
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
fairyModel.FamilyActionInfoEvent += OnFamilyActionEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
m_AwardRecord = 0;
|
rechargePlayerIDs.Clear();
|
getAwardPlayerNums.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
if (IsOpen)
|
QueryFamilyRecharge();
|
}
|
|
public override void UnInit()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
fairyModel.FamilyActionInfoEvent -= OnFamilyActionEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
if (!fairySiegeActModel.TryGetRedpoint(FairySiegeRedPointType.Help, out Redpoint redpointHelp))
|
return false;
|
if (!fairySiegeActModel.TryGetRedpoint(FairySiegeRedPointType.Gift, out Redpoint redpointGift))
|
return false;
|
return redpointHelp.state == RedPointState.Simple || redpointGift.state == RedPointState.Simple;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
|
}
|
}
|
|
private void OperationEndEvent(Operation type, int state)
|
{
|
if (type == operaType && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
UpdateHelpRedpoint();
|
UpdateGiftRedpoint();
|
}
|
}
|
|
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 VipModel_rechargeCountEvent(int obj)
|
{
|
if (IsOpen)
|
{
|
UpdateGiftRedpoint();
|
}
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
UpdateGiftRedpoint();
|
}
|
|
public int GetBuyTotalCnt()
|
{
|
OperationFamilyRechargeConn act;
|
OperationTimeHepler.Instance.TryGetOperation(FairySiegeHelpModel.operaType, out act);
|
|
if (act == null)
|
return 0;
|
int total = 0;
|
for (int i = 0; i < act.ctgIDs.Count; i++)
|
{
|
int ctgID = act.ctgIDs[i];
|
VipModel.RechargeCount rechargeCount;
|
if (vipModel.TryGetRechargeCount(ctgID, out rechargeCount))
|
{
|
total += rechargeCount.totalCount;
|
}
|
}
|
return total;
|
}
|
|
public Int2 GetBuyCntInfo(int ctgID)
|
{
|
OperationFamilyRechargeConn act;
|
OperationTimeHepler.Instance.TryGetOperation(FairySiegeHelpModel.operaType, out act);
|
|
VipModel.RechargeCount rechargeCount;
|
vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
|
|
var ctgConfig = CTGConfig.Get(ctgID);
|
int buyCnt = 0;
|
int totalCnt = 0;
|
if (ctgConfig.DailyBuyCount != 0)
|
{
|
buyCnt = rechargeCount.todayCount;
|
totalCnt = ctgConfig.DailyBuyCount;
|
}
|
else
|
{
|
buyCnt = rechargeCount.totalCount;
|
totalCnt = ctgConfig.TotalBuyCount;
|
}
|
|
return new Int2(buyCnt, totalCnt);
|
}
|
|
//0 不可领取(未达标或者领取超过家族总人数上限) 1 可领取 2 已领取
|
public int GetAwardState(int index)
|
{
|
//校验日期
|
OperationFamilyRechargeConn actInfo;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out actInfo);
|
if (actInfo == null) return 0;
|
|
if ((m_AwardRecord & 1 << index) > 0)
|
return 2;
|
|
int rechargeNum = rechargePlayerIDs.Count;
|
|
PlayerFairyData.FairyData fairy = PlayerDatas.Instance.fairyData.fairy;
|
if (fairy == null) return 0;
|
FamilyConfig cfg = FamilyConfig.Get(fairy.FamilyLV);
|
|
int memberCnt = cfg.memberCnt;
|
int needNum = actInfo.needPlayers[index];
|
|
if (rechargeNum >= needNum)
|
{
|
if (getAwardPlayerNums.ContainsKey(needNum) && getAwardPlayerNums[needNum] >= memberCnt)
|
{
|
return 0;
|
}
|
else
|
{
|
return 1;
|
}
|
}
|
|
return 0;
|
}
|
|
public void UpdateHelpRedpoint()
|
{
|
if (!IsOpen)
|
return;
|
// 没有参赛资格
|
if (!fairySiegeActModel.hasQualification())
|
return;
|
int stateValue;
|
if (!fairySiegeActModel.TryGetCurrentStateValue(out stateValue))
|
return;
|
int state = fairySiegeActModel.GetStateByStateValue(stateValue); //0 公示期 1 备战期 2 开战期 3 休战期 4 领奖期
|
if (state == 0 || state == 4)
|
return;
|
if (!fairySiegeActModel.TryGetRedpoint(FairySiegeRedPointType.Help, out Redpoint redpoint))
|
return;
|
redpoint.state = RedPointState.None;
|
OperationFamilyRechargeConn actInfo;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out actInfo);
|
if (actInfo == null)
|
return;
|
for (int i = 0; i < actInfo.needPlayers.Count; i++)
|
{
|
if (GetAwardState(i) == 1)
|
{
|
redpoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
public void UpdateGiftRedpoint()
|
{
|
if (!IsOpen)
|
return;
|
int stateValue;
|
if (!fairySiegeActModel.TryGetCurrentStateValue(out stateValue))
|
return;
|
int state = fairySiegeActModel.GetStateByStateValue(stateValue); //0 公示期 1 备战期 2 开战期 3 休战期 4 领奖期
|
if (state == 0 || state == 4)
|
return;
|
if (!fairySiegeActModel.TryGetRedpoint(FairySiegeRedPointType.Gift, out Redpoint redpoint))
|
return;
|
redpoint.state = RedPointState.None;
|
OperationFamilyRechargeConn act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
if (act == null)
|
return;
|
//商店免费
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int i = 0; i < storeCnt; i++)
|
{
|
if (_list[i].MoneyNumber == 0)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[i], out remainNum);
|
if (remainNum > 0)
|
{
|
redpoint.state = RedPointState.Simple;
|
}
|
}
|
}
|
}
|
|
public void UpdateActFamilyCTGAssistPlayerInfo(HAA78_tagMCActFamilyCTGAssistPlayerInfo netPack)
|
{
|
if (actNum != netPack.ActNum)
|
return;
|
m_AwardRecord = (int)netPack.AwardRecord;
|
UpdateAwardEvent?.Invoke();
|
UpdateHelpRedpoint();
|
UpdateGiftRedpoint();
|
}
|
|
public void SendGetAward(int num)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 74;
|
getReward.DataEx = (uint)num;
|
getReward.DataExStr = actNum.ToString();
|
getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
|
private void OnFamilyActionEvent(int familyID, int type)
|
{
|
if (familyID != PlayerDatas.Instance.baseData.FamilyId)
|
{
|
return;
|
}
|
if (type != 14)
|
{
|
return;
|
}
|
var datas = fairyModel.familyActions[familyID][14];
|
if (datas.Length == 0)
|
{
|
return;
|
}
|
var data = datas[0];
|
|
if (data.Value1 != actNum)
|
return;
|
|
//data.UseData [[280182,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],{'9':1,'10':1,'1':50,'5':1}]
|
|
JsonData json = JsonMapper.ToObject(data.UseData);
|
rechargePlayerIDs = new List<int>();
|
getAwardPlayerNums = new Dictionary<int, int>();
|
|
rechargePlayerIDs = JsonMapper.ToObject<List<int>>(json[0].ToJson());
|
|
JsonData awardNums = json[1];
|
foreach (var key in awardNums.Keys)
|
{
|
getAwardPlayerNums[int.Parse(key)] = (int)awardNums[key];
|
}
|
|
// 处理各档位领取成员明细
|
if (json.Count > 2) // 兼容旧数据可能只有2个元素的情况
|
{
|
JsonData awardMembers = json[2];
|
foreach (var key in awardMembers.Keys)
|
{
|
int tier = int.Parse(key);
|
JsonData memberIdsJson = awardMembers[key];
|
List<int> memberIds = JsonMapper.ToObject<List<int>>(memberIdsJson.ToJson());
|
getAwardMembers[tier] = memberIds;
|
}
|
}
|
UpdateAwardEvent?.Invoke();
|
UpdateHelpRedpoint();
|
}
|
|
private void QueryFamilyRecharge()
|
{
|
if (PlayerDatas.Instance.baseData.FamilyId == 0)
|
{
|
return;
|
}
|
var pack = new CA408_tagCGQueryFamilyAction();
|
pack.ActionType = 14;
|
pack.FamilyID = PlayerDatas.Instance.baseData.FamilyId;
|
GameNetSystem.Instance.SendInfo(pack);
|
}
|
|
private void OnRefreshFairyMine()
|
{
|
if (!PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
rechargePlayerIDs.Clear();
|
getAwardPlayerNums.Clear();
|
}
|
if (IsOpen)
|
QueryFamilyRecharge();
|
}
|
}
|
}
|