123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System;
- using BattleIce;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- public class MapAwakeSystem: AwakeSystem<Map, JObject>
- {
- /// <summary>
- /// 本地地图场景实体创建
- /// </summary>
- /// <param name="self"></param>
- protected override void Awake(Map self, JObject opts)
- {
- self.createTime = TimeHelper.ServerNow();
- Log.Debug($"create area opts:{opts}");
- self.LogicServerId = opts.SelectToken("logicServerId") != null? Convert.ToInt32(opts.SelectToken("logicServerId")) : 0;
- self.MapId = Convert.ToInt32(opts.SelectToken("areaId"));
- self.Prop = MapConfigCategory.Instance.Get(self.MapId);
- self.Type = self.Prop.Type;
- }
- }
- public class MapDestroySystem: DestroySystem<Map>
- {
- /// <summary>
- /// 本地地图场景实体销毁
- /// </summary>
- /// <param name="self"></param>
- protected override void Destroy(Map self)
- {
- }
- }
- [FriendOf(typeof (Map))]
- [FriendOf(typeof (BattleIceAgentComponent))]
- public static class MapSystem
- {
- public static ZoneManagerPrx GetZoneManager(this Map self)
- {
- return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
- }
- public static XmdsManagerPrx GetXmdsManager(this Map self)
- {
- return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceXmdsManager;
- }
- public static GetPlayerData GetPlayerData(this Map self, long playerId)
- {
- string result = self.GetXmdsManager().getPlayerData(playerId.ToString().Trim(), true);
- return string.IsNullOrEmpty(result)? null : JsonConvert.DeserializeObject<GetPlayerData>(result);
- }
- /** 从战斗服同步角色数据 **/
- public static void SyncPlayerHistoryData(this Map self, WNPlayer player)
- {
- GetPlayerData result = self.GetPlayerData(player.GetId());
- if (result == null)
- {
- return;
- }
- player.GetComponent<PlayerTempDataComponent>().SyncNowData(self.MapId, self.InstanceId, result);
- player.GetComponent<PlayerTempDataComponent>().SyncHistoryData(self.Prop, self.InstanceId, result);
- }
- /** 场景添加角色 **/
- public static void AddPlayer(this Map self, WNPlayer player)
- {
- Log.Info($"addPlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
- self.SetForce(player);
- player.Map = self;
- }
- /** 分配阵营 **/
- public static void SetForce(this Map self, WNPlayer player)
- {
- player.Force = (int)AreaForce.FORCEA;
- }
- /** 移除角色,通用框架接口 切换场景/掉线会自动调用,尽量 不要手动调用 **/
- public static void RemovePlayer(this Map self, WNPlayer player, bool keepObject)
- {
- Log.Info($"removePlayer: playerId={player.GetId()}, mapId={self.MapId}, ip={player.Session.RemoteAddress}");
- self.Players.TryGetValue(player.GetId(), out WNPlayer actorPlayer);
- if (actorPlayer != null)
- {
- self.Players.Remove(player.GetId());
- }
- }
- /** 玩家进入场景请求 **/
- public static void PlayerEnterRequest(this Map self, WNPlayer player)
- {
- try
- {
- self.GetZoneManager().playerEnterRequest(player.GetId().ToString().Trim(), self.InstanceId.ToString().Trim(),
- player.toJSON4EnterScene(self));
- }
- catch (Exception e)
- {
- Log.Warning(
- $"playerEnterRequest: playerName={player.GetName()}, instanceId={self.InstanceId}, mapName={self.Prop.Name}, serverID={self.BattleServerId}, e={e}");
- }
- }
- /** 玩家离开场景请求 **/
- public static void PlayerLeaveRequest(this Map self, WNPlayer player, bool keepObject)
- {
- try
- {
- self.GetZoneManager().playerLeaveRequest(player.GetId().ToString().Trim(), self.InstanceId.ToString().Trim(), keepObject);
- }
- catch (Exception e)
- {
- Log.Warning($"playerLeaveRequest: catch - {e}");
- }
- Log.Debug($"playerLeaveRequest--------------------{player.GetName()} - {self.InstanceId} - {self.Prop.Name}");
- }
- /** 玩家登录事件 **/
- public static void OnPlayerLogin(this Map self, WNPlayer player)
- {
- }
- /** 角色成功进入场景 **/
- public static void OnPlayerEntered(this Map self, WNPlayer player)
- {
- }
- public static void BindBattleServer(this Map self, WNPlayer player, string serverId)
- {
- self.BattleServerId = serverId;
- }
- }
- }
|