123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- using System;
- using System.Collections.Generic;
- using System.Text.Json;
- using BattleIce;
- using JsonSerializer = System.Text.Json.JsonSerializer;
- namespace ET.Server
- {
- [FriendOf(typeof (WNPlayer))]
- [FriendOf(typeof (BattleIceAgentComponent))]
- public static class PlayerSystem
- {
- public class PlayerAwakeSystem: AwakeSystem<WNPlayer, Session>
- {
- protected override void Awake(WNPlayer self, Session session)
- {
- Log.Info($"创建玩家实体...");
- PlayerInfo playerInfo = session.GetComponent<SessionPlayerComponent>().PlayerInfo;
- // 绑定sessionId
- self.GameSessionActorId = session.InstanceId;
- self.Session = session;
- self.BasicProp = CharacterConfigCategory.Instance.Get(playerInfo.Pro);
- self.BornType = (int)BORN_TYPE.NORMAL;
- self.EnterState = (int)ENTER_STATE.online;
- // 玩家基础数据组件
- self.AddComponent<PlayerDataComponent, PlayerInfo>(playerInfo);
- // 玩家临时数据组件
- self.AddComponent<PlayerTempDataComponent>();
- // 玩家技能组件
- self.AddComponent<PlayerSkillComponent>();
- // 玩家货币组件
- self.AddComponent<PlayerMoneyComponent>();
- // 玩家属性组件
- self.AddComponent<PlayerBtlComponent>();
- }
- }
- public class PlayerDestroySystem: DestroySystem<WNPlayer>
- {
- 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>
- /// 获取玩家类型
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- public static int GetPlayerType(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.PlayerType;
- }
- /// <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)
- {
- // 登录第一次进场景处理,此次登陆登出期间只处理一次
- if (self.ReadyFirst)
- {
- self.ReadyFirst = false;
- }
- }
- /** 角色登录成功,加载完所有数据后,将角色相关的信息主动推送到客户端 **/
- public static void OnLogin(this WNPlayer self)
- {
- try
- {
- // todo 角色登陆成功 各组件调用
- self.ReadyFirst = true;
- // todo 设置角色登录时间
- }
- catch (Exception e)
- {
- Log.Debug($"OnLogin 出错:{e}");
- }
- }
- /** 向客户端推送角色相关数据 **/
- public static void OnEndEnterScene(this WNPlayer self)
- {
- self.GetXmdsManager().playerReady(self.GetId().ToString());
- self.Map.Actors.TryGetValue(self.GetId(), out Struct.Actor actor);
- if (actor != null)
- {
- if (actor.Ready)
- {
- Log.Warning($"$OnEndEnterScene跳过 : playerId={self.GetId()}, 玩家场景:{self.Map.MapId}, 进入场景:" + (self.Map?.MapId ?? -1));
- return;
- }
- actor.Ready = true;
- }
- // todo 弹幕游戏的设置, 后面会调整
- //PKMode设置为All
- self.GetXmdsManager().refreshPlayerPKMode(self.GetId().ToString(), false, (int)PkModel.All);
- //设置为自动战斗
- self.GetXmdsManager().autoBattle(self.Id.ToString().Trim(), self.GetId().ToString(), true);
- Log.Info($"OnEndEnterScene : mapId={self.Map.MapId}, map={self.Map.Prop.Name}");
- }
- /// <summary>
- /// 战斗服角色数据
- /// </summary>
- /// <param name="self"></param>
- /// <returns></returns>
- private static Dictionary<string, object> GetBattlerServerBasic(this WNPlayer self)
- {
- Dictionary<string, object> data = new Dictionary<string, object>();
- data.Add("name", self.GetName());
- data.Add("alliesForce", 0);
- data.Add("force", 1);
- data.Add("pro", self.GetPro());
- data.Add("serverId", ConstGame.GameServerId);
- data.Add("titleId", 0);
- data.Add("level", self.GetLevel());
- data.Add("vip", 0);
- data.Add("upLevel", 1);
- // 无悬赏
- data.Add("beReward", 0);
- data.Add("logicServerId", ConstGame.GameServerId);
- data.Add("sex", self.GetSex());
- data.Add("uuid", self.GetId().ToString());
- data.Add("potionAddition", 0);
- return data;
- }
- /// <summary>
- /// 场景中角色需求数据
- /// </summary>
- /// <param name="self"></param>
- /// <param name="map"></param>
- /// <returns></returns>
- public static string ToJSON4EnterScene(this WNPlayer self, Map map)
- {
- var json = new
- {
- effects = self.GetComponent<PlayerBtlComponent>().GetBattleServerEffects(),
- effectsExt = new { },
- skills = self.GetComponent<PlayerSkillComponent>().ToJson4BattleServerSkills,
- tasks = new { },
- flags = new { },
- playerEntered = map.HasPlayerEntered,
- avatars = new { },
- basic = self.GetBattlerServerBasic(),
- connectServerId = "bs-" + ConstGame.GameServerId,
- uid = self.GetId().ToString(),
- unitTemplateID = self.BasicProp.TemplateId,
- robot = false,
- tempData = self.GetComponent<PlayerTempDataComponent>().ToJson4BattleServerTempData,
- pkInfo = new { mode = 0, value = 0, level = 1, },
- //petBase,
- addTestPetData = 0,
- sceneData = new { allowAutoGuard = 3, },
- };
- return JsonSerializer.Serialize(json, new JsonSerializerOptions { IncludeFields = true });
- }
- }
- }
|