Przeglądaj źródła

【优化】1.增加礼物置顶;2.解决评论添加单位有时instanceId不一致;3.评论添加玩家后关掉客户端,再重新开启,再次评论添加玩家报错;4.榜单优化为游戏服计算;5.仙女棒和能力药丸复活单位细节处理

johnclot69 1 rok temu
rodzic
commit
0f8cc26dc0
24 zmienionych plików z 492 dodań i 133 usunięć
  1. 8 5
      Config/Proto/InnerMessage_S_20001.proto
  2. 1 1
      Config/Proto/OuterMessage_C_10001.proto
  3. 15 52
      DotNet/Hotfix/Helper/MapHelper.cs
  4. 49 7
      DotNet/Hotfix/Scenes/Game/GameDouyinComponentSystem.cs
  5. 7 2
      DotNet/Hotfix/Scenes/Game/GameMapComponentSystem.cs
  6. 1 1
      DotNet/Hotfix/Scenes/Game/Handler/C2G_AddUnitsToMapHandler.cs
  7. 2 0
      DotNet/Hotfix/Scenes/Game/Handler/C2G_BindPlayerHandler.cs
  8. 5 3
      DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs
  9. 4 4
      DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveCommentHandler.cs
  10. 86 22
      DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveGiftHandler.cs
  11. 22 2
      DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveLikeHandler.cs
  12. 193 0
      DotNet/Hotfix/Scenes/Game/Map/MapDouyinLiveGiftComponentSystem.cs
  13. 2 0
      DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs
  14. 10 4
      DotNet/Hotfix/Scenes/Game/Map/MapRankComponentSystem.cs
  15. 30 10
      DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs
  16. 9 6
      DotNet/Hotfix/Scenes/Game/Session/SessionPlayerComponentSystem.cs
  17. 8 6
      DotNet/Hotfix/Scenes/Router/HttpDouyinApiCallbackHandler.cs
  18. 3 1
      DotNet/Model/Const/ConstGame.cs
  19. 7 1
      DotNet/Model/Const/Struct.cs
  20. 12 3
      DotNet/Model/Generate/Message/InnerMessage_S_20001.cs
  21. 1 1
      DotNet/Model/Generate/Message/OuterMessage_C_10001.cs
  22. 3 1
      DotNet/Model/Scenes/Game/Map/Map.cs
  23. 13 0
      DotNet/Model/Scenes/Game/Map/MapDouyinLiveGiftComponent.cs
  24. 1 1
      Unity/Assets/Scripts/Codes/Model/Client/Generate/Message/OuterMessage_C_10001.cs

+ 8 - 5
Config/Proto/InnerMessage_S_20001.proto

@@ -167,7 +167,7 @@ message R2G_LiveComment // IActorMessage
 	string OpenId = 1;
 	int64 RoomId = 2;
 	string Content = 3;		// 评论内容
-	string Nickname = 4;
+	string NickName = 4;
 	string Url = 5;
 }
 
@@ -176,14 +176,17 @@ message R2G_LiveGift // IActorMessage
 	string OpenId = 1;
 	int64 RoomId = 2;
 	string NickName = 3;
-	string GiftId = 4;
-	int64 GiftNum = 5;		// 送出的礼物数量
-	int64 GiftValue = 6;	// 礼物总价值,单位分
+	string Url = 4;
+	string GiftId = 5;
+	int64 GiftNum = 6;		// 送出的礼物数量
+	int64 GiftValue = 7;	// 礼物总价值,单位分
 }
 
 message R2G_LiveLike // IActorMessage
 {
 	string OpenId = 1;
 	int64 RoomId = 2;
-	int64 Likes = 3;
+	string NickName = 3;
+	string Url = 4;
+	int64 Likes = 5;
 }

+ 1 - 1
Config/Proto/OuterMessage_C_10001.proto

@@ -288,7 +288,7 @@ message G2C_TriggrBattleFunction // IResponse
 message RankInfo
 {
 	string Name = 1;		// 名称
-	int32 Value = 2;		// 贡献值
+	int64 Value = 2;		// 贡献值
 	int32 Ranking = 3;		// 排名
 }
 

+ 15 - 52
DotNet/Hotfix/Helper/MapHelper.cs

