From 838faa593859441a7a7a99d82924f4c8d1722605 Mon Sep 17 00:00:00 2001 From: xeon Date: Mon, 12 Feb 2024 04:03:50 +0300 Subject: [PATCH] Remove hardcode for FightRoleInfo --- GameServer/Controllers/CreatureController.cs | 90 +++++++++----------- GameServer/Systems/Entity/PlayerEntity.cs | 18 +++- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/GameServer/Controllers/CreatureController.cs b/GameServer/Controllers/CreatureController.cs index 41640c9..9135f6e 100644 --- a/GameServer/Controllers/CreatureController.cs +++ b/GameServer/Controllers/CreatureController.cs @@ -1,5 +1,4 @@ -using System.Security.Principal; -using Core.Config; +using Core.Config; using GameServer.Controllers.Attributes; using GameServer.Models; using GameServer.Network; @@ -81,7 +80,7 @@ internal class CreatureController : Controller IEnumerable oldEntities = _entitySystem.EnumerateEntities() .Where(e => e is PlayerEntity entity && entity.PlayerId == _modelManager.Player.Id) - .Cast().ToArray(); + .Cast(); foreach (PlayerEntity oldEntity in oldEntities) { @@ -122,18 +121,7 @@ internal class CreatureController : Controller await Session.Push(MessageId.UpdatePlayerAllFightRoleNotify, new UpdatePlayerAllFightRoleNotify { PlayerId = _modelManager.Player.Id, - FightRoleInfos = - { - newEntities.Select(entity => new FightRoleInformation - { - EntityId = entity.Id, - CurHp = 1000, - MaxHp = 1000, - IsControl = _modelManager.Creature.PlayerEntityId == entity.Id, - RoleId = entity.ConfigId, - RoleLevel = 1, - }) - } + FightRoleInfos = { GetFightRoleInfos() } }); } @@ -178,48 +166,50 @@ internal class CreatureController : Controller await OnVisionSkillChanged(); } - private SceneInformation CreateSceneInfo() + private SceneInformation CreateSceneInfo() => new() { - SceneInformation scene = new() + InstanceId = _modelManager.Creature.InstanceId, + OwnerId = _modelManager.Creature.OwnerId, + CurContextId = _modelManager.Player.Id, + TimeInfo = new(), + AoiData = new PlayerSceneAoiData { - InstanceId = _modelManager.Creature.InstanceId, - OwnerId = _modelManager.Creature.OwnerId, - CurContextId = _modelManager.Player.Id, - TimeInfo = new(), - AoiData = new(), - PlayerInfos = + Entities = { _entitySystem.Pb } + }, + PlayerInfos = + { + new ScenePlayerInformation { - new ScenePlayerInformation + PlayerId = _modelManager.Player.Id, + Level = 1, + IsOffline = false, + Location = new() { - PlayerId = _modelManager.Player.Id, - Level = 1, - IsOffline = false, - Location = new() - { - X = 4000, - Y = -2000, - Z = 260 - }, - PlayerName = _modelManager.Player.Name - } + X = 4000, + Y = -2000, + Z = 260 + }, + PlayerName = _modelManager.Player.Name, + FightRoleInfos = { GetFightRoleInfos() } } - }; - - for (int i = 0; i < _modelManager.Player.Characters.Length; i++) - { - scene.PlayerInfos[0].FightRoleInfos.Add(new FightRoleInformation - { - EntityId = i + 1, - CurHp = 1000, - MaxHp = 1000, - IsControl = i == 0, - RoleId = _modelManager.Player.Characters[i], - RoleLevel = 1, - }); } + }; - scene.AoiData.Entities.AddRange(_entitySystem.Pb); - return scene; + private IEnumerable GetFightRoleInfos() + { + IEnumerable playerEntities = _entitySystem.EnumerateEntities() + .Where(e => e is PlayerEntity entity && entity.PlayerId == _modelManager.Player.Id) + .Cast(); + + return playerEntities.Select(playerEntity => new FightRoleInformation + { + EntityId = playerEntity.Id, + CurHp = playerEntity.Health, + MaxHp = playerEntity.HealthMax, + IsControl = playerEntity.Id == _modelManager.Creature.PlayerEntityId, + RoleId = playerEntity.ConfigId, + RoleLevel = 1, + }); } private void CreateTeamPlayerEntities() diff --git a/GameServer/Systems/Entity/PlayerEntity.cs b/GameServer/Systems/Entity/PlayerEntity.cs index 35b4b65..38cf427 100644 --- a/GameServer/Systems/Entity/PlayerEntity.cs +++ b/GameServer/Systems/Entity/PlayerEntity.cs @@ -21,6 +21,18 @@ internal class PlayerEntity : EntityBase set => ComponentSystem.Get().WeaponId = value; } + public int Health + { + get => ComponentSystem.Get().GetAttribute(EAttributeType.Life); + set => ComponentSystem.Get().SetAttribute(EAttributeType.Life, value); + } + + public int HealthMax + { + get => ComponentSystem.Get().GetAttribute(EAttributeType.LifeMax); + set => ComponentSystem.Get().SetAttribute(EAttributeType.LifeMax, value); + } + public override void OnCreate() { base.OnCreate(); @@ -33,14 +45,14 @@ internal class PlayerEntity : EntityBase visionSkillComponent.SetExploreTool(1001); _ = ComponentSystem.Create(); + _ = ComponentSystem.Create(); + + InitAttributes(); } public override void Activate() { base.Activate(); - - _ = ComponentSystem.Create(); - InitAttributes(); } private void InitAttributes()