ECS characterinfo (#5669)

This commit is contained in:
ShadowCommander
2021-12-11 15:12:55 -08:00
committed by GitHub
parent 237a90cd48
commit 703c23d8a5
9 changed files with 272 additions and 306 deletions

View File

@@ -1,63 +0,0 @@
using System;
using System.Collections.Generic;
using Content.Server.Mind.Components;
using Content.Server.Roles;
using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Network;
using Robust.Shared.Players;
namespace Content.Server.CharacterInfo
{
[RegisterComponent]
public class CharacterInfoComponent : SharedCharacterInfoComponent
{
[Obsolete("Component Messages are deprecated, use Entity Events instead.")]
public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession? session = null)
{
if(session?.AttachedEntity != Owner) return;
switch (message)
{
case RequestCharacterInfoMessage _:
var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession";
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out MindComponent? mindComponent))
{
var mind = mindComponent.Mind;
if (mind != null)
{
// getting conditions
foreach (var objective in mind.AllObjectives)
{
if (!conditions.ContainsKey(objective.Prototype.Issuer))
conditions[objective.Prototype.Issuer] = new List<ConditionInfo>();
foreach (var condition in objective.Conditions)
{
conditions[objective.Prototype.Issuer].Add(new ConditionInfo(condition.Title,
condition.Description, condition.Icon, condition.Progress));
}
}
// getting jobtitle
foreach (var role in mind.AllRoles)
{
if (role.GetType() == typeof(Job))
{
jobTitle = role.Name;
break;
}
}
}
}
#pragma warning disable 618
SendNetworkMessage(new CharacterInfoMessage(jobTitle, conditions));
#pragma warning restore 618
break;
}
}
}
}

View File

@@ -0,0 +1,59 @@
using System.Collections.Generic;
using Content.Server.Mind.Components;
using Content.Server.Roles;
using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.CharacterInfo;
public class CharacterInfoSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RequestCharacterInfoEvent>(OnRequestCharacterInfoEvent);
}
private void OnRequestCharacterInfoEvent(RequestCharacterInfoEvent msg, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue
|| args.SenderSession.AttachedEntity != msg.EntityUid)
return;
var entity = args.SenderSession.AttachedEntity.Value;
var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession";
if (EntityManager.TryGetComponent(entity, out MindComponent? mindComponent) && mindComponent.Mind != null)
{
var mind = mindComponent.Mind;
// Get objectives
foreach (var objective in mind.AllObjectives)
{
if (!conditions.ContainsKey(objective.Prototype.Issuer))
conditions[objective.Prototype.Issuer] = new List<ConditionInfo>();
foreach (var condition in objective.Conditions)
{
conditions[objective.Prototype.Issuer].Add(new ConditionInfo(condition.Title,
condition.Description, condition.Icon, condition.Progress));
}
}
// Get job title
foreach (var role in mind.AllRoles)
{
if (role.GetType() != typeof(Job)) continue;
jobTitle = role.Name;
break;
}
}
RaiseNetworkEvent(new CharacterInfoEvent(entity, jobTitle, conditions),
Filter.SinglePlayer(args.SenderSession));
}
}