123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof (MapEventComponent))]
- [FriendOf(typeof (Map))]
- public static class MapEventComponentSystem
- {
- public class MapEventComponentAwakeSystem: AwakeSystem<MapEventComponent>
- {
- /// <summary>
- /// 场景事件组件创建
- /// </summary>
- /// <param name="self"></param>
- protected override void Awake(MapEventComponent self)
- {
- Log.Info($"创建战斗服事件组件...");
- }
- }
- public class MapEventComponentDestroySystem: DestroySystem<MapEventComponent>
- {
- /// <summary>
- /// 场景事件组件销毁
- /// </summary>
- /// <param name="self"></param>
- protected override void Destroy(MapEventComponent self)
- {
- Log.Info($"销毁战斗服事件组件...");
- }
- }
- /// <summary>
- /// 单位死亡事件
- /// </summary>
- /// <param name="self"></param>
- /// <param name="msg"></param>
- public static void OnUnitDead(this MapEventComponent self, JObject msg)
- {
- }
- /// <summary>
- /// 副本消息
- /// </summary>
- /// <param name="self"></param>
- /// <param name="msg"></param>
- public static void OnMessageEvent(this MapEventComponent self, JObject msg)
- {
- switch (Convert.ToString(msg.SelectToken("msg")))
- {
- case "Dead:Tower1":
- {
- Log.Debug($"塔1死亡事件...");
- self.GetParent<Map>().DeadUnits.Add(1001);
- return;
- }
- case "Dead:Tower2":
- {
- Log.Debug($"塔2死亡事件...");
- self.GetParent<Map>().DeadUnits.Add(1002);
- return;
- }
- case "Dead:Tower3":
- {
- Log.Debug($"塔3死亡事件...");
- self.GetParent<Map>().DeadUnits.Add(1003);
- return;
- }
- }
- }
- /// <summary>
- /// 场景结算事件
- /// </summary>
- /// <param name="self"></param>
- public static void OnGameOver(this MapEventComponent self)
- {
- Map map = self.GetParent<Map>();
- map.IsGameOver = true;
- if (map.Players is not { Count: > 0 })
- {
- return;
- }
- foreach (WNPlayer player in map.Players.Values.Where(player => player != null))
- {
- // 记录玩家历史
- map.SyncPlayerHistoryData(player);
- // 战斗服场景玩家离开
- map.PlayerLeaveRequest(player, false);
- // 本地场景移除玩家
- map.RemovePlayer(player, false);
- // 战斗服结束场景
- map.GetZoneManager().destroyZoneRequest(map.Id.ToString());
- player.Map = null;
- }
- }
- /// <summary>
- /// 拾取道具
- /// </summary>
- /// <param name="self"></param>
- /// <param name="msg"></param>
- public static void OnPickItem(this MapEventComponent self, JObject msg)
- {
- }
- /// <summary>
- /// 击杀boss
- /// </summary>
- /// <param name="self"></param>
- /// <param name="msg"></param>
- public static void OnKillBoss(this MapEventComponent self, JObject msg)
- {
- }
- /// <summary>
- /// 战报统计
- /// </summary>
- /// <param name="self"></param>
- /// <param name="msg"></param>
- public static void OnBattleReport(this MapEventComponent self, JObject msg)
- {
- string data = Convert.ToString(msg.SelectToken("data"));
- if (string.IsNullOrEmpty(data))
- {
- return;
- }
- List<Struct.BattleReports> battleReports = JsonConvert.DeserializeObject<List<Struct.BattleReports>>(data);
- if (battleReports is not { Count: > 0 })
- {
- return;
- }
- Map map = self.GetParent<Map>();
- List<Struct.BattleReports> list = (from report in battleReports
- where report.Force == 1
- let ID = report.ID
- let PlayerUUID = string.IsNullOrEmpty(report.PlayerUUID)? "0" : report.PlayerUUID
- let TemplateID = report.TemplateId
- let Name = "玩家" + ID + "." + TemplateID
- let Force = report.Force
- let TotalDamage = report.TotalDamage
- select new Struct.BattleReports(ID, PlayerUUID, TemplateID, Name, Force, TotalDamage)).ToList();
- map.GetComponent<MapRankComponent>().UpdateRank(list, map);
- }
- }
- }
|