123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- 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<WNPlayer, Session, PlayerInfo>
- {
- /// <summary>
- /// 玩家实体创建
- /// </summary>
- /// <param name="self"></param>
- /// <param name="session"></param>
- /// <param name="playerInfo"></param>
- protected override void Awake(WNPlayer self, Session session, PlayerInfo playerInfo)
- {
- Log.Info($"创建玩家实体...");
- }
- }
- public class PlayerDestroySystem: DestroySystem<WNPlayer>
- {
- /// <summary>
- /// 玩家实体销毁
- /// </summary>
- /// <param name="self"></param>
- protected override void Destroy(WNPlayer self)
- {
- Log.Info($"销毁玩家实体...");
- }
- }
- /// <summary>
- /// 获取角色id
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static long GetId(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Id;
- }
- /// <summary>
- /// 获取账号id
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static long GetUserId(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.UserId;
- }
- /// <summary>
- /// 获取名称
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static string GetName(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Name;
- }
- /// <summary>
- /// 获取性别
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static int GetSex(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Sex;
- }
- /// <summary>
- /// 获取职业
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static int GetPro(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Pro;
- }
- /// <summary>
- /// 获取经验
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static long GetExp(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Exp;
- }
- /// <summary>
- /// 获取等级
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static int GetLevel(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Level;
- }
- /// <summary>
- /// 获取金币
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static long GetGold(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Gold;
- }
- /// <summary>
- /// 获取场景实例id
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static long GetMapInstanceId(this WNPlayer self)
- {
- return self.Map.InstanceId;
- }
- /** 获取服务器id **/
- public static int GetLogicServerId(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.LogicServerId;
- }
- public static ZoneManagerPrx GetZoneManager(this WNPlayer self)
- {
- return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceZoneManager;
- }
- public static XmdsManagerPrx GetXmdsManager(this WNPlayer self)
- {
- return self.DomainScene().GetComponent<BattleIceAgentComponent>().IceXmdsManager;
- }
- /** bornData相关初始化 **/
- public static void InitBornData(this WNPlayer self)
- {
- switch (self.BornType)
- {
- case (int)BORN_TYPE.HISTORY:
- self.GetComponent<PlayerTempDataComponent>().MapData.mapId = self.GetComponent<PlayerTempDataComponent>().MapData.historyMapId;
- self.GetComponent<PlayerTempDataComponent>().MapData.mapInstanceId =
- self.GetComponent<PlayerTempDataComponent>().MapData.historyMapInstanceId;
- self.GetComponent<PlayerTempDataComponent>().MapData.x = self.GetComponent<PlayerTempDataComponent>().MapData.historyX;
- self.GetComponent<PlayerTempDataComponent>().MapData.y = self.GetComponent<PlayerTempDataComponent>().MapData.historyY;
- break;
- case (int)BORN_TYPE.BORN:
- self.GetComponent<PlayerTempDataComponent>().MapData.mapId = self.GetComponent<PlayerTempDataComponent>().MapData.bornMapId;
- self.GetComponent<PlayerTempDataComponent>().MapData.mapInstanceId =
- self.GetComponent<PlayerTempDataComponent>().MapData.bornMapInstanceId;
- self.GetComponent<PlayerTempDataComponent>().MapData.x = self.GetComponent<PlayerTempDataComponent>().MapData.bornX;
- self.GetComponent<PlayerTempDataComponent>().MapData.y = self.GetComponent<PlayerTempDataComponent>().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<GamePlayerComponent>().Add(self.GetId(), self);
- }
- /** 向客户端推送角色相关数据 **/
- public static void OnEndEnterScene(this WNPlayer self)
- {
- bool ready = self.GetComponent<PlayerTempDataComponent>().MapData.ready;
- if (ready)
- {
- Log.Warning($"$OnEndEnterScene跳过 : playerId={self.GetId()}, 玩家场景:{self.Map.MapId}, 进入场景:" + (self.Map?.MapId ?? -1));
- return;
- }
- self.GetComponent<PlayerTempDataComponent>().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 = 99999,
- HPPer = 1,
- HP = 88888,
- Attack = 10,
- AttackPer = 100,
- },
- effectsExt = new { },
- // skills = self.ToJson4BattleServerSkillInfos,
- skills = new List<SkillInfo>()
- {
- new SkillInfo
- {
- id = 90210,
- level = 1,
- type = 3,
- skillTime = 0,
- cdTime = 0,
- flag = 0
- },
- new SkillInfo
- {
- id = 90203,
- level = 1,
- type = 1,
- 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 = 0,
- y = 30,
- direction = 0f,
- hp = 100000,
- 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;
- }
- }
- }
|