Remove hardcode for FightRoleInfo

This commit is contained in:
xeon 2024-02-12 04:03:50 +03:00
parent 5b927b99a8
commit 838faa5938
2 changed files with 55 additions and 53 deletions

View file

@ -1,5 +1,4 @@
using System.Security.Principal; using Core.Config;
using Core.Config;
using GameServer.Controllers.Attributes; using GameServer.Controllers.Attributes;
using GameServer.Models; using GameServer.Models;
using GameServer.Network; using GameServer.Network;
@ -81,7 +80,7 @@ internal class CreatureController : Controller
IEnumerable<PlayerEntity> oldEntities = _entitySystem.EnumerateEntities() IEnumerable<PlayerEntity> oldEntities = _entitySystem.EnumerateEntities()
.Where(e => e is PlayerEntity entity && entity.PlayerId == _modelManager.Player.Id) .Where(e => e is PlayerEntity entity && entity.PlayerId == _modelManager.Player.Id)
.Cast<PlayerEntity>().ToArray(); .Cast<PlayerEntity>();
foreach (PlayerEntity oldEntity in oldEntities) foreach (PlayerEntity oldEntity in oldEntities)
{ {
@ -122,18 +121,7 @@ internal class CreatureController : Controller
await Session.Push(MessageId.UpdatePlayerAllFightRoleNotify, new UpdatePlayerAllFightRoleNotify await Session.Push(MessageId.UpdatePlayerAllFightRoleNotify, new UpdatePlayerAllFightRoleNotify
{ {
PlayerId = _modelManager.Player.Id, PlayerId = _modelManager.Player.Id,
FightRoleInfos = FightRoleInfos = { GetFightRoleInfos() }
{
newEntities.Select(entity => new FightRoleInformation
{
EntityId = entity.Id,
CurHp = 1000,
MaxHp = 1000,
IsControl = _modelManager.Creature.PlayerEntityId == entity.Id,
RoleId = entity.ConfigId,
RoleLevel = 1,
})
}
}); });
} }
@ -178,15 +166,16 @@ internal class CreatureController : Controller
await OnVisionSkillChanged(); await OnVisionSkillChanged();
} }
private SceneInformation CreateSceneInfo() private SceneInformation CreateSceneInfo() => new()
{
SceneInformation scene = new()
{ {
InstanceId = _modelManager.Creature.InstanceId, InstanceId = _modelManager.Creature.InstanceId,
OwnerId = _modelManager.Creature.OwnerId, OwnerId = _modelManager.Creature.OwnerId,
CurContextId = _modelManager.Player.Id, CurContextId = _modelManager.Player.Id,
TimeInfo = new(), TimeInfo = new(),
AoiData = new(), AoiData = new PlayerSceneAoiData
{
Entities = { _entitySystem.Pb }
},
PlayerInfos = PlayerInfos =
{ {
new ScenePlayerInformation new ScenePlayerInformation
@ -200,28 +189,29 @@ internal class CreatureController : Controller
Y = -2000, Y = -2000,
Z = 260 Z = 260
}, },
PlayerName = _modelManager.Player.Name PlayerName = _modelManager.Player.Name,
FightRoleInfos = { GetFightRoleInfos() }
} }
} }
}; };
for (int i = 0; i < _modelManager.Player.Characters.Length; i++) private IEnumerable<FightRoleInformation> GetFightRoleInfos()
{ {
scene.PlayerInfos[0].FightRoleInfos.Add(new FightRoleInformation IEnumerable<PlayerEntity> playerEntities = _entitySystem.EnumerateEntities()
.Where(e => e is PlayerEntity entity && entity.PlayerId == _modelManager.Player.Id)
.Cast<PlayerEntity>();
return playerEntities.Select(playerEntity => new FightRoleInformation
{ {
EntityId = i + 1, EntityId = playerEntity.Id,
CurHp = 1000, CurHp = playerEntity.Health,
MaxHp = 1000, MaxHp = playerEntity.HealthMax,
IsControl = i == 0, IsControl = playerEntity.Id == _modelManager.Creature.PlayerEntityId,
RoleId = _modelManager.Player.Characters[i], RoleId = playerEntity.ConfigId,
RoleLevel = 1, RoleLevel = 1,
}); });
} }
scene.AoiData.Entities.AddRange(_entitySystem.Pb);
return scene;
}
private void CreateTeamPlayerEntities() private void CreateTeamPlayerEntities()
{ {
for (int i = 0; i < _modelManager.Formation.RoleIds.Length; i++) for (int i = 0; i < _modelManager.Formation.RoleIds.Length; i++)

View file

@ -21,6 +21,18 @@ internal class PlayerEntity : EntityBase
set => ComponentSystem.Get<EntityEquipComponent>().WeaponId = value; set => ComponentSystem.Get<EntityEquipComponent>().WeaponId = value;
} }
public int Health
{
get => ComponentSystem.Get<EntityAttributeComponent>().GetAttribute(EAttributeType.Life);
set => ComponentSystem.Get<EntityAttributeComponent>().SetAttribute(EAttributeType.Life, value);
}
public int HealthMax
{
get => ComponentSystem.Get<EntityAttributeComponent>().GetAttribute(EAttributeType.LifeMax);
set => ComponentSystem.Get<EntityAttributeComponent>().SetAttribute(EAttributeType.LifeMax, value);
}
public override void OnCreate() public override void OnCreate()
{ {
base.OnCreate(); base.OnCreate();
@ -33,14 +45,14 @@ internal class PlayerEntity : EntityBase
visionSkillComponent.SetExploreTool(1001); visionSkillComponent.SetExploreTool(1001);
_ = ComponentSystem.Create<EntityEquipComponent>(); _ = ComponentSystem.Create<EntityEquipComponent>();
_ = ComponentSystem.Create<EntityAttributeComponent>();
InitAttributes();
} }
public override void Activate() public override void Activate()
{ {
base.Activate(); base.Activate();
_ = ComponentSystem.Create<EntityAttributeComponent>();
InitAttributes();
} }
private void InitAttributes() private void InitAttributes()