using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class RedEnvelopeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
|
{
|
PlayerRedPacketDatas redPackdata { get { return ModelCenter.Instance.GetModel<PlayerRedPacketDatas>(); } }
|
OSRedEnvelopeModel envelopeModel { get { return ModelCenter.Instance.GetModel<OSRedEnvelopeModel>(); } }
|
|
public override void Init()
|
{
|
ParseConfig();
|
SysNotifyMgr.Instance.OnSystemNotifyEvent += OnSystemNotifyEvent;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
serverInited = true;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
serverInited = false;
|
m_RedEnvelopeDict.Clear();
|
}
|
|
bool serverInited = false;
|
|
private Dictionary<int, RedEnvelope> m_RedEnvelopeDict = new Dictionary<int, RedEnvelope>();
|
|
public event Action EnvelopeUpdateEvent;
|
public event Action<int> EnvelopeGetEvent;
|
|
public void UpdateRedEnvelope(HA404_tagGCFamilyRedPacketInfo _pak)
|
{
|
for (int i = 0; i < _pak.Count; i++)
|
{
|
var info = _pak.RedPacketInfo[i];
|
RedEnvelope _envelope = new RedEnvelope()
|
{
|
id = (int)info.RedPacketID,
|
player = (int)info.PlayerID,
|
playerName = info.Name,
|
time = info.Time,
|
job = info.PlayeJob,
|
moneyType = info.MoneyType,
|
moneyNum = info.MoneyNum,
|
type = info.GetWay,
|
packCount = info.PacketCnt,
|
state = info.State,
|
Wish = UIHelper.ServerStringTrim(info.Wish)
|
};
|
m_RedEnvelopeDict[(int)info.RedPacketID] = _envelope;
|
if (EnvelopeGetEvent != null)
|
{
|
EnvelopeGetEvent(_envelope.id);
|
}
|
}
|
if (EnvelopeUpdateEvent != null)
|
{
|
EnvelopeUpdateEvent();
|
}
|
}
|
|
|
public void UpdateRedEnvelope(HA405_tagGCFamilyRedPacketGrabInfo vNetData)
|
{
|
RedEnvelope envelope;
|
if (TryGetEnvelope((int)vNetData.RedPacketID, out envelope))
|
{
|
if (envelope.packCount == vNetData.Count
|
&& envelope.state != 3)
|
{
|
UpdateRedEnvelope(envelope, 3);
|
}
|
}
|
bool self = false;
|
for (int i = 0; i < vNetData.Count; i++)
|
{
|
if (UIHelper.ServerStringTrim(vNetData.GrabInfo[i].Name).Equals(
|
UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName)))
|
{
|
self = true;
|
break;
|
}
|
}
|
if (vNetData.RedPacketID == cacheEnvelopeId)
|
{
|
if (!WindowCenter.Instance.CheckOpen<RedDetailsTipsWin>())
|
{
|
envelopeSfx = vNetData.RedPacketID == envelopeSfx && self ? envelopeSfx : 0;
|
ModelCenter.Instance.GetModel<PlayerRedPacketDatas>().redpackDetailId = (int)vNetData.RedPacketID;
|
WindowCenter.Instance.Open<RedDetailsTipsWin>();
|
}
|
cacheEnvelopeId = 0;
|
}
|
}
|
|
public void UpdateRedEnvelope(RedEnvelope envelope, int _state)
|
{
|
m_RedEnvelopeDict[(int)envelope.id] = new RedEnvelope()
|
{
|
id = envelope.id,
|
player = envelope.player,
|
playerName = envelope.playerName,
|
time = envelope.time,
|
job = envelope.job,
|
moneyType = envelope.moneyType,
|
moneyNum = envelope.moneyNum,
|
type = envelope.type,
|
packCount = envelope.packCount,
|
state = _state,
|
Wish = UIHelper.ServerStringTrim(envelope.Wish)
|
};
|
if (EnvelopeUpdateEvent != null)
|
{
|
EnvelopeUpdateEvent();
|
}
|
}
|
|
public event Action EnvelopeDelEvent;
|
|
public bool TryGetEnvelope(int _id,out RedEnvelope _envelope)
|
{
|
return m_RedEnvelopeDict.TryGetValue(_id, out _envelope);
|
}
|
|
public void UpdateRedEnvelope(HAC05_tagGCRedPacketDel _pak)
|
{
|
for (int i = 0; i < _pak.Cnt; i++)
|
{
|
var _id = (int)_pak.DelRedPacketID[i];
|
if (m_RedEnvelopeDict.ContainsKey(_id))
|
{
|
m_RedEnvelopeDict.Remove(_id);
|
}
|
}
|
if (EnvelopeDelEvent != null)
|
{
|
EnvelopeDelEvent();
|
}
|
}
|
|
public void SendGetEnvelope(int _id)
|
{
|
RedEnvelope _envelope;
|
if(m_RedEnvelopeDict.TryGetValue(_id,out _envelope))
|
{
|
if (_envelope.state == 1)
|
{
|
CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
|
_pak.RedPaketID = (uint)_id;
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
}
|
}
|
|
public bool TryGetLatestEnvelope(out RedEnvelope envelope)
|
{
|
envelope = default(RedEnvelope);
|
bool _has = false;
|
foreach (var _envelope in m_RedEnvelopeDict.Values)
|
{
|
if (_envelope.state == 1)
|
{
|
envelope = _envelope;
|
_has = true;
|
}
|
}
|
return _has;
|
}
|
|
public void GetEnvelopes(int _type, ref List<int> _list)
|
{
|
_list.Clear();
|
foreach (var _id in m_RedEnvelopeDict.Keys)
|
{
|
if (m_RedEnvelopeDict[_id].type == _type)
|
{
|
_list.Add(_id);
|
}
|
}
|
}
|
|
public bool CheckEnvelopeLimit(int _id, bool _tip = false)
|
{
|
if (!m_RedEnvelopeDict.ContainsKey(_id))
|
{
|
return false;
|
}
|
RedEnvelope _envelope = m_RedEnvelopeDict[_id];
|
var _OSRedModel = ModelCenter.Instance.GetModel<OSRedEnvelopeModel>();
|
var _OSRedType = _OSRedModel.OSRedEnvelopeType;
|
if (_envelope.type == _OSRedType)
|
{
|
if (TimeUtility.OpenDay >= _OSRedModel.openDays)
|
{
|
if (_tip)
|
{
|
SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
|
}
|
return false;
|
}
|
if (_OSRedModel.getEnvelopeTimes <= 0)
|
{
|
if (_tip)
|
{
|
SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
|
}
|
return false;
|
}
|
}
|
return true;
|
}
|
|
public int cacheEnvelopeId = 0;
|
public int envelopeSfx { get; set; }
|
public void RequestDetail(int _id)
|
{
|
cacheEnvelopeId = _id;
|
CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
|
_pak.RedPaketID = (uint)_id;
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
|
|
#region 红包雨特效
|
DateTime sfxRedpackTime = DateTime.Now;
|
|
private void OnSystemNotifyEvent(string _key)
|
{
|
if (_key.Equals("OSRedpackSfx"))
|
{
|
CheckRedpackSfx();
|
}
|
}
|
|
public void CheckRedpackSfx()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.OpenServerRedEnvelope))
|
{
|
return;
|
}
|
if (envelopeModel.getEnvelopeTimes <= 0)
|
{
|
return;
|
}
|
if (!serverInited)
|
{
|
return;
|
}
|
if (!(StageManager.Instance.CurrentStage is DungeonStage)
|
|| WindowCenter.Instance.CheckOpen<LoadingWin>())
|
{
|
return;
|
}
|
if (DateTime.Now >= sfxRedpackTime)
|
{
|
var _effect = EffectMgr.Instance.PlayUIEffect(5162, 4500, WindowCenter.Instance.uiRoot.tipsCanvas, false);
|
sfxRedpackTime = sfxRedpackTime.AddSeconds(_effect != null ? _effect.duration : 0);
|
}
|
}
|
#endregion
|
|
void ParseConfig()
|
{
|
}
|
|
public struct RedEnvelope
|
{
|
public int id;
|
public int player;
|
public string playerName;
|
public uint time;
|
public int job;
|
public int moneyType;
|
public int moneyNum;
|
public int type;
|
public int packCount;
|
public int state; //0未发,1未领取,2已领取,3全部领完
|
public string Wish; //祝福语
|
}
|
}
|
}
|
|