@@ -9,42 +9,6 @@ namespace ET.Server
     /// </summary>
     public static class MapHelper
     {
-        /// <summary>
-        /// 进入指定场景
-        /// </summary>
-        /// <param name="player"></param>
-        /// <param name="instanceId"></param>
-        /// <param name="targetX"></param>
-        /// <param name="targetY"></param>
-        /// <param name="forceChange"></param>
-        public static void EnterAreaByInstanceId(WNPlayer player, long instanceId, float targetX, float targetY, bool forceChange)
-        {
-            Map map = player.DomainScene().GetComponent<GameMapComponent>().Get(instanceId);
-            AreaData areaData = new AreaData(map.MapId, instanceId);
-            areaData.targetX = targetX;
-            areaData.targetY = targetY;
-            DispatchByInstanceId(player, areaData, forceChange);
-        }
-
-        /// <summary>
-        /// 根据场景实例id进入相应场景
-        /// </summary>
-        /// <param name="player"></param>
-        /// <param name="areaData"></param>
-        /// <param name="forceCreate"></param>
-        /// <returns></returns>
-        public static Map DispatchByInstanceId(WNPlayer player, AreaData areaData, bool forceCreate)
-        {
-            if (player.GetMapInstanceId() == areaData.instanceId)
-            {
-                return null;
-            }
-
-            ChangeArea(player, areaData, forceCreate);
-
-            return player.DomainScene().GetComponent<GameMapComponent>().Get(areaData.instanceId);
-        }
-
         /// <summary>
         /// 实际切换地图
         /// </summary>
@@ -131,29 +95,28 @@ namespace ET.Server
         {
             Map map = null;
 
-            // 角色身上绑定的场景信息
-            PlayerMapInfo playerMapInfo = player.GetComponent<PlayerTempDataComponent>().MapData;
+            GameMapComponent component = player.DomainScene().GetComponent<GameMapComponent>();
 
-            // 执行普通场景逻辑
-            MapConfig prop = MapConfigCategory.Instance.Get(playerMapInfo.mapId);
-            if (prop != null)
-            {
-                map = player.DomainScene().GetComponent<GameMapComponent>().Get(playerMapInfo.mapInstanceId);
-            }
+            map = component.GetMapByRoomId(player.GetRoomId());
 
-            if (map == null)
+            // 销毁老场景
+            if (map != null)
             {
-                // 创建一个场景
-                JObject jsonObject = new JObject();
-                jsonObject.Add("id", player.GetId());
-                jsonObject.Add("logicServerId", player.GetLogicServerId());
-                jsonObject.Add("areaId", playerMapInfo.mapId);
-                map = CreateMap(player, jsonObject, false);
+                component.Remove(map.Id, map.RoomId);
+                map.Dispose();
+                map = null;
             }
 
+            // 创建一个场景
+            JObject jsonObject = new JObject();
+            jsonObject.Add("id", player.GetId());
+            jsonObject.Add("logicServerId", player.GetLogicServerId());
+            jsonObject.Add("areaId", 10098);
+            map = CreateMap(player, jsonObject, false);
+
             if (map != null)
             {
-                ChangeArea(player, new AreaData(10098, map.Id), false);
+                map = ChangeArea(player, new AreaData(10098, map.Id), false);
             }
 
             return map;

+ 49 - 7
DotNet/Hotfix/Scenes/Game/GameDouyinComponentSystem.cs

@@ -13,7 +13,6 @@ namespace ET.Server
         {
             protected override void Awake(GameDouyinComponent self)
             {
-                self.InitAccessToken();
             }
         }
 
@@ -21,7 +20,6 @@ namespace ET.Server
         {
             protected override void Destroy(GameDouyinComponent self)
             {
-                Log.Info($"销毁session玩家抖音组件");
             }
         }
 
@@ -51,11 +49,6 @@ namespace ET.Server
         /// <param name="self"></param>
         private static void InitAccessToken(this GameDouyinComponent self)
         {
-            if (self.TokenIsNull)
-            {
-                return;
-            }
-
             // 请求头
             Dictionary<string, string> head = new Dictionary<string, string>();
             // 参数
@@ -128,6 +121,55 @@ namespace ET.Server
             return jObject;
         }
 
+        /// <summary>
+        /// 礼物置顶
+        /// </summary>
+        /// <param name="self"></param>
+        /// <param name="roomId"></param>
+        public static void TopGifts(this GameDouyinComponent self, long roomId)
+        {
+            if (self.TokenIsNull)
+            {
+                return;
+            }
+            if (string.IsNullOrEmpty(self.AccessToken.Trim()))
+            {
+                Log.Error($"TopGifts...AccessToken为null");
+                return;
+            }
+            // 礼物参数
+            JArray item = new JArray();
+            foreach (string itemKey in DouyinItem.GiftHash.Keys)
+            {
+                item.Add(itemKey);
+            }
+            // 请求头
+            Dictionary<string, string> head = new Dictionary<string, string>();
+            head.Add("x-token", self.AccessToken.Trim());
+            // 参数
+            JObject param = new JObject();
+            param.Add("room_id", roomId.ToString());
+            param.Add("app_id", DouyinConst.Appid);
+            param.Add("sec_gift_id_list", item);
+
+            string str = HttpHelper.PostRequestByDouyin(DouyinConst.TopGiftUrl, head, param);
+
+            if (string.IsNullOrEmpty(str))
+            {
+                Log.Error($"TopGifts - TopGiftUrl请求失败...返回为null");
+                return;
+            }
+
+            JObject jObject = JObject.Parse(str);
+
+            int errNo = Convert.ToInt32(jObject.SelectToken("errcode"));
+
+            if (errNo != 0)
+            {
+                Log.Error($"TopGifts - TopGiftUrl请求成功...返回错误:{errNo}");
+            }
+        }
+
         /// <summary>
         /// 签名验证
         /// </summary>

+ 7 - 2
DotNet/Hotfix/Scenes/Game/GameMapComponentSystem.cs

@@ -42,9 +42,11 @@ namespace ET.Server
             return map;
         }
 
-        public static void Remove(this GameMapComponent self, long instanceId)
+        public static void Remove(this GameMapComponent self, long instanceId, long roomId)
         {
             self.allMaps.Remove(instanceId);
+            // 移除一下roomId与instanceId的关系
+            self.rooms.Remove(roomId);
         }
 
         public static Map[] GetAll(this GameMapComponent self)
@@ -54,7 +56,10 @@ namespace ET.Server
 
         public static Map GetMapByRoomId(this GameMapComponent self, long roomId)
         {
-            long instanceId = self.rooms[roomId];
+            if (!self.rooms.TryGetValue(roomId, out long instanceId))
+            {
+                return null;
+            }
 
             if (instanceId > 0)
             {

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/C2G_AddUnitsToMapHandler.cs

@@ -57,7 +57,7 @@ namespace ET.Server
             // 临时openId
             string _openId = player.GetComponent<PlayerDataComponent>().Data.Id.ToString();
 
-            player.Map.AddUnitPlayer(_openId, request.UnitId, objId, 0);
+            player.Map.AddUnitPlayer(_openId, request.UnitId, objId, 0, unit.name, "");
 
             reply();
         }

+ 2 - 0
DotNet/Hotfix/Scenes/Game/Handler/C2G_BindPlayerHandler.cs

@@ -37,6 +37,8 @@ namespace ET.Server
             {
                 // 重新登录,赋值session
                 player.Session = session;
+
+                Log.Debug($"重新登录,赋值session...");
             }
             else
             {

+ 5 - 3
DotNet/Hotfix/Scenes/Game/Handler/C2G_LoginGameHandler.cs

@@ -25,8 +25,6 @@ namespace ET.Server
 
             bool tokenIsNull = string.IsNullOrEmpty(request.Token.Trim());
 
-            scene.GetComponent<GameDouyinComponent>().TokenIsNull = tokenIsNull;
-
             // 预先创建数据
             PlayerInfo playerInfo = new PlayerInfo();
             playerInfo.Id = IdGenerater.Instance.GenerateUnitId(scene.DomainZone());
@@ -38,6 +36,8 @@ namespace ET.Server
                 playerInfo.AnchorOpenId = playerInfo.Id.ToString();
                 playerInfo.AvatarUrl = "";
                 playerInfo.Name = "主播-" + playerInfo.Id;
+
+                scene.GetComponent<GameDouyinComponent>().TokenIsNull = true;
             }
             else
             {
@@ -51,11 +51,13 @@ namespace ET.Server
                     return;
                 }
 
-                var info = roomInfo.SelectToken("data").SelectToken("info");
+                JToken info = roomInfo.SelectToken("data").SelectToken("info");
                 playerInfo.RoomId = Convert.ToInt64(info.SelectToken("room_id"));
                 playerInfo.AnchorOpenId = Convert.ToString(info.SelectToken("anchor_open_id"));
                 playerInfo.AvatarUrl = Convert.ToString(info.SelectToken("avatar_url"));
                 playerInfo.Name = Convert.ToString(info.SelectToken("nick_name"));
+
+                scene.GetComponent<GameDouyinComponent>().TokenIsNull = false;
             }
 
             playerInfo.Sex = 0;

+ 4 - 4
DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveCommentHandler.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Numerics;
 
 namespace ET.Server
 {
@@ -54,7 +55,7 @@ namespace ET.Server
                     break;
             }
 
-            var pos = map.GetRandomPlayerPos();
+            Vector2 pos = map.GetRandomPlayerPos();
 
             Struct.MonsterUnit unit = new Struct.MonsterUnit();
             unit.id = templateId;
@@ -62,13 +63,12 @@ namespace ET.Server
             unit.x = pos.X;
             unit.y = pos.Y;
             unit.autoGuard = true;
-            unit.name = request.Nickname;
+            unit.name = request.NickName;
             unit.alias = request.Url;
-            
 
             int objId = await map.AddUnits(unit, true);
 
-            map.AddUnitPlayer(request.OpenId, templateId, objId, 0);
+            map.AddUnitPlayer(request.OpenId, templateId, objId, 0, request.NickName, request.Url);
 
             await ETTask.CompletedTask;
         }

+ 86 - 22
DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveGiftHandler.cs

@@ -1,4 +1,6 @@
-using System.Text.Json;
+using System.Linq;
+using System.Numerics;
+using System.Text.Json;
 
 namespace ET.Server
 {
@@ -33,35 +35,97 @@ namespace ET.Server
             if (map.Player != null)
             {
                 MessageHelper.SendToClient(map.Player, new G2C_GiftInfoPush { NickName = request.NickName, GiftType = DouyinItem.GiftHash[request.GiftId],
-                    GiftNum = (int)request.GiftNum, Url = "", TotalMoney = unitPlayerData.GiftMoney, UnitId = unitPlayerData.ObjId});
+                    GiftNum = (int)request.GiftNum, Url = request.Url, TotalMoney = unitPlayerData.GiftMoney, UnitId = unitPlayerData.ObjId});
             }
 
+            int[] units = new int[] { 101, 121, 111, 131 };
+
             Struct.TriggerEventNotify notify = null;
-            if (request.GiftId == DouyinItem.GiftId_1)
-            {
-                //TODO:复活合适的人
-                map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
-                {
-                    message = BattleNotify.TiktokGift_1.ToString(),
-                    TriggerUnits = unitPlayerData.ObjId.ToString()
-                })) ;
-                return;
-            }
-            else if(request.GiftId == DouyinItem.GiftId_10)
-            {
-                //TODO:复活合适的人
-                map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
-                {
-                    message = BattleNotify.TiktokGift_10.ToString(),
-                    TriggerUnits = unitPlayerData.ObjId.ToString()
-                }));
-                return;
-            }
 
             for (int i = 0; i < request.GiftNum; i++)
             {
+                int objId = 0;
+
                 switch (request.GiftId)
                 {
+                    case DouyinItem.GiftId_1:
+                        // 仙女棒
+
+                        // 自己死了复活自己, 自己没死复活其他人
+                        objId = unitPlayerData.DeadState == 1? unitPlayerData.ObjId : map.DeadUnitPlayer.Count > 0? map.DeadUnitPlayer.First() : 0;
+
+                        if (objId > 0)
+                        {
+                            map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
+                            {
+                                message = BattleNotify.TiktokGift_1.ToString(),
+                                TriggerUnits = objId.ToString()
+                            })) ;
+                        }
+                        else
+                        {
+                            // 补充一个单位
+                            Vector2 pos = map.GetRandomPlayerPos();
+
+                            Struct.MonsterUnit unit = new Struct.MonsterUnit();
+                            unit.id = RandomGenerator.RandomArray(units);
+                            unit.force = 1;
+                            unit.x = pos.X;
+                            unit.y = pos.Y;
+                            unit.autoGuard = true;
+                            unit.name = "Nickname";
+                            unit.alias = "Url";
+
+                            int _objId = await map.AddUnits(unit, true);
+
+                            map.AddUnitPlayer(request.OpenId, unit.id, _objId, 0, request.NickName, request.Url);
+                        }
+                        break;
+                    case DouyinItem.GiftId_10:
+                        // 能量药丸
+
+                        objId = 0;
+                        // 自己死了复活自己
+                        if (unitPlayerData.DeadState == 1)
+                        {
+                            objId = unitPlayerData.ObjId;
+                        }
+                        else
+                        {
+                            // 自己没死复活其他3个人
+                            int index = 0;
+                            foreach (int deadObjId in map.DeadUnitPlayer.Where(deadObjId => deadObjId > 0 && index < 3))
+                            {
+                                map.GetXmdsManager().notifyBattleServer(map.Id.ToString(), NotifyBSName.TriggerEvent, JsonSerializer.Serialize(new Struct.TriggerEventNotify()
+                                {
+                                    message = BattleNotify.TiktokGift_10.ToString(),
+                                    TriggerUnits = deadObjId.ToString()
+                                })) ;
+                                index += 1;
+                            }
+                            // 不够则补充单位
+                            if (3 - index > 0)
+                            {
+                                for (int j = 0; j < 3 - index; j++)
+                                {
+                                    Vector2 pos = map.GetRandomPlayerPos();
+
+                                    Struct.MonsterUnit unit = new Struct.MonsterUnit();
+                                    unit.id = RandomGenerator.RandomArray(units);
+                                    unit.force = 1;
+                                    unit.x = pos.X;
+                                    unit.y = pos.Y;
+                                    unit.autoGuard = true;
+                                    unit.name = "Nickname";
+                                    unit.alias = "Url";
+
+                                    int _objId = await map.AddUnits(unit, true);
+
+                                    map.AddUnitPlayer(request.OpenId, unit.id, _objId, 0, request.NickName, request.Url);
+                                }
+                            }
+                        }
+                        break;
                     case DouyinItem.GiftId_52:
                         // 甜甜圈
                         const long maxLevel = 3; // 等级上限

+ 22 - 2
DotNet/Hotfix/Scenes/Game/Handler/R2G_LiveLikeHandler.cs

@@ -1,4 +1,5 @@
-using System.Text.Json;
+using System.Numerics;
+using System.Text.Json;
 
 namespace ET.Server
 {
@@ -20,7 +21,26 @@ namespace ET.Server
             }
 
             // 数据是否存在
-            Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByOpenId(request.OpenId) ?? map.AddUnitPlayer(request.OpenId, 0, 0, request.Likes);
+            Struct.UnitPlayerData unitPlayerData = map.GetUnitPlayerByOpenId(request.OpenId);
+
+            if (unitPlayerData == null)
+            {
+                int[] units = new int[] { 101, 121, 111, 131 };
+                Vector2 pos = map.GetRandomPlayerPos();
+
+                Struct.MonsterUnit unit = new Struct.MonsterUnit();
+                unit.id = RandomGenerator.RandomArray(units);
+                unit.force = 1;
+                unit.x = pos.X;
+                unit.y = pos.Y;
+                unit.autoGuard = true;
+                unit.name = request.NickName;
+                unit.alias = request.Url;
+
+                int objId = await map.AddUnits(unit, true);
+
+                unitPlayerData = map.AddUnitPlayer(request.OpenId, unit.id, objId, 0, request.NickName, request.Url);
+            }
 
             // 累计增加点赞数
             unitPlayerData.Likes += request.Likes;

+ 193 - 0
DotNet/Hotfix/Scenes/Game/Map/MapDouyinLiveGiftComponentSystem.cs

@@ -0,0 +1,193 @@
+using System;
+using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+
+namespace ET.Server
+{
+    [FriendOf(typeof (MapDouyinLiveGiftComponent))]
+    public static class MapDouyinLiveGiftComponentSystem
+    {
+        public class MapDouyinLiveGiftComponentAwakeSystem: AwakeSystem<MapDouyinLiveGiftComponent>
+        {
+            protected override void Awake(MapDouyinLiveGiftComponent self)
+            {
+                Log.Info($"创建抖音直播礼物任务组件...");
+            }
+        }
+
+        public class MapDouyinLiveGiftComponentDestroySystem: DestroySystem<MapDouyinLiveGiftComponent>
+        {
+            protected override void Destroy(MapDouyinLiveGiftComponent self)
+            {
+                Log.Info($"销毁抖音直播礼物任务组件");
+
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
+
+                self.StopTask();
+            }
+        }
+
+        public class MapDouyinLiveGiftComponentUpdateSystem: UpdateSystem<MapDouyinLiveGiftComponent>
+        {
+            protected override void Update(MapDouyinLiveGiftComponent self)
+            {
+                bool tokenIsNull = self.GetParent<Map>().TokenIsNull();
+
+                if (tokenIsNull)
+                {
+                    return;
+                }
+                // 运行中状态
+                if (self.Status == 3)
+                {
+                    return;
+                }
+
+                Log.Debug($"检查抖音直播礼物任务状态...Status={self.Status}");
+
+                self.Status = self.CheckTaskStatus();
+
+                switch (self.Status)
+                {
+                    case -1:
+                    {
+                        // 接口请求出错
+                        Log.Debug($"检查抖音直播礼物任务状态 - 抖音接口请求出错");
+                        break;
+                    }
+                    case 1:
+                    {
+                        // 数据推送回调任务不存在
+                        Log.Debug($"检查抖音直播礼物任务状态 - 任务已经被删除,可能是因为主播取消挂载/已关播");
+                        break;
+                    }
+                    case 2:
+                    {
+                        // 数据推送回调任务未启动则启动
+                        Log.Debug($"检查抖音直播礼物任务状态 - 任务启动...");
+                        self.StartTask();
+                        break;
+                    }
+                    case 3:
+                        // 数据推送回调任务运行中,不处理
+                        break;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 启动礼物推送任务
+        /// </summary>
+        /// <param name="self"></param>
+        private static void StartTask(this MapDouyinLiveGiftComponent self)
+        {
+            // 请求头
+            Dictionary<string, string> head = new Dictionary<string, string>();
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
+            // 参数
+            JObject param = new JObject();
+            param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
+            param.Add("appid", DouyinConst.Appid);
+            param.Add("msg_type", "live_gift");
+
+            string str = HttpHelper.PostRequestByDouyin(DouyinConst.StartTaskUrl, head, param);
+
+            if (string.IsNullOrEmpty(str))
+            {
+                Log.Error($"启动礼物推送任务 - StartTaskUrl 请求失败...返回为null");
+                return;
+            }
+
+            JObject jObject = JObject.Parse(str);
+
+            int errNo = Convert.ToInt32(jObject.SelectToken("err_no"));
+
+            if (errNo != 0)
+            {
+                Log.Error($"启动礼物推送任务 - StartTaskUrl 请求成功...返回错误:{errNo}");
+                return;
+            }
+
+            self.LogId = Convert.ToInt64(jObject.SelectToken("data").SelectToken("logid"));
+            self.TaskId = Convert.ToInt64(jObject.SelectToken("data").SelectToken("task_id"));
+        }
+
+        /// <summary>
+        /// 停止礼物推送任务
+        /// </summary>
+        /// <param name="self"></param>
+        private static void StopTask(this MapDouyinLiveGiftComponent self)
+        {
+            // 请求头
+            Dictionary<string, string> head = new Dictionary<string, string>();
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
+            // 参数
+            JObject param = new JObject();
+            param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
+            param.Add("appid", DouyinConst.Appid);
+            param.Add("msg_type", "live_gift");
+
+            string str = HttpHelper.PostRequestByDouyin(DouyinConst.StopTaskUrl, head, param);
+
+            if (string.IsNullOrEmpty(str))
+            {
+                Log.Error($"停止礼物推送任务 - StopTaskUrl 请求失败...返回为null");
+                return;
+            }
+
+            JObject jObject = JObject.Parse(str);
+
+            int errNo = Convert.ToInt32(jObject.SelectToken("err_no"));
+
+            if (errNo != 0)
+            {
+                Log.Error($"停止礼物推送任务 - StopTaskUrl 请求成功...返回错误:{errNo}");
+                return;
+            }
+
+            self.LogId = Convert.ToInt64(jObject.SelectToken("data").SelectToken("logid"));
+        }
+
+        /// <summary>
+        /// 检查礼物推送任务状态 (1-任务不存在, 2-任务未启动, 3-任务运行中)
+        /// </summary>
+        /// <param name="self"></param>
+        /// <returns></returns>
+        private static int CheckTaskStatus(this MapDouyinLiveGiftComponent self)
+        {
+            Dictionary<string, string> head = new Dictionary<string, string>();
+            head.Add("access-token", self.GetParent<Map>().GetDouyinAccessToken());
+            // 参数
+            Dictionary<string, string> param = new Dictionary<string, string>();
+            param.Add("roomid", self.GetParent<Map>().RoomId.ToString());
+            param.Add("appid", DouyinConst.Appid);
+            param.Add("msg_type", "live_gift");
+
+            string str = HttpHelper.GetRequestByDouyin(DouyinConst.CheckTaskUrl, head, param);
+
+            if (string.IsNullOrEmpty(str))
+            {
+                Log.Error($"检查礼物推送任务状态 - CheckTaskUrl 请求失败...返回为null");
+                return -1;
+            }
+
+            JObject jObject = JObject.Parse(str);
+
+            int errNo = Convert.ToInt32(jObject.SelectToken("err_no"));
+
+            if (errNo != 0)
+            {
+                Log.Error($"检查礼物推送任务状态 - CheckTaskUrl 请求成功...返回错误:{errNo}");
+                return -1;
+            }
+
+            self.LogId = Convert.ToInt64(jObject.SelectToken("data").SelectToken("logid"));
+            return Convert.ToInt32(jObject.SelectToken("data").SelectToken("status"));
+        }
+    }
+}

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

@@ -85,6 +85,7 @@ namespace ET.Server
                             if (unitPlayerData != null)
                             {
                                 unitPlayerData.DeadState = 1;
+                                map.DeadUnitPlayer.Add(unitPlayerData.ObjId);
                             }
                             return;
                         }
@@ -102,6 +103,7 @@ namespace ET.Server
                         if (unitPlayerData != null)
                         {
                             unitPlayerData.DeadState = 0;
+                            map.DeadUnitPlayer.Remove(unitPlayerData.ObjId);
                         }
                         return;
                     }

+ 10 - 4
DotNet/Hotfix/Scenes/Game/Map/MapRankComponentSystem.cs

@@ -89,9 +89,12 @@ namespace ET.Server
 
             List<RankInfo> infoListProto = new List<RankInfo>();
 
-            foreach (RankInfo info in from unitPlayerData in list where ranking <= 3 select new RankInfo())
+            foreach (Struct.UnitPlayerData unitPlayerData in list.TakeWhile(unitPlayerData => ranking <= 3))
             {
-                info.Name = "unitPlayerData.Name";
+                RankInfo info = new RankInfo();
+                info.Name = unitPlayerData.Name;
+                // info.Url = unitPlayerData.Url;
+                info.Value = unitPlayerData.ContributeValue;
                 info.Ranking = ranking;
                 infoListProto.Add(info);
 
@@ -152,9 +155,12 @@ namespace ET.Server
 
             List<RankInfo> infoListProto = new List<RankInfo>();
 
-            foreach (RankInfo info in from unitPlayerData in list where ranking <= 50 select new RankInfo())
+            foreach (Struct.UnitPlayerData unitPlayerData in list.TakeWhile(unitPlayerData => ranking <= 50))
             {
-                info.Name = "unitPlayerData.Name";
+                RankInfo info = new RankInfo();
+                info.Name = unitPlayerData.Name;
+                // info.Url = unitPlayerData.Url;
+                info.Value = unitPlayerData.ContributeValue;
                 info.Ranking = ranking;
                 infoListProto.Add(info);
 

+ 30 - 10
DotNet/Hotfix/Scenes/Game/Map/MapSystem.cs

@@ -16,7 +16,7 @@ namespace ET.Server
         {
             protected override void Awake(Map self, JObject opts, WNPlayer player)
             {
-                Log.Debug($"create area opts:{JsonConvert.SerializeObject(opts, Formatting.Indented)}");
+                Log.Debug($"创建场景实体...create area opts:{opts.ToString()}");
                 self.RoomId = player.GetRoomId();
                 self.createTime = TimeHelper.ServerNow();
                 self.LogicServerId = opts.SelectToken("logicServerId") != null? Convert.ToInt32(opts.SelectToken("logicServerId")) : 0;
@@ -25,17 +25,26 @@ namespace ET.Server
                 self.Type = self.Prop.Type;
                 self.Player = player;
                 self.UnitPlayers = new Dictionary<string, Struct.UnitPlayerData>();
+                self.DeadUnits = new List<int>();
+                self.DeadUnitPlayer = new List<int>();
 
                 // 战斗服事件组件
                 self.AddComponent<MapEventComponent>();
-                // 场景复活组件
-                // self.AddComponent<MapReliveTimeComponent>();
                 // 场景排行榜组件
                 self.AddComponent<MapRankComponent>();
-                // 场景抖音直播评论组件
+                // token为空过滤一下抖音相关组件
+                if (self.TokenIsNull())
+                {
+                    return;
+                }
+                // 抖音直播评论任务组件
                 self.AddComponent<MapDouyinLiveCommentComponent>();
-                // 场景抖音直播点赞组件
+                // 抖音直播礼物任务组件
+                self.AddComponent<MapDouyinLiveGiftComponent>();
+                // 抖音直播点赞任务组件
                 self.AddComponent<MapDouyinLiveLikeComponent>();
+                // 抖音直播礼物置顶
+                self.DomainScene().GetComponent<GameDouyinComponent>().TopGifts(self.RoomId);
             }
         }
 
@@ -43,6 +52,7 @@ namespace ET.Server
         {
             protected override void Destroy(Map self)
             {
+                Log.Info($"销毁场景");
             }
         }
 
@@ -297,7 +307,9 @@ namespace ET.Server
         /// <param name="templateId"></param>
         /// <param name="objId"></param>
         /// <param name="likes"></param>
-        public static Struct.UnitPlayerData AddUnitPlayer(this Map self, string openId, int templateId, int objId, long likes)
+        /// <param name="name"></param>
+        /// <param name="url"></param>
+        public static Struct.UnitPlayerData AddUnitPlayer(this Map self, string openId, int templateId, int objId, long likes, string name, string url)
         {
             if (string.IsNullOrEmpty(openId) || templateId <= 0 || objId <= 0 || self.IsGameOver())
             {
@@ -311,6 +323,8 @@ namespace ET.Server
                 unitPlayerData = self.UnitPlayers[openId];
                 unitPlayerData.TemplateId = templateId;
                 unitPlayerData.ObjId = objId;
+                unitPlayerData.Name = name;
+                unitPlayerData.Url = url;
                 unitPlayerData.Map = self;
 
                 self.UnitPlayers[openId] = unitPlayerData;
@@ -321,6 +335,8 @@ namespace ET.Server
                 unitPlayerData.OpenId = openId;
                 unitPlayerData.TemplateId = templateId;
                 unitPlayerData.ObjId = objId;
+                unitPlayerData.Name = name;
+                unitPlayerData.Url = url;
                 unitPlayerData.Level = 1;
                 unitPlayerData.Likes = 0;
                 unitPlayerData.ReliveTime = 0;
@@ -398,7 +414,7 @@ namespace ET.Server
         /// <returns></returns>
         public static string GetDouyinAccessToken(this Map self)
         {
-            return self.Player.DomainScene().GetComponent<GameDouyinComponent>().AccessToken;
+            return self.DomainScene().GetComponent<GameDouyinComponent>().AccessToken;
         }
 
         /// <summary>
@@ -411,13 +427,17 @@ namespace ET.Server
             return self.DomainScene().GetComponent<GameDouyinComponent>().TokenIsNull;
         }
 
-        //获得当前战场(当前塔位置),随机位置
+        /// <summary>
+        /// 获得当前战场(当前塔位置),随机位置
+        /// </summary>
+        /// <param name="self"></param>
+        /// <returns></returns>
         public static Vector2 GetRandomPlayerPos(this Map self)
         {
             Vector2[] TowerPos = { new Vector2() { X = 103, Y = 197 }, new Vector2() { X = 190, Y = 133 }, new Vector2() { X = 104, Y = 69 } };
             int index = self.CurBattleIndex;
-            var tower = TowerPos[index];
-            var rand = new Random();
+            Vector2 tower = TowerPos[index];
+            Random rand = new Random();
             float r;
             double ang;
             if (index == 0)

+ 9 - 6
DotNet/Hotfix/Scenes/Game/Session/SessionPlayerComponentSystem.cs

@@ -28,25 +28,28 @@ namespace ET.Server
 
                 Log.Info($"玩家断线了, playerId={self.PlayerId}, name={player.GetName()}");
 
-                // 玩家离开
-                player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
-
                 Map map = player.Map;
                 if (map != null)
                 {
+                    // 玩家离开
+                    player.GetComponent<PlayerTempDataComponent>().MapData.ready = false;
                     // 记录玩家历史
                     map.SyncPlayerHistoryData(player);
                     // 战斗服场景玩家离开
                     map.PlayerLeaveRequest(player, false);
                     // 本地场景移除玩家
                     map.RemovePlayer(player, false);
-                    // 移除本地组件数据
-                    map.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
+                    // 移除本地玩家数据
+                    self.DomainScene().GetComponent<GamePlayerComponent>().Remove(player.GetId());
                     // 战斗服结束场景
-                    map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
+                    map.GetZoneManager().destroyZoneRequest(self.Id.ToString());
+                    // 移除本地场景数据
+                    map.DomainScene().GetComponent<GameMapComponent>().Remove(map.Id, map.RoomId);
                 }
 
                 player.Dispose();
+
+                map.Dispose();
             }
         }
 

+ 8 - 6
DotNet/Hotfix/Scenes/Router/HttpDouyinApiCallbackHandler.cs

@@ -23,6 +23,8 @@ namespace ET.Server
 
             string msgType = context.Request.Headers["x-msg-type"];
 
+            Log.Debug($"抖音推送数据http回调 - msgType={msgType}");
+
             if (string.IsNullOrEmpty(msgType))
             {
                 Log.Error($"抖音推送数据http回调 找不到请求头:x-msg-type");
@@ -44,21 +46,21 @@ namespace ET.Server
                 case "live_comment":
                 {
                     // 直播间评论
-                    Log.Debug($"收到抖音推送http回调 评论添加玩家回调...");
+                    Log.Debug($"收到抖音推送http回调 评论回调...");
                     LiveComment(domain, context, bodyStr, roomId);
                     break;
                 }
                 case "live_gift":
                 {
                     // 直播间送礼
-                    Log.Debug($"收到抖音推送http回调 直播间刷礼物回调...");
+                    Log.Debug($"收到抖音推送http回调 刷礼物回调...");
                     LiveGift(domain, context, bodyStr, roomId);
                     break;
                 }
                 case "live_like":
                 {
                     // 直播间点赞
-                    Log.Debug($"收到抖音推送http回调 点赞10次增加等级回调...");
+                    Log.Debug($"收到抖音推送http回调 点赞回调...");
                     LiveLike(domain, context, bodyStr, roomId);
                     break;
                 }
@@ -104,7 +106,7 @@ namespace ET.Server
 
                 foreach (StartSceneConfig config in list.Where(config => config is { Id: 10001 }))
                 {
-                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveComment() { OpenId = secOpenId, RoomId = roomId, Content = content, Nickname = nickname, Url = avatarUrl});
+                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveComment() { OpenId = secOpenId, RoomId = roomId, Content = content, NickName = nickname, Url = avatarUrl});
                     break;
                 }
 
@@ -155,7 +157,7 @@ namespace ET.Server
 
                 foreach (StartSceneConfig config in list.Where(config => config is { Id: 10001 }))
                 {
-                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveGift() { OpenId = secOpenId, RoomId = roomId, NickName = nickname, GiftId = secGiftId, GiftNum = giftNum, GiftValue = giftValue});
+                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveGift() { OpenId = secOpenId, RoomId = roomId, NickName = nickname, Url = avatarUrl, GiftId = secGiftId, GiftNum = giftNum, GiftValue = giftValue});
                     break;
                 }
 
@@ -202,7 +204,7 @@ namespace ET.Server
 
                 foreach (StartSceneConfig config in list.Where(config => config is { Id: 10001 }))
                 {
-                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveLike() { OpenId = secOpenId, RoomId = roomId, Likes = likeNum});
+                    MessageHelper.SendActor(config.InstanceId, new R2G_LiveLike() { OpenId = secOpenId, RoomId = roomId, NickName = nickname, Url = avatarUrl, Likes = likeNum});
                     break;
                 }
 

+ 3 - 1
DotNet/Model/Const/ConstGame.cs

@@ -32,11 +32,13 @@ namespace ET.Server
         public const string GetAccessTokenUrl = "https://developer.toutiao.com/api/apps/v2/token";
         /** POST 获取直播间信息 **/
         public const string GetLiveInfoUrl = "https://webcast.bytedance.com/api/webcastmate/info";
+        /** POST 礼物置顶 **/
+        public const string TopGiftUrl = "https://webcast.bytedance.com/api/gift/top_gift";
         /** POST 启动抖音推送回调任务 **/
         public const string StartTaskUrl = "https://webcast.bytedance.com/api/live_data/task/start";
         /** POST 停止抖音推送回调任务 **/
         public const string StopTaskUrl = "https://webcast.bytedance.com/api/live_data/task/stop";
-        /** GET 获取任务状态 **/
+        /** GET 查询任务状态 **/
         public const string CheckTaskUrl = "https://webcast.bytedance.com/api/live_data/task/get";
     }
 

+ 7 - 1
DotNet/Model/Const/Struct.cs

@@ -230,6 +230,12 @@
             /** 战斗服objId **/
             public int ObjId { get; set; }
 
+            /** 昵称 **/
+            public string Name { get; set; }
+
+            /** 头像url **/
+            public string Url { get; set; }
+
             /** 等级 (最大为3) **/
             public long Level { get; set; }
 
@@ -287,7 +293,7 @@
             /** 事件名称 **/
             public string message { get; set; }
 
-            //触发的单位objectId列表
+            /** 触发的单位objectId列表 **/
             public string TriggerUnits { get; set; }
         }
     }

+ 12 - 3
DotNet/Model/Generate/Message/InnerMessage_S_20001.cs

@@ -355,7 +355,7 @@ namespace ET
 		public string Content { get; set; }
 
 		[ProtoMember(4)]
-		public string Nickname { get; set; }
+		public string NickName { get; set; }
 
 		[ProtoMember(5)]
 		public string Url { get; set; }
@@ -376,12 +376,15 @@ namespace ET
 		public string NickName { get; set; }
 
 		[ProtoMember(4)]
-		public string GiftId { get; set; }
+		public string Url { get; set; }
 
 		[ProtoMember(5)]
-		public long GiftNum { get; set; }
+		public string GiftId { get; set; }
 
 		[ProtoMember(6)]
+		public long GiftNum { get; set; }
+
+		[ProtoMember(7)]
 		public long GiftValue { get; set; }
 
 	}
@@ -397,6 +400,12 @@ namespace ET
 		public long RoomId { get; set; }
 
 		[ProtoMember(3)]
+		public string NickName { get; set; }
+
+		[ProtoMember(4)]
+		public string Url { get; set; }
+
+		[ProtoMember(5)]
 		public long Likes { get; set; }
 
 	}

+ 1 - 1
DotNet/Model/Generate/Message/OuterMessage_C_10001.cs

@@ -595,7 +595,7 @@ namespace ET
 		public string Name { get; set; }
 
 		[ProtoMember(2)]
-		public int Value { get; set; }
+		public long Value { get; set; }
 
 		[ProtoMember(3)]
 		public int Ranking { get; set; }

+ 3 - 1
DotNet/Model/Scenes/Game/Map/Map.cs

@@ -33,12 +33,14 @@ namespace ET.Server
         public long ConfigNum { get; set; }
         /** 死亡的单位(塔) **/
         public List<int> DeadUnits { get; set; }
+        /** 死亡的单位玩家 **/
+        public List<int> DeadUnitPlayer { get; set; }
 
         /** 游戏结束标记 **/
         [StaticField]
         public bool IsGameOver = false;
 
-        //当前战场中心
+        /** 当前战场中心 **/
         public int CurBattleIndex = 0;
     }
 }

+ 13 - 0
DotNet/Model/Scenes/Game/Map/MapDouyinLiveGiftComponent.cs

@@ -0,0 +1,13 @@
+namespace ET.Server
+{
+    [ComponentOf(typeof (Map))]
+    public class MapDouyinLiveGiftComponent: Entity, IAwake, IDestroy, IUpdate
+    {
+        /** 任务id **/
+        public long TaskId { get; set; }
+        /** 请求链路id, 用于出问题时提供给开平具体定位 **/
+        public long LogId { get; set; }
+        /** 任务运行状态 **/
+        public int Status { get; set; }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Client/Generate/Message/OuterMessage_C_10001.cs

@@ -595,7 +595,7 @@ namespace ET
 		public string Name { get; set; }
 
 		[ProtoMember(2)]
-		public int Value { get; set; }
+		public long Value { get; set; }
 
 		[ProtoMember(3)]
 		public int Ranking { get; set; }