Updates the Content EntitySystems with the changes to the event API.

Visual Studio wants to update the version of the solution, and change some GUIDs around.
This commit is contained in:
Acruid
2020-02-18 19:43:54 -08:00
parent ffd06df700
commit c51533686b
10 changed files with 199 additions and 277 deletions

View File

@@ -1,9 +1,7 @@
using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
@@ -37,17 +35,12 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Initialize();
SubscribeEvent<ExamineSystemMessages.RequestExamineInfoMessage>((sender, ev) => ExamineInfoRequest(ev));
IoCManager.InjectDependencies(this);
}
public override void RegisterMessageTypes()
{
base.RegisterMessageTypes();
RegisterMessageType<ExamineSystemMessages.RequestExamineInfoMessage>();
}
private FormattedMessage GetExamineText(IEntity entity)
private static FormattedMessage GetExamineText(IEntity entity)
{
var message = new FormattedMessage();
@@ -82,11 +75,10 @@ namespace Content.Server.GameObjects.EntitySystems
return message;
}
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
private void ExamineInfoRequest(ExamineSystemMessages.RequestExamineInfoMessage request)
{
base.HandleNetMessage(channel, message);
if (!(message is ExamineSystemMessages.RequestExamineInfoMessage request))
var channel = request.NetChannel;
if(channel == null)
return;
var session = _playerManager.GetSessionByChannel(channel);

View File

@@ -1,4 +1,4 @@
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Mobs;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Server.GameObjects.EntitySystems;
@@ -6,7 +6,6 @@ using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Input;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Players;
using static Content.Shared.GameObjects.EntitySystemMessages.CombatModeSystemMessages;
@@ -24,17 +23,45 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Initialize();
SubscribeEvent<SetTargetZoneMessage>(SetTargetZoneHandler);
SubscribeEvent<SetCombatModeActiveMessage>(SetCombatModeActiveHandler);
var inputSystem = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSystem.BindMap.BindFunction(ContentKeyFunctions.ToggleCombatMode,
InputCmdHandler.FromDelegate(CombatModeToggled));
}
public override void RegisterMessageTypes()
private void SetCombatModeActiveHandler(object sender, SetCombatModeActiveMessage ev)
{
base.RegisterMessageTypes();
if (!TryGetCombatComponent(ev, out var combatModeComponent))
return;
combatModeComponent.IsInCombatMode = ev.Active;
}
private void SetTargetZoneHandler(object sender, SetTargetZoneMessage ev)
{
if (!TryGetCombatComponent(ev, out var combatModeComponent))
return;
combatModeComponent.ActiveZone = ev.TargetZone;
}
private bool TryGetCombatComponent(EntitySystemMessage ev, out CombatModeComponent combatModeComponent)
{
if (ev.NetChannel == null)
{
combatModeComponent = default;
return false;
}
var player = _playerManager.GetSessionByChannel(ev.NetChannel);
if (player.AttachedEntity != null && player.AttachedEntity.TryGetComponent(out combatModeComponent))
return true;
combatModeComponent = default;
return false;
RegisterMessageType<SetTargetZoneMessage>();
RegisterMessageType<SetCombatModeActiveMessage>();
}
private static void CombatModeToggled(ICommonSession session)
@@ -49,28 +76,5 @@ namespace Content.Server.GameObjects.EntitySystems
combatModeComponent.IsInCombatMode = !combatModeComponent.IsInCombatMode;
}
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
{
base.HandleNetMessage(channel, message);
var player = _playerManager.GetSessionByChannel(channel);
if (player.AttachedEntity == null
|| !player.AttachedEntity.TryGetComponent(out CombatModeComponent combatModeComponent))
{
return;
}
switch (message)
{
case SetTargetZoneMessage setTargetZone:
combatModeComponent.ActiveZone = setTargetZone.TargetZone;
break;
case SetCombatModeActiveMessage setActive:
combatModeComponent.IsInCombatMode = setActive.Active;
break;
}
}
}
}

View File

@@ -41,6 +41,9 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Initialize();
SubscribeEvent<EntRemovedFromContainerMessage>(HandleContainerModified);
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleContainerModified);
var input = EntitySystemManager.GetEntitySystem<InputSystem>();
input.BindMap.BindFunction(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands));
input.BindMap.BindFunction(ContentKeyFunctions.Drop, new PointerInputCmdHandler(HandleDrop));
@@ -62,13 +65,6 @@ namespace Content.Server.GameObjects.EntitySystems
base.Shutdown();
}
/// <inheritdoc />
public override void SubscribeEvents()
{
SubscribeEvent<EntRemovedFromContainerMessage>(HandleContainerModified);
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleContainerModified);
}
private static void HandleContainerModified(object sender, ContainerModifiedMessage args)
{
if (args.Container.Owner.TryGetComponent(out IHandsComponent handsComponent))

View File

@@ -14,16 +14,10 @@ namespace Content.Server.GameObjects.EntitySystems
/// <inheritdoc />
public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(ServerStorageComponent));
}
/// <inheritdoc />
public override void SubscribeEvents()
{
base.SubscribeEvents();
SubscribeEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
EntityQuery = new TypeEntityQuery(typeof(ServerStorageComponent));
}
/// <inheritdoc />

