123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- using System;
- using System.Linq;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- [FriendOf(typeof(MapEventComponent))]
- [FriendOfAttribute(typeof(ET.Server.Map))]
- public static class MapEventComponentSystem
- {
- public class MapEventComponentAwakeSystem : AwakeSystem<MapEventComponent, Map>
- {
-
-
-
-
-
- protected override void Awake(MapEventComponent self, Map map)
- {
- Log.Info($"创建事件组件...");
- }
- }
- public class MapEventComponentDestroySystem : DestroySystem<MapEventComponent>
- {
-
-
-
-
- protected override void Destroy(MapEventComponent self)
- {
- Log.Info($"销毁事件组件...");
- }
- }
-
- public static void OnReady(this MapEventComponent self, WNPlayer player)
- {
- }
-
- public static void OnPlayerLogin(this MapEventComponent self, WNPlayer player)
- {
- }
-
- public static void OnPlayerEntered(this MapEventComponent self, WNPlayer player)
- {
- }
-
- public static void OnUnitDead(this MapEventComponent self, Map map, JObject msg)
- {
- 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[] atkAssistantList = JsonConvert.DeserializeObject<long[]>(Convert.ToString(msg.SelectToken("atkAssistantList")) ?? string.Empty);
- WNPlayer hitFinalPlayer = null;
-
- if (belongPlayerId > 0)
- {
- hitFinalPlayer = map.GetPlayer(belongPlayerId);
- }
- if (hitFinalPlayer == null && hitFinalPlayerId > 0)
- {
- hitFinalPlayer = map.GetPlayer(hitFinalPlayerId);
- }
- switch (unitType)
- {
- case 0:
-
- int unitTemplateId = Convert.ToInt32(msg.SelectToken("unitTemplateId"));
- Monster monsterProp = MonsterCategory.Instance.Get(unitTemplateId);
- if (monsterProp == null)
- {
- Log.Error($"unitDead not fount montster : {unitTemplateId}, {map.MapId}, {msg}");
- return;
- }
-
- Log.Debug($"怪物死亡处理...");
- break;
- case 1:
-
- long unitPlayerId = Convert.ToInt64(msg.SelectToken("unitPlayerId"));
- if (hitFinalPlayerId <= 0)
- {
-
- int attackerTemplateId = Convert.ToInt32(msg.SelectToken("attackerTemplateId"));
- Log.Debug($"玩家死亡...被boss杀死...playerId={unitPlayerId}, bossId={attackerTemplateId}");
- }
- else
- {
-
- Log.Debug($"玩家死亡...被玩家杀死...playerId={unitPlayerId}, 攻击者={hitFinalPlayerId}");
- }
-
- WNPlayer unitPlayer = map.GetPlayer(unitPlayerId);
- if (unitPlayer == null)
- {
- return;
- }
- unitPlayer.AddComponent<PlayerReliveTimeComponent, WNPlayer>(unitPlayer);
- break;
- case 2:
-
- break;
- }
- }
-
- public static void OnMessageEvent(this MapEventComponent self, JObject msg)
- {
- }
-
- public static void OnGameOver(this MapEventComponent self, Map map)
- {
- 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;
- }
- }
-
- public static void OnPickItem(this MapEventComponent self, JObject msg)
- {
- }
-
- public static void OnKillBoss(this MapEventComponent self, JObject msg)
- {
- }
-
- public static void OnBattleReport(this MapEventComponent self, JObject msg)
- {
- }
- }
- }
|