Parcourir la source

【优化】1.礼物置顶时机;2.仙女棒/能量药丸逻辑

johnclot69 il y a 1 an
Parent
commit
3523054333

+ 51 - 29
DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveGiftHandler.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using System.Numerics;
 using System.Text;
@@ -31,66 +32,78 @@ namespace ET.Server
                 return;
             }
 
-            unitPlayerData.GiftMoney += (int)request.GiftValue;
-
-            // 推送客户端
-            if (map.Player != null)
-            {
-                MessageHelper.SendToClient(map.Player, new G2C_GiftInfoPush { NickName = request.NickName, GiftType = DouyinItem.GiftHash[request.GiftId],
-                    GiftNum = (int)request.GiftNum, Url = request.Url, TotalMoney = unitPlayerData.GiftMoney, UnitId = unitPlayerData.ObjId});
-            }
-
             Struct.TriggerEventNotify notify = null;
 
             if (DouyinItem.GiftId_1.Equals(request.GiftId) || DouyinItem.GiftId_10.Equals(request.GiftId))
             {
                 // 仙女棒 自己死了复活自己, 自己没死复活其他人, 不够则补充单位
                 // 能量药丸 自己死了复活自己, 自己没死复活其他3个人, 不够则补充单位
-
-                StringBuilder objIds = new StringBuilder();
+                List<int> objIds = new List<int>();
 
                 notify = new Struct.TriggerEventNotify();
 
+                long cnt = request.GiftNum * (DouyinItem.GiftId_1.Equals(request.GiftId)? 1 : 3);
+
+                // 先判断自己状态
                 if (unitPlayerData.DeadState == 1)
                 {
-                    objIds.Append(unitPlayerData.ObjId);
+                    objIds.Add(unitPlayerData.ObjId);
+                    unitPlayerData.DeadState = 0;
+                    cnt -= 1;
                 }
-                else
+                // 其他死亡玩家
+                if (cnt > 0)
                 {
-                    long cnt = request.GiftNum * (DouyinItem.GiftId_1.Equals(request.GiftId)? 1 : 3);
-
-                    foreach (int objId in map.DeadUnitPlayer)
+                    for (int i = 0; i < map.DeadUnitPlayer.Count; i++)
                     {
-                        if (objId > 0)
+                        int objId = map.DeadUnitPlayer[i];
+                        if (objId > 0 && objId != unitPlayerData.ObjId && !objIds.Exists(o => o == objId))
                         {
-                            objIds.Append(objId).Append(',');
+                            objIds.Add(objId);
+                            map.DeadUnitPlayer.Remove(objId);
                             cnt -= 1;
                         }
+
                         if (cnt <= 0)
                         {
                             break;
                         }
                     }
-
-                    if (cnt > 0)
+                }
+                // 死亡玩家不够,则补充活着的玩家
+                if (cnt > 0)
+                {
+                    foreach (Struct.UnitPlayerData unitPlayer in map.UnitPlayers.Values)
                     {
-                        // 补充单位
-                        for (int i = 0; i < cnt; i++)
+                        if (unitPlayer != null && unitPlayer.ObjId != unitPlayerData.ObjId && !objIds.Exists(o => o == unitPlayer.ObjId))
+                        {
+                            objIds.Add(unitPlayer.ObjId);
+                            cnt -= 1;
+                        }
+                        if (cnt <= 0)
                         {
-                            // 临时openId
-                            string _openId = (10000 + new Random().Next(999)).ToString();
-                            Vector2 pos = map.GetRandomPlayerPos();
-                            string name = map.GetRandomPlayerName();
-                            await map.AddUnitPlayer(_openId, 0, 1, "", pos.X, pos.Y, name, "");
+                            break;
                         }
                     }
                 }
 
                 notify.message = DouyinItem.GiftId_1.Equals(request.GiftId)? BattleNotify.TiktokGift_1.ToString() : BattleNotify.TiktokGift_10.ToString();
-                notify.TriggerUnits = objIds.ToString();
+                notify.TriggerUnits = "";
+                for (int i = 0; i < objIds.Count; i++)
+                {
+                    int objId = objIds[i];
+                    if (objId > 0)
+                    {
+                        notify.TriggerUnits += objId;
+                        if (i < objIds.Count - 1)
+                        {
+                            notify.TriggerUnits += ",";
+                        }
+                    }
+                }
                 map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(notify));
 
-                // Log.Debug($"============================================仙女棒/能量药丸 notifyBattleServer - data={JsonSerializer.Serialize(notify)}");
+                Log.Debug($"============================================仙女棒/能量药丸 notifyBattleServer - data={JsonSerializer.Serialize(notify)}");
             }
             else
             {
@@ -144,6 +157,15 @@ namespace ET.Server
                     await TimerComponent.Instance.WaitAsync(30);
                 }
             }
+
+            unitPlayerData.GiftMoney += (int)request.GiftValue;
+
+            // 推送客户端
+            if (map.Player != null)
+            {
+                MessageHelper.SendToClient(map.Player, new G2C_GiftInfoPush { NickName = request.NickName, GiftType = DouyinItem.GiftHash[request.GiftId],
+                    GiftNum = (int)request.GiftNum, Url = request.Url, TotalMoney = unitPlayerData.GiftMoney, UnitId = unitPlayerData.ObjId});
+            }
         }
     }
 }

+ 8 - 2
DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs

@@ -79,7 +79,10 @@ namespace ET.Server
                             if (unitPlayerData != null)
                             {
                                 unitPlayerData.DeadState = 1;
-                                map.DeadUnitPlayer.Add(unitPlayerData.ObjId);
+                                if (!map.DeadUnitPlayer.Exists(o => o == unitPlayerData.ObjId))
+                                {
+                                    map.DeadUnitPlayer.Add(unitPlayerData.ObjId);
+                                }
                             }
                         }
                     }
@@ -96,7 +99,10 @@ namespace ET.Server
                         if (unitPlayerData != null)
                         {
                             unitPlayerData.DeadState = 0;
-                            map.DeadUnitPlayer.Remove(unitPlayerData.ObjId);
+                            if (map.DeadUnitPlayer.Exists(o => o == unitPlayerData.ObjId))
+                            {
+                                map.DeadUnitPlayer.Remove(unitPlayerData.ObjId);
+                            }
                         }
                     }
                     break;

+ 2 - 2
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -37,14 +37,14 @@ namespace ET.Server
                 {
                     return;
                 }
+                // 抖音直播礼物置顶
+                Root.Instance.Scene.GetComponent<GameDouyinComponent>().TopGifts(self.RoomId);
                 // 抖音直播评论任务组件
                 self.AddComponent<MapDouyinLiveCommentComponent>();
                 // 抖音直播礼物任务组件
                 self.AddComponent<MapDouyinLiveGiftComponent>();
                 // 抖音直播点赞任务组件
                 self.AddComponent<MapDouyinLiveLikeComponent>();
-                // 抖音直播礼物置顶
-                Root.Instance.Scene.GetComponent<GameDouyinComponent>().TopGifts(self.RoomId);
             }
         }