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,48 +166,50 @@ internal class CreatureController : Controller
await OnVisionSkillChanged(); 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, Entities = { _entitySystem.Pb }
OwnerId = _modelManager.Creature.OwnerId, },
CurContextId = _modelManager.Player.Id, PlayerInfos =
TimeInfo = new(), {
AoiData = new(), new ScenePlayerInformation
PlayerInfos =
{ {
new ScenePlayerInformation PlayerId = _modelManager.Player.Id,
Level = 1,
IsOffline = false,
Location = new()
{ {
PlayerId = _modelManager.Player.Id, X = 4000,
Level = 1, Y = -2000,
IsOffline = false, Z = 260
Location = new() },
{ PlayerName = _modelManager.Player.Name,
X = 4000, FightRoleInfos = { GetFightRoleInfos() }
Y = -2000,
Z = 260
},
PlayerName = _modelManager.Player.Name
}
} }
};
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); private IEnumerable<FightRoleInformation> GetFightRoleInfos()
return scene; {
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 = playerEntity.Id,
CurHp = playerEntity.Health,
MaxHp = playerEntity.HealthMax,
IsControl = playerEntity.Id == _modelManager.Creature.PlayerEntityId,
RoleId = playerEntity.ConfigId,
RoleLevel = 1,
});
} }
private void CreateTeamPlayerEntities() private void CreateTeamPlayerEntities()

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()