using System.Collections.Generic; using BattleIce; namespace ET.Server { [FriendOf(typeof (PlayerTempDataComponent))] public static class PlayerTempDataComponentSystem { public class PlayerTempDataComponentAwakeSystem: AwakeSystem { protected override void Awake(PlayerTempDataComponent self) { Log.Info($"创建玩家临时数据组件..."); self.MapData = new PlayerMapInfo(); self.MapData.mapId = 10099; self.MapData.x = 1586; self.MapData.y = 1566; // self.MapData.direction = System.MathF.PI / 2; self.MapData.hp = PLAYER.initHp; self.MapData.mp = PLAYER.initMp; self.ToJson4BattleServerTempData = self.GetBattleServerTempData(); } } public class PlayerTempDataComponentDestroySystem: DestroySystem { protected override void Destroy(PlayerTempDataComponent self) { } } /** 同步场景出生数据 **/ public static void SyncBornData(this PlayerTempDataComponent self, float bornX, float bornY, int bornAreaId) { self.MapData.bornX = bornX; self.MapData.bornY = bornY; self.MapData.bornMapId = bornAreaId; } /** 同步场景临时数据 **/ public static void SyncNowData(this PlayerTempDataComponent self, int areaId, long instanceId, GetPlayerData data) { self.MapData.x = data.x; self.MapData.y = data.y; self.MapData.direction = data.direction; self.MapData.hp = data.hp; self.MapData.mp = data.mp; self.MapData.mapId = areaId; self.MapData.mapInstanceId = instanceId; } /** 同步场景历史数据 **/ public static void SyncHistoryData(this PlayerTempDataComponent self, MapConfig prop, long instanceId, GetPlayerData data) { self.MapData.historyX = data.x; self.MapData.historyY = data.y; self.MapData.historyDirection = data.direction; self.MapData.historyMapId = prop.Id; self.MapData.historyMapInstanceId = instanceId; } /// /// 发送给场景服的数据 /// /// /// private static Dictionary GetBattleServerTempData(this PlayerTempDataComponent self) { Dictionary data = new Dictionary(); data.Add("x", self.MapData.x); data.Add("y", self.MapData.y); data.Add("direction", self.MapData.direction); data.Add("hp", self.MapData.hp > 0 ? self.MapData.hp : self.GetParent().GetComponent().GetAllInflus(PlayerBtlData.MaxHP)); data.Add("mp", self.MapData.mp); return data; } } }