using vnxbqy.UI; using System; using System.Collections.Generic; using System.Linq; using LitJson; using UnityEngine; class FlowerGiftModel : ILModel { public SelectPlayer jumpPlayer; //从外面点击的玩家信息 public event Action OnSelectPlayer; //要赠送的对象(jumpPlayer + 列表) SelectPlayer m_SelectPlayer; public SelectPlayer selectPlayer { get { return m_SelectPlayer; } set { m_SelectPlayer = value; OnSelectPlayer?.Invoke(); } } public bool giveToggle = false; public int charmValue = 0; //魅力值 public Dictionary charmSourceDict = new Dictionary(); public uint feedBackFlowerGiverID = 0; //查看送花者ID FriendsModel friendsModel { get { return ModelCenter.Instance.GetModelEx();}} protected override void Init() { GameEvent.playerLoginOkEvent += OnPlayerLoginOkEvent; GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent; GameEvent.playerDataRefreshEvent += OnPlayerDataRefreshEvent; } protected override void UnInit() { GameEvent.playerLoginOkEvent -= OnPlayerLoginOkEvent; GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent; GameEvent.playerDataRefreshEvent -= OnPlayerDataRefreshEvent; } void OnBeforePlayerDataInitializeEvent() { charmValue = 0; charmSourceDict.Clear(); flowersReceive.Clear(); giveToggle = false; } public struct SelectPlayer { public int playerID; public string name; public int closeCnt; //亲密度 } //!!!_socialPlayerDict 里存玩家信息没有sortvalue,_groupDict里只有sortvalue public int GetCloseCnt(int playerID) { var playerInfo = friendsModel.GetFriendDictByType(5); if (playerInfo == null) return 0; if (!playerInfo.ContainsKey((uint)playerID)) return 0; return (int)playerInfo[(uint)playerID].SortValue; } public List playerList = new List(); public void GetPlayerList() { playerList.Clear(); if (WeddingModel.Instance.m_CoupleID != 0) { playerList.Add(new SelectPlayer() { playerID = (int)WeddingModel.Instance.m_CoupleID, name = WeddingModel.Instance.m_CoupleName, closeCnt = GetCloseCnt((int)WeddingModel.Instance.m_CoupleID), }); } var friendDict = friendsModel.GetFriendDictByType(2); if (friendDict == null) return; var keyList = friendDict.Keys.ToList(); for (int i = 0; i < keyList.Count; i++) { uint playerID = keyList[i]; var playerInfo = friendsModel.GetFirendInfo(playerID, 2); if (playerInfo == null) continue; if (playerID == WeddingModel.Instance.m_CoupleID) continue; var player = new SelectPlayer { playerID = (int)playerID, name = playerInfo.PlayerName.Trim().Replace("\0", ""), closeCnt = GetCloseCnt((int)playerID), }; playerList.Add(player); } playerList.Sort(SortPlayer); } int SortPlayer(SelectPlayer friendA, SelectPlayer friendB) { bool ca = friendA.playerID == WeddingModel.Instance.m_CoupleID; bool cb = friendB.playerID == WeddingModel.Instance.m_CoupleID; if (ca != cb) { return cb.CompareTo(ca); } return friendB.closeCnt.CompareTo(friendA.closeCnt); } public void UpdateCharm(IL_HB325_tagGCPlayerCharmValueInfo netData) { charmValue = (int)netData.CharmValueTotal; UpdateCharmRedPoint(); } private Redpoint charmRedpoint = new Redpoint(10101, MainRedPoint.CharmRedPoint); void UpdateCharmRedPoint() { charmRedpoint.state = RedPointState.None; var charmLV = (int)PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.default11); var config = ILLoveCharmConfig.Get(charmLV); var nextConfig = ILLoveCharmConfig.Get(charmLV + 1); if (charmValue >= config.UpNeedCharm && nextConfig != null) { charmRedpoint.state = RedPointState.Simple; } } void OnPlayerDataRefreshEvent(PlayerDataType dataType) { if (dataType != PlayerDataType.default11) { return; } UpdateCharmRedPoint(); } public void QueryCharm(uint playerID, byte queryType) { var pack = new IL_CB309_tagCGCharmOfferBillboardQuery(); pack.PlayerID = playerID; pack.QueryType = queryType; pack.QueryCount = 5; GameNetSystem.Instance.SendInfo(pack); } public void UpdateCharmSource(IL_HB319_tagGCCharmOfferBillboardDataList netPack) { charmSourceDict.Clear(); for (int i = 0; i < netPack.DataCount; i++) { var info = netPack.OfferBillboardDataList[i]; charmSourceDict[info.PlayerName] = (int)info.CharmValue; } if (netPack.PlayerID == PlayerDatas.Instance.baseData.PlayerID) { WindowCenter.Instance.OpenIL(); return; } if (!WindowCenter.Instance.IsOpen("CharmSourceWin")) { WindowCenter.Instance.OpenIL(); } } public event Action OnReceiveFlower; public Dictionary> flowersReceive = new Dictionary>(); public void UpdateReceiveFlowers(IL_HB320_tagGCSendGiftsOKList netPack) { for (int i = 0; i < netPack.SendGiftsOKList.Length; i++) { if (!flowersReceive.ContainsKey(netPack.SendGiftsOKList[i].PlayerID)) { flowersReceive[netPack.SendGiftsOKList[i].PlayerID] = new List(); } flowersReceive[netPack.SendGiftsOKList[i].PlayerID].Add(new FlowersReceive() { Name = netPack.SendGiftsOKList[i].Name.Trim().Replace("\0", ""), GiftNum = netPack.SendGiftsOKList[i].GiftNum, GiftCount = netPack.SendGiftsOKList[i].GiftCount, SendTime = netPack.SendGiftsOKList[i].SendTime }); } SaveFlowerReceive(); OnReceiveFlower?.Invoke(); } string bigSplit = "<&>"; string nameSplit = "<@>"; string listSplit = "<#>"; string smallSplit = "<->"; //id(|=|)name(|=|)GiftNum(|-)GiftCount(|-)SendTime(|@|)GiftNum(|-)GiftCount(|-)SendTime(|@|)(|&|) //id2(|=|)name2(|=|)GiftNum(|-)GiftCount(|-)SendTime(|@|)GiftNum(|-)GiftCount(|-)SendTime(|@|) void SaveFlowerReceive() { var fullString = string.Empty; var keyList = flowersReceive.Keys.ToList(); for (int i = 0; i < keyList.Count; i++) { if (fullString != string.Empty) { fullString += bigSplit; } var info = flowersReceive[keyList[i]]; if (info.Count > 0) { fullString += (keyList[i] + nameSplit + info[0].Name + nameSplit); } for (int j = 0; j < info.Count; j++) { fullString += info[j].GiftNum.ToString() + smallSplit; fullString += info[j].GiftCount.ToString() + smallSplit; fullString += info[j].SendTime.ToString() + listSplit; } } DebugEx.Log("IL_HB320_tagGCSendGiftsOKList " + fullString); LocalSave.SetString("FlowerReceive" + PlayerDatas.Instance.PlayerId, fullString); } void RestoreFlowerReceive() { try { var result = LocalSave.GetString("FlowerReceive" + PlayerDatas.Instance.PlayerId); if (result == string.Empty) return; string[] info1 = CommonFunc.Instance.StringSplit(result, bigSplit); for (int i = 0; i < info1.Length; i++) { if (info1[i] == string.Empty) continue; var info2 = CommonFunc.Instance.StringSplit(info1[i], nameSplit); uint playerID = uint.Parse(info2[0]); string name = info2[1]; if (!flowersReceive.ContainsKey(playerID)) { flowersReceive[playerID] = new List(); } var info3 = CommonFunc.Instance.StringSplit(info2[2], listSplit); for (int j = 0; j < info3.Length; j++) { if (info3[j] == string.Empty) continue; var info4 = CommonFunc.Instance.StringSplit(info3[j], smallSplit); flowersReceive[playerID].Add(new FlowersReceive() { Name = name, GiftNum = (ushort)int.Parse(info4[0]), GiftCount = (uint)int.Parse(info4[1]), SendTime = (uint)int.Parse(info4[2]) }); } } } catch { Debug.Log("RestoreFlowerReceive faile"); } } void OnPlayerLoginOkEvent() { RestoreFlowerReceive(); } //获取记录的送花玩家信息 public List GetOncPlayerFlowersInfo() { if (flowersReceive.Count == 0) return null; var playerID = flowersReceive.Keys.ToList()[0]; var flowers = flowersReceive[playerID]; flowersReceive.Remove(playerID); feedBackFlowerGiverID = playerID; SaveFlowerReceive(); return flowers; } //赠送鲜花者信息 需要查询 public byte FeedBackJob; public ushort FeedBackLV; //等级 public ushort FeedBackRealmLV; //境界 public byte FeedBackOnlineType; //在线状态, 0 不在线 1在线 public void UpdatePlayerShortInfo(HB309_tagGCAnswerPlayerShortInfo netPack) { if (netPack.PlayerID != 0 && netPack.PlayerID == feedBackFlowerGiverID) { FeedBackJob = netPack.Job; FeedBackLV = netPack.LV; FeedBackRealmLV = netPack.RealmLV; FeedBackOnlineType = netPack.OnlineType; } } public struct FlowersReceive { public string Name; // 赠送方玩家名 public ushort GiftNum; // 赠送礼物编号 public uint GiftCount; // 赠送礼物数量 public uint SendTime; // 赠送时间戳 } }