View File

@@ -2,10 +2,8 @@
using System.Reflection;
using Content.Shared.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using static Content.Shared.GameObjects.EntitySystemMessages.VerbSystemMessages;
@@ -22,120 +20,112 @@ namespace Content.Server.GameObjects.EntitySystems
{
base.Initialize();
SubscribeEvent<RequestVerbsMessage>((sender, ev) => RequestVerbs(ev));
SubscribeEvent<UseVerbMessage>((sender, ev) => UseVerb(ev));
IoCManager.InjectDependencies(this);
}
public override void RegisterMessageTypes()
private void UseVerb(UseVerbMessage use)
{
base.RegisterMessageTypes();
var channel = use.NetChannel;
if(channel == null)
return;
RegisterMessageType<RequestVerbsMessage>();
RegisterMessageType<UseVerbMessage>();
if (!_entityManager.TryGetEntity(use.EntityUid, out var entity))
{
return;
}
var session = _playerManager.GetSessionByChannel(channel);
var userEntity = session.AttachedEntity;
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
{
if ($"{component.GetType()}:{verb.GetType()}" != use.VerbKey)
{
continue;
}
if (verb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
{
break;
}
}
verb.Activate(userEntity, component);
break;
}
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
{
if (globalVerb.GetType().ToString() != use.VerbKey)
{
continue;
}
if (globalVerb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
{
break;
}
}
globalVerb.Activate(userEntity, entity);
break;
}
}
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
private void RequestVerbs(RequestVerbsMessage req)
{
base.HandleNetMessage(channel, message);
var channel = req.NetChannel;
if (channel == null)
return;
switch (message)
if (!_entityManager.TryGetEntity(req.EntityUid, out var entity))
{
case RequestVerbsMessage req:
{
if (!_entityManager.TryGetEntity(req.EntityUid, out var entity))
{
return;
}
var session = _playerManager.GetSessionByChannel(channel);
var userEntity = session.AttachedEntity;
var data = new List<VerbsResponseMessage.VerbData>();
//Get verbs, component dependent.
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
{
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if(VerbUtility.IsVerbInvisible(verb, userEntity, component, out var vis))
continue;
// TODO: These keys being giant strings is inefficient as hell.
data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component),
$"{component.GetType()}:{verb.GetType()}",
vis == VerbVisibility.Visible));
}
//Get global verbs. Visible for all entities regardless of their components.
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
{
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if(VerbUtility.IsVerbInvisible(globalVerb, userEntity, entity, out var vis))
continue;
data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity),
globalVerb.GetType().ToString(), vis == VerbVisibility.Visible));
}
var response = new VerbsResponseMessage(data, req.EntityUid);
RaiseNetworkEvent(response, channel);
break;
}
case UseVerbMessage use:
{
if (!_entityManager.TryGetEntity(use.EntityUid, out var entity))
{
return;
}
var session = _playerManager.GetSessionByChannel(channel);
var userEntity = session.AttachedEntity;
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
{
if ($"{component.GetType()}:{verb.GetType()}" != use.VerbKey)
{
continue;
}
if (verb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
{
break;
}
}
verb.Activate(userEntity, component);
break;
}
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
{
if (globalVerb.GetType().ToString() != use.VerbKey)
{
continue;
}
if (globalVerb.RequireInteractionRange)
{
var distanceSquared = (userEntity.Transform.WorldPosition - entity.Transform.WorldPosition)
.LengthSquared;
if (distanceSquared > VerbUtility.InteractionRangeSquared)
{
break;
}
}
globalVerb.Activate(userEntity, entity);
break;
}
break;
}
return;
}
var session = _playerManager.GetSessionByChannel(channel);
var userEntity = session.AttachedEntity;
var data = new List<VerbsResponseMessage.VerbData>();
//Get verbs, component dependent.
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
{
if (verb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if (VerbUtility.IsVerbInvisible(verb, userEntity, component, out var vis))
continue;
// TODO: These keys being giant strings is inefficient as hell.
data.Add(new VerbsResponseMessage.VerbData(verb.GetText(userEntity, component),
$"{component.GetType()}:{verb.GetType()}",
vis == VerbVisibility.Visible));
}
//Get global verbs. Visible for all entities regardless of their components.
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
{
if (globalVerb.RequireInteractionRange && !VerbUtility.InVerbUseRange(userEntity, entity))
continue;
if (VerbUtility.IsVerbInvisible(globalVerb, userEntity, entity, out var vis))
continue;
data.Add(new VerbsResponseMessage.VerbData(globalVerb.GetText(userEntity, entity),
globalVerb.GetType().ToString(), vis == VerbVisibility.Visible));
}
var response = new VerbsResponseMessage(data, req.EntityUid);
RaiseNetworkEvent(response, channel);
}
}
}