using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
|
//红包信息
|
public class FamilyRedPacket//红包信息
|
{
|
public int RedPacketID;//红包唯一ID
|
public int PlayerID;//玩家ID
|
public string Name;//玩家名字
|
public int Time;//时间
|
public int PlayeJob;//玩家职业
|
public int MoneyType;//金钱类型//1是V6红包
|
public int MoneyNum;//金钱数量
|
public int GetWay; //获得途径
|
public int PacketCnt; //可抢个数
|
public int State; //0未发,1未领取,2已领取,3全部领完
|
public string Wish; //祝福语
|
public byte IsAnonymous; //是否匿名
|
public int Face; //基本脸型
|
public int FacePic; //头像框
|
|
}
|
|
public class FamilyRedPacktGrabinfo//家族抢红包的信息
|
{
|
|
public string Name;//玩家名字
|
public int PlayerJob;//玩家职业
|
public int MoneyNum;//金钱数量
|
public int Face; //基本脸型
|
public int FacePic; //头像框
|
|
|
}
|
public class RedPacketModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
|
public Dictionary<int, FamilyRedPacket> _DicRedBag = new Dictionary<int, FamilyRedPacket>();//接收红包信息
|
public Dictionary<int, FamilyRedPacktGrabinfo> _DicRedGrabinfo = new Dictionary<int, FamilyRedPacktGrabinfo>();//获取抢红包的信息字典
|
public Dictionary<int, List<int>> redBagTypes = new Dictionary<int, List<int>>(); //红包类型的大分类,1仙盟 2全服 3节日
|
public delegate void RedEnvelopeToAdd(FamilyRedPacket _familyRedPacket);
|
public static event RedEnvelopeToAdd Event_RedEnvelopeToAdd;//红包的添加
|
public delegate void RedEnvelopeToRefresh(FamilyRedPacket _familyRedPacket);
|
public static event RedEnvelopeToRefresh Event_RedEnvelopeToRefresh;//红包的刷新
|
|
public delegate void DetailsRedEnvelopeRefresh();
|
public static event DetailsRedEnvelopeRefresh Event_DetailsRedEnvelopeRefresh;//红包详情的信息刷新
|
|
public event Action ServerGrabCntEvent; // 可抢个数刷新
|
public event Action RedbagRefresh; //红包刷新
|
public event Action RedpackDelEvent; //红包删除
|
public int UseLimit = 0;//V6红包使用额度
|
public int ServerGrabCnt = 0;// 全服红包已抢次数
|
public bool _v6RedBool = false; //是否v6红包
|
|
public int RedBagId = 0;//获取当前选中红包的ID
|
|
public int redpackDetailId = 0;
|
|
public bool IsRedBagGetBool = false;
|
public static event Action OnRedBagGetEvent;//是否有可领取的红包
|
|
private const int Redpoint_key1 = 1070202;
|
public Redpoint redPointStre1 = new Redpoint(10702, Redpoint_key1);
|
|
public int RedEnvelopeID = 0;//发红包的ID(用于默认弹出开)
|
|
private int GrabRedBagId = 0;
|
public override void Init()
|
{
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
|
ParseConfig();
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
void ParseConfig()
|
{
|
redBagTypes.Clear();
|
var config = JsonMapper.ToObject(FuncConfigConfig.Get("RedPacketClassify").Numerical1);
|
foreach (var key in config.Keys)
|
{
|
redBagTypes[int.Parse(key)] = new List<int> (JsonMapper.ToObject<int[]>(config[key].ToJson()));
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
UseLimit = 0;
|
RedEnvelopeID = 0;
|
IsRedBagGetBool = false;
|
RedBagId = 0;
|
_DicRedBag.Clear();
|
_DicRedGrabinfo.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
private void OnRefreshFairyMine()//退出仙盟
|
{
|
if (_DicRedBag.Count > 0 && !PlayerDatas.Instance.fairyData.HasFairy)
|
{
|
var list = _DicRedBag.Values.ToList();
|
for (int i = 0; i < list.Count; i++)
|
{
|
if (IsDisplayInFamily(list[i].GetWay))
|
{
|
_DicRedBag.Remove(list[i].RedPacketID);
|
}
|
}
|
IsRedBagGet();
|
RedbagRefresh?.Invoke();
|
}
|
}
|
|
public void UpdateDelRedpack(HAC05_tagGCRedPacketDel _pak)
|
{
|
for (int i = 0; i < _pak.Cnt; i++)
|
{
|
var _id = (int)_pak.DelRedPacketID[i];
|
if (_DicRedBag.ContainsKey(_id))
|
{
|
|
_DicRedBag.Remove(_id);
|
}
|
}
|
RedpackDelEvent?.Invoke();
|
IsRedBagGet();
|
RedbagRefresh?.Invoke();
|
}
|
|
|
public void RedEnvelopeInfo(HA404_tagGCFamilyRedPacketInfo info)//家族红包总信息
|
{
|
|
|
if ((int)info.IsAll == 1)
|
{
|
_DicRedBag.Clear();
|
for (int i = 0; i < info.Count; i++)
|
{
|
if (!_DicRedBag.ContainsKey((int)info.RedPacketInfo[i].RedPacketID))
|
{
|
FamilyRedPacket _familyRed = new FamilyRedPacket();
|
_familyRed.RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
|
_familyRed.PlayerID = (int)info.RedPacketInfo[i].PlayerID;
|
_familyRed.Name = info.RedPacketInfo[i].Name;
|
_familyRed.Time = (int)info.RedPacketInfo[i].Time;
|
_familyRed.PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
|
_familyRed.MoneyType = (int)info.RedPacketInfo[i].MoneyType;
|
_familyRed.MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
|
_familyRed.GetWay = (int)info.RedPacketInfo[i].GetWay;
|
_familyRed.PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
|
_familyRed.State = (int)info.RedPacketInfo[i].State;
|
_familyRed.Wish = (string)info.RedPacketInfo[i].Wish;
|
_familyRed.IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
|
_familyRed.Face = (int)info.RedPacketInfo[i].Face;
|
_familyRed.FacePic = (int)info.RedPacketInfo[i].FacePic;
|
_DicRedBag.Add((int)info.RedPacketInfo[i].RedPacketID, _familyRed);
|
|
}
|
|
}
|
|
}
|
else
|
{
|
for (int i = 0; i < info.Count; i++)
|
{
|
if (!_DicRedBag.ContainsKey((int)info.RedPacketInfo[i].RedPacketID))
|
{
|
FamilyRedPacket _familyRed = new FamilyRedPacket();
|
_familyRed.RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
|
_familyRed.PlayerID = (int)info.RedPacketInfo[i].PlayerID;
|
_familyRed.Name = info.RedPacketInfo[i].Name;
|
_familyRed.Time = (int)info.RedPacketInfo[i].Time;
|
_familyRed.PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
|
_familyRed.MoneyType = (int)info.RedPacketInfo[i].MoneyType;
|
_familyRed.MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
|
_familyRed.GetWay = (int)info.RedPacketInfo[i].GetWay;
|
_familyRed.PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
|
_familyRed.State = (int)info.RedPacketInfo[i].State;
|
_familyRed.Wish = (string)info.RedPacketInfo[i].Wish;
|
_familyRed.IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
|
_familyRed.Face = (int)info.RedPacketInfo[i].Face;
|
_familyRed.FacePic = (int)info.RedPacketInfo[i].FacePic;
|
_DicRedBag.Add((int)info.RedPacketInfo[i].RedPacketID, _familyRed);
|
|
if (Event_RedEnvelopeToAdd != null)
|
Event_RedEnvelopeToAdd(_familyRed);
|
}
|
else
|
{
|
|
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PlayerID = (int)info.RedPacketInfo[i].PlayerID;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Name = info.RedPacketInfo[i].Name;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Time = (int)info.RedPacketInfo[i].Time;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].MoneyType = (int)info.RedPacketInfo[i].MoneyType;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].GetWay = (int)info.RedPacketInfo[i].GetWay;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].State = (int)info.RedPacketInfo[i].State;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Face = (int)info.RedPacketInfo[i].Face;
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].FacePic = (int)info.RedPacketInfo[i].FacePic;
|
if ((int)info.RedPacketInfo[i].RedPacketID == GrabRedBagId)
|
{
|
var Values = _DicRedGrabinfo.Values;
|
foreach (var value in Values)
|
{
|
if (value.Name == PlayerDatas.Instance.baseData.PlayerName)
|
{
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].State = 2;
|
}
|
}
|
}
|
_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Wish = (string)info.RedPacketInfo[i].Wish;
|
if (Event_RedEnvelopeToRefresh != null)
|
{
|
Event_RedEnvelopeToRefresh(_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID]);
|
}
|
if (WindowCenter.Instance.IsOpen<RedBagTipsWin>() || WindowCenter.Instance.IsOpen<FullServerRechargeRedpackWin>())
|
{
|
RedBagPoppingOpen();
|
}
|
|
}
|
}
|
}
|
|
IsRedBagGet();
|
RedPacketRedDot();
|
RedbagRefresh?.Invoke();
|
}
|
|
private void RedBagPoppingOpen()
|
{
|
if (_DicRedBag.ContainsKey(RedEnvelopeID) && WindowCenter.Instance.IsOpen<RedBagTipsWin>())
|
{
|
var redBag = _DicRedBag[RedEnvelopeID];
|
if (IsDisplayInFamily(redBag.GetWay) && redBag.GetWay != 0 && redBag.PlayerID == PlayerDatas.Instance.PlayerId && redBag.State == 1)
|
{
|
RedBagId = RedEnvelopeID;
|
WindowCenter.Instance.Open<RedpackOpenWin>();//打开领取界面
|
RedEnvelopeID = 0;
|
}
|
}
|
|
if (_DicRedBag.ContainsKey(RedEnvelopeID) && WindowCenter.Instance.IsOpen<FullServerRechargeRedpackWin>())
|
{
|
var redBag = _DicRedBag[RedEnvelopeID];
|
if (redBag.GetWay == FullServerRechargeRedpackModel.FullServer_Recharge_Redpack && redBag.PlayerID == PlayerDatas.Instance.PlayerId && redBag.State == 1)
|
{
|
RedBagId = RedEnvelopeID;
|
WindowCenter.Instance.Open<RedpackOpenWin>();//打开领取界面
|
}
|
}
|
|
}
|
|
|
public void IsRedBagGet()
|
{
|
var existUnGetRedpack = false; //切换有无时通知
|
//仙盟开启才判断
|
if (!FuncOpen.Instance.IsFuncOpen(15))
|
return;
|
foreach (var value in _DicRedBag.Values)
|
{
|
if (!IsDisplayInFamily(value.GetWay))
|
{
|
continue;
|
}
|
if (value.State == 1)
|
{
|
existUnGetRedpack = true;
|
break;
|
}
|
}
|
if (IsRedBagGetBool != existUnGetRedpack)
|
{
|
IsRedBagGetBool = existUnGetRedpack;
|
OnRedBagGetEvent?.Invoke();
|
}
|
}
|
|
|
private void RedPacketRedDot()
|
{
|
redPointStre1.state = RedPointState.None;
|
bool _bool = false;
|
foreach (var value in _DicRedBag.Values)
|
{
|
|
if (value.PlayerID == PlayerDatas.Instance.baseData.PlayerID && value.State == 0 && IsDisplayInFamily(value.GetWay))
|
{
|
_bool = true;
|
}
|
if (value.State == 1 && IsDisplayInFamily(value.GetWay))
|
{
|
_bool = true;
|
}
|
}
|
if (_bool)
|
{
|
redPointStre1.state = RedPointState.Simple;
|
}
|
|
}
|
|
public string RedPacketMaxName = null;//最大红包数量的ID
|
public void GrabRedEnvelope( HA405_tagGCFamilyRedPacketGrabInfo info)//家族抢红包信息
|
{
|
GrabRedBagId = (int)info.RedPacketID;
|
int _moneyNum = 0;
|
_DicRedGrabinfo.Clear();
|
|
for (int i = 0; i < info.Count;i++)
|
{
|
if (!_DicRedGrabinfo.ContainsKey(i))
|
{
|
FamilyRedPacktGrabinfo _familyRed = new FamilyRedPacktGrabinfo();
|
|
_familyRed.Name = info.GrabInfo[i].Name;
|
_familyRed.PlayerJob = info.GrabInfo[i].PlayeJob;
|
_familyRed.MoneyNum = (int)info.GrabInfo[i].MoneyNum;
|
_familyRed.Face = (int)info.GrabInfo[i].Face;
|
_familyRed.FacePic = (int)info.GrabInfo[i].FacePic;
|
if ((int)info.GrabInfo[i].MoneyNum > _moneyNum)
|
{
|
_moneyNum = (int)info.GrabInfo[i].MoneyNum;
|
RedPacketMaxName = info.GrabInfo[i].Name;
|
|
}
|
_DicRedGrabinfo.Add(i, _familyRed);
|
|
|
}
|
|
|
}
|
|
if (Event_DetailsRedEnvelopeRefresh != null)
|
Event_DetailsRedEnvelopeRefresh();
|
|
|
|
|
}
|
|
public bool IsDisplayInFamily(int getWay)
|
{
|
foreach (var key in redBagTypes.Keys)
|
{
|
if (key == 1) continue;
|
if (redBagTypes[key].Contains(getWay))
|
return false;
|
}
|
return true;
|
}
|
|
public bool IsDisplayRechargeTH(FamilyRedPacket redbag)
|
{
|
if (!redBagTypes[2].Contains(redbag.GetWay))
|
return false;
|
|
if (redbag.State == 0 && redbag.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
|
{
|
//过滤别人的可发红包
|
return false;
|
}
|
return true;
|
}
|
|
public void UpdateServerGrabCntEvent()
|
{
|
ServerGrabCntEvent?.Invoke();
|
}
|
}
|