Browse Source

【增加】贡献榜

johnclot69 1 year ago
parent
commit
faab2dd275

+ 12 - 0
Config/Proto/OuterMessage_C_10001.proto

@@ -287,6 +287,18 @@ message G2C_TriggrBattleFunction // IResponse
 	string Message = 3;
 }
 
+message RankInfo
+{
+	string Name = 1;		// 名称
+	int32 Value = 2;		// 贡献值
+	int32 Ranking = 3;		// 排名
+}
+
+message G2C_RankNotify // IActorMessage
+{
+	repeated RankInfo InfoList = 1;	// 排行榜list
+}
+
 message G2C_TestHotfixMessage // IMessage
 {
 	string Info = 1;

+ 2 - 2
DotNet/Hotfix/Helper/BattleServerEventHelper.cs

@@ -15,7 +15,7 @@ namespace ET.Server
         /// <param name="msg"></param>
         public static void AreaBattleServerEvent(JObject msg)
         {
-            Log.Debug($"AreaBattleServerEvent msg: {JsonConvert.SerializeObject(msg, Formatting.Indented)}");
+            // Log.Debug($"AreaBattleServerEvent msg: {JsonConvert.SerializeObject(msg, Formatting.Indented)}");
             long instanceId = Convert.ToInt64(msg.SelectToken("instanceId"));
             Map map = GameMapComponent.Instance.Get(instanceId);
             if (map == null)
@@ -55,7 +55,7 @@ namespace ET.Server
                 case "BattleReportEventB2R":
                 {
                     // 战斗统计事件
-                    map.GetComponent<MapEventComponent>().OnBattleReport(msg);
+                    map.GetComponent<MapEventComponent>().OnBattleReport(map, msg);
                     return;
                 }
                 default:

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

@@ -39,7 +39,7 @@ namespace ET.Server
 
             Struct.MonsterUnit unit = new Struct.MonsterUnit();
             unit.id = request.UnitId;
-            unit.force = request.Force;
+            unit.force = 1;
             if (!string.IsNullOrEmpty(request.Flag))
             {
                 unit.flag = request.Flag;

+ 56 - 13
DotNet/Hotfix/Scenes/Game/Map/MapEventComponentSystem.cs

@@ -1,28 +1,28 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 
 namespace ET.Server
 {
-    [FriendOf(typeof(MapEventComponent))]
-    [FriendOfAttribute(typeof(ET.Server.Map))]
+    [FriendOf(typeof (MapEventComponent))]
+    [FriendOfAttribute(typeof (Map))]
     public static class MapEventComponentSystem
     {
-        public class MapEventComponentAwakeSystem : AwakeSystem<MapEventComponent, Map>
+        public class MapEventComponentAwakeSystem: AwakeSystem<MapEventComponent>
         {
             /// <summary>
             /// 场景事件组件创建
             /// </summary>
             /// <param name="self"></param>
-            /// <param name="map"></param>
-            protected override void Awake(MapEventComponent self, Map map)
+            protected override void Awake(MapEventComponent self)
             {
                 Log.Info($"创建事件组件...");
             }
         }
 
-        public class MapEventComponentDestroySystem : DestroySystem<MapEventComponent>
+        public class MapEventComponentDestroySystem: DestroySystem<MapEventComponent>
         {
             /// <summary>
             /// 场景事件组件销毁
@@ -37,7 +37,6 @@ namespace ET.Server
         /** 玩家进场景后推的消息 **/
         public static void OnReady(this MapEventComponent self, WNPlayer player)
         {
-
         }
 
         /** 玩家登录事件 **/
@@ -56,8 +55,8 @@ namespace ET.Server
             Log.Debug($"单位死亡...");
             int unitType = Convert.ToInt32(msg.SelectToken("unitType"));
             // 攻击者
-            long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
-            long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == "" ? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
+            long hitFinalPlayerId = msg.SelectToken("hitFinal").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("hitFinal"));
+            long belongPlayerId = msg.SelectToken("belongPlayerId").ToString() == ""? 0 : Convert.ToInt64(msg.SelectToken("belongPlayerId"));
             long[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
             WNPlayer hitFinalPlayer = null;
 
@@ -83,6 +82,7 @@ namespace ET.Server
                         Log.Error($"unitDead not fount montster : {unitTemplateId}, {map.MapId}, {msg}");
                         return;
                     }
+
                     // todo 怪物死亡处理逻辑
                     Log.Debug($"怪物死亡处理...");
                     break;
@@ -121,7 +121,6 @@ namespace ET.Server
         /** 副本消息 **/
         public static void OnMessageEvent(this MapEventComponent self, JObject msg)
         {
-
         }
 
         /** 场景结算事件 **/
@@ -150,19 +149,63 @@ namespace ET.Server
         /** 拾取道具 **/
         public static void OnPickItem(this MapEventComponent self, JObject msg)
         {
-
         }
 
         /** 击杀boss **/
         public static void OnKillBoss(this MapEventComponent self, JObject msg)
         {
-
         }
 
         /** 战斗统计 **/
-        public static void OnBattleReport(this MapEventComponent self, JObject msg)
+        public static void OnBattleReport(this MapEventComponent self, Map map, JObject msg)
         {
+            string data = Convert.ToString(msg.SelectToken("data"));
+            if (string.IsNullOrEmpty(data))
+            {
+                return;
+            }
+
+            List<Struct.BattleReports> list = new List<Struct.BattleReports>();
+
+            var battleReports = JsonConvert.DeserializeObject<List<Struct.BattleReports>>(data);
+            if (battleReports is { Count: > 0 })
+            {
+                foreach (Struct.BattleReports report in battleReports)
+                {
+                    // 过滤一下非我方单位
+                    if (report.Force != 1)
+                    {
+                        continue;
+                    }
+
+                    uint ID = report.ID;
+                    long PlayerUUID = string.IsNullOrEmpty(report.PlayerUUID)? 0 : Convert.ToInt64(report.PlayerUUID);
+                    int TemplateID = report.TemplateId;
+                    int Force = report.Force;
+                    int TotalDamage = report.TotalDamage;
+
+                    string name = "";
+                    if (PlayerUUID > 0)
+                    {
+                        name = "玩家-" + TemplateID;
+                    }
+                    else
+                    {
+                        if (TemplateID > 0)
+                        {
+                            Monster prop = MonsterCategory.Instance.Get(TemplateID);
+                            if (prop != null)
+                            {
+                                name = prop.Name;
+                            }
+                        }
+                    }
+
+                    list.Add(new Struct.BattleReports(ID, report.PlayerUUID, TemplateID, name, Force, TotalDamage));
+                }
+            }
 
+            map.GetComponent<MapRankComponent>().UpdateRank(list, map);
         }
     }
 }

+ 110 - 0
DotNet/Hotfix/Scenes/Game/Map/MapRankComponentSystem.cs

@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace ET.Server
+{
+    [FriendOf(typeof (MapRankComponent))]
+    [FriendOfAttribute(typeof (Map))]
+    public static class MapRankComponentSystem
+    {
+        public class MapRankComponentAwakeSystem: AwakeSystem<MapRankComponent>
+        {
+            /// <summary>
+            /// 场景贡献榜组件创建
+            /// </summary>
+            /// <param name="self"></param>
+            protected override void Awake(MapRankComponent self)
+            {
+                Log.Info($"创建场景贡献榜组件");
+            }
+        }
+
+        public class MapRankComponentDestroySystem: DestroySystem<MapRankComponent>
+        {
+            /// <summary>
+            /// 场景贡献榜组件销毁
+            /// </summary>
+            /// <param name="self"></param>
+            protected override void Destroy(MapRankComponent self)
+            {
+                Log.Debug($"销毁场景贡献榜组件");
+            }
+        }
+
+        /// <summary>
+        /// 更新排行榜数据
+        /// </summary>
+        /// <param name="self"></param>
+        /// <param name="dataList"></param>
+        /// <param name="map"></param>
+        public static void UpdateRank(this MapRankComponent self, List<Struct.BattleReports> dataList, Map map)
+        {
+            foreach (Struct.BattleReports data in dataList)
+            {
+                bool isExist = false;
+
+                foreach (Struct.BattleReports br in self.RankList.Where(br => data.ID == br.ID))
+                {
+                    isExist = true;
+                    br.TotalDamage = data.TotalDamage;
+                }
+
+                if (!isExist)
+                {
+                    self.RankList.Add(data);
+                }
+            }
+
+            self.Sort(map);
+        }
+
+        /// <summary>
+        /// 排序
+        /// </summary>
+        /// <param name="self"></param>
+        /// <param name="map"></param>
+        private static void Sort(this MapRankComponent self, Map map)
+        {
+            List<Struct.BattleReports> list = new List<Struct.BattleReports>();
+
+            self.RankList.ForEach(br => list.Add(br));
+
+            if (list is { Count: > 0 })
+            {
+                list.Sort((r1, r2) => r2.TotalDamage.CompareTo(r1.TotalDamage));
+            }
+
+            self.ViewRankList.Clear();
+
+            int ranking = 1;
+
+            List<RankInfo> infoListProto = new List<RankInfo>();
+
+            foreach (Struct.BattleReports battleReports in list.Where(battleReports => ranking <= 3))
+            {
+                // 客户端消息
+                RankInfo info = new RankInfo();
+                info.Name = battleReports.Name;
+                info.Value = battleReports.TotalDamage;
+                info.Ranking = ranking;
+                infoListProto.Add(info);
+
+                self.ViewRankList.Add(ranking, battleReports);
+
+                ranking += 1;
+            }
+
+            bool isEqual = self.ViewRankList.Values.SequenceEqual(list);
+            if (isEqual)
+            {
+                return;
+            }
+
+            foreach (WNPlayer player in map.Players.Values)
+            {
+                MessageHelper.SendToClient(player, new G2C_RankNotify() { InfoList = infoListProto });
+            }
+        }
+    }
+}

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

@@ -26,8 +26,10 @@ namespace ET.Server
                 self.MapId = Convert.ToInt32(opts.SelectToken("areaId"));
                 self.Prop = MapConfigCategory.Instance.Get(self.MapId);
                 self.Type = self.Prop.Type;
-                // 添加组件
-                self.AddComponent<MapEventComponent, Map>(self);
+                // 场景事件组件
+                self.AddComponent<MapEventComponent>();
+                // 场景排行榜组件
+                self.AddComponent<MapRankComponent>();
             }
         }
 

+ 32 - 6
DotNet/Model/Generate/Message/OuterMessage_C_10001.cs

@@ -593,6 +593,30 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.RankInfo)]
+	[ProtoContract]
+	public partial class RankInfo: ProtoObject
+	{
+		[ProtoMember(1)]
+		public string Name { get; set; }
+
+		[ProtoMember(2)]
+		public int Value { get; set; }
+
+		[ProtoMember(3)]
+		public int Ranking { get; set; }
+
+	}
+
+	[Message(OuterMessage.G2C_RankNotify)]
+	[ProtoContract]
+	public partial class G2C_RankNotify: ProtoObject, IActorMessage
+	{
+		[ProtoMember(1)]
+		public List<RankInfo> InfoList { get; set; }
+
+	}
+
 	[Message(OuterMessage.G2C_TestHotfixMessage)]
 	[ProtoContract]
 	public partial class G2C_TestHotfixMessage: ProtoObject, IMessage
@@ -714,11 +738,13 @@ namespace ET
 		 public const ushort G2C_RemoveUnit = 10038;
 		 public const ushort C2G_TriggrBattleFunction = 10039;
 		 public const ushort G2C_TriggrBattleFunction = 10040;
-		 public const ushort G2C_TestHotfixMessage = 10041;
-		 public const ushort C2M_TestRobotCase = 10042;
-		 public const ushort M2C_TestRobotCase = 10043;
-		 public const ushort C2G_Benchmark = 10044;
-		 public const ushort G2C_Benchmark = 10045;
-		 public const ushort R2C_Disconnect = 10046;
+		 public const ushort RankInfo = 10041;
+		 public const ushort G2C_RankNotify = 10042;
+		 public const ushort G2C_TestHotfixMessage = 10043;
+		 public const ushort C2M_TestRobotCase = 10044;
+		 public const ushort M2C_TestRobotCase = 10045;
+		 public const ushort C2G_Benchmark = 10046;
+		 public const ushort G2C_Benchmark = 10047;
+		 public const ushort R2C_Disconnect = 10048;
 	}
 }

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

@@ -3,7 +3,7 @@
 namespace ET.Server
 {
     [ComponentOf(typeof (Map))]
-    public class MapEventComponent: Entity, IAwake<Map>, IDestroy
+    public class MapEventComponent: Entity, IAwake, IDestroy
     {
         /** 已杀的boss列表 **/
         [StaticField]

+ 16 - 0
DotNet/Model/Scenes/Game/Map/MapRankComponent.cs

@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+
+namespace ET.Server
+{
+    [ComponentOf(typeof (Map))]
+    public class MapRankComponent: Entity, IAwake, IDestroy
+    {
+        /** 排行榜缓存数据 **/
+        [StaticField]
+        public List<Struct.BattleReports> RankList = new List<Struct.BattleReports>();
+
+        /** 用于客户端显示的数据 [key:阵营, value:[key:排名, value:战报数据]]**/
+        [StaticField]
+        public Dictionary<int, Struct.BattleReports> ViewRankList = new Dictionary<int, Struct.BattleReports>();
+    }
+}

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

@@ -593,6 +593,30 @@ namespace ET
 
 	}
 
+	[Message(OuterMessage.RankInfo)]
+	[ProtoContract]
+	public partial class RankInfo: ProtoObject
+	{
+		[ProtoMember(1)]
+		public string Name { get; set; }
+
+		[ProtoMember(2)]
+		public int Value { get; set; }
+
+		[ProtoMember(3)]
+		public int Ranking { get; set; }
+
+	}
+
+	[Message(OuterMessage.G2C_RankNotify)]
+	[ProtoContract]
+	public partial class G2C_RankNotify: ProtoObject, IActorMessage
+	{
+		[ProtoMember(1)]
+		public List<RankInfo> InfoList { get; set; }
+
+	}
+
 	[Message(OuterMessage.G2C_TestHotfixMessage)]
 	[ProtoContract]
 	public partial class G2C_TestHotfixMessage: ProtoObject, IMessage
@@ -714,11 +738,13 @@ namespace ET
 		 public const ushort G2C_RemoveUnit = 10038;
 		 public const ushort C2G_TriggrBattleFunction = 10039;
 		 public const ushort G2C_TriggrBattleFunction = 10040;
-		 public const ushort G2C_TestHotfixMessage = 10041;
-		 public const ushort C2M_TestRobotCase = 10042;
-		 public const ushort M2C_TestRobotCase = 10043;
-		 public const ushort C2G_Benchmark = 10044;
-		 public const ushort G2C_Benchmark = 10045;
-		 public const ushort R2C_Disconnect = 10046;
+		 public const ushort RankInfo = 10041;
+		 public const ushort G2C_RankNotify = 10042;
+		 public const ushort G2C_TestHotfixMessage = 10043;
+		 public const ushort C2M_TestRobotCase = 10044;
+		 public const ushort M2C_TestRobotCase = 10045;
+		 public const ushort C2G_Benchmark = 10046;
+		 public const ushort G2C_Benchmark = 10047;
+		 public const ushort R2C_Disconnect = 10048;
 	}
 }

+ 32 - 0
Unity/Assets/Scripts/Codes/Model/Share/Const/Struct.cs

@@ -5,6 +5,9 @@
     /// </summary>
     public class Struct
     {
+        /// <summary>
+        /// 数据结构 int_int
+        /// </summary>
         public class IntIntData
         {
             public int value1 { get; set; }
@@ -181,5 +184,34 @@
                 this.birthDirection = birthDirection;
             }
         }
+
+        /// <summary>
+        /// 战报数据
+        /// </summary>
+        public class BattleReports
+        {
+            public uint ID { get; set; }
+            public string PlayerUUID { get; set; }
+            /** 模板id **/
+            public int TemplateId { get; set; }
+            /** 单位名称 **/
+            public string Name { get; set; }
+            /** 阵营 **/
+            public int Force { get; set; }
+            /** 对所有单位输出的总伤害 **/
+            public int TotalDamage { get; set; }
+            /** 对所有单位输出的总治疗量 **/
+            public int TotalHealing { get; set; }
+
+            public BattleReports(uint id, string PlayerUUID, int templateId, string name, int force, int totalDamage)
+            {
+                this.ID = id;
+                this.PlayerUUID = PlayerUUID;
+                this.TemplateId = templateId;
+                this.Name = name;
+                this.Force = force;
+                this.TotalDamage = totalDamage;
+            }
+        }
     }
 }