using System.Collections.Generic; using System.Text.Json; using BattleIce; namespace ET.Server { [FriendOf(typeof (WNPlayer))] [FriendOf(typeof (BattleIceAgentComponent))] public static class PlayerSystem { public class PlayerAwakeSystem: AwakeSystem { /// /// 玩家实体创建 /// /// /// /// protected override void Awake(WNPlayer self, Session session, PlayerInfo playerInfo) { Log.Info($"创建玩家实体..."); } } public class PlayerDestroySystem: DestroySystem { /// /// 玩家实体销毁 /// /// protected override void Destroy(WNPlayer self) { Log.Info($"销毁玩家实体..."); } } /// /// 获取角色id /// /// /// public static long GetId(this WNPlayer self) { return self.GetComponent().Data.Id; } /// /// 获取玩家类型 /// /// /// public static int GetPlayerType(this WNPlayer self) { return self.GetComponent().Data.PlayerType; } /// /// 获取账号id /// /// /// public static long GetUserId(this WNPlayer self) { return self.GetComponent().Data.UserId; } /// /// 获取名称 /// /// /// public static string GetName(this WNPlayer self) { return self.GetComponent().Data.Name; } /// /// 获取性别 /// /// /// public static int GetSex(this WNPlayer self) { return self.GetComponent().Data.Sex; } /// /// 获取职业 /// /// /// public static int GetPro(this WNPlayer self) { return self.GetComponent().Data.Pro; } /// /// 获取经验 /// /// /// public static long GetExp(this WNPlayer self) { return self.GetComponent().Data.Exp; } /// /// 获取等级 /// /// /// public static int GetLevel(this WNPlayer self) { return self.GetComponent().Data.Level; } /// /// 获取金币 /// /// /// public static long GetGold(this WNPlayer self) { return self.GetComponent().Data.Gold; } /// /// 获取场景实例id /// /// /// public static long GetMapInstanceId(this WNPlayer self) { return self.Map.InstanceId; } /** 获取服务器id **/ public static int GetLogicServerId(this WNPlayer self) { return self.GetComponent().Data.LogicServerId; } public static ZoneManagerPrx GetZoneManager(this WNPlayer self) { return self.DomainScene().GetComponent().IceZoneManager; } public static XmdsManagerPrx GetXmdsManager(this WNPlayer self) { return self.DomainScene().GetComponent().IceXmdsManager; } /** bornData相关初始化 **/ public static void InitBornData(this WNPlayer self) { switch (self.BornType) { case (int)BORN_TYPE.HISTORY: self.GetComponent().MapData.mapId = self.GetComponent().MapData.historyMapId; self.GetComponent().MapData.mapInstanceId = self.GetComponent().MapData.historyMapInstanceId; self.GetComponent().MapData.x = self.GetComponent().MapData.historyX; self.GetComponent().MapData.y = self.GetComponent().MapData.historyY; break; case (int)BORN_TYPE.BORN: self.GetComponent().MapData.mapId = self.GetComponent().MapData.bornMapId; self.GetComponent().MapData.mapInstanceId = self.GetComponent().MapData.bornMapInstanceId; self.GetComponent().MapData.x = self.GetComponent().MapData.bornX; self.GetComponent().MapData.y = self.GetComponent().MapData.bornY; break; } } /** 客户端资源加载完成通知 给客户端推送的数据要在这里 **/ public static void OnReady(this WNPlayer self) { self.OnEndEnterScene(); // 登录第一次进场景处理,此次登陆登出期间只处理一次 if (self.ReadyFirst) { self.ReadyFirst = false; } } /** 玩家登录事件 **/ public static void OnLogin(this WNPlayer self) { self.ReadyFirst = true; self.DomainScene().GetComponent().Add(self.GetId(), self); } /** 向客户端推送角色相关数据 **/ public static void OnEndEnterScene(this WNPlayer self) { bool ready = self.GetComponent().MapData.ready; if (ready) { Log.Warning($"$OnEndEnterScene跳过 : playerId={self.GetId()}, 玩家场景:{self.Map.MapId}, 进入场景:" + (self.Map?.MapId ?? -1)); return; } self.GetComponent().MapData.ready = true; self.GetXmdsManager().playerReady(self.GetId().ToString().Trim()); //PKMode设置为All self.GetXmdsManager().refreshPlayerPKMode(self.GetId().ToString().Trim(), false, (int)PkModel.All); //设置为自动战斗 self.GetXmdsManager().autoBattle(self.Map.Id.ToString().Trim(), self.GetId().ToString().Trim(), true); } /** 场景中角色需求数据 **/ public static string ToJSON4EnterScene(this WNPlayer self, Map map) { var json = new { effects = new { MaxHP = 8888, HPPer = 0.6, Attack = 20, AttackPer = 100, MoveSpeed = 5, }, effectsExt = new { }, // skills = self.ToJson4BattleServerSkillInfos, skills = new List() { new SkillInfo { id = 510200, level = 1, type = 1, skillTime = 0, cdTime = 0, flag = 0, autoLaunch = false, }, new SkillInfo { id = 90203, level = 1, type = 3, skillTime = 0, cdTime = 0, flag = 0 }, }, tasks = new { }, flags = new { }, playerEntered = false, avatars = new { }, basic = new { name = self.GetName(), alliesForce = 0, force = 1, pro = self.GetPro(), serverId = ConstGame.GameServerId, titleId = 0, level = self.GetLevel(), vip = 0, upLevel = 1, // 无悬赏 beReward = 0, logicServerId = ConstGame.GameServerId, sex = self.GetSex(), uuid = self.GetId().ToString(), potionAddition = 0 }, connectServerId = "bs-" + ConstGame.GameServerId, uid = self.GetId().ToString(), unitTemplateID = 1, robot = false, tempData = new { //x = this.getPlayerAreaData().bornX, //y = this.getPlayerAreaData().bornY, x = 230, y = 100, direction = System.MathF.PI / 2, hp = 666, mp = 0, }, pkInfo = new { mode = 0, value = 0, level = 1, }, //petBase, addTestPetData = 0, sceneData = new { allowAutoGuard = 3, }, }; string retjson = JsonSerializer.Serialize(json, new JsonSerializerOptions { IncludeFields = true }); Log.Debug($"{self.GetName()}, enterSceneData:{retjson.ToString()}"); return retjson; } } }