123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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>
- {
-
-
-
-
-
-
- protected override void Awake(WNPlayer self, Session session, PlayerInfo playerInfo)
- {
- Log.Info($"创建玩家实体...");
- }
- }
- public class PlayerDestroySystem: DestroySystem<WNPlayer>
- {
-
-
-
-
- protected override void Destroy(WNPlayer self)
- {
- Log.Info($"销毁玩家实体...");
- }
- }
-
-
-
-
-
- public static long GetId(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Id;
- }
-
-
-
-
-
- public static int GetPlayerType(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.PlayerType;
- }
-
-
-
-
-
- public static long GetUserId(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.UserId;
- }
-
-
-
-
-
- public static string GetName(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Name;
- }
-
-
-
-
-
- public static int GetSex(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Sex;
- }
-
-
-
-
-
- public static int GetPro(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Pro;
- }
-
-
-
-
-
- public static long GetExp(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Exp;
- }
-
-
-
-
-
- public static int GetLevel(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Level;
- }
-
-
-
-
-
- public static long GetGold(this WNPlayer self)
- {
- return self.GetComponent<PlayerDataComponent>().Data.Gold;
- }
-
-
-
-
-
- public static long GetMapInstanceId(this WNPlayer self)
- {
- return self.Map.InstanceId;
- }
-
- 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;
- }
-
- 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());
-
- 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 = new List<SkillInfo>()
- {
-
- },
- 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 = 230,
- y = 100,
- direction = System.MathF.PI / 2,
- hp = 666,
- mp = 0,
- },
- pkInfo = new { mode = 0, value = 0, level = 1, },
-
- addTestPetData = 0,
- sceneData = new { allowAutoGuard = 3, },
- };
- string retjson = JsonSerializer.Serialize(json, new JsonSerializerOptions { IncludeFields = true });
- Log.Debug($"{self.GetName()}, enterSceneData:{retjson.ToString()}");
- return retjson;
- }
- }
- }
|