Merge remote-tracking branch 'upstream/master' into upstream-sync

# Conflicts:
#	Content.Client/Links/UILinks.cs
#	README.md
#	Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml
#	Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml
#	Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml
#	Resources/Prototypes/Roles/Jobs/Science/research_director.yml
#	Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml
This commit is contained in:
Morbo
2022-09-30 17:57:03 +03:00
368 changed files with 388518 additions and 378849 deletions

View File

@@ -155,7 +155,7 @@ namespace Content.Client.Administration.Systems
if (function == EngineKeyFunctions.UIClick)
_clientConsoleHost.ExecuteCommand($"vv {uid}");
else if (function == ContentKeyFunctions.OpenContextMenu)
else if (function == EngineKeyFunctions.UseSecondary)
_verbSystem.VerbMenu.OpenVerbMenu(uid, true);
else
return;
@@ -173,7 +173,7 @@ namespace Content.Client.Administration.Systems
if (function == EngineKeyFunctions.UIClick)
_clientConsoleHost.ExecuteCommand($"vv {uid}");
else if (function == ContentKeyFunctions.OpenContextMenu)
else if (function == EngineKeyFunctions.UseSecondary)
_verbSystem.VerbMenu.OpenVerbMenu(uid, true);
else
return;

View File

@@ -15,7 +15,7 @@ namespace Content.Client.Administration.UI
public AdminMenuWindow()
{
MinSize = SetSize = (500, 250);
MinSize = (500, 250);
Title = Loc.GetString("admin-menu-title");
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

View File

@@ -54,7 +54,7 @@ namespace Content.Client.Administration.UI.CustomControls
if (OverrideText != null && args.Button.Children.FirstOrDefault()?.Children?.FirstOrDefault() is Label label)
label.Text = GetText(selectedPlayer);
}
else if (args.Event.Function == ContentKeyFunctions.OpenContextMenu)
else if (args.Event.Function == EngineKeyFunctions.UseSecondary)
{
_verbSystem.VerbMenu.OpenVerbMenu(selectedPlayer.EntityUid);
}

View File

@@ -0,0 +1,53 @@
using Content.Shared.BarSign;
using Content.Shared.Power;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Client.BarSign;
public sealed class BarSignSystem : VisualizerSystem<BarSignComponent>
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BarSignComponent, ComponentHandleState>(OnHandleState);
}
private void OnHandleState(EntityUid uid, BarSignComponent component, ref ComponentHandleState args)
{
if (args.Current is not BarSignComponentState state)
return;
component.CurrentSign = state.CurrentSign;
UpdateAppearance(component);
}
protected override void OnAppearanceChange(EntityUid uid, BarSignComponent component, ref AppearanceChangeEvent args)
{
UpdateAppearance(component, args.Component, args.Sprite);
}
private void UpdateAppearance(BarSignComponent sign, AppearanceComponent? appearance = null, SpriteComponent? sprite = null)
{
if (!Resolve(sign.Owner, ref appearance, ref sprite))
return;
appearance.TryGetData(PowerDeviceVisuals.Powered, out bool powered);
if (powered
&& sign.CurrentSign != null
&& _prototypeManager.TryIndex(sign.CurrentSign, out BarSignPrototype? proto))
{
sprite.LayerSetState(0, proto.Icon);
sprite.LayerSetShader(0, "unshaded");
}
else
{
sprite.LayerSetState(0, "empty");
sprite.LayerSetShader(0, null, null);
}
}
}

View File

@@ -4,8 +4,8 @@ using Content.Shared.Targeting;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.GameStates;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
namespace Content.Client.CombatMode
{
@@ -23,6 +23,16 @@ namespace Content.Client.CombatMode
SubscribeLocalEvent<CombatModeComponent, PlayerAttachedEvent>((_, component, _) => component.PlayerAttached());
SubscribeLocalEvent<CombatModeComponent, PlayerDetachedEvent>((_, component, _) => component.PlayerDetached());
SubscribeLocalEvent<SharedCombatModeComponent, ComponentHandleState>(OnHandleState);
}
private void OnHandleState(EntityUid uid, SharedCombatModeComponent component, ref ComponentHandleState args)
{
if (args.Current is not CombatModeComponentState state)
return;
component.IsInCombatMode = state.IsInCombatMode;
component.ActiveZone = state.TargetingZone;
}
public override void Shutdown()
@@ -33,8 +43,12 @@ namespace Content.Client.CombatMode
public bool IsInCombatMode()
{
return EntityManager.TryGetComponent(_playerManager.LocalPlayer?.ControlledEntity, out CombatModeComponent? combatMode) &&
combatMode.IsInCombatMode;
var entity = _playerManager.LocalPlayer?.ControlledEntity;
if (entity == null)
return false;
return IsInCombatMode(entity.Value);
}
private void OnTargetingZoneChanged(TargetingZone obj)
@@ -42,8 +56,4 @@ namespace Content.Client.CombatMode
EntityManager.RaisePredictiveEvent(new CombatModeSystemMessages.SetTargetZoneMessage(obj));
}
}
public static class A
{
}
}

View File

@@ -1,61 +0,0 @@
using Content.Client.NPC;
using JetBrains.Annotations;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
namespace Content.Client.Commands
{
/// <summary>
/// This is used to handle the tooltips above AI mobs
/// </summary>
[UsedImplicitly]
internal sealed class DebugAiCommand : IConsoleCommand
{
// ReSharper disable once StringLiteralTypo
public string Command => "debugai";
public string Description => "Handles all tooltip debugging above AI mobs";
public string Help => "debugai [hide/paths/thonk]";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
#if DEBUG
if (args.Length < 1)
{
shell.RemoteExecuteCommand(argStr);
return;
}
var anyAction = false;
var debugSystem = EntitySystem.Get<ClientAiDebugSystem>();
foreach (var arg in args)
{
switch (arg)
{
case "hide":
debugSystem.Disable();
anyAction = true;
break;
// This will show the pathfinding numbers above the mob's head
case "paths":
debugSystem.ToggleTooltip(AiDebugMode.Paths);
anyAction = true;
break;
// Shows stats on what the AI was thinking.
case "thonk":
debugSystem.ToggleTooltip(AiDebugMode.Thonk);
anyAction = true;
break;
default:
continue;
}
}
if(!anyAction)
shell.RemoteExecuteCommand(argStr);
#else
shell.RemoteExecuteCommand(argStr);
#endif
}
}
}

View File

@@ -1,74 +1,61 @@
using System.Linq;
using Content.Client.NPC;
using Content.Shared.NPC;
using JetBrains.Annotations;
using Robust.Shared.Console;
using Robust.Shared.GameObjects;
namespace Content.Client.Commands
{
[UsedImplicitly]
internal sealed class DebugPathfindingCommand : IConsoleCommand
public sealed class DebugPathfindingCommand : IConsoleCommand
{
// ReSharper disable once StringLiteralTypo
public string Command => "pathfinder";
public string Description => "Toggles visibility of pathfinding debuggers.";
public string Help => "pathfinder [hide/nodes/routes/graph/regioncache/regions]";
public string Help => "pathfinder [options]";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
#if DEBUG
if (args.Length < 1)
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<PathfindingSystem>();
if (args.Length == 0)
{
shell.RemoteExecuteCommand(argStr);
system.Modes = PathfindingDebugMode.None;
return;
}
var anyAction = false;
var debugSystem = EntitySystem.Get<ClientPathfindingDebugSystem>();
foreach (var arg in args)
{
switch (arg)
if (!Enum.TryParse<PathfindingDebugMode>(arg, out var mode))
{
case "hide":
debugSystem.Disable();
anyAction = true;
break;
// Shows all nodes on the closed list
case "nodes":
debugSystem.ToggleTooltip(PathfindingDebugMode.Nodes);
anyAction = true;
break;
// Will show just the constructed route
case "routes":
debugSystem.ToggleTooltip(PathfindingDebugMode.Route);
anyAction = true;
break;
// Shows all of the pathfinding chunks
case "graph":
debugSystem.ToggleTooltip(PathfindingDebugMode.Graph);
anyAction = true;
break;
// Shows every time the cached reachable regions are hit (whether cached already or not)
case "regioncache":
debugSystem.ToggleTooltip(PathfindingDebugMode.CachedRegions);
anyAction = true;
break;
// Shows all of the regions in each chunk
case "regions":
debugSystem.ToggleTooltip(PathfindingDebugMode.Regions);
anyAction = true;
break;
default:
continue;
shell.WriteError($"Unrecognised pathfinder args {arg}");
continue;
}
system.Modes ^= mode;
shell.WriteLine($"Toggled {arg} to {(system.Modes & mode) != 0x0}");
}
}
public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length > 1)
{
return CompletionResult.Empty;
}
if(!anyAction)
shell.RemoteExecuteCommand(argStr);
#else
shell.RemoteExecuteCommand(argStr);
#endif
var values = Enum.GetValues<PathfindingDebugMode>().ToList();
var options = new List<CompletionOption>();
foreach (var val in values)
{
if (val == PathfindingDebugMode.None)
continue;
options.Add(new CompletionOption(val.ToString()));
}
return CompletionResult.FromOptions(options);
}
}
}

View File

@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using Content.Client.CombatMode;
using Content.Client.Examine;
using Content.Client.Gameplay;
using Content.Client.Verbs;
using Content.Client.Viewport;
using Content.Shared.CCVar;
using Content.Shared.CombatMode;
using Content.Shared.Input;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
@@ -45,6 +47,7 @@ namespace Content.Client.ContextMenu.UI
private readonly VerbSystem _verbSystem;
private readonly ExamineSystem _examineSystem;
private readonly SharedCombatModeSystem _combatMode;
/// <summary>
/// This maps the currently displayed entities to the actual GUI elements.
@@ -59,12 +62,13 @@ namespace Content.Client.ContextMenu.UI
IoCManager.InjectDependencies(this);
_verbSystem = verbSystem;
_examineSystem = EntitySystem.Get<ExamineSystem>();
_examineSystem = _entityManager.EntitySysManager.GetEntitySystem<ExamineSystem>();
_combatMode = _entityManager.EntitySysManager.GetEntitySystem<CombatModeSystem>();
_cfg.OnValueChanged(CCVars.EntityMenuGroupingType, OnGroupingChanged, true);
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenContextMenu, new PointerInputCmdHandler(HandleOpenEntityMenu, outsidePrediction: true))
.Bind(EngineKeyFunctions.UseSecondary, new PointerInputCmdHandler(HandleOpenEntityMenu, outsidePrediction: true))
.Register<EntityMenuPresenter>();
}
@@ -109,7 +113,7 @@ namespace Content.Client.ContextMenu.UI
return;
// open verb menu?
if (args.Function == ContentKeyFunctions.OpenContextMenu)
if (args.Function == EngineKeyFunctions.UseSecondary)
{
_verbSystem.VerbMenu.OpenVerbMenu(entity.Value);
args.Handle();
@@ -160,6 +164,9 @@ namespace Content.Client.ContextMenu.UI
if (_stateManager.CurrentState is not GameplayStateBase)
return false;
if (_combatMode.IsInCombatMode(args.Session?.AttachedEntity))
return false;
var coords = args.Coordinates.ToMap(_entityManager);
if (_verbSystem.TryGetEntityMenuEntities(coords, out var entities))

View File

@@ -50,10 +50,6 @@ public sealed class DoAfterOverlay : Overlay
}
var worldPosition = _transform.GetWorldPosition(xform);
if (!args.WorldAABB.Contains(worldPosition))
continue;
var index = 0;
var worldMatrix = Matrix3.CreateTranslation(worldPosition);

View File

@@ -1,8 +1,7 @@
namespace Content.Client.Effects;
/// <summary>
/// Deletes the attached entity whenever any animation completes. Used for temporary client-side entities.
/// </summary>
[RegisterComponent]
public sealed class EffectVisualsComponent : Component
{
public float Length;
public float Accumulator = 0f;
}
public sealed class EffectVisualsComponent : Component {}

View File

@@ -57,6 +57,7 @@ public sealed class HumanoidSystem : SharedHumanoidSystem
profile.Species,
customBaseLayers,
profile.Appearance.SkinColor,
profile.Sex,
new(), // doesn't exist yet
markings.GetForwardEnumerator().ToList());
}

View File

@@ -36,14 +36,16 @@ public sealed class HumanoidVisualizerSystem : VisualizerSystem<HumanoidComponen
return;
}
bool dirty;
var dirty = data.SkinColor != component.SkinColor || data.Sex != component.Sex;
component.Sex = data.Sex;
if (data.CustomBaseLayerInfo.Count != 0)
{
dirty = MergeCustomBaseSprites(uid, baseSprites.Sprites, data.CustomBaseLayerInfo, component);
dirty |= MergeCustomBaseSprites(uid, baseSprites.Sprites, data.CustomBaseLayerInfo, component);
}
else
{
dirty = MergeCustomBaseSprites(uid, baseSprites.Sprites, null, component);
dirty |= MergeCustomBaseSprites(uid, baseSprites.Sprites, null, component);
}
if (dirty)
@@ -442,6 +444,4 @@ public sealed class HumanoidVisualizerSystem : VisualizerSystem<HumanoidComponen
}
}
}
}

View File

@@ -179,8 +179,7 @@ public sealed partial class MarkingPicker : Control
foreach (var marking in markings.Values)
{
if (_currentMarkings.TryGetCategory(_selectedMarkingCategory, out var listing)
&& listing.Contains(marking.AsMarking()))
if (_currentMarkings.TryGetMarking(_selectedMarkingCategory, marking.ID, out _))
{
continue;
}

View File

@@ -27,7 +27,6 @@ namespace Content.Client.Input
common.AddFunction(ContentKeyFunctions.TakeScreenshot);
common.AddFunction(ContentKeyFunctions.TakeScreenshotNoUI);
common.AddFunction(ContentKeyFunctions.Point);
common.AddFunction(ContentKeyFunctions.OpenContextMenu);
// Not in engine, because engine cannot check for sanbox/admin status before starting placement.
common.AddFunction(ContentKeyFunctions.EditorCopyObject);

View File

@@ -11,6 +11,7 @@ using Content.Shared.Interaction;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -70,7 +71,7 @@ namespace Content.Client.Items.Managers
_entitySystemManager.GetEntitySystem<ExamineSystem>()
.DoExamine(item.Value);
}
else if (args.Function == ContentKeyFunctions.OpenContextMenu)
else if (args.Function == EngineKeyFunctions.UseSecondary)
{
_entitySystemManager.GetEntitySystem<VerbSystem>().VerbMenu.OpenVerbMenu(item.Value);
}

View File

@@ -12,7 +12,6 @@ namespace Content.Client.Items.Systems;
public sealed class ItemSystem : SharedItemSystem
{
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly IResourceCache _resCache = default!;
public override void Initialize()
@@ -30,8 +29,8 @@ public sealed class ItemSystem : SharedItemSystem
public override void VisualsChanged(EntityUid uid)
{
// if the item is in a container, it might be equipped to hands or inventory slots --> update visuals.
if (_containerSystem.TryGetContainingContainer(uid, out var container))
RaiseLocalEvent(container.Owner, new VisualsChangedEvent(uid, container.ID), true);
if (Container.TryGetContainingContainer(uid, out var container))
RaiseLocalEvent(container.Owner, new VisualsChangedEvent(uid, container.ID));
}
/// <summary>

View File

@@ -1,5 +1,6 @@
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Content.Shared.Interaction.Events;
using Content.Shared.MobState;
using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
@@ -26,6 +27,13 @@ public sealed partial class MobStateSystem : SharedMobStateSystem
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttach);
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetach);
SubscribeLocalEvent<MobStateComponent, ComponentHandleState>(OnMobHandleState);
SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(OnAttack);
}
private void OnAttack(EntityUid uid, MobStateComponent component, AttackAttemptEvent args)
{
if (IsIncapacitated(uid, component))
args.Cancel();
}
public override void Shutdown()

View File

@@ -1,197 +0,0 @@
using Content.Client.Stylesheets;
using Content.Shared.AI;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.NPC
{
public sealed class ClientAiDebugSystem : EntitySystem
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
public AiDebugMode Tooltips { get; private set; } = AiDebugMode.None;
private readonly Dictionary<EntityUid, PanelContainer> _aiBoxes = new();
public override void Update(float frameTime)
{
base.Update(frameTime);
if (Tooltips == 0)
{
if (_aiBoxes.Count > 0)
{
foreach (var (_, panel) in _aiBoxes)
{
panel.Dispose();
}
_aiBoxes.Clear();
}
return;
}
var deletedEntities = new List<EntityUid>(0);
foreach (var (entity, panel) in _aiBoxes)
{
if (Deleted(entity))
{
deletedEntities.Add(entity);
continue;
}
if (!_eyeManager.GetWorldViewport().Contains(EntityManager.GetComponent<TransformComponent>(entity).WorldPosition))
{
panel.Visible = false;
continue;
}
var (x, y) = _eyeManager.CoordinatesToScreen(EntityManager.GetComponent<TransformComponent>(entity).Coordinates).Position;
var offsetPosition = new Vector2(x - panel.Width / 2, y - panel.Height - 50f);
panel.Visible = true;
LayoutContainer.SetPosition(panel, offsetPosition);
}
foreach (var entity in deletedEntities)
{
_aiBoxes.Remove(entity);
}
}
public override void Initialize()
{
base.Initialize();
UpdatesOutsidePrediction = true;
SubscribeNetworkEvent<SharedAiDebug.UtilityAiDebugMessage>(HandleUtilityAiDebugMessage);
SubscribeNetworkEvent<SharedAiDebug.AStarRouteMessage>(HandleAStarRouteMessage);
SubscribeNetworkEvent<SharedAiDebug.JpsRouteMessage>(HandleJpsRouteMessage);
}
private void HandleUtilityAiDebugMessage(SharedAiDebug.UtilityAiDebugMessage message)
{
if ((Tooltips & AiDebugMode.Thonk) != 0)
{
// I guess if it's out of range we don't know about it?
var entity = message.EntityUid;
TryCreatePanel(entity);
// Probably shouldn't access by index but it's a debugging tool so eh
var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(0);
label.Text = $"Current Task: {message.FoundTask}\n" +
$"Task score: {message.ActionScore}\n" +
$"Planning time (ms): {message.PlanningTime * 1000:0.0000}\n" +
$"Considered {message.ConsideredTaskCount} tasks";
}
}
private void HandleAStarRouteMessage(SharedAiDebug.AStarRouteMessage message)
{
if ((Tooltips & AiDebugMode.Paths) != 0)
{
var entity = message.EntityUid;
TryCreatePanel(entity);
var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1);
label.Text = $"Pathfinding time (ms): {message.TimeTaken * 1000:0.0000}\n" +
$"Nodes traversed: {message.CameFrom.Count}\n" +
$"Nodes per ms: {message.CameFrom.Count / (message.TimeTaken * 1000)}";
}
}
private void HandleJpsRouteMessage(SharedAiDebug.JpsRouteMessage message)
{
if ((Tooltips & AiDebugMode.Paths) != 0)
{
var entity = message.EntityUid;
TryCreatePanel(entity);
var label = (Label) _aiBoxes[entity].GetChild(0).GetChild(1);
label.Text = $"Pathfinding time (ms): {message.TimeTaken * 1000:0.0000}\n" +
$"Jump Nodes: {message.JumpNodes.Count}\n" +
$"Jump Nodes per ms: {message.JumpNodes.Count / (message.TimeTaken * 1000)}";
}
}
public void Disable()
{
foreach (var tooltip in _aiBoxes.Values)
{
tooltip.Dispose();
}
_aiBoxes.Clear();
Tooltips = AiDebugMode.None;
}
public void EnableTooltip(AiDebugMode tooltip)
{
Tooltips |= tooltip;
}
public void DisableTooltip(AiDebugMode tooltip)
{
Tooltips &= ~tooltip;
}
public void ToggleTooltip(AiDebugMode tooltip)
{
if ((Tooltips & tooltip) != 0)
{
DisableTooltip(tooltip);
}
else
{
EnableTooltip(tooltip);
}
}
private bool TryCreatePanel(EntityUid entity)
{
if (!_aiBoxes.ContainsKey(entity))
{
var userInterfaceManager = IoCManager.Resolve<IUserInterfaceManager>();
var actionLabel = new Label
{
MouseFilter = Control.MouseFilterMode.Ignore,
};
var pathfindingLabel = new Label
{
MouseFilter = Control.MouseFilterMode.Ignore,
};
var vBox = new BoxContainer()
{
Orientation = LayoutOrientation.Vertical,
SeparationOverride = 15,
Children = {actionLabel, pathfindingLabel},
};
var panel = new PanelContainer
{
StyleClasses = { StyleNano.StyleClassTooltipPanel },
Children = {vBox},
MouseFilter = Control.MouseFilterMode.Ignore,
ModulateSelfOverride = Color.White.WithAlpha(0.75f),
};
userInterfaceManager.StateRoot.AddChild(panel);
_aiBoxes[entity] = panel;
return true;
}
return false;
}
}
[Flags]
public enum AiDebugMode : byte
{
None = 0,
Paths = 1 << 1,
Thonk = 1 << 2,
}
}

View File

@@ -1,520 +0,0 @@
using System.Linq;
using Content.Shared.AI;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Timing;
namespace Content.Client.NPC
{
public sealed class ClientPathfindingDebugSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public PathfindingDebugMode Modes { get; private set; } = PathfindingDebugMode.None;
private float _routeDuration = 4.0f; // How long before we remove a route from the overlay
private DebugPathfindingOverlay? _overlay;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<SharedAiDebug.AStarRouteMessage>(HandleAStarRouteMessage);
SubscribeNetworkEvent<SharedAiDebug.JpsRouteMessage>(HandleJpsRouteMessage);
SubscribeNetworkEvent<SharedAiDebug.PathfindingGraphMessage>(HandleGraphMessage);
SubscribeNetworkEvent<SharedAiDebug.ReachableChunkRegionsDebugMessage>(HandleRegionsMessage);
SubscribeNetworkEvent<SharedAiDebug.ReachableCacheDebugMessage>(HandleCachedRegionsMessage);
// I'm lazy
EnableOverlay();
}
public override void Shutdown()
{
base.Shutdown();
DisableOverlay();
}
private void HandleAStarRouteMessage(SharedAiDebug.AStarRouteMessage message)
{
if ((Modes & PathfindingDebugMode.Nodes) != 0 ||
(Modes & PathfindingDebugMode.Route) != 0)
{
_overlay?.AStarRoutes.Add(message);
Timer.Spawn(TimeSpan.FromSeconds(_routeDuration), () =>
{
if (_overlay == null) return;
_overlay.AStarRoutes.Remove(message);
});
}
}
private void HandleJpsRouteMessage(SharedAiDebug.JpsRouteMessage message)
{
if ((Modes & PathfindingDebugMode.Nodes) != 0 ||
(Modes & PathfindingDebugMode.Route) != 0)
{
_overlay?.JpsRoutes.Add(message);
Timer.Spawn(TimeSpan.FromSeconds(_routeDuration), () =>
{
if (_overlay == null) return;
_overlay.JpsRoutes.Remove(message);
});
}
}
private void HandleGraphMessage(SharedAiDebug.PathfindingGraphMessage message)
{
EnableOverlay().UpdateGraph(message.Graph);
}
private void HandleRegionsMessage(SharedAiDebug.ReachableChunkRegionsDebugMessage message)
{
EnableOverlay().UpdateRegions(message.GridId, message.Regions);
}
private void HandleCachedRegionsMessage(SharedAiDebug.ReachableCacheDebugMessage message)
{
EnableOverlay().UpdateCachedRegions(message.GridId, message.Regions, message.Cached);
}
private DebugPathfindingOverlay EnableOverlay()
{
if (_overlay != null)
{
return _overlay;
}
var overlayManager = IoCManager.Resolve<IOverlayManager>();
_overlay = new DebugPathfindingOverlay(EntityManager, _eyeManager, _playerManager, _prototypeManager) {Modes = Modes};
overlayManager.AddOverlay(_overlay);
return _overlay;
}
private void DisableOverlay()
{
if (_overlay == null)
{
return;
}
_overlay.Modes = 0;
var overlayManager = IoCManager.Resolve<IOverlayManager>();
overlayManager.RemoveOverlay(_overlay);
_overlay = null;
}
public void Disable()
{
Modes = PathfindingDebugMode.None;
DisableOverlay();
}
public void EnableMode(PathfindingDebugMode tooltip)
{
Modes |= tooltip;
if (Modes != 0)
{
EnableOverlay();
}
if (_overlay != null)
{
_overlay.Modes = Modes;
}
if (tooltip == PathfindingDebugMode.Graph)
{
RaiseNetworkEvent(new SharedAiDebug.RequestPathfindingGraphMessage());
}
if (tooltip == PathfindingDebugMode.Regions)
{
RaiseNetworkEvent(new SharedAiDebug.SubscribeReachableMessage());
}
// TODO: Request region graph, although the client system messages didn't seem to be going through anymore
// So need further investigation.
}
public void DisableMode(PathfindingDebugMode mode)
{
if (mode == PathfindingDebugMode.Regions && (Modes & PathfindingDebugMode.Regions) != 0)
{
RaiseNetworkEvent(new SharedAiDebug.UnsubscribeReachableMessage());
}
Modes &= ~mode;
if (Modes == 0)
{
DisableOverlay();
}
else if (_overlay != null)
{
_overlay.Modes = Modes;
}
}
public void ToggleTooltip(PathfindingDebugMode mode)
{
if ((Modes & mode) != 0)
{
DisableMode(mode);
}
else
{
EnableMode(mode);
}
}
}
internal sealed class DebugPathfindingOverlay : Overlay
{
private readonly IEyeManager _eyeManager;
private readonly IPlayerManager _playerManager;
private readonly IEntityManager _entities;
// TODO: Add a box like the debug one and show the most recent path stuff
public override OverlaySpace Space => OverlaySpace.ScreenSpace;
private readonly ShaderInstance _shader;
public PathfindingDebugMode Modes { get; set; } = PathfindingDebugMode.None;
// Graph debugging
public readonly Dictionary<int, List<Vector2>> Graph = new();
private readonly Dictionary<int, Color> _graphColors = new();
// Cached regions
public readonly Dictionary<EntityUid, Dictionary<int, List<Vector2>>> CachedRegions =
new();
private readonly Dictionary<EntityUid, Dictionary<int, Color>> _cachedRegionColors =
new();
// Regions
public readonly Dictionary<EntityUid, Dictionary<int, Dictionary<int, List<Vector2>>>> Regions =
new();
private readonly Dictionary<EntityUid, Dictionary<int, Dictionary<int, Color>>> _regionColors =
new();
// Route debugging
// As each pathfinder is very different you'll likely want to draw them completely different
public readonly List<SharedAiDebug.AStarRouteMessage> AStarRoutes = new();
public readonly List<SharedAiDebug.JpsRouteMessage> JpsRoutes = new();
public DebugPathfindingOverlay(IEntityManager entities, IEyeManager eyeManager, IPlayerManager playerManager, IPrototypeManager prototypeManager)
{
_entities = entities;
_eyeManager = eyeManager;
_playerManager = playerManager;
_shader = prototypeManager.Index<ShaderPrototype>("unshaded").Instance();
}
#region Graph
public void UpdateGraph(Dictionary<int, List<Vector2>> graph)
{
Graph.Clear();
_graphColors.Clear();
var robustRandom = IoCManager.Resolve<IRobustRandom>();
foreach (var (chunk, nodes) in graph)
{
Graph[chunk] = nodes;
_graphColors[chunk] = new Color(robustRandom.NextFloat(), robustRandom.NextFloat(),
robustRandom.NextFloat(), 0.3f);
}
}
private void DrawGraph(DrawingHandleScreen screenHandle, Box2 viewport)
{
foreach (var (chunk, nodes) in Graph)
{
foreach (var tile in nodes)
{
if (!viewport.Contains(tile)) continue;
var screenTile = _eyeManager.WorldToScreen(tile);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, _graphColors[chunk]);
}
}
}
#endregion
#region Regions
//Server side debugger should increment every region
public void UpdateCachedRegions(EntityUid gridId, Dictionary<int, List<Vector2>> messageRegions, bool cached)
{
if (!CachedRegions.ContainsKey(gridId))
{
CachedRegions.Add(gridId, new Dictionary<int, List<Vector2>>());
_cachedRegionColors.Add(gridId, new Dictionary<int, Color>());
}
foreach (var (region, nodes) in messageRegions)
{
CachedRegions[gridId][region] = nodes;
if (cached)
{
_cachedRegionColors[gridId][region] = Color.Blue.WithAlpha(0.3f);
}
else
{
_cachedRegionColors[gridId][region] = Color.LimeGreen.WithAlpha(0.3f);
}
Timer.Spawn(3000, () =>
{
if (CachedRegions[gridId].ContainsKey(region))
{
CachedRegions[gridId].Remove(region);
_cachedRegionColors[gridId].Remove(region);
}
});
}
}
private void DrawCachedRegions(DrawingHandleScreen screenHandle, Box2 viewport)
{
var transform = _entities.GetComponentOrNull<TransformComponent>(_playerManager.LocalPlayer?.ControlledEntity);
if (transform == null || transform.GridUid == null || !CachedRegions.TryGetValue(transform.GridUid.Value, out var entityRegions))
{
return;
}
foreach (var (region, nodes) in entityRegions)
{
foreach (var tile in nodes)
{
if (!viewport.Contains(tile)) continue;
var screenTile = _eyeManager.WorldToScreen(tile);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, _cachedRegionColors[transform.GridUid.Value][region]);
}
}
}
public void UpdateRegions(EntityUid gridId, Dictionary<int, Dictionary<int, List<Vector2>>> messageRegions)
{
if (!Regions.ContainsKey(gridId))
{
Regions.Add(gridId, new Dictionary<int, Dictionary<int, List<Vector2>>>());
_regionColors.Add(gridId, new Dictionary<int, Dictionary<int, Color>>());
}
var robustRandom = IoCManager.Resolve<IRobustRandom>();
foreach (var (chunk, regions) in messageRegions)
{
Regions[gridId][chunk] = new Dictionary<int, List<Vector2>>();
_regionColors[gridId][chunk] = new Dictionary<int, Color>();
foreach (var (region, nodes) in regions)
{
Regions[gridId][chunk].Add(region, nodes);
_regionColors[gridId][chunk][region] = new Color(robustRandom.NextFloat(), robustRandom.NextFloat(),
robustRandom.NextFloat(), 0.5f);
}
}
}
private void DrawRegions(DrawingHandleScreen screenHandle, Box2 viewport)
{
var attachedEntity = _playerManager.LocalPlayer?.ControlledEntity;
if (!_entities.TryGetComponent(attachedEntity, out TransformComponent? transform) ||
transform.GridUid == null ||
!Regions.TryGetValue(transform.GridUid.Value, out var entityRegions))
{
return;
}
foreach (var (chunk, regions) in entityRegions)
{
foreach (var (region, nodes) in regions)
{
foreach (var tile in nodes)
{
if (!viewport.Contains(tile)) continue;
var screenTile = _eyeManager.WorldToScreen(tile);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, _regionColors[transform.GridUid.Value][chunk][region]);
}
}
}
}
#endregion
#region Pathfinder
private void DrawAStarRoutes(DrawingHandleScreen screenHandle, Box2 viewport)
{
foreach (var route in AStarRoutes)
{
// Draw box on each tile of route
foreach (var position in route.Route)
{
if (!viewport.Contains(position)) continue;
var screenTile = _eyeManager.WorldToScreen(position);
// worldHandle.DrawLine(position, nextWorld.Value, Color.Blue);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, Color.Orange.WithAlpha(0.25f));
}
}
}
private void DrawAStarNodes(DrawingHandleScreen screenHandle, Box2 viewport)
{
foreach (var route in AStarRoutes)
{
var highestGScore = route.GScores.Values.Max();
foreach (var (tile, score) in route.GScores)
{
if ((route.Route.Contains(tile) && (Modes & PathfindingDebugMode.Route) != 0) ||
!viewport.Contains(tile))
{
continue;
}
var screenTile = _eyeManager.WorldToScreen(tile);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, new Color(
0.0f,
score / highestGScore,
1.0f - (score / highestGScore),
0.1f));
}
}
}
private void DrawJpsRoutes(DrawingHandleScreen screenHandle, Box2 viewport)
{
foreach (var route in JpsRoutes)
{
// Draw box on each tile of route
foreach (var position in route.Route)
{
if (!viewport.Contains(position)) continue;
var screenTile = _eyeManager.WorldToScreen(position);
// worldHandle.DrawLine(position, nextWorld.Value, Color.Blue);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, Color.Orange.WithAlpha(0.25f));
}
}
}
private void DrawJpsNodes(DrawingHandleScreen screenHandle, Box2 viewport)
{
foreach (var route in JpsRoutes)
{
foreach (var tile in route.JumpNodes)
{
if ((route.Route.Contains(tile) && (Modes & PathfindingDebugMode.Route) != 0) ||
!viewport.Contains(tile))
{
continue;
}
var screenTile = _eyeManager.WorldToScreen(tile);
var box = new UIBox2(
screenTile.X - 15.0f,
screenTile.Y - 15.0f,
screenTile.X + 15.0f,
screenTile.Y + 15.0f);
screenHandle.DrawRect(box, new Color(
0.0f,
1.0f,
0.0f,
0.2f));
}
}
}
#endregion
protected override void Draw(in OverlayDrawArgs args)
{
if (Modes == 0)
{
return;
}
var screenHandle = args.ScreenHandle;
screenHandle.UseShader(_shader);
var viewport = args.WorldAABB;
if ((Modes & PathfindingDebugMode.Route) != 0)
{
DrawAStarRoutes(screenHandle, viewport);
DrawJpsRoutes(screenHandle, viewport);
}
if ((Modes & PathfindingDebugMode.Nodes) != 0)
{
DrawAStarNodes(screenHandle, viewport);
DrawJpsNodes(screenHandle, viewport);
}
if ((Modes & PathfindingDebugMode.Graph) != 0)
{
DrawGraph(screenHandle, viewport);
}
if ((Modes & PathfindingDebugMode.CachedRegions) != 0)
{
DrawCachedRegions(screenHandle, viewport);
}
if ((Modes & PathfindingDebugMode.Regions) != 0)
{
DrawRegions(screenHandle, viewport);
}
screenHandle.UseShader(null);
}
}
[Flags]
public enum PathfindingDebugMode : byte
{
None = 0,
Route = 1 << 0,
Graph = 1 << 1,
Nodes = 1 << 2,
CachedRegions = 1 << 3,
Regions = 1 << 4,
}
}

View File

@@ -15,9 +15,11 @@
<Label Text="Pathfinder" HorizontalAlignment="Center"/>
</controls:StripeBack>
<BoxContainer Name="PathfinderBox" Orientation="Vertical">
<CheckBox Name="PathNodes" Text="Nodes"/>
<CheckBox Name="PathCrumbs" Text="Breadcrumbs"/>
<CheckBox Name="PathPolys" Text="Polygons"/>
<CheckBox Name="PathNeighbors" Text="Neighbors"/>
<CheckBox Name="PathRouteCosts" Text="Route costs"/>
<CheckBox Name="PathRoutes" Text="Routes"/>
<CheckBox Name="PathRegions" Text="Regions"/>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -1,4 +1,5 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.NPC;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
@@ -12,21 +13,18 @@ public sealed partial class NPCWindow : FancyWindow
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
var sysManager = IoCManager.Resolve<IEntitySystemManager>();
var debugSys = sysManager.GetEntitySystem<ClientAiDebugSystem>();
var path = sysManager.GetEntitySystem<ClientPathfindingDebugSystem>();
var path = sysManager.GetEntitySystem<PathfindingSystem>();
NPCPath.Pressed = (debugSys.Tooltips & AiDebugMode.Paths) != 0x0;
NPCThonk.Pressed = (debugSys.Tooltips & AiDebugMode.Thonk) != 0x0;
PathCrumbs.Pressed = (path.Modes & PathfindingDebugMode.Breadcrumbs) != 0x0;
PathPolys.Pressed = (path.Modes & PathfindingDebugMode.Polys) != 0x0;
PathNeighbors.Pressed = (path.Modes & PathfindingDebugMode.PolyNeighbors) != 0x0;
PathRouteCosts.Pressed = (path.Modes & PathfindingDebugMode.RouteCosts) != 0x0;
PathRoutes.Pressed = (path.Modes & PathfindingDebugMode.Routes) != 0x0;
NPCPath.OnToggled += args => debugSys.ToggleTooltip(AiDebugMode.Paths);
NPCThonk.OnToggled += args => debugSys.ToggleTooltip(AiDebugMode.Thonk);
PathNodes.Pressed = (path.Modes & PathfindingDebugMode.Nodes) != 0x0;
PathRegions.Pressed = (path.Modes & PathfindingDebugMode.Regions) != 0x0;
PathRoutes.Pressed = (path.Modes & PathfindingDebugMode.Route) != 0x0;
PathNodes.OnToggled += args => path.ToggleTooltip(PathfindingDebugMode.Nodes);
PathRegions.OnToggled += args => path.ToggleTooltip(PathfindingDebugMode.Regions);
PathRoutes.OnToggled += args => path.ToggleTooltip(PathfindingDebugMode.Route);
PathCrumbs.OnToggled += args => path.Modes ^= PathfindingDebugMode.Breadcrumbs;
PathPolys.OnToggled += args => path.Modes ^= PathfindingDebugMode.Polys;
PathNeighbors.OnToggled += args => path.Modes ^= PathfindingDebugMode.PolyNeighbors;
PathRouteCosts.OnToggled += args => path.Modes ^= PathfindingDebugMode.RouteCosts;
PathRoutes.OnToggled += args => path.Modes ^= PathfindingDebugMode.Routes;
}
}

View File

@@ -0,0 +1,526 @@
using System.Linq;
using System.Text;
using Content.Shared.NPC;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.ResourceManagement;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.NPC
{
public sealed class PathfindingSystem : SharedPathfindingSystem
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
public PathfindingDebugMode Modes
{
get => _modes;
set
{
var overlayManager = IoCManager.Resolve<IOverlayManager>();
if (value == PathfindingDebugMode.None)
{
Breadcrumbs.Clear();
Polys.Clear();
overlayManager.RemoveOverlay<PathfindingOverlay>();
}
else if (!overlayManager.HasOverlay<PathfindingOverlay>())
{
overlayManager.AddOverlay(new PathfindingOverlay(EntityManager, _eyeManager, _inputManager, _mapManager, _cache, this));
}
_modes = value;
RaiseNetworkEvent(new RequestPathfindingDebugMessage()
{
Mode = _modes,
});
}
}
private PathfindingDebugMode _modes = PathfindingDebugMode.None;
// It's debug data IDC if it doesn't support snapshots I just want something fast.
public Dictionary<EntityUid, Dictionary<Vector2i, List<PathfindingBreadcrumb>>> Breadcrumbs = new();
public Dictionary<EntityUid, Dictionary<Vector2i, Dictionary<Vector2i, List<DebugPathPoly>>>> Polys = new();
public readonly List<(TimeSpan Time, PathRouteMessage Message)> Routes = new();
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<PathBreadcrumbsMessage>(OnBreadcrumbs);
SubscribeNetworkEvent<PathBreadcrumbsRefreshMessage>(OnBreadcrumbsRefresh);
SubscribeNetworkEvent<PathPolysMessage>(OnPolys);
SubscribeNetworkEvent<PathPolysRefreshMessage>(OnPolysRefresh);
SubscribeNetworkEvent<PathRouteMessage>(OnRoute);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!_timing.IsFirstTimePredicted)
return;
for (var i = 0; i < Routes.Count; i++)
{
var route = Routes[i];
if (_timing.RealTime < route.Time)
break;
Routes.RemoveAt(i);
}
}
private void OnRoute(PathRouteMessage ev)
{
Routes.Add((_timing.RealTime + TimeSpan.FromSeconds(0.5), ev));
}
private void OnPolys(PathPolysMessage ev)
{
Polys = ev.Polys;
}
private void OnPolysRefresh(PathPolysRefreshMessage ev)
{
var chunks = Polys.GetOrNew(ev.GridUid);
chunks[ev.Origin] = ev.Polys;
}
public override void Shutdown()
{
base.Shutdown();
// Don't send any messages to server, just shut down quietly.
_modes = PathfindingDebugMode.None;
}
private void OnBreadcrumbs(PathBreadcrumbsMessage ev)
{
Breadcrumbs = ev.Breadcrumbs;
}
private void OnBreadcrumbsRefresh(PathBreadcrumbsRefreshMessage ev)
{
if (!Breadcrumbs.TryGetValue(ev.GridUid, out var chunks))
return;
chunks[ev.Origin] = ev.Data;
}
}
public sealed class PathfindingOverlay : Overlay
{
private readonly IEntityManager _entManager;
private readonly IEyeManager _eyeManager;
private readonly IInputManager _inputManager;
private readonly IMapManager _mapManager;
private readonly PathfindingSystem _system;
public override OverlaySpace Space => OverlaySpace.ScreenSpace | OverlaySpace.WorldSpace;
private readonly Font _font;
public PathfindingOverlay(
IEntityManager entManager,
IEyeManager eyeManager,
IInputManager inputManager,
IMapManager mapManager,
IResourceCache cache,
PathfindingSystem system)
{
_entManager = entManager;
_eyeManager = eyeManager;
_inputManager = inputManager;
_mapManager = mapManager;
_system = system;
_font = new VectorFont(cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Regular.ttf"), 10);
}
protected override void Draw(in OverlayDrawArgs args)
{
switch (args.DrawingHandle)
{
case DrawingHandleScreen screenHandle:
DrawScreen(args, screenHandle);
break;
case DrawingHandleWorld worldHandle:
DrawWorld(args, worldHandle);
break;
}
}
private void DrawScreen(OverlayDrawArgs args, DrawingHandleScreen screenHandle)
{
var mousePos = _inputManager.MouseScreenPosition;
var mouseWorldPos = _eyeManager.ScreenToMap(mousePos);
var aabb = new Box2(mouseWorldPos.Position - SharedPathfindingSystem.ChunkSize, mouseWorldPos.Position + SharedPathfindingSystem.ChunkSize);
if ((_system.Modes & PathfindingDebugMode.Crumb) != 0x0 &&
mouseWorldPos.MapId == args.MapId)
{
var found = false;
foreach (var grid in _mapManager.FindGridsIntersecting(mouseWorldPos.MapId, aabb))
{
if (found || !_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
continue;
var localAABB = grid.InvWorldMatrix.TransformBox(aabb.Enlarged(float.Epsilon - SharedPathfindingSystem.ChunkSize));
var worldMatrix = grid.WorldMatrix;
foreach (var chunk in crumbs)
{
if (found)
continue;
var origin = chunk.Key * SharedPathfindingSystem.ChunkSize;
var chunkAABB = new Box2(origin, origin + SharedPathfindingSystem.ChunkSize);
if (!chunkAABB.Intersects(localAABB))
continue;
PathfindingBreadcrumb? nearest = null;
var nearestDistance = float.MaxValue;
foreach (var crumb in chunk.Value)
{
var crumbMapPos = worldMatrix.Transform(_system.GetCoordinate(chunk.Key, crumb.Coordinates));
var distance = (crumbMapPos - mouseWorldPos.Position).Length;
if (distance < nearestDistance)
{
nearestDistance = distance;
nearest = crumb;
}
}
if (nearest != null)
{
var text = new StringBuilder();
// Sandbox moment
var coords = $"Point coordinates: {nearest.Value.Coordinates.ToString()}";
var gridCoords =
$"Grid coordinates: {_system.GetCoordinate(chunk.Key, nearest.Value.Coordinates).ToString()}";
var layer = $"Layer: {nearest.Value.Data.CollisionLayer.ToString()}";
var mask = $"Mask: {nearest.Value.Data.CollisionMask.ToString()}";
text.AppendLine(coords);
text.AppendLine(gridCoords);
text.AppendLine(layer);
text.AppendLine(mask);
text.AppendLine($"Flags:");
foreach (var flag in Enum.GetValues<PathfindingBreadcrumbFlag>())
{
if ((flag & nearest.Value.Data.Flags) == 0x0)
continue;
var flagStr = $"- {flag.ToString()}";
text.AppendLine(flagStr);
}
screenHandle.DrawString(_font, mousePos.Position, text.ToString());
found = true;
break;
}
}
}
}
if ((_system.Modes & PathfindingDebugMode.Poly) != 0x0 &&
mouseWorldPos.MapId == args.MapId)
{
if (!_mapManager.TryFindGridAt(mouseWorldPos, out var grid))
return;
var found = false;
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data))
return;
var tileRef = grid.GetTileRef(mouseWorldPos);
var localPos = tileRef.GridIndices;
var chunkOrigin = localPos / SharedPathfindingSystem.ChunkSize;
if (!data.TryGetValue(chunkOrigin, out var chunk) ||
!chunk.TryGetValue(new Vector2i(localPos.X % SharedPathfindingSystem.ChunkSize,
localPos.Y % SharedPathfindingSystem.ChunkSize), out var tile))
{
return;
}
var invGridMatrix = grid.InvWorldMatrix;
DebugPathPoly? nearest = null;
var nearestDistance = float.MaxValue;
foreach (var poly in tile)
{
if (poly.Box.Contains(invGridMatrix.Transform(mouseWorldPos.Position)))
{
nearest = poly;
break;
}
}
if (nearest != null)
{
var text = new StringBuilder();
/*
// Sandbox moment
var coords = $"Point coordinates: {nearest.Value.Coordinates.ToString()}";
var gridCoords =
$"Grid coordinates: {_system.GetCoordinate(chunk.Key, nearest.Value.Coordinates).ToString()}";
var layer = $"Layer: {nearest.Value.Data.CollisionLayer.ToString()}";
var mask = $"Mask: {nearest.Value.Data.CollisionMask.ToString()}";
text.AppendLine(coords);
text.AppendLine(gridCoords);
text.AppendLine(layer);
text.AppendLine(mask);
text.AppendLine($"Flags:");
foreach (var flag in Enum.GetValues<PathfindingBreadcrumbFlag>())
{
if ((flag & nearest.Value.Data.Flags) == 0x0)
continue;
var flagStr = $"- {flag.ToString()}";
text.AppendLine(flagStr);
}
foreach (var neighbor in )
screenHandle.DrawString(_font, mousePos.Position, text.ToString());
found = true;
break;
*/
}
}
}
private void DrawWorld(OverlayDrawArgs args, DrawingHandleWorld worldHandle)
{
var mousePos = _inputManager.MouseScreenPosition;
var mouseWorldPos = _eyeManager.ScreenToMap(mousePos);
var aabb = new Box2(mouseWorldPos.Position - Vector2.One / 4f, mouseWorldPos.Position + Vector2.One / 4f);
if ((_system.Modes & PathfindingDebugMode.Breadcrumbs) != 0x0 &&
mouseWorldPos.MapId == args.MapId)
{
foreach (var grid in _mapManager.FindGridsIntersecting(mouseWorldPos.MapId, aabb))
{
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
continue;
worldHandle.SetTransform(grid.WorldMatrix);
var localAABB = grid.InvWorldMatrix.TransformBox(aabb);
foreach (var chunk in crumbs)
{
var origin = chunk.Key * SharedPathfindingSystem.ChunkSize;
var chunkAABB = new Box2(origin, origin + SharedPathfindingSystem.ChunkSize);
if (!chunkAABB.Intersects(localAABB))
continue;
foreach (var crumb in chunk.Value)
{
if (crumb.Equals(PathfindingBreadcrumb.Invalid))
{
continue;
}
const float edge = 1f / SharedPathfindingSystem.SubStep / 4f;
var masked = crumb.Data.CollisionMask != 0 || crumb.Data.CollisionLayer != 0;
Color color;
if ((crumb.Data.Flags & PathfindingBreadcrumbFlag.Space) != 0x0)
{
color = Color.Green;
}
else if (masked)
{
color = Color.Blue;
}
else
{
color = Color.Orange;
}
var coordinate = _system.GetCoordinate(chunk.Key, crumb.Coordinates);
worldHandle.DrawRect(new Box2(coordinate - edge, coordinate + edge), color.WithAlpha(0.25f));
}
}
}
}
if ((_system.Modes & PathfindingDebugMode.Polys) != 0x0 &&
mouseWorldPos.MapId == args.MapId)
{
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, aabb))
{
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data))
continue;
worldHandle.SetTransform(grid.WorldMatrix);
var localAABB = grid.InvWorldMatrix.TransformBox(aabb);
foreach (var chunk in data)
{
var origin = chunk.Key * SharedPathfindingSystem.ChunkSize;
var chunkAABB = new Box2(origin, origin + SharedPathfindingSystem.ChunkSize);
if (!chunkAABB.Intersects(localAABB))
continue;
foreach (var tile in chunk.Value)
{
foreach (var poly in tile.Value)
{
worldHandle.DrawRect(poly.Box, Color.Green.WithAlpha(0.25f));
worldHandle.DrawRect(poly.Box, Color.Red, false);
}
}
}
}
}
if ((_system.Modes & PathfindingDebugMode.PolyNeighbors) != 0x0 &&
mouseWorldPos.MapId == args.MapId)
{
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, aabb))
{
if (!_system.Polys.TryGetValue(grid.GridEntityId, out var data) ||
!_entManager.TryGetComponent<TransformComponent>(grid.GridEntityId, out var gridXform))
continue;
var (_, _, worldMatrix, invMatrix) = gridXform.GetWorldPositionRotationMatrixWithInv();
worldHandle.SetTransform(worldMatrix);
var localAABB = invMatrix.TransformBox(aabb);
foreach (var chunk in data)
{
var origin = chunk.Key * SharedPathfindingSystem.ChunkSize;
var chunkAABB = new Box2(origin, origin + SharedPathfindingSystem.ChunkSize);
if (!chunkAABB.Intersects(localAABB))
continue;
foreach (var tile in chunk.Value)
{
foreach (var poly in tile.Value)
{
foreach (var neighborPoly in poly.Neighbors)
{
Color color;
Vector2 neighborPos;
if (neighborPoly.EntityId != poly.GraphUid)
{
color = Color.Green;
var neighborMap = neighborPoly.ToMap(_entManager);
if (neighborMap.MapId != args.MapId)
continue;
neighborPos = invMatrix.Transform(neighborMap.Position);
}
else
{
color = Color.Blue;
neighborPos = neighborPoly.Position;
}
worldHandle.DrawLine(poly.Box.Center, neighborPos, color);
}
}
}
}
}
}
if ((_system.Modes & PathfindingDebugMode.Chunks) != 0x0)
{
foreach (var grid in _mapManager.FindGridsIntersecting(args.MapId, args.WorldBounds))
{
if (!_system.Breadcrumbs.TryGetValue(grid.GridEntityId, out var crumbs))
continue;
worldHandle.SetTransform(grid.WorldMatrix);
var localAABB = grid.InvWorldMatrix.TransformBox(args.WorldBounds);
foreach (var chunk in crumbs)
{
var origin = chunk.Key * SharedPathfindingSystem.ChunkSize;
var chunkAABB = new Box2(origin, origin + SharedPathfindingSystem.ChunkSize);
if (!chunkAABB.Intersects(localAABB))
continue;
worldHandle.DrawRect(chunkAABB, Color.Red, false);
}
}
}
if ((_system.Modes & PathfindingDebugMode.Routes) != 0x0)
{
foreach (var route in _system.Routes)
{
foreach (var node in route.Message.Path)
{
if (!_entManager.TryGetComponent<TransformComponent>(node.GraphUid, out var graphXform))
continue;
worldHandle.SetTransform(graphXform.WorldMatrix);
worldHandle.DrawRect(node.Box, Color.Orange.WithAlpha(0.10f));
}
}
}
if ((_system.Modes & PathfindingDebugMode.RouteCosts) != 0x0)
{
var matrix = EntityUid.Invalid;
foreach (var route in _system.Routes)
{
var highestGScore = route.Message.Costs.Values.Max();
foreach (var (node, cost) in route.Message.Costs)
{
if (matrix != node.GraphUid)
{
if (!_entManager.TryGetComponent<TransformComponent>(node.GraphUid, out var graphXform))
continue;
matrix = node.GraphUid;
worldHandle.SetTransform(graphXform.WorldMatrix);
}
worldHandle.DrawRect(node.Box, new Color(0f, cost / highestGScore, 1f - (cost / highestGScore), 0.10f));
}
}
}
worldHandle.SetTransform(Matrix3.Identity);
}
}
}

View File

@@ -105,6 +105,7 @@ namespace Content.Client.Options.UI.Tabs
AddHeader("ui-options-header-interaction-basic");
AddButton(EngineKeyFunctions.Use);
AddButton(EngineKeyFunctions.UseSecondary);
AddButton(ContentKeyFunctions.UseItemInHand);
AddButton(ContentKeyFunctions.AltUseItemInHand);
AddButton(ContentKeyFunctions.ActivateItemInWorld);
@@ -134,7 +135,6 @@ namespace Content.Client.Options.UI.Tabs
AddButton(ContentKeyFunctions.CycleChatChannelForward);
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
AddButton(ContentKeyFunctions.OpenCharacterMenu);
AddButton(ContentKeyFunctions.OpenContextMenu);
AddButton(ContentKeyFunctions.OpenCraftingMenu);
AddButton(ContentKeyFunctions.OpenInventoryMenu);
AddButton(ContentKeyFunctions.OpenInfo);

View File

@@ -0,0 +1,8 @@
using Content.Shared.Revenant.EntitySystems;
namespace Content.Client.Revenant;
public sealed class CorporealSystem : SharedCorporealSystem
{
}

View File

@@ -1,16 +0,0 @@
using Content.Shared.Revenant;
namespace Content.Client.Revenant;
[RegisterComponent]
public sealed class RevenantComponent : SharedRevenantComponent
{
[DataField("state")]
public string State = "idle";
[DataField("corporealState")]
public string CorporealState = "active";
[DataField("stunnedState")]
public string StunnedState = "stunned";
[DataField("harvestingState")]
public string HarvestingState = "harvesting";
}

View File

@@ -0,0 +1,58 @@
using Content.Shared.Revenant.Components;
using Content.Shared.Revenant.EntitySystems;
using Robust.Client.GameObjects;
namespace Content.Client.Revenant;
public sealed class RevenantOverloadedLightsSystem : SharedRevenantOverloadedLightsSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RevenantOverloadedLightsComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<RevenantOverloadedLightsComponent, ComponentShutdown>(OnShutdown);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var (comp, light) in EntityQuery<RevenantOverloadedLightsComponent, PointLightComponent>())
{
//this looks cool :HECK:
light.Energy = 2f * Math.Abs((float) Math.Sin(0.25 * Math.PI * comp.Accumulator));
}
}
private void OnStartup(EntityUid uid, RevenantOverloadedLightsComponent component, ComponentStartup args)
{
var light = EnsureComp<PointLightComponent>(uid);
component.OriginalEnergy = light.Energy;
component.OriginalEnabled = light.Enabled;
light.Enabled = component.OriginalEnabled;
Dirty(light);
}
private void OnShutdown(EntityUid uid, RevenantOverloadedLightsComponent component, ComponentShutdown args)
{
if (!TryComp<PointLightComponent>(component.Owner, out var light))
return;
if (component.OriginalEnergy == null)
{
RemComp<PointLightComponent>(component.Owner);
return;
}
light.Energy = component.OriginalEnergy.Value;
light.Enabled = component.OriginalEnabled;
Dirty(light);
}
protected override void OnZap(RevenantOverloadedLightsComponent component)
{
}
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Revenant;
using Content.Shared.Revenant.Components;
using Robust.Client.GameObjects;
namespace Content.Client.Revenant;

View File

@@ -37,6 +37,11 @@ namespace Content.Client.Rotation
var entMan = IoCManager.Resolve<IEntityManager>();
var sprite = entMan.GetComponent<ISpriteComponent>(component.Owner);
if (sprite.Rotation.Equals(rotation))
{
return;
}
if (!entMan.TryGetComponent(sprite.Owner, out AnimationPlayerComponent? animation))
{
sprite.Rotation = rotation;

View File

@@ -60,7 +60,9 @@ namespace Content.Client.Vehicle
private void OnRiderHandleState(EntityUid uid, RiderComponent component, ref ComponentHandleState args)
{
// Server should only be sending states for our entity.
if (uid != _playerManager.LocalPlayer?.ControlledEntity)
return;
if (args.Current is not RiderComponentState state) return;
component.Vehicle = state.Entity;

View File

@@ -0,0 +1,46 @@
using Content.Shared.VoiceMask;
using Robust.Client.GameObjects;
namespace Content.Client.VoiceMask;
public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
{
public VoiceMaskBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
}
private VoiceMaskNameChangeWindow? _window;
protected override void Open()
{
base.Open();
_window = new();
_window.OpenCentered();
_window.OnNameChange += OnNameSelected;
_window.OnClose += Close;
}
private void OnNameSelected(string name)
{
SendMessage(new VoiceMaskChangeNameMessage(name));
}
protected override void UpdateState(BoundUserInterfaceState state)
{
if (state is not VoiceMaskBuiState cast || _window == null)
{
return;
}
_window.UpdateState(cast.Name);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Close();
}
}

View File

@@ -0,0 +1,11 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'voice-mask-name-change-window'}"
MinSize="5 20">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'voice-mask-name-change-info'}" />
<BoxContainer Orientation="Horizontal">
<LineEdit Name="NameSelector" HorizontalExpand="True" />
<Button Name="NameSelectorSet" Text="{Loc 'voice-mask-name-change-set'}" />
</BoxContainer>
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,26 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.VoiceMask;
[GenerateTypedNameReferences]
public sealed partial class VoiceMaskNameChangeWindow : DefaultWindow
{
public Action<string>? OnNameChange;
public VoiceMaskNameChangeWindow()
{
RobustXamlLoader.Load(this);
NameSelectorSet.OnPressed += _ =>
{
OnNameChange!(NameSelector.Text);
};
}
public void UpdateState(string name)
{
NameSelector.Text = name;
}
}

View File

@@ -1,53 +0,0 @@
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Weapons.Melee.Components
{
[RegisterComponent]
public sealed class MeleeLungeComponent : Component
{
private const float ResetTime = 0.3f;
private const float BaseOffset = 0.25f;
private Angle _angle;
private float _time;
public void SetData(Angle angle)
{
_angle = angle;
_time = 0;
}
public void Update(float frameTime)
{
_time += frameTime;
var offset = Vector2.Zero;
var deleteSelf = false;
if (_time > ResetTime)
{
deleteSelf = true;
}
else
{
offset = _angle.RotateVec((0, -BaseOffset));
offset *= (ResetTime - _time) / ResetTime;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (entMan.TryGetComponent(Owner, out ISpriteComponent? spriteComponent))
{
spriteComponent.Offset = offset;
}
if (deleteSelf)
{
entMan.RemoveComponent<MeleeLungeComponent>(Owner);
}
}
}
}

View File

@@ -1,79 +0,0 @@
using Content.Shared.Weapons.Melee;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Weapons.Melee.Components
{
[RegisterComponent]
public sealed class MeleeWeaponArcAnimationComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
private MeleeWeaponAnimationPrototype? _meleeWeaponAnimation;
private float _timer;
private SpriteComponent? _sprite;
private Angle _baseAngle;
protected override void Initialize()
{
base.Initialize();
_sprite = _entMan.GetComponent<SpriteComponent>(Owner);
}
public void SetData(MeleeWeaponAnimationPrototype prototype, Angle baseAngle, EntityUid attacker, bool followAttacker = true)
{
_meleeWeaponAnimation = prototype;
_sprite?.AddLayer(new RSI.StateId(prototype.State));
_baseAngle = baseAngle;
if(followAttacker)
_entMan.GetComponent<TransformComponent>(Owner).AttachParent(attacker);
}
internal void Update(float frameTime)
{
if (_meleeWeaponAnimation == null)
{
return;
}
_timer += frameTime;
var (r, g, b, a) =
Vector4.Clamp(_meleeWeaponAnimation.Color + _meleeWeaponAnimation.ColorDelta * _timer, Vector4.Zero, Vector4.One);
if (_sprite != null)
{
_sprite.Color = new Color(r, g, b, a);
}
var transform = _entMan.GetComponent<TransformComponent>(Owner);
switch (_meleeWeaponAnimation.ArcType)
{
case WeaponArcType.Slash:
var angle = Angle.FromDegrees(_meleeWeaponAnimation.Width)/2;
transform.WorldRotation = _baseAngle + Angle.Lerp(-angle, angle, (float) (_timer / _meleeWeaponAnimation.Length.TotalSeconds));
break;
case WeaponArcType.Poke:
transform.WorldRotation = _baseAngle;
if (_sprite != null)
{
_sprite.Offset -= (0, _meleeWeaponAnimation.Speed * frameTime);
}
break;
}
if (_meleeWeaponAnimation.Length.TotalSeconds <= _timer)
{
_entMan.DeleteEntity(Owner);
}
}
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Client.Weapons.Melee.Components;
/// <summary>
/// Used for melee attack animations. Typically just has a fadeout.
/// </summary>
[RegisterComponent]
public sealed class WeaponArcVisualsComponent : Component
{
[ViewVariables, DataField("animation")]
public WeaponArcAnimation Animation = WeaponArcAnimation.None;
}
public enum WeaponArcAnimation : byte
{
None,
Thrust,
Slash,
}

View File

@@ -0,0 +1,75 @@
using Content.Shared.CombatMode;
using Content.Shared.Weapons.Melee;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Map;
namespace Content.Client.Weapons.Melee;
/// <summary>
/// Debug overlay showing the arc and range of a melee weapon.
/// </summary>
public sealed class MeleeArcOverlay : Overlay
{
private readonly IEntityManager _entManager;
private readonly IEyeManager _eyeManager;
private readonly IInputManager _inputManager;
private readonly IPlayerManager _playerManager;
private readonly MeleeWeaponSystem _melee;
private readonly SharedCombatModeSystem _combatMode;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
public MeleeArcOverlay(IEntityManager entManager, IEyeManager eyeManager, IInputManager inputManager, IPlayerManager playerManager, MeleeWeaponSystem melee, SharedCombatModeSystem combatMode)
{
_entManager = entManager;
_eyeManager = eyeManager;
_inputManager = inputManager;
_playerManager = playerManager;
_melee = melee;
_combatMode = combatMode;
}
protected override void Draw(in OverlayDrawArgs args)
{
var player = _playerManager.LocalPlayer?.ControlledEntity;
if (!_entManager.TryGetComponent<TransformComponent>(player, out var xform) ||
!_combatMode.IsInCombatMode(player))
{
return;
}
var weapon = _melee.GetWeapon(player.Value);
if (weapon == null)
return;
var mousePos = _inputManager.MouseScreenPosition;
var mapPos = _eyeManager.ScreenToMap(mousePos);
if (mapPos.MapId != args.MapId)
return;
var playerPos = xform.MapPosition;
if (mapPos.MapId != playerPos.MapId)
return;
var diff = mapPos.Position - playerPos.Position;
if (diff.Equals(Vector2.Zero))
return;
diff = diff.Normalized * Math.Min(weapon.Range, diff.Length);
args.WorldHandle.DrawLine(playerPos.Position, playerPos.Position + diff, Color.Aqua);
if (weapon.Angle.Theta == 0)
return;
args.WorldHandle.DrawLine(playerPos.Position, playerPos.Position + new Angle(-weapon.Angle / 2).RotateVec(diff), Color.Orange);
args.WorldHandle.DrawLine(playerPos.Position, playerPos.Position + new Angle(weapon.Angle / 2).RotateVec(diff), Color.Orange);
}
}

View File

@@ -1,20 +0,0 @@
using Content.Client.Weapons.Melee.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Client.Weapons.Melee
{
[UsedImplicitly]
public sealed class MeleeLungeSystem : EntitySystem
{
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
foreach (var meleeLungeComponent in EntityManager.EntityQuery<MeleeLungeComponent>(true))
{
meleeLungeComponent.Update(frameTime);
}
}
}
}

View File

@@ -0,0 +1,40 @@
using Content.Shared.CombatMode;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Shared.Console;
using Robust.Shared.Map;
namespace Content.Client.Weapons.Melee;
public sealed class MeleeSpreadCommand : IConsoleCommand
{
public string Command => "showmeleespread";
public string Description => "Shows the current weapon's range and arc for debugging";
public string Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
var collection = IoCManager.Instance;
if (collection == null)
return;
var overlayManager = collection.Resolve<IOverlayManager>();
if (overlayManager.RemoveOverlay<MeleeArcOverlay>())
{
return;
}
var sysManager = collection.Resolve<IEntitySystemManager>();
overlayManager.AddOverlay(new MeleeArcOverlay(
collection.Resolve<IEntityManager>(),
collection.Resolve<IEyeManager>(),
collection.Resolve<IInputManager>(),
collection.Resolve<IPlayerManager>(),
sysManager.GetEntitySystem<MeleeWeaponSystem>(),
sysManager.GetEntitySystem<SharedCombatModeSystem>()));
}
}

View File

@@ -2,31 +2,17 @@ using Content.Shared.Weapons;
using Content.Shared.Weapons.Melee;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.Utility;
namespace Content.Client.Weapons.Melee;
public sealed partial class MeleeWeaponSystem
{
private static readonly Animation DefaultDamageAnimation = new()
{
Length = TimeSpan.FromSeconds(DamageAnimationLength),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Color),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Color.Red, 0f),
new AnimationTrackProperty.KeyFrame(Color.White, DamageAnimationLength)
}
}
}
};
private const float DamageAnimationLength = 0.15f;
/// <summary>
/// It's a little on the long side but given we use multiple colours denoting what happened it makes it easier to register.
/// </summary>
private const float DamageAnimationLength = 0.30f;
private const string DamageAnimationKey = "damage-effect";
private void InitializeEffect()
@@ -47,27 +33,25 @@ public sealed partial class MeleeWeaponSystem
/// <summary>
/// Gets the red effect animation whenever the server confirms something is hit
/// </summary>
public Animation? GetDamageAnimation(EntityUid uid, SpriteComponent? sprite = null)
private Animation? GetDamageAnimation(EntityUid uid, Color color, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref sprite, false))
return null;
// 90% of them are going to be this so why allocate a new class.
if (sprite.Color.Equals(Color.White))
return DefaultDamageAnimation;
return new Animation
{
Length = TimeSpan.FromSeconds(DamageAnimationLength),
AnimationTracks =
{
new AnimationTrackComponentProperty()
new AnimationTrackComponentProperty
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Color),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Color.Red * sprite.Color, 0f),
new AnimationTrackProperty.KeyFrame(color * sprite.Color, 0f),
new AnimationTrackProperty.KeyFrame(sprite.Color, DamageAnimationLength)
}
}
@@ -77,36 +61,44 @@ public sealed partial class MeleeWeaponSystem
private void OnDamageEffect(DamageEffectEvent ev)
{
if (Deleted(ev.Entity))
return;
var color = ev.Color;
var player = EnsureComp<AnimationPlayerComponent>(ev.Entity);
// Need to stop the existing animation first to ensure the sprite color is fixed.
// Otherwise we might lerp to a red colour instead.
if (_animation.HasRunningAnimation(ev.Entity, player, DamageAnimationKey))
foreach (var ent in ev.Entities)
{
_animation.Stop(ev.Entity, player, DamageAnimationKey);
if (Deleted(ent))
{
continue;
}
var player = EnsureComp<AnimationPlayerComponent>(ent);
player.NetSyncEnabled = false;
// Need to stop the existing animation first to ensure the sprite color is fixed.
// Otherwise we might lerp to a red colour instead.
if (_animation.HasRunningAnimation(ent, player, DamageAnimationKey))
{
_animation.Stop(ent, player, DamageAnimationKey);
}
if (!TryComp<SpriteComponent>(ent, out var sprite))
{
continue;
}
if (TryComp<DamageEffectComponent>(ent, out var effect))
{
sprite.Color = effect.Color;
}
var animation = GetDamageAnimation(ent, color, sprite);
if (animation == null)
continue;
var comp = EnsureComp<DamageEffectComponent>(ent);
comp.NetSyncEnabled = false;
comp.Color = sprite.Color;
_animation.Play(player, animation, DamageAnimationKey);
}
if (!TryComp<SpriteComponent>(ev.Entity, out var sprite))
{
return;
}
if (TryComp<DamageEffectComponent>(ev.Entity, out var effect))
{
sprite.Color = effect.Color;
}
var animation = GetDamageAnimation(ev.Entity, sprite);
if (animation == null)
return;
var comp = EnsureComp<DamageEffectComponent>(ev.Entity);
comp.NetSyncEnabled = false;
comp.Color = sprite.Color;
_animation.Play(player, DefaultDamageAnimation, DamageAnimationKey);
}
}

View File

@@ -1,133 +1,417 @@
using System;
using Content.Client.CombatMode;
using Content.Client.Gameplay;
using Content.Client.Hands;
using Content.Client.Weapons.Melee.Components;
using Content.Shared.Examine;
using Content.Shared.MobState.Components;
using Content.Shared.Weapons.Melee;
using JetBrains.Annotations;
using Content.Shared.Weapons.Melee.Events;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.State;
using Robust.Shared.Animations;
using Robust.Shared.Input;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using static Content.Shared.Weapons.Melee.MeleeWeaponSystemMessages;
namespace Content.Client.Weapons.Melee
namespace Content.Client.Weapons.Melee;
public sealed partial class MeleeWeaponSystem : SharedMeleeWeaponSystem
{
public sealed partial class MeleeWeaponSystem : EntitySystem
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
[Dependency] private readonly IStateManager _stateManager = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly InputSystem _inputSystem = default!;
private const string MeleeLungeKey = "melee-lunge";
public override void Initialize()
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AnimationPlayerSystem _animation = default!;
[Dependency] private readonly EffectSystem _effectSystem = default!;
base.Initialize();
InitializeEffect();
_overlayManager.AddOverlay(new MeleeWindupOverlay(EntityManager, _timing, _protoManager, _cache));
SubscribeNetworkEvent<DamageEffectEvent>(OnDamageEffect);
SubscribeNetworkEvent<MeleeLungeEvent>(OnMeleeLunge);
}
public override void Initialize()
public override void Shutdown()
{
base.Shutdown();
_overlayManager.RemoveOverlay<MeleeWindupOverlay>();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (!Timing.IsFirstTimePredicted)
return;
var entityNull = _player.LocalPlayer?.ControlledEntity;
if (entityNull == null)
return;
var entity = entityNull.Value;
var weapon = GetWeapon(entity);
if (weapon == null)
return;
if (!CombatMode.IsInCombatMode(entity) || !Blocker.CanAttack(entity))
{
InitializeEffect();
SubscribeNetworkEvent<PlayMeleeWeaponAnimationMessage>(PlayWeaponArc);
SubscribeNetworkEvent<PlayLungeAnimationMessage>(PlayLunge);
SubscribeNetworkEvent<DamageEffectEvent>(OnDamageEffect);
}
public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);
foreach (var arcAnimationComponent in EntityManager.EntityQuery<MeleeWeaponArcAnimationComponent>(true))
weapon.Attacking = false;
if (weapon.WindUpStart != null)
{
arcAnimationComponent.Update(frameTime);
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weapon.Owner));
}
return;
}
private void PlayWeaponArc(PlayMeleeWeaponAnimationMessage msg)
var useDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.Use);
var altDown = _inputSystem.CmdStates.GetState(EngineKeyFunctions.UseSecondary);
var currentTime = Timing.CurTime;
// Heavy attack.
if (altDown == BoundKeyState.Down)
{
if (!_prototypeManager.TryIndex(msg.ArcPrototype, out MeleeWeaponAnimationPrototype? weaponArc))
// We did the click to end the attack but haven't pulled the key up.
if (weapon.Attacking)
{
Logger.Error("Tried to play unknown weapon arc prototype '{0}'", msg.ArcPrototype);
return;
}
var attacker = msg.Attacker;
if (!EntityManager.EntityExists(msg.Attacker))
// If it's an unarmed attack then do a disarm
if (weapon.Owner == entity)
{
// FIXME: This should never happen.
Logger.Error($"Tried to play a weapon arc {msg.ArcPrototype}, but the attacker does not exist. attacker={msg.Attacker}, source={msg.Source}");
EntityUid? target = null;
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
EntityCoordinates coordinates;
if (MapManager.TryFindGridAt(mousePos, out var grid))
{
coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mousePos, EntityManager);
}
else
{
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager);
}
if (_stateManager.CurrentState is GameplayStateBase screen)
{
target = screen.GetEntityUnderPosition(mousePos);
}
EntityManager.RaisePredictiveEvent(new DisarmAttackEvent(target, coordinates));
return;
}
if (!Deleted(attacker))
// Otherwise do heavy attack if it's a weapon.
// Start a windup
if (weapon.WindUpStart == null)
{
var lunge = attacker.EnsureComponent<MeleeLungeComponent>();
lunge.SetData(msg.Angle);
var entity = EntityManager.SpawnEntity(weaponArc.Prototype, EntityManager.GetComponent<TransformComponent>(attacker).Coordinates);
EntityManager.GetComponent<TransformComponent>(entity).LocalRotation = msg.Angle;
var weaponArcAnimation = EntityManager.GetComponent<MeleeWeaponArcAnimationComponent>(entity);
weaponArcAnimation.SetData(weaponArc, msg.Angle, attacker, msg.ArcFollowAttacker);
// Due to ISpriteComponent limitations, weapons that don't use an RSI won't have this effect.
if (EntityManager.EntityExists(msg.Source) &&
msg.TextureEffect &&
EntityManager.TryGetComponent(msg.Source, out ISpriteComponent? sourceSprite) &&
sourceSprite.BaseRSI?.Path is { } path)
{
var curTime = _gameTiming.CurTime;
var effect = new EffectSystemMessage
{
EffectSprite = path.ToString(),
RsiState = sourceSprite.LayerGetState(0).Name,
Coordinates = EntityManager.GetComponent<TransformComponent>(attacker).Coordinates,
Color = Vector4.Multiply(new Vector4(255, 255, 255, 125), 1.0f),
ColorDelta = Vector4.Multiply(new Vector4(0, 0, 0, -10), 1.0f),
Velocity = msg.Angle.ToWorldVec(),
Acceleration = msg.Angle.ToWorldVec() * 5f,
Born = curTime,
DeathTime = curTime.Add(TimeSpan.FromMilliseconds(300f)),
};
_effectSystem.CreateEffect(effect);
}
EntityManager.RaisePredictiveEvent(new StartHeavyAttackEvent(weapon.Owner));
weapon.WindUpStart = currentTime;
}
foreach (var hit in msg.Hits)
// Try to do a heavy attack.
if (useDown == BoundKeyState.Down)
{
if (!EntityManager.EntityExists(hit))
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
EntityCoordinates coordinates;
// Bro why would I want a ternary here
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (MapManager.TryFindGridAt(mousePos, out var grid))
{
continue;
coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mousePos, EntityManager);
}
else
{
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager);
}
if (!EntityManager.TryGetComponent(hit, out ISpriteComponent? sprite))
{
continue;
}
var originalColor = sprite.Color;
var newColor = Color.Red * originalColor;
sprite.Color = newColor;
hit.SpawnTimer(100, () =>
{
// Only reset back to the original color if something else didn't change the color in the mean time.
if (sprite.Color == newColor)
{
sprite.Color = originalColor;
}
});
EntityManager.RaisePredictiveEvent(new HeavyAttackEvent(weapon.Owner, coordinates));
}
return;
}
private void PlayLunge(PlayLungeAnimationMessage msg)
if (weapon.WindUpStart != null)
{
if (EntityManager.EntityExists(msg.Source))
EntityManager.RaisePredictiveEvent(new StopHeavyAttackEvent(weapon.Owner));
}
// Light attack
if (useDown == BoundKeyState.Down)
{
if (weapon.Attacking || weapon.NextAttack > Timing.CurTime)
{
msg.Source.EnsureComponent<MeleeLungeComponent>().SetData(msg.Angle);
return;
}
var mousePos = _eyeManager.ScreenToMap(_inputManager.MouseScreenPosition);
EntityCoordinates coordinates;
// Bro why would I want a ternary here
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (MapManager.TryFindGridAt(mousePos, out var grid))
{
coordinates = EntityCoordinates.FromMap(grid.GridEntityId, mousePos, EntityManager);
}
else
{
// FIXME: This should never happen.
Logger.Error($"Tried to play a lunge animation, but the entity \"{msg.Source}\" does not exist.");
coordinates = EntityCoordinates.FromMap(MapManager.GetMapEntityId(mousePos.MapId), mousePos, EntityManager);
}
EntityUid? target = null;
// TODO: UI Refactor update I assume
if (_stateManager.CurrentState is GameplayStateBase screen)
{
target = screen.GetEntityUnderPosition(mousePos);
}
EntityManager.RaisePredictiveEvent(new LightAttackEvent(target, weapon.Owner, coordinates));
return;
}
if (weapon.Attacking)
{
EntityManager.RaisePredictiveEvent(new StopAttackEvent(weapon.Owner));
}
}
protected override bool DoDisarm(EntityUid user, DisarmAttackEvent ev, MeleeWeaponComponent component)
{
if (!base.DoDisarm(user, ev, component))
return false;
if (!HasComp<CombatModeComponent>(user))
return false;
// If target doesn't have hands then we can't disarm so will let the player know it's pointless.
if (!HasComp<HandsComponent>(ev.Target!.Value))
{
if (Timing.IsFirstTimePredicted && HasComp<MobStateComponent>(ev.Target.Value))
PopupSystem.PopupEntity(Loc.GetString("disarm-action-disarmable", ("targetName", ev.Target.Value)), ev.Target.Value, Filter.Local());
return false;
}
return true;
}
protected override void Popup(string message, EntityUid? uid, EntityUid? user)
{
if (!Timing.IsFirstTimePredicted || uid == null)
return;
PopupSystem.PopupEntity(message, uid.Value, Filter.Local());
}
private void OnMeleeLunge(MeleeLungeEvent ev)
{
DoLunge(ev.Entity, ev.Angle, ev.LocalPos, ev.Animation);
}
/// <summary>
/// Does all of the melee effects for a player that are predicted, i.e. character lunge and weapon animation.
/// </summary>
public override void DoLunge(EntityUid user, Angle angle, Vector2 localPos, string? animation)
{
if (!Timing.IsFirstTimePredicted)
return;
var lunge = GetLungeAnimation(localPos);
// Stop any existing lunges on the user.
_animation.Stop(user, MeleeLungeKey);
_animation.Play(user, lunge, MeleeLungeKey);
// Clientside entity to spawn
if (animation != null)
{
var animationUid = Spawn(animation, new EntityCoordinates(user, Vector2.Zero));
if (localPos != Vector2.Zero && TryComp<SpriteComponent>(animationUid, out var sprite))
{
sprite[0].AutoAnimated = false;
if (TryComp<WeaponArcVisualsComponent>(animationUid, out var arcComponent))
{
sprite.NoRotation = true;
sprite.Rotation = localPos.ToWorldAngle();
var distance = Math.Clamp(localPos.Length / 2f, 0.2f, 1f);
switch (arcComponent.Animation)
{
case WeaponArcAnimation.Slash:
_animation.Play(animationUid, GetSlashAnimation(sprite, angle), "melee-slash");
break;
case WeaponArcAnimation.Thrust:
_animation.Play(animationUid, GetThrustAnimation(sprite, distance), "melee-thrust");
break;
case WeaponArcAnimation.None:
sprite.Offset = localPos.Normalized * distance;
_animation.Play(animationUid, GetStaticAnimation(sprite), "melee-fade");
break;
}
}
}
}
}
private Animation GetSlashAnimation(SpriteComponent sprite, Angle arc)
{
var slashStart = 0.03f;
var slashEnd = 0.065f;
var length = slashEnd + 0.05f;
var startRotation = sprite.Rotation - arc / 2;
var endRotation = sprite.Rotation + arc / 2;
sprite.NoRotation = true;
return new Animation()
{
Length = TimeSpan.FromSeconds(length),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Rotation),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(startRotation, 0f),
new AnimationTrackProperty.KeyFrame(startRotation, slashStart),
new AnimationTrackProperty.KeyFrame(endRotation, slashEnd)
}
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(startRotation.RotateVec(new Vector2(0f, -1f)), 0f),
new AnimationTrackProperty.KeyFrame(startRotation.RotateVec(new Vector2(0f, -1f)), slashStart),
new AnimationTrackProperty.KeyFrame(endRotation.RotateVec(new Vector2(0f, -1f)), slashEnd)
}
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Color),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Color, slashEnd),
new AnimationTrackProperty.KeyFrame(sprite.Color.WithAlpha(0f), length),
}
}
}
};
}
private Animation GetThrustAnimation(SpriteComponent sprite, float distance)
{
var length = 0.15f;
var thrustEnd = 0.05f;
return new Animation()
{
Length = TimeSpan.FromSeconds(length),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Rotation.RotateVec(new Vector2(0f, -distance / 5f)), 0f),
new AnimationTrackProperty.KeyFrame(sprite.Rotation.RotateVec(new Vector2(0f, -distance)), thrustEnd),
new AnimationTrackProperty.KeyFrame(sprite.Rotation.RotateVec(new Vector2(0f, -distance)), length),
}
},
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Color),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Color, thrustEnd),
new AnimationTrackProperty.KeyFrame(sprite.Color.WithAlpha(0f), length),
}
}
}
};
}
/// <summary>
/// Get the fadeout for static weapon arcs.
/// </summary>
private Animation GetStaticAnimation(SpriteComponent sprite)
{
var length = 0.15f;
return new()
{
Length = TimeSpan.FromSeconds(length),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Color),
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Color, 0f),
new AnimationTrackProperty.KeyFrame(sprite.Color.WithAlpha(0f), length)
}
}
}
};
}
/// <summary>
/// Get the sprite offset animation to use for mob lunges.
/// </summary>
private Animation GetLungeAnimation(Vector2 direction)
{
var length = 0.1f;
return new Animation
{
Length = TimeSpan.FromSeconds(length),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(direction.Normalized * 0.15f, 0f),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, length)
}
}
}
};
}
}

View File

@@ -0,0 +1,135 @@
using Content.Client.DoAfter;
using Content.Client.Resources;
using Content.Shared.Weapons.Melee;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.Weapons.Melee;
public sealed class MeleeWindupOverlay : Overlay
{
private readonly IEntityManager _entManager;
private readonly IGameTiming _timing;
private readonly SharedTransformSystem _transform;
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;
private readonly Texture _texture;
private readonly ShaderInstance _shader;
public MeleeWindupOverlay(IEntityManager entManager, IGameTiming timing, IPrototypeManager protoManager, IResourceCache cache)
{
_entManager = entManager;
_timing = timing;
_transform = _entManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
_texture = cache.GetTexture("/Textures/Interface/Misc/progress_bar.rsi/icon.png");
_shader = protoManager.Index<ShaderPrototype>("unshaded").Instance();
}
protected override void Draw(in OverlayDrawArgs args)
{
var handle = args.WorldHandle;
var rotation = args.Viewport.Eye?.Rotation ?? Angle.Zero;
var spriteQuery = _entManager.GetEntityQuery<SpriteComponent>();
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
var tickTime = (float) _timing.TickPeriod.TotalSeconds;
var tickFraction = _timing.TickFraction / (float) ushort.MaxValue * tickTime;
// If you use the display UI scale then need to set max(1f, displayscale) because 0 is valid.
const float scale = 1f;
var scaleMatrix = Matrix3.CreateScale(new Vector2(scale, scale));
var rotationMatrix = Matrix3.CreateRotation(-rotation);
handle.UseShader(_shader);
var currentTime = _timing.CurTime;
foreach (var comp in _entManager.EntityQuery<MeleeWeaponComponent>(true))
{
if (comp.WindUpStart == null ||
comp.Attacking)
{
continue;
}
if (!xformQuery.TryGetComponent(comp.Owner, out var xform) ||
xform.MapID != args.MapId)
{
continue;
}
var worldPosition = _transform.GetWorldPosition(xform);
var worldMatrix = Matrix3.CreateTranslation(worldPosition);
Matrix3.Multiply(scaleMatrix, worldMatrix, out var scaledWorld);
Matrix3.Multiply(rotationMatrix, scaledWorld, out var matty);
handle.SetTransform(matty);
var offset = -_texture.Height / scale;
// Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped
// by the bar.
float yOffset;
if (spriteQuery.TryGetComponent(comp.Owner, out var sprite))
{
yOffset = -sprite.Bounds.Height / 2f - 0.05f;
}
else
{
yOffset = -0.5f;
}
// Position above the entity (we've already applied the matrix transform to the entity itself)
// Offset by the texture size for every do_after we have.
var position = new Vector2(-_texture.Width / 2f / EyeManager.PixelsPerMeter,
yOffset / scale + offset / EyeManager.PixelsPerMeter * scale);
// Draw the underlying bar texture
handle.DrawTexture(_texture, position);
// Draw the items overlapping the texture
const float startX = 2f;
const float endX = 22f;
// Area marking where to release
var ReleaseWidth = 2f * SharedMeleeWeaponSystem.GracePeriod / (float) comp.WindupTime.TotalSeconds * EyeManager.PixelsPerMeter;
var releaseMiddle = (endX - startX) / 2f + startX;
var releaseBox = new Box2(new Vector2(releaseMiddle - ReleaseWidth / 2f, 3f) / EyeManager.PixelsPerMeter,
new Vector2(releaseMiddle + ReleaseWidth / 2f, 4f) / EyeManager.PixelsPerMeter);
releaseBox = releaseBox.Translated(position);
handle.DrawRect(releaseBox, Color.LimeGreen);
// Wraps around back to 0
var totalDuration = comp.WindupTime.TotalSeconds * 2;
var elapsed = (currentTime - comp.WindUpStart.Value).TotalSeconds % (2 * totalDuration);
var value = elapsed / totalDuration;
if (value > 1)
{
value = 2 - value;
}
var fraction = (float) value;
var xPos = (endX - startX) * fraction + startX;
// In pixels
const float Width = 2f;
// If we hit the end we won't draw half the box so we need to subtract the end pos from it
var endPos = xPos + Width / 2f;
var box = new Box2(new Vector2(Math.Max(startX, endPos - Width), 3f) / EyeManager.PixelsPerMeter,
new Vector2(Math.Min(endX, endPos), 4f) / EyeManager.PixelsPerMeter);
box = box.Translated(position);
handle.DrawRect(box, Color.White);
}
handle.UseShader(null);
handle.SetTransform(Matrix3.Identity);
}
}

View File

@@ -5,7 +5,7 @@ namespace Content.Client.Weapons.Ranged;
public sealed class ShowSpreadCommand : IConsoleCommand
{
public string Command => "showspread";
public string Command => "showgunspread";
public string Description => $"Shows gun spread overlay for debugging";
public string Help => $"{Command}";
public void Execute(IConsoleShell shell, string argStr, string[] args)

View File

@@ -13,11 +13,11 @@ public sealed class GunSpreadOverlay : Overlay
public override OverlaySpace Space => OverlaySpace.WorldSpace;
private IEntityManager _entManager;
private IEyeManager _eye;
private IGameTiming _timing;
private IInputManager _input;
private IPlayerManager _player;
private GunSystem _guns;
private readonly IEyeManager _eye;
private readonly IGameTiming _timing;
private readonly IInputManager _input;
private readonly IPlayerManager _player;
private readonly GunSystem _guns;
public GunSpreadOverlay(IEntityManager entManager, IEyeManager eyeManager, IGameTiming timing, IInputManager input, IPlayerManager player, GunSystem system)
{

View File

@@ -6,11 +6,9 @@ using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Weapons.Melee;
using NUnit.Framework;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Reflection;
@@ -78,18 +76,14 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(entitySystemManager.TryGetEntitySystem<InteractionSystem>(out var interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem<TestInteractionSystem>(out var testInteractionSystem));
var attack = false;
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(target)); attack = true; };
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, false, target);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(attack);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
@@ -144,18 +138,14 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(entitySystemManager.TryGetEntitySystem<InteractionSystem>(out var interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem<TestInteractionSystem>(out var testInteractionSystem));
var attack = false;
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(target)); attack = true; };
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, false, target);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(attack, Is.False);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
@@ -208,18 +198,14 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(entitySystemManager.TryGetEntitySystem<InteractionSystem>(out var interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem<TestInteractionSystem>(out var testInteractionSystem));
var attack = false;
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(target)); attack = true; };
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, false, target);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(attack);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
@@ -273,18 +259,14 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(entitySystemManager.TryGetEntitySystem<InteractionSystem>(out var interactionSystem));
Assert.That(entitySystemManager.TryGetEntitySystem<TestInteractionSystem>(out var testInteractionSystem));
var attack = false;
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
{
testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(target)); attack = true; };
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(target)); interactHand = true; };
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, false, target);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(attack, Is.False);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
@@ -344,7 +326,6 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
await server.WaitIdleAsync();
var attack = false;
var interactUsing = false;
var interactHand = false;
await server.WaitAssertion(() =>
@@ -352,19 +333,14 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
Assert.That(container.Insert(user));
Assert.That(sEntities.GetComponent<TransformComponent>(user).Parent.Owner, Is.EqualTo(containerEntity));
testInteractionSystem.AttackEvent = (_, _, ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); attack = true; };
testInteractionSystem.InteractUsingEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactUsing = true; };
testInteractionSystem.InteractHandEvent = (ev) => { Assert.That(ev.Target, Is.EqualTo(containerEntity)); interactHand = true; };
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, false, target);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
Assert.That(attack, Is.False);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand, Is.False);
interactionSystem.DoAttack(user, sEntities.GetComponent<TransformComponent>(containerEntity).Coordinates, false, containerEntity);
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(containerEntity).Coordinates, containerEntity);
Assert.That(attack);
Assert.That(interactUsing, Is.False);
Assert.That(interactHand);
@@ -383,14 +359,12 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
[Reflect(false)]
public sealed class TestInteractionSystem : EntitySystem
{
public ComponentEventHandler<HandsComponent, ClickAttackEvent>? AttackEvent;
public EntityEventHandler<InteractUsingEvent>? InteractUsingEvent;
public EntityEventHandler<InteractHandEvent>? InteractHandEvent;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HandsComponent, ClickAttackEvent>((u, c, e) => AttackEvent?.Invoke(u, c, e));
SubscribeLocalEvent<InteractUsingEvent>((e) => InteractUsingEvent?.Invoke(e));
SubscribeLocalEvent<InteractHandEvent>((e) => InteractHandEvent?.Invoke(e));
}

View File

@@ -1,13 +1,6 @@
using Content.Server.Weapon.Melee;
using Content.Server.Stunnable;
using Content.Shared.Inventory.Events;
using Content.Server.Weapon.Melee.Components;
using Content.Server.Clothing.Components;
using Content.Server.Damage.Components;
using Content.Server.Damage.Events;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Weapons.Melee;
using Robust.Shared.Containers;
namespace Content.Server.Abilities.Boxer
@@ -24,25 +17,22 @@ namespace Content.Server.Abilities.Boxer
SubscribeLocalEvent<BoxingGlovesComponent, StaminaMeleeHitEvent>(OnStamHit);
}
private void OnInit(EntityUid uid, BoxerComponent boxer, ComponentInit args)
private void OnInit(EntityUid uid, BoxerComponent component, ComponentInit args)
{
if (TryComp<MeleeWeaponComponent>(uid, out var meleeComp))
meleeComp.Range *= boxer.RangeBonus;
meleeComp.Range *= component.RangeBonus;
}
private void GetDamageModifiers(EntityUid uid, BoxerComponent component, ItemMeleeDamageEvent args)
{
if (component.UnarmedModifiers == default!)
{
Logger.Warning("BoxerComponent on " + uid + " couldn't get damage modifiers. Know that adding components with damage modifiers through VV or similar is unsupported.");
return;
}
args.ModifiersList.Add(component.UnarmedModifiers);
}
private void OnStamHit(EntityUid uid, BoxingGlovesComponent component, StaminaMeleeHitEvent args)
{
_containerSystem.TryGetContainingContainer(uid, out var equipee);
if (TryComp<BoxerComponent>(equipee?.Owner, out var boxer))
if (!_containerSystem.TryGetContainingContainer(uid, out var equipee))
return;
if (TryComp<BoxerComponent>(equipee.Owner, out var boxer))
args.Multiplier *= boxer.BoxingGlovesModifier;
}
}

View File

@@ -3,7 +3,7 @@ using Content.Server.Atmos.Components;
using Content.Server.Stunnable;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Server.Weapon.Melee;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.ActionBlocker;
using Content.Shared.Alert;
using Content.Shared.Atmos;

View File

@@ -81,7 +81,10 @@ namespace Content.Server.Atmos.EntitySystems
{
component.Target = target;
component.User = user;
component.LastPosition = Transform(target ?? user).Coordinates;
if (target != null)
component.LastPosition = Transform(target.Value).Coordinates;
else
component.LastPosition = null;
component.Enabled = true;
Dirty(component);
UpdateAppearance(component);

View File

@@ -1,5 +1,7 @@
using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Atmos.Piping.Unary.Components
{
@@ -55,7 +57,7 @@ namespace Content.Server.Atmos.Piping.Unary.Components
/// </summary>
[DataField("baseMinTemperature")]
[ViewVariables(VVAccess.ReadWrite)]
public float BaseMinTemperature = 96.625f; // Selected so that tier-1 parts can reach 73.15k
public float BaseMinTemperature = 96.625f; // Selected so that tier-1 parts can reach 73.15k
/// <summary>
/// Maximum temperature the device can reach with a 0 total laser quality. Usually the quality will be at
@@ -78,5 +80,17 @@ namespace Content.Server.Atmos.Piping.Unary.Components
[DataField("maxTemperatureDelta")]
[ViewVariables(VVAccess.ReadWrite)]
public float MaxTemperatureDelta = 300;
/// <summary>
/// The machine part that affects the heat capacity.
/// </summary>
[DataField("machinePartHeatCapacity", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartHeatCapacity = "MatterBin";
/// <summary>
/// The machine part that affects the temperature range.
/// </summary>
[DataField("machinePartTemperature", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartTemperature = "Laser";
}
}

View File

@@ -15,6 +15,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
[UsedImplicitly]
public sealed class GasThermoMachineSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
@@ -33,14 +34,12 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnThermoMachineUpdated(EntityUid uid, GasThermoMachineComponent thermoMachine, AtmosDeviceUpdateEvent args)
{
var appearance = EntityManager.GetComponentOrNull<AppearanceComponent>(thermoMachine.Owner);
if (!thermoMachine.Enabled
|| !EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)
|| !nodeContainer.TryGetNode(thermoMachine.InletName, out PipeNode? inlet))
{
DirtyUI(uid, thermoMachine);
appearance?.SetData(ThermoMachineVisuals.Enabled, false);
_appearance.SetData(uid, ThermoMachineVisuals.Enabled, false);
return;
}
@@ -49,7 +48,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (!MathHelper.CloseTo(combinedHeatCapacity, 0, 0.001f))
{
appearance?.SetData(ThermoMachineVisuals.Enabled, true);
_appearance.SetData(uid, ThermoMachineVisuals.Enabled, true);
var combinedEnergy = thermoMachine.HeatCapacity * thermoMachine.TargetTemperature + airHeatCapacity * inlet.Air.Temperature;
inlet.Air.Temperature = combinedEnergy / combinedHeatCapacity;
}
@@ -59,38 +58,15 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
private void OnThermoMachineLeaveAtmosphere(EntityUid uid, GasThermoMachineComponent component, AtmosDeviceDisabledEvent args)
{
if (EntityManager.TryGetComponent(uid, out AppearanceComponent? appearance))
{
appearance.SetData(ThermoMachineVisuals.Enabled, false);
}
_appearance.SetData(uid, ThermoMachineVisuals.Enabled, false);
DirtyUI(uid, component);
}
private void OnGasThermoRefreshParts(EntityUid uid, GasThermoMachineComponent component, RefreshPartsEvent args)
{
// Here we evaluate the average quality of relevant machine parts.
var nLasers = 0;
var nBins= 0;
var matterBinRating = 0;
var laserRating = 0;
foreach (var part in args.Parts)
{
switch (part.PartType)
{
case MachinePart.MatterBin:
nBins += 1;
matterBinRating += part.Rating;
break;
case MachinePart.Laser:
nLasers += 1;
laserRating += part.Rating;
break;
}
}
laserRating /= nLasers;
matterBinRating /= nBins;
var matterBinRating = args.PartRatings[component.MachinePartHeatCapacity];
var laserRating = args.PartRatings[component.MachinePartTemperature];
component.HeatCapacity = 5000 * MathF.Pow(matterBinRating, 2);

View File

@@ -165,14 +165,13 @@ namespace Content.Server.Atmos.Portable
/// </summary>
private void OnScrubberAnalyzed(EntityUid uid, PortableScrubberComponent component, GasAnalyzerScanEvent args)
{
var gasMixDict = new Dictionary<string, GasMixture?>();
var gasMixDict = new Dictionary<string, GasMixture?> { { Name(uid), component.Air } };
// If it's connected to a port, include the port side
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
if (TryComp(uid, out NodeContainerComponent? nodeContainer))
{
if(nodeContainer != null && nodeContainer.TryGetNode(component.PortName, out PipeNode? port))
if(nodeContainer.TryGetNode(component.PortName, out PipeNode? port))
gasMixDict.Add(component.PortName, port.Air);
}
gasMixDict.Add(Name(uid), component.Air);
args.GasMixtures = gasMixDict;
}
}

View File

@@ -1,10 +0,0 @@
namespace Content.Server.BarSign
{
[RegisterComponent]
public sealed class BarSignComponent : Component
{
[DataField("current")]
[ViewVariables(VVAccess.ReadOnly)]
public string? CurrentSign;
}
}

View File

@@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Power.Components;
using Robust.Server.GameObjects;
using Content.Shared.BarSign;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
@@ -14,56 +13,20 @@ namespace Content.Server.BarSign.Systems
public override void Initialize()
{
SubscribeLocalEvent<BarSignComponent, PowerChangedEvent>(UpdateBarSignVisuals);
SubscribeLocalEvent<BarSignComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<BarSignComponent, ComponentGetState>(OnGetState);
}
private void UpdateBarSignVisuals(EntityUid owner, BarSignComponent component, PowerChangedEvent args)
private void OnGetState(EntityUid uid, BarSignComponent component, ref ComponentGetState args)
{
var lifestage = MetaData(owner).EntityLifeStage;
if (lifestage is < EntityLifeStage.Initialized or >= EntityLifeStage.Terminating) return;
if (!TryComp(owner, out SpriteComponent? sprite))
{
Logger.ErrorS("barSign", "Barsign is missing sprite component");
return;
}
if (!TryGetBarSignPrototype(component, out var prototype))
{
prototype = Setup(owner, component);
}
if (args.Powered)
{
sprite.LayerSetState(0, prototype.Icon);
sprite.LayerSetShader(0, "unshaded");
}
else
{
sprite.LayerSetState(0, "empty");
sprite.LayerSetShader(0, "shaded");
}
args.State = new BarSignComponentState(component.CurrentSign);
}
private bool TryGetBarSignPrototype(BarSignComponent component, [NotNullWhen(true)] out BarSignPrototype? prototype)
private void OnMapInit(EntityUid uid, BarSignComponent component, MapInitEvent args)
{
if (component.CurrentSign != null)
{
if (_prototypeManager.TryIndex(component.CurrentSign, out prototype))
{
return true;
}
Logger.ErrorS("barSign", $"Invalid bar sign prototype: \"{component.CurrentSign}\"");
}
else
{
prototype = null;
}
return false;
}
return;
private BarSignPrototype Setup(EntityUid owner, BarSignComponent component)
{
var prototypes = _prototypeManager
.EnumeratePrototypes<BarSignPrototype>()
.Where(p => !p.Hidden)
@@ -71,13 +34,13 @@ namespace Content.Server.BarSign.Systems
var newPrototype = _random.Pick(prototypes);
var meta = Comp<MetaDataComponent>(owner);
var meta = Comp<MetaDataComponent>(uid);
var name = newPrototype.Name != string.Empty ? newPrototype.Name : "barsign-component-name";
meta.EntityName = Loc.GetString(name);
meta.EntityDescription = Loc.GetString(newPrototype.Description);
component.CurrentSign = newPrototype.ID;
return newPrototype;
Dirty(component);
}
}
}

View File

@@ -78,7 +78,7 @@ namespace Content.Server.Bed
if (HasComp<SleepingComponent>(healedEntity))
damage *= bedComponent.SleepMultiplier;
_damageableSystem.TryChangeDamage(healedEntity, bedComponent.Damage, true);
_damageableSystem.TryChangeDamage(healedEntity, damage, true);
}
}
}

View File

@@ -1,3 +1,4 @@
using System.ComponentModel;
using Content.Server.Botany.Components;
using Content.Server.Botany.Systems;
using Content.Shared.Atmos;
@@ -68,21 +69,40 @@ public struct SeedChemQuantity
public class SeedData
{
#region Tracking
private string _name = String.Empty;
private string _noun = String.Empty;
private string _displayName = String.Empty;
/// <summary>
/// The name of this seed. Determines the name of seed packets.
/// </summary>
[DataField("name")] public string Name = string.Empty;
[DataField("name")]
public string Name
{
get => _name;
private set => _name = Loc.GetString(value);
}
/// <summary>
/// The noun for this type of seeds. E.g. for fungi this should probably be "spores" instead of "seeds". Also
/// used to determine the name of seed packets.
/// </summary>
[DataField("noun")] public string Noun = "seeds";
[DataField("noun")]
public string Noun
{
get => _noun;
private set => _noun = Loc.GetString(value);
}
/// <summary>
/// Name displayed when examining the hydroponics tray. Describes the actual plant, not the seed itself.
/// </summary>
[DataField("displayName")] public string DisplayName = string.Empty;
[DataField("displayName")]
public string DisplayName
{
get => _displayName;
private set => _displayName = Loc.GetString(value);
}
[DataField("mysterious")] public bool Mysterious;

View File

@@ -1,4 +0,0 @@
namespace Content.Server.CPUJob.JobQueues.Queues
{
public sealed class AiActionJobQueue : JobQueue {}
}

View File

@@ -259,12 +259,15 @@ public sealed partial class ChatSystem : SharedChatSystem
return;
}
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
RaiseLocalEvent(source, nameEv);
message = TransformSpeech(source, message);
if (message.Length == 0)
return;
var messageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",
("entityName", Name(source)));
("entityName", nameEv.Name));
SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);
_listener.PingListeners(source, message, null);
@@ -295,8 +298,12 @@ public sealed partial class ChatSystem : SharedChatSystem
var transformSource = Transform(source);
var sourceCoords = transformSource.Coordinates;
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
RaiseLocalEvent(source, nameEv);
var messageWrap = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", Name(source)));
("entityName", nameEv.Name));
var xforms = GetEntityQuery<TransformComponent>();
var ghosts = GetEntityQuery<GhostComponent>();
@@ -530,6 +537,18 @@ public sealed partial class ChatSystem : SharedChatSystem
#endregion
}
public sealed class TransformSpeakerNameEvent : EntityEventArgs
{
public EntityUid Sender;
public string Name;
public TransformSpeakerNameEvent(EntityUid sender, string name)
{
Sender = sender;
Name = name;
}
}
/// <summary>
/// Raised broadcast in order to transform speech.
/// </summary>

View File

@@ -1,7 +1,6 @@
using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Interaction.Components;
using Content.Server.Weapon.Melee;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
@@ -12,6 +11,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Player;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Interaction;
using Content.Server.Weapons.Melee;
namespace Content.Server.Chemistry.Components
{
@@ -78,7 +78,8 @@ namespace Content.Server.Chemistry.Components
target.Value.PopupMessage(Loc.GetString("hypospray-component-feel-prick-message"));
var meleeSys = EntitySystem.Get<MeleeWeaponSystem>();
var angle = Angle.FromWorldVec(_entMan.GetComponent<TransformComponent>(target.Value).WorldPosition - _entMan.GetComponent<TransformComponent>(user).WorldPosition);
meleeSys.SendLunge(angle, user);
// TODO: This should just be using melee attacks...
// meleeSys.SendLunge(angle, user);
}
SoundSystem.Play(_injectSound.GetSound(), Filter.Pvs(user), user);

View File

@@ -1,7 +1,10 @@
using System.Linq;
using Content.Server.Chemistry.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
namespace Content.Server.Chemistry.EntitySystems
{
@@ -10,7 +13,7 @@ namespace Content.Server.Chemistry.EntitySystems
private void InitializeHypospray()
{
SubscribeLocalEvent<HyposprayComponent, AfterInteractEvent>(OnAfterInteract);
SubscribeLocalEvent<HyposprayComponent, ClickAttackEvent>(OnClickAttack);
SubscribeLocalEvent<HyposprayComponent, MeleeHitEvent>(OnAttack);
SubscribeLocalEvent<HyposprayComponent, SolutionChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
}
@@ -39,12 +42,12 @@ namespace Content.Server.Chemistry.EntitySystems
comp.TryDoInject(target, user);
}
public void OnClickAttack(EntityUid uid, HyposprayComponent comp, ClickAttackEvent args)
public void OnAttack(EntityUid uid, HyposprayComponent comp, MeleeHitEvent args)
{
if (args.Target == null)
if (!args.HitEntities.Any())
return;
comp.TryDoInject(args.Target.Value, args.User);
comp.TryDoInject(args.HitEntities.First(), args.User);
}
}
}

View File

@@ -17,6 +17,7 @@ using Content.Server.MobState;
using Content.Shared.Chemistry.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Chat.Systems;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Materials;
using Content.Server.Stack;
@@ -31,7 +32,6 @@ using Robust.Shared.Configuration;
using Robust.Shared.Containers;
using Robust.Shared.Physics.Components;
namespace Content.Server.Cloning.Systems
{
public sealed class CloningSystem : EntitySystem
@@ -48,6 +48,7 @@ namespace Content.Server.Cloning.Systems
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly TransformSystem _transformSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedStackSystem _stackSystem = default!;
[Dependency] private readonly StackSystem _serverStackSystem = default!;
[Dependency] private readonly SpillableSystem _spillableSystem = default!;
@@ -63,6 +64,7 @@ namespace Content.Server.Cloning.Systems
base.Initialize();
SubscribeLocalEvent<CloningPodComponent, ComponentInit>(OnComponentInit);
SubscribeLocalEvent<CloningPodComponent, RefreshPartsEvent>(OnPartsRefreshed);
SubscribeLocalEvent<CloningPodComponent, MachineDeconstructedEvent>(OnDeconstruct);
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<BeingClonedComponent, MindAddedMessage>(HandleMindAdded);
@@ -77,17 +79,20 @@ namespace Content.Server.Cloning.Systems
_signalSystem.EnsureReceiverPorts(uid, CloningPodComponent.PodPort);
}
private void OnPartsRefreshed(EntityUid uid, CloningPodComponent component, RefreshPartsEvent args)
{
var materialRating = args.PartRatings[component.MachinePartMaterialUse];
var speedRating = args.PartRatings[component.MachinePartCloningSpeed];
component.BiomassRequirementMultiplier = MathF.Pow(component.PartRatingMaterialMultiplier, materialRating - 1);
component.CloningTime = component.BaseCloningTime * MathF.Pow(component.PartRatingSpeedMultiplier, speedRating - 1);
}
private void OnDeconstruct(EntityUid uid, CloningPodComponent component, MachineDeconstructedEvent args)
{
_serverStackSystem.SpawnMultiple(_material.GetMaterialAmount(uid, "Biomass"), 100, "Biomass", Transform(uid).Coordinates);
}
private void UpdateAppearance(CloningPodComponent clonePod)
{
if (TryComp<AppearanceComponent>(clonePod.Owner, out var appearance))
appearance.SetData(CloningPodVisuals.Status, clonePod.Status);
}
internal void TransferMindToClone(Mind.Mind mind)
{
if (!ClonesWaitingForMind.TryGetValue(mind, out var entity) ||
@@ -106,7 +111,7 @@ namespace Content.Server.Cloning.Systems
if (clonedComponent.Parent == EntityUid.Invalid ||
!EntityManager.EntityExists(clonedComponent.Parent) ||
!TryComp<CloningPodComponent>(clonedComponent.Parent, out var cloningPodComponent) ||
clonedComponent.Owner != cloningPodComponent.BodyContainer?.ContainedEntity)
clonedComponent.Owner != cloningPodComponent.BodyContainer.ContainedEntity)
{
EntityManager.RemoveComponent<BeingClonedComponent>(clonedComponent.Owner);
return;
@@ -142,7 +147,7 @@ namespace Content.Server.Cloning.Systems
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod)
{
if (!Resolve(uid, ref clonePod) || bodyToClone == null)
if (!Resolve(uid, ref clonePod))
return false;
if (HasComp<ActiveCloningPodComponent>(uid))
@@ -175,7 +180,7 @@ namespace Content.Server.Cloning.Systems
if (!TryComp<PhysicsComponent>(bodyToClone, out var physics))
return false;
int cloningCost = (int) physics.FixturesMass;
var cloningCost = (int) Math.Round(physics.FixturesMass * clonePod.BiomassRequirementMultiplier);
if (_configManager.GetCVar(CCVars.BiomassEasyMode))
cloningCost = (int) Math.Round(cloningCost * EasyModeCloningCost);
@@ -221,7 +226,6 @@ namespace Content.Server.Cloning.Systems
cloneMindReturn.Mind = mind;
cloneMindReturn.Parent = clonePod.Owner;
clonePod.BodyContainer.Insert(mob);
clonePod.CapturedMind = mind;
ClonesWaitingForMind.Add(mind, mob);
UpdateStatus(CloningPodStatus.NoMind, clonePod);
_euiManager.OpenEui(new AcceptCloningEui(mind, this), client);
@@ -235,7 +239,7 @@ namespace Content.Server.Cloning.Systems
{
foreach (var special in mind.CurrentJob.Prototype.Special)
{
if (special.GetType() == typeof(AddComponentSpecial))
if (special is AddComponentSpecial)
special.AfterEquip(mob);
}
}
@@ -246,7 +250,7 @@ namespace Content.Server.Cloning.Systems
public void UpdateStatus(CloningPodStatus status, CloningPodComponent cloningPod)
{
cloningPod.Status = status;
UpdateAppearance(cloningPod);
_appearance.SetData(cloningPod.Owner, CloningPodVisuals.Status, cloningPod.Status);
}
public override void Update(float frameTime)
@@ -280,7 +284,6 @@ namespace Content.Server.Cloning.Systems
EntityManager.RemoveComponent<BeingClonedComponent>(entity);
clonePod.BodyContainer.Remove(entity);
clonePod.CapturedMind = null;
clonePod.CloningProgress = 0f;
clonePod.UsedBiomass = 0;
UpdateStatus(CloningPodStatus.Idle, clonePod);

View File

@@ -1,5 +1,7 @@
using Content.Shared.Cloning;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Containers;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Cloning.Components
{
@@ -7,14 +9,69 @@ namespace Content.Server.Cloning.Components
public sealed class CloningPodComponent : Component
{
public const string PodPort = "CloningPodReceiver";
[ViewVariables] public ContainerSlot BodyContainer = default!;
[ViewVariables] public Mind.Mind? CapturedMind;
[ViewVariables] public float CloningProgress = 0;
[ViewVariables] public int UsedBiomass = 70;
[ViewVariables] public bool FailedClone = false;
[DataField("cloningTime")]
[ViewVariables] public float CloningTime = 30f;
[ViewVariables] public CloningPodStatus Status;
[ViewVariables]
public ContainerSlot BodyContainer = default!;
/// <summary>
/// How long the cloning has been going on for.
/// </summary>
[ViewVariables]
public float CloningProgress = 0;
[ViewVariables]
public int UsedBiomass = 70;
[ViewVariables]
public bool FailedClone = false;
/// <summary>
/// The base amount of time it takes to clone a body
/// </summary>
[DataField("baseCloningTime")]
public float BaseCloningTime = 30f;
/// <summary>
/// The multiplier for cloning duration
/// </summary>
[DataField("partRatingSpeedMultiplier")]
public float PartRatingSpeedMultiplier = 0.75f;
/// <summary>
/// The machine part that affects cloning speed
/// </summary>
[DataField("machinePartCloningSpeed", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartCloningSpeed = "ScanningModule";
/// <summary>
/// The current amount of time it takes to clone a body
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float CloningTime = 30f;
/// <summary>
/// The machine part that affects how much biomass is needed to clone a body.
/// </summary>
[DataField("partRatingMaterialMultiplier")]
public float PartRatingMaterialMultiplier = 0.85f;
/// <summary>
/// The current multiplier on the body weight, which determines the
/// amount of biomass needed to clone.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float BiomassRequirementMultiplier = 1;
/// <summary>
/// The machine part that decreases the amount of material needed for cloning
/// </summary>
[DataField("machinePartMaterialUse", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartMaterialUse = "Manipulator";
[ViewVariables(VVAccess.ReadWrite)]
public CloningPodStatus Status;
[ViewVariables]
public EntityUid? ConnectedConsole;
}
}

View File

@@ -13,6 +13,7 @@ using Content.Server.Disease.Components;
using Content.Server.IdentityManagement;
using Content.Server.Nutrition.EntitySystems;
using Content.Server.Popups;
using Content.Server.VoiceMask;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.IdentityManagement.Components;
using Robust.Shared.Player;
@@ -87,6 +88,8 @@ namespace Content.Server.Clothing
_clothing.SetEquippedPrefix(uid, mask.IsToggled ? "toggled" : null, clothing);
}
// shouldn't this be an event?
// toggle ingestion blocking
if (TryComp<IngestionBlockerComponent>(uid, out var blocker))
blocker.Enabled = !mask.IsToggled;
@@ -99,6 +102,10 @@ namespace Content.Server.Clothing
if (TryComp<IdentityBlockerComponent>(uid, out var identity))
identity.Enabled = !mask.IsToggled;
// toggle voice masking
if (TryComp<VoiceMaskComponent>(uid, out var voiceMask))
voiceMask.Enabled = !mask.IsToggled;
// toggle breath tool connection (skip during equip since that is handled in LungSystem)
if (isEquip || !TryComp<BreathToolComponent>(uid, out var breathTool))
return;

View File

@@ -1,132 +1,22 @@
using Content.Server.Actions.Events;
using Content.Server.Administration.Components;
using Content.Server.Administration.Logs;
using Content.Server.CombatMode.Disarm;
using Content.Server.Hands.Components;
using Content.Server.Popups;
using Content.Server.Contests;
using Content.Server.Weapon.Melee;
using Content.Shared.ActionBlocker;
using Content.Shared.Audio;
using Content.Shared.CombatMode;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.IdentityManagement;
using Content.Shared.Stunnable;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Physics;
using Robust.Shared.GameStates;
namespace Content.Server.CombatMode
{
[UsedImplicitly]
public sealed class CombatModeSystem : SharedCombatModeSystem
{
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly MeleeWeaponSystem _meleeWeaponSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger= default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ContestsSystem _contests = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedCombatModeComponent, DisarmActionEvent>(OnEntityActionPerform);
SubscribeLocalEvent<SharedCombatModeComponent, ComponentGetState>(OnGetState);
}
private void OnEntityActionPerform(EntityUid uid, SharedCombatModeComponent component, DisarmActionEvent args)
private void OnGetState(EntityUid uid, SharedCombatModeComponent component, ref ComponentGetState args)
{
if (args.Handled)
return;
if (!_actionBlockerSystem.CanAttack(args.Performer))
return;
if (TryComp<HandsComponent>(args.Performer, out var hands)
&& hands.ActiveHand != null
&& !hands.ActiveHand.IsEmpty)
{
_popupSystem.PopupEntity(Loc.GetString("disarm-action-free-hand"), args.Performer, Filter.Entities(args.Performer));
return;
}
EntityUid? inTargetHand = null;
if (TryComp<HandsComponent>(args.Target, out HandsComponent? targetHandsComponent)
&& targetHandsComponent.ActiveHand != null
&& !targetHandsComponent.ActiveHand.IsEmpty)
{
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
}
var attemptEvent = new DisarmAttemptEvent(args.Target, args.Performer,inTargetHand);
if (inTargetHand != null)
{
RaiseLocalEvent(inTargetHand.Value, attemptEvent, true);
}
RaiseLocalEvent(args.Target, attemptEvent, true);
if (attemptEvent.Cancelled)
return;
var diff = Transform(args.Target).MapPosition.Position - Transform(args.Performer).MapPosition.Position;
var angle = Angle.FromWorldVec(diff);
var filterAll = Filter.Pvs(args.Performer);
var filterOther = filterAll.RemoveWhereAttachedEntity(e => e == args.Performer);
args.Handled = true;
var chance = CalculateDisarmChance(args.Performer, args.Target, inTargetHand, component);
if (_random.Prob(chance))
{
SoundSystem.Play(component.DisarmFailSound.GetSound(), Filter.Pvs(args.Performer), args.Performer, AudioHelpers.WithVariation(0.025f));
var msgOther = Loc.GetString(
"disarm-action-popup-message-other-clients",
("performerName", Identity.Entity(args.Performer, EntityManager)),
("targetName", Identity.Entity(args.Target, EntityManager)));
var msgUser = Loc.GetString("disarm-action-popup-message-cursor", ("targetName", Identity.Entity(args.Target, EntityManager)));
_popupSystem.PopupEntity(msgOther, args.Performer, filterOther);
_popupSystem.PopupEntity(msgUser, args.Performer, Filter.Entities(args.Performer));
_meleeWeaponSystem.SendLunge(angle, args.Performer);
return;
}
_meleeWeaponSystem.SendAnimation("disarm", angle, args.Performer, args.Performer, new[] { args.Target });
SoundSystem.Play(component.DisarmSuccessSound.GetSound(), filterAll, args.Performer, AudioHelpers.WithVariation(0.025f));
_adminLogger.Add(LogType.DisarmedAction, $"{ToPrettyString(args.Performer):user} used disarm on {ToPrettyString(args.Target):target}");
var eventArgs = new DisarmedEvent() { Target = args.Target, Source = args.Performer, PushProbability = (1 - chance) };
RaiseLocalEvent(args.Target, eventArgs, true);
}
private float CalculateDisarmChance(EntityUid disarmer, EntityUid disarmed, EntityUid? inTargetHand, SharedCombatModeComponent disarmerComp)
{
if (HasComp<DisarmProneComponent>(disarmer))
return 1.0f;
if (HasComp<DisarmProneComponent>(disarmed))
return 0.0f;
var contestResults = 1 - _contests.OverallStrengthContest(disarmer, disarmed);
float chance = (disarmerComp.BaseDisarmFailChance + contestResults);
if (inTargetHand != null && TryComp<DisarmMalusComponent>(inTargetHand, out var malus))
{
chance += malus.Malus;
}
return Math.Clamp(chance, 0f, 1f);
args.State = new CombatModeComponentState(component.IsInCombatMode, component.ActiveZone);
}
}
}

View File

@@ -1,5 +1,7 @@
using Content.Shared.Construction.Prototypes;
using Content.Shared.Stacks;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Server.Construction.Components
{
@@ -9,8 +11,8 @@ namespace Content.Server.Construction.Components
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables]
[DataField("requirements")]
public readonly Dictionary<MachinePart, int> Requirements = new();
[DataField("requirements", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, MachinePartPrototype>))]
public readonly Dictionary<string, int> Requirements = new();
[ViewVariables]
[DataField("materialRequirements")]

View File

@@ -1,9 +1,11 @@
using System.Threading.Tasks;
using Content.Server.Stack;
using Content.Shared.Construction;
using Content.Shared.Construction.Prototypes;
using Content.Shared.Interaction;
using Content.Shared.Tag;
using Robust.Shared.Containers;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Server.Construction.Components
{
@@ -16,8 +18,8 @@ namespace Content.Server.Construction.Components
[ViewVariables]
public bool HasBoard => BoardContainer?.ContainedEntities.Count != 0;
[ViewVariables]
public readonly Dictionary<MachinePart, int> Progress = new();
[DataField("progress", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, MachinePartPrototype>)), ViewVariables]
public readonly Dictionary<string, int> Progress = new();
[ViewVariables]
public readonly Dictionary<string, int> MaterialProgress = new();
@@ -28,8 +30,8 @@ namespace Content.Server.Construction.Components
[ViewVariables]
public readonly Dictionary<string, int> TagProgress = new();
[ViewVariables]
public Dictionary<MachinePart, int> Requirements = new();
[DataField("requirements", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, MachinePartPrototype>)),ViewVariables]
public Dictionary<string, int> Requirements = new();
[ViewVariables]
public Dictionary<string, int> MaterialRequirements = new();

View File

@@ -1,25 +1,14 @@
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Construction.Components
{
[RegisterComponent]
public sealed class MachinePartComponent : Component
{
// I'm so sorry for hard-coding this. But trust me, it should make things less painful.
public static IReadOnlyDictionary<MachinePart, string> Prototypes { get; } = new Dictionary<MachinePart, string>()
{
{MachinePart.Capacitor, "CapacitorStockPart"},
{MachinePart.ScanningModule, "ScanningModuleStockPart"},
{MachinePart.Manipulator, "MicroManipulatorStockPart"},
{MachinePart.Laser, "MicroLaserStockPart"},
{MachinePart.MatterBin, "MatterBinStockPart"},
{MachinePart.Ansible, "AnsibleSubspaceStockPart"},
{MachinePart.Filter, "FilterSubspaceStockPart"},
{MachinePart.Amplifier, "AmplifierSubspaceStockPart"},
{MachinePart.Treatment, "TreatmentSubspaceStockPart"},
{MachinePart.Analyzer, "AnalyzerSubspaceStockPart"},
{MachinePart.Crystal, "CrystalSubspaceStockPart"},
{MachinePart.Transmitter, "TransmitterSubspaceStockPart"}
};
[ViewVariables] [DataField("part")] public MachinePart PartType { get; private set; } = MachinePart.Capacitor;
[ViewVariables]
[DataField("part", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string PartType { get; private set; } = default!;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("rating")]

View File

@@ -13,8 +13,9 @@ namespace Content.Server.Construction.Conditions
public bool Condition(EntityUid uid, IEntityManager entityManager)
{
//if it doesn't have a wire panel, then just let it work.
if (!entityManager.TryGetComponent(uid, out WiresComponent? wires))
return false;
return true;
return wires.IsPanelOpen == Open;
}

View File

@@ -1,4 +1,6 @@
using System.Linq;
using Content.Server.Construction.Components;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Containers;
namespace Content.Server.Construction;
@@ -36,11 +38,32 @@ public sealed partial class ConstructionSystem
return parts;
}
public Dictionary<string, float> GetPartsRatings(List<MachinePartComponent> parts)
{
var output = new Dictionary<string, float>();
foreach (var type in _prototypeManager.EnumeratePrototypes<MachinePartPrototype>())
{
var amount = 0;
var sumRating = 0;
foreach (var part in parts.Where(part => part.PartType == type.ID))
{
amount++;
sumRating += part.Rating;
}
var rating = amount != 0 ? sumRating / amount : 0;
output.Add(type.ID, rating);
}
return output;
}
public void RefreshParts(MachineComponent component)
{
EntityManager.EventBus.RaiseLocalEvent(component.Owner, new RefreshPartsEvent()
var parts = GetAllParts(component);
EntityManager.EventBus.RaiseLocalEvent(component.Owner, new RefreshPartsEvent
{
Parts = GetAllParts(component),
Parts = parts,
PartRatings = GetPartsRatings(parts),
}, true);
}
@@ -69,14 +92,16 @@ public sealed partial class ConstructionSystem
throw new Exception($"Entity with prototype {component.BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!");
}
var xform = Transform(component.Owner);
foreach (var (part, amount) in machineBoard.Requirements)
{
var partProto = _prototypeManager.Index<MachinePartPrototype>(part);
for (var i = 0; i < amount; i++)
{
var p = EntityManager.SpawnEntity(MachinePartComponent.Prototypes[part], Transform(component.Owner).Coordinates);
var p = EntityManager.SpawnEntity(partProto.StockPartPrototype, xform.Coordinates);
if (!partContainer.Insert(p))
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}!");
throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {partProto.StockPartPrototype ?? "N/A"}!");
}
}
@@ -115,4 +140,6 @@ public sealed partial class ConstructionSystem
public sealed class RefreshPartsEvent : EntityEventArgs
{
public IReadOnlyList<MachinePartComponent> Parts = new List<MachinePartComponent>();
public Dictionary<string, float> PartRatings = new Dictionary<string, float>();
}

View File

@@ -183,7 +183,7 @@ public sealed class MachineFrameSystem : EntitySystem
public void ResetProgressAndRequirements(MachineFrameComponent component, MachineBoardComponent machineBoard)
{
component.Requirements = new Dictionary<MachinePart, int>(machineBoard.Requirements);
component.Requirements = new Dictionary<string, int>(machineBoard.Requirements);
component.MaterialRequirements = new Dictionary<string, int>(machineBoard.MaterialIdRequirements);
component.ComponentRequirements = new Dictionary<string, GenericPartInfo>(machineBoard.ComponentRequirements);
component.TagRequirements = new Dictionary<string, GenericPartInfo>(machineBoard.TagRequirements);

View File

@@ -1,20 +0,0 @@
namespace Content.Server.Construction
{
public enum MachinePart : byte
{
Capacitor,
ScanningModule,
Manipulator,
Laser,
MatterBin,
// Subspace parts.
Ansible,
Filter,
Amplifier,
Treatment,
Analyzer,
Crystal,
Transmitter,
}
}

View File

@@ -14,7 +14,7 @@ namespace Content.Server.Contests
/// >1 = Advantage to roller
/// <1 = Advantage to target
/// Roller should be the entity with an advantage from being bigger/healthier/more skilled, etc.
/// <summary>
/// </summary>
public sealed class ContestsSystem : EntitySystem
{
[Dependency] private readonly SharedMobStateSystem _mobStateSystem = default!;
@@ -27,13 +27,10 @@ namespace Content.Server.Contests
if (!Resolve(roller, ref rollerPhysics, false) || !Resolve(target, ref targetPhysics, false))
return 1f;
if (rollerPhysics == null || targetPhysics == null)
return 1f;
if (targetPhysics.FixturesMass == 0)
return 1f;
return (rollerPhysics.FixturesMass / targetPhysics.FixturesMass);
return rollerPhysics.FixturesMass / targetPhysics.FixturesMass;
}
/// <summary>
@@ -47,18 +44,15 @@ namespace Content.Server.Contests
if (!Resolve(roller, ref rollerDamage, false) || !Resolve(target, ref targetDamage, false))
return 1f;
if (rollerDamage == null || targetDamage == null)
return 1f;
// First, we'll see what health they go into crit at.
float rollerThreshold = 100f;
float targetThreshold = 100f;
if (TryComp<MobStateComponent>(roller, out var rollerState) && rollerState != null &&
if (TryComp<MobStateComponent>(roller, out var rollerState) &&
_mobStateSystem.TryGetEarliestIncapacitatedState(rollerState, 10000, out _, out var rollerCritThreshold))
rollerThreshold = (float) rollerCritThreshold;
if (TryComp<MobStateComponent>(target, out var targetState) && targetState != null &&
if (TryComp<MobStateComponent>(target, out var targetState) &&
_mobStateSystem.TryGetEarliestIncapacitatedState(targetState, 10000, out _, out var targetCritThreshold))
targetThreshold = (float) targetCritThreshold;
@@ -97,8 +91,9 @@ namespace Content.Server.Contests
var massMultiplier = massWeight / weightTotal;
var stamMultiplier = stamWeight / weightTotal;
return ((DamageContest(roller, target) * damageMultiplier) + (MassContest(roller, target) * massMultiplier)
+ (StaminaContest(roller, target) * stamMultiplier));
return DamageContest(roller, target) * damageMultiplier +
MassContest(roller, target) * massMultiplier +
StaminaContest(roller, target) * stamMultiplier;
}
/// <summary>
@@ -109,6 +104,7 @@ namespace Content.Server.Contests
{
return score switch
{
// TODO: Should just be a curve
<= 0 => 1f,
<= 0.25f => 0.9f,
<= 0.5f => 0.75f,

View File

@@ -19,6 +19,9 @@ namespace Content.Server.Cuffs.Components
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
private string _brokenName = string.Empty;
private string _brokenDesc = string.Empty;
/// <summary>
/// The time it takes to apply a <see cref="CuffedComponent"/> to an entity.
@@ -81,14 +84,22 @@ namespace Content.Server.Cuffs.Components
/// </summary>
[ViewVariables]
[DataField("brokenName")]
public string BrokenName { get; set; } = default!;
public string BrokenName
{
get => _brokenName;
private set => _brokenName = Loc.GetString(value);
}
/// <summary>
/// The iconstate used for broken handcuffs
/// </summary>
[ViewVariables]
[DataField("brokenDesc")]
public string BrokenDesc { get; set; } = default!;
public string BrokenDesc
{
get => _brokenDesc;
private set => _brokenDesc = Loc.GetString(value);
}
[ViewVariables]
public bool Broken

View File

@@ -7,10 +7,4 @@ public sealed class StaminaDamageOnHitComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("damage")]
public float Damage = 30f;
/// <summary>
/// Play a sound when this knocks down an entity.
/// </summary>
[DataField("knockdownSound")]
public SoundSpecifier? KnockdownSound;
}

View File

@@ -1,9 +1,9 @@
using Content.Server.Damage.Components;
using Content.Server.Damage.Events;
using Content.Server.Popups;
using Content.Server.Weapon.Melee;
using Content.Server.Administration.Logs;
using Content.Server.CombatMode;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Alert;
using Content.Shared.Rounding;
using Content.Shared.Stunnable;
@@ -123,7 +123,7 @@ public sealed class StaminaSystem : EntitySystem
foreach (var comp in toHit)
{
var oldDamage = comp.StaminaDamage;
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp, component.KnockdownSound);
TakeStaminaDamage(comp.Owner, damage / toHit.Count, comp);
if (comp.StaminaDamage.Equals(oldDamage))
{
_popup.PopupEntity(Loc.GetString("stamina-resist"), comp.Owner, Filter.Entities(args.User));
@@ -150,7 +150,7 @@ public sealed class StaminaSystem : EntitySystem
_alerts.ShowAlert(uid, AlertType.Stamina, (short) severity);
}
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null, SoundSpecifier? knockdownSound = null)
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null)
{
if (!Resolve(uid, ref component, false) || component.Critical) return;
@@ -181,8 +181,6 @@ public sealed class StaminaSystem : EntitySystem
{
if (component.StaminaDamage >= component.CritThreshold)
{
if (knockdownSound != null)
SoundSystem.Play(knockdownSound.GetSound(), Filter.Pvs(uid, entityManager: EntityManager), uid, knockdownSound.Params);
EnterStamCrit(uid, component);
}
}

View File

@@ -742,26 +742,14 @@ namespace Content.Server.Database
if (filter.AnyPlayers != null)
{
var players = await db.AdminLogPlayer
.Where(player => filter.AnyPlayers.Contains(player.PlayerUserId))
.ToListAsync();
if (players.Count > 0)
{
query = from log in query
join player in db.AdminLogPlayer on log.Id equals player.LogId
where filter.AnyPlayers.Contains(player.Player.UserId)
select log;
}
query = query.Where(log => log.Players.Any(p => filter.AnyPlayers.Contains(p.PlayerUserId)));
}
if (filter.AllPlayers != null)
{
// TODO ADMIN LOGGING
query = query.Where(log => log.Players.All(p => filter.AllPlayers.Contains(p.PlayerUserId)));
}
query = query.Distinct();
if (filter.LastLogId != null)
{
query = filter.DateOrder switch
@@ -781,9 +769,14 @@ namespace Content.Server.Database
$"Unknown {nameof(DateOrder)} value {filter.DateOrder}")
};
const int hardLogLimit = 500_000;
if (filter.Limit != null)
{
query = query.Take(filter.Limit.Value);
query = query.Take(Math.Min(filter.Limit.Value, hardLogLimit));
}
else
{
query = query.Take(hardLogLimit);
}
return query;

View File

@@ -25,6 +25,9 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
/// <summary>
/// Gets the given device list as a dictionary
/// </summary>
/// <remarks>
/// If any entity in the device list is pre-map init, it will show the entity UID of the device instead.
/// </remarks>
public Dictionary<string, EntityUid> GetDeviceList(EntityUid uid, DeviceListComponent? deviceList = null)
{
if (!Resolve(uid, ref deviceList))
@@ -37,7 +40,11 @@ public sealed class DeviceListSystem : SharedDeviceListSystem
if (!TryComp(deviceUid, out DeviceNetworkComponent? deviceNet))
continue;
devices.Add(deviceNet.Address, deviceUid);
var address = MetaData(deviceUid).EntityLifeStage == EntityLifeStage.MapInitialized
? deviceNet.Address
: $"UID: {deviceUid.ToString()}";
devices.Add(address, deviceUid);
}

View File

@@ -285,6 +285,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
_robustRandom.NextDouble() > 0.75 ||
!component.Container.Insert(args.Thrown))
{
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-thrown-missed"), uid, Filter.Pvs(uid));
return;
}

View File

@@ -170,7 +170,7 @@ public sealed class DoorSystem : SharedDoorSystem
args.Verbs.Add(new AlternativeVerb()
{
Text = "Pry door",
Text = Loc.GetString("door-pry"),
Impact = LogImpact.Low,
Act = () => TryPryDoor(uid, args.User, args.User, component, true),
});
@@ -180,7 +180,7 @@ public sealed class DoorSystem : SharedDoorSystem
/// <summary>
/// Pry open a door. This does not check if the user is holding the required tool.
/// </summary>
private bool TryPryDoor(EntityUid target, EntityUid tool, EntityUid user, DoorComponent door, bool force = false)
public bool TryPryDoor(EntityUid target, EntityUid tool, EntityUid user, DoorComponent door, bool force = false)
{
if (door.BeingPried)
return false;

View File

@@ -21,6 +21,7 @@ using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Audio;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;

View File

@@ -7,7 +7,6 @@ namespace Content.Server.Entry
"ConstructionGhost",
"IconSmooth",
"InteractionOutline",
"MeleeWeaponArcAnimation",
"AnimationsTest",
"ItemStatus",
"Marker",

View File

@@ -1,7 +1,7 @@
using Content.Server.Flash.Components;
using Content.Server.Light.EntitySystems;
using Content.Server.Stunnable;
using Content.Server.Weapon.Melee;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Examine;
using Content.Shared.Flash;
using Content.Shared.IdentityManagement;

View File

@@ -19,11 +19,14 @@ using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Linq;
using System.Threading.Tasks;
using Robust.Shared.Asynchronous;
namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
[Dependency] private readonly ITaskManager _taskManager = default!;
private static readonly Counter RoundNumberMetric = Metrics.CreateCounter(
"ss14_round_number",
"Round number.");
@@ -152,16 +155,18 @@ namespace Content.Server.GameTicking
var playerIds = _playerGameStatuses.Keys.Select(player => player.UserId).ToArray();
var serverName = _configurationManager.GetCVar(CCVars.AdminLogsServerName);
// TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN
// Task.Run as a terrible dirty workaround to avoid synchronization context deadlock from .Result here.
// This whole setup logic should be made asynchronous so we can properly wait on the DB AAAAAAAAAAAAAH
#pragma warning disable RA0004
RoundId = Task.Run(async () =>
var task = Task.Run(async () =>
{
var server = await _db.AddOrGetServer(serverName);
return await _db.AddNewRound(server, playerIds);
}).Result;
#pragma warning restore RA0004
});
_taskManager.BlockWaitOnTask(task);
RoundId = task.GetAwaiter().GetResult();
var startingEvent = new RoundStartingEvent(RoundId);
RaiseLocalEvent(startingEvent);

View File

@@ -1,5 +1,7 @@
using Content.Server.Radio.Components;
using Content.Server.VoiceMask;
using Content.Shared.Chat;
using Content.Shared.IdentityManagement;
using Content.Shared.Radio;
using Robust.Server.GameObjects;
using Robust.Shared.Network;
@@ -28,12 +30,19 @@ namespace Content.Server.Ghost.Components
var playerChannel = actor.PlayerSession.ConnectedClient;
var name = _entMan.GetComponent<MetaDataComponent>(speaker).EntityName;
if (_entMan.TryGetComponent(speaker, out VoiceMaskComponent? mask) && mask.Enabled)
{
name = Identity.Name(speaker, _entMan);
}
var msg = new MsgChatMessage
{
Channel = ChatChannel.Radio,
Message = message,
//Square brackets are added here to avoid issues with escaping
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(speaker).EntityName))
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
};
_netManager.ServerSendMessage(msg, playerChannel);

View File

@@ -1,7 +1,9 @@
using Content.Server.Chat.Systems;
using Content.Server.Radio.Components;
using Content.Server.Radio.EntitySystems;
using Content.Server.VoiceMask;
using Content.Shared.Chat;
using Content.Shared.IdentityManagement;
using Content.Shared.Radio;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
@@ -58,6 +60,13 @@ namespace Content.Server.Headset
var playerChannel = actor.PlayerSession.ConnectedClient;
var name = _entMan.GetComponent<MetaDataComponent>(source).EntityName;
if (_entMan.TryGetComponent(source, out VoiceMaskComponent? mask) && mask.Enabled)
{
name = Identity.Name(source, _entMan);
}
message = _chatSystem.TransformSpeech(source, message);
if (message.Length == 0)
return;
@@ -67,7 +76,7 @@ namespace Content.Server.Headset
Channel = ChatChannel.Radio,
Message = message,
//Square brackets are added here to avoid issues with escaping
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(source).EntityName))
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
};
_netManager.ServerSendMessage(msg, playerChannel);

View File

@@ -7,7 +7,4 @@ namespace Content.Server.CharacterAppearance.Components;
public sealed class RandomHumanoidAppearanceComponent : Component
{
[DataField("randomizeName")] public bool RandomizeName = true;
[DataField("ignoredSpecies", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<SpeciesPrototype>))]
public readonly HashSet<string> IgnoredSpecies = new();
}

View File

@@ -39,6 +39,7 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem
component.Species,
component.CustomBaseLayers,
component.SkinColor,
component.Sex,
component.AllHiddenLayers.ToList(),
component.CurrentMarkings.GetForwardEnumerator().ToList());
}
@@ -50,19 +51,20 @@ public sealed partial class HumanoidSystem : SharedHumanoidSystem
return;
}
SetSpecies(uid, humanoid.Species, false, humanoid);
if (!string.IsNullOrEmpty(humanoid.Initial)
&& _prototypeManager.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
if (string.IsNullOrEmpty(humanoid.Initial)
|| !_prototypeManager.TryIndex(humanoid.Initial, out HumanoidProfilePrototype? startingSet))
{
// Do this first, because profiles currently do not support custom base layers
foreach (var (layer, info) in startingSet.CustomBaseLayers)
{
humanoid.CustomBaseLayers.Add(layer, info);
}
LoadProfile(uid, startingSet.Profile, humanoid);
LoadProfile(uid, HumanoidCharacterProfile.DefaultWithSpecies(humanoid.Species), humanoid);
return;
}
// Do this first, because profiles currently do not support custom base layers
foreach (var (layer, info) in startingSet.CustomBaseLayers)
{
humanoid.CustomBaseLayers.Add(layer, info);
}
LoadProfile(uid, startingSet.Profile, humanoid);
}
private void OnExamined(EntityUid uid, HumanoidComponent component, ExaminedEvent args)

View File

@@ -17,14 +17,14 @@ public sealed class RandomHumanoidAppearanceSystem : EntitySystem
private void OnMapInit(EntityUid uid, RandomHumanoidAppearanceComponent component, MapInitEvent args)
{
// If we have an initial profile/base layer set, do not randomize this humanoid.
if (TryComp(uid, out HumanoidComponent? humanoid) && !string.IsNullOrEmpty(humanoid.Initial))
if (!TryComp(uid, out HumanoidComponent? humanoid) || !string.IsNullOrEmpty(humanoid.Initial))
{
return;
}
var profile = HumanoidCharacterProfile.Random(component.IgnoredSpecies);
var profile = HumanoidCharacterProfile.RandomWithSpecies(humanoid.Species);
_humanoid.LoadProfile(uid, profile);
_humanoid.LoadProfile(uid, profile, humanoid);
if (component.RandomizeName)
{

View File

@@ -1,18 +1,14 @@
using Content.Server.Administration.Logs;
using Content.Server.Hands.Components;
using Content.Server.Pulling;
using Content.Server.Storage.Components;
using Content.Server.Weapon.Melee.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Database;
using Content.Shared.DragDrop;
using Content.Shared.Input;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Pulling.Components;
using Content.Shared.Weapons.Melee;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
@@ -20,7 +16,6 @@ using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Players;
using Robust.Shared.Random;
using static Content.Shared.Storage.SharedStorageComponent;
namespace Content.Server.Interaction
{
@@ -34,9 +29,8 @@ namespace Content.Server.Interaction
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly PullingSystem _pullSystem = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
public override void Initialize()
{
@@ -61,7 +55,7 @@ namespace Content.Server.Interaction
if (Deleted(target))
return false;
if (!target.TryGetContainer(out var container))
if (!_container.TryGetContainingContainer(target, out var container))
return false;
if (!TryComp(container.Owner, out ServerStorageComponent? storage))
@@ -74,7 +68,7 @@ namespace Content.Server.Interaction
return false;
// we don't check if the user can access the storage entity itself. This should be handed by the UI system.
return _uiSystem.SessionHasOpenUi(container.Owner, StorageUiKey.Key, actor.PlayerSession);
return _uiSystem.SessionHasOpenUi(container.Owner, SharedStorageComponent.StorageUiKey.Key, actor.PlayerSession);
}
#region Drag drop
@@ -132,21 +126,6 @@ namespace Content.Server.Interaction
}
#endregion
/// <summary>
/// Entity will try and use their active hand at the target location.
/// Don't use for players
/// </summary>
/// <param name="entity"></param>
/// <param name="coords"></param>
/// <param name="uid"></param>
internal void AiUseInteraction(EntityUid entity, EntityCoordinates coords, EntityUid uid)
{
if (HasComp<ActorComponent>(entity))
throw new InvalidOperationException();
UserInteraction(entity, coords, uid);
}
private bool HandleTryPullObject(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
{
if (!ValidateClientInput(session, coords, uid, out var userEntity))
@@ -169,103 +148,5 @@ namespace Content.Server.Interaction
return _pullSystem.TogglePull(userEntity.Value, pull);
}
public override void DoAttack(EntityUid user, EntityCoordinates coordinates, bool wideAttack, EntityUid? target = null)
{
// TODO PREDICTION move server-side interaction logic into the shared system for interaction prediction.
if (!ValidateInteractAndFace(user, coordinates))
return;
// Check general interaction blocking.
if (!_actionBlockerSystem.CanInteract(user, target))
return;
// Check combat-specific action blocking.
if (!_actionBlockerSystem.CanAttack(user, target))
return;
if (!wideAttack)
{
// Check if interacted entity is in the same container, the direct child, or direct parent of the user.
if (target != null && !Deleted(target.Value) && !ContainerSystem.IsInSameOrParentContainer(user, target.Value) && !CanAccessViaStorage(user, target.Value))
{
Logger.WarningS("system.interaction",
$"User entity {ToPrettyString(user):user} clicked on object {ToPrettyString(target.Value):target} that isn't the parent, child, or in the same container");
return;
}
// TODO: Replace with body attack range when we get something like arm length or telekinesis or something.
var unobstructed = (target == null)
? InRangeUnobstructed(user, coordinates)
: InRangeUnobstructed(user, target.Value);
if (!unobstructed)
return;
}
else if (ContainerSystem.IsEntityInContainer(user))
{
// No wide attacking while in containers (holos, lockers, etc).
// Can't think of a valid case where you would want this.
return;
}
// Verify user has a hand, and find what object they are currently holding in their active hand
if (TryComp(user, out HandsComponent? hands))
{
var item = hands.ActiveHandEntity;
if (!Deleted(item))
{
var meleeVee = new MeleeAttackAttemptEvent();
RaiseLocalEvent(item.Value, ref meleeVee, true);
if (meleeVee.Cancelled) return;
if (wideAttack)
{
var ev = new WideAttackEvent(item.Value, user, coordinates);
RaiseLocalEvent(item.Value, ev, false);
if (ev.Handled)
return;
}
else
{
var ev = new ClickAttackEvent(item.Value, user, coordinates, target);
RaiseLocalEvent(item.Value, ev, false);
if (ev.Handled)
return;
}
}
else if (!wideAttack && target != null && HasComp<ItemComponent>(target.Value))
{
// We pick up items if our hand is empty, even if we're in combat mode.
InteractHand(user, target.Value);
return;
}
}
// TODO: Make this saner?
// Attempt to do unarmed combat. We don't check for handled just because at this point it doesn't matter.
var used = user;
if (_inventory.TryGetSlotEntity(user, "gloves", out var gloves) && HasComp<MeleeWeaponComponent>(gloves))
used = (EntityUid) gloves;
if (wideAttack)
{
var ev = new WideAttackEvent(used, user, coordinates);
RaiseLocalEvent(used, ev, false);
if (ev.Handled)
_adminLogger.Add(LogType.AttackUnarmedWide, LogImpact.Low, $"{ToPrettyString(user):user} wide attacked at {coordinates}");
}
else
{
var ev = new ClickAttackEvent(used, user, coordinates, target);
RaiseLocalEvent(used, ev, false);
}
}
}
}

View File

@@ -7,7 +7,7 @@ using Content.Server.Doors.Components;
using Content.Server.Magic.Events;
using Content.Server.Popups;
using Content.Server.Spawners.Components;
using Content.Server.Weapon.Ranged.Systems;
using Content.Server.Weapons.Ranged.Systems;
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Body.Components;

View File

@@ -1,5 +1,7 @@
using Content.Shared.Storage;
using System.Threading;
using Content.Shared.Construction.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Medical.BiomassReclaimer
{
@@ -34,15 +36,40 @@ namespace Content.Server.Medical.BiomassReclaimer
/// <summary>
/// How many units of biomass it produces for each unit of mass.
/// </summary>
[DataField("yieldPerUnitMass")]
[ViewVariables(VVAccess.ReadWrite)]
public float YieldPerUnitMass = 0.4f;
/// <summary>
/// The base yield when no components are upgraded
/// </summary>
[DataField("baseYieldPerUnitMass")]
public float BaseYieldPerUnitMass = 0.4f;
/// <summary>
/// Machine part whose rating modifies the yield per mass.
/// </summary>
[DataField("machinePartYieldAmount", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartYieldAmount = "Manipulator";
/// <summary>
/// Lower number = faster processing.
/// Good for machine upgrading I guess.
/// </summmary>
public float ProcessingSpeedMultiplier = 0.5f;
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float ProcessingSpeedMultiplier = 0.4f;
/// <summary>
/// The base multiplier of processing speed with no upgrades
/// that is used with the weight to calculate the yield
/// </summary>
[DataField("baseProcessingSpeedMultiplier")]
public float BaseProcessingSpeedMultiplier = 0.4f;
/// <summary>
/// The machine part that increses the processing speed.
/// </summary>
[DataField("machinePartProcessSpeed", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartProcessingSpeed = "Laser";
/// <summary>
/// Will this refuse to gib a living mob?

View File

@@ -15,6 +15,7 @@ using Content.Server.Power.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Body.Components;
using Content.Server.Climbing;
using Content.Server.Construction;
using Content.Server.DoAfter;
using Content.Server.Humanoid;
using Content.Server.Mind.Components;
@@ -91,6 +92,7 @@ namespace Content.Server.Medical.BiomassReclaimer
SubscribeLocalEvent<ActiveBiomassReclaimerComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
SubscribeLocalEvent<BiomassReclaimerComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<BiomassReclaimerComponent, ClimbedOnEvent>(OnClimbedOn);
SubscribeLocalEvent<BiomassReclaimerComponent, RefreshPartsEvent>(OnRefreshParts);
SubscribeLocalEvent<ReclaimSuccessfulEvent>(OnReclaimSuccessful);
SubscribeLocalEvent<ReclaimCancelledEvent>(OnReclaimCancelled);
}
@@ -148,6 +150,19 @@ namespace Content.Server.Medical.BiomassReclaimer
StartProcessing(args.Climber, component);
}
private void OnRefreshParts(EntityUid uid, BiomassReclaimerComponent component, RefreshPartsEvent args)
{
var laserRating = args.PartRatings[component.MachinePartProcessingSpeed];
var manipRating = args.PartRatings[component.MachinePartYieldAmount];
//sloping down from 1/2 multiplier
component.ProcessingSpeedMultiplier =
component.BaseProcessingSpeedMultiplier * MathF.Pow(0.65f, laserRating - 1) + 0.1f;
//linear increase by .1 per rating
component.YieldPerUnitMass = component.BaseYieldPerUnitMass + (manipRating - 1) * 0.1f;
}
private void OnReclaimSuccessful(ReclaimSuccessfulEvent args)
{
if (!TryComp<BiomassReclaimerComponent>(args.Reclaimer, out var reclaimer))
@@ -210,19 +225,20 @@ namespace Content.Server.Medical.BiomassReclaimer
return false;
// Reject souled bodies in easy mode.
if (_configManager.GetCVar(CCVars.BiomassEasyMode) && HasComp<HumanoidComponent>(dragged) &&
if (_configManager.GetCVar(CCVars.BiomassEasyMode) &&
HasComp<HumanoidComponent>(dragged) &&
TryComp<MindComponent>(dragged, out var mindComp))
{
if (mindComp.Mind?.UserId != null && _playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out var client))
return false;
}
{
if (mindComp.Mind?.UserId != null && _playerManager.TryGetSessionById(mindComp.Mind.UserId.Value, out _))
return false;
}
return true;
}
private sealed class ReclaimCancelledEvent : EntityEventArgs
private readonly struct ReclaimCancelledEvent
{
public EntityUid Reclaimer;
public readonly EntityUid Reclaimer;
public ReclaimCancelledEvent(EntityUid reclaimer)
{
@@ -230,11 +246,11 @@ namespace Content.Server.Medical.BiomassReclaimer
}
}
private sealed class ReclaimSuccessfulEvent : EntityEventArgs
private readonly struct ReclaimSuccessfulEvent
{
public EntityUid User;
public EntityUid Target;
public EntityUid Reclaimer;
public readonly EntityUid User;
public readonly EntityUid Target;
public readonly EntityUid Reclaimer;
public ReclaimSuccessfulEvent(EntityUid user, EntityUid target, EntityUid reclaimer)
{
User = user;

View File

@@ -10,18 +10,20 @@ using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.MobState.Components;
using Content.Shared.Stacks;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Medical;
public sealed class HealingSystem : EntitySystem
{
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly StackSystem _stacks = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
@@ -40,10 +42,12 @@ public sealed class HealingSystem : EntitySystem
if (_mobStateSystem.IsDead(uid))
return;
if (TryComp<StackComponent>(args.Component.Owner, out var stack) && stack.Count < 1) return;
if (TryComp<StackComponent>(args.Component.Owner, out var stack) && stack.Count < 1)
return;
if (component.DamageContainerID is not null &&
!component.DamageContainerID.Equals(component.DamageContainerID)) return;
!component.DamageContainerID.Equals(component.DamageContainerID))
return;
if (args.Component.BloodlossModifier != 0)
{
@@ -66,7 +70,8 @@ public sealed class HealingSystem : EntitySystem
if (args.Component.HealingEndSound != null)
{
SoundSystem.Play(args.Component.HealingEndSound.GetSound(), Filter.Pvs(uid, entityManager:EntityManager), uid, AudioHelpers.WithVariation(0.125f).WithVolume(-5f));
_audio.PlayPvs(args.Component.HealingEndSound, uid,
AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f));
}
}
@@ -77,7 +82,8 @@ public sealed class HealingSystem : EntitySystem
private void OnHealingUse(EntityUid uid, HealingComponent component, UseInHandEvent args)
{
if (args.Handled) return;
if (args.Handled)
return;
if (TryHeal(uid, args.User, args.User, component))
args.Handled = true;
@@ -85,7 +91,8 @@ public sealed class HealingSystem : EntitySystem
private void OnHealingAfterInteract(EntityUid uid, HealingComponent component, AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || args.Target == null) return;
if (args.Handled || !args.CanReach || args.Target == null)
return;
if (TryHeal(uid, args.User, args.Target.Value, component))
args.Handled = true;
@@ -123,13 +130,13 @@ public sealed class HealingSystem : EntitySystem
if (component.HealingBeginSound != null)
{
SoundSystem.Play(component.HealingBeginSound.GetSound(), Filter.Pvs(uid, entityManager:EntityManager), uid, AudioHelpers.WithVariation(0.125f).WithVolume(-5f));
_audio.PlayPvs(component.HealingBeginSound, uid,
AudioHelpers.WithVariation(0.125f, _random).WithVolume(-5f));
}
var delay = component.Delay;
if (user == target)
delay *= component.SelfHealPenaltyMultiplier;
var delay = user != target
? component.Delay
: component.Delay * GetScaledHealingPenalty(user, component);
_doAfter.DoAfter(new DoAfterEventArgs(user, delay, component.CancelToken.Token, target)
{
@@ -159,6 +166,25 @@ public sealed class HealingSystem : EntitySystem
return true;
}
/// <summary>
/// Scales the self-heal penalty based on the amount of damage taken
/// </summary>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <returns></returns>
public float GetScaledHealingPenalty(EntityUid uid, HealingComponent component)
{
var output = component.Delay;
if (!TryComp<MobStateComponent>(uid, out var mobState) || !TryComp<DamageableComponent>(uid, out var damageable))
return output;
_mobStateSystem.TryGetEarliestCriticalState(mobState, 0, out var _, out var amount);
var percentDamage = (float) (damageable.TotalDamage / amount);
//basically make it scale from 1 to the multiplier.
var modifier = percentDamage * (component.SelfHealPenaltyMultiplier - 1) + 1;
return Math.Max(modifier, 1);
}
private sealed class HealingCompleteEvent : EntityEventArgs
{
public EntityUid User;

View File

@@ -35,6 +35,11 @@ public enum CombatStatus : byte
/// </summary>
TargetUnreachable,
/// <summary>
/// If the target is outside of our melee range.
/// </summary>
TargetOutOfRange,
/// <summary>
/// Set if the weapon we were assigned is no longer valid.
/// </summary>

View File

@@ -1,5 +1,6 @@
using System.Threading;
using Content.Server.CPUJob.JobQueues;
using Content.Server.NPC.Pathfinding;
using Robust.Shared.Map;
namespace Content.Server.NPC.Components;
@@ -10,24 +11,23 @@ namespace Content.Server.NPC.Components;
[RegisterComponent]
public sealed class NPCSteeringComponent : Component
{
[ViewVariables] public Job<Queue<TileRef>>? Pathfind = null;
/// <summary>
/// Have we currently requested a path.
/// </summary>
[ViewVariables]
public bool Pathfind => PathfindToken != null;
[ViewVariables] public CancellationTokenSource? PathfindToken = null;
/// <summary>
/// Current path we're following to our coordinates.
/// </summary>
[ViewVariables] public Queue<TileRef> CurrentPath = new();
[ViewVariables] public Queue<PathPoly> CurrentPath = new();
/// <summary>
/// End target that we're trying to move to.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public EntityCoordinates Coordinates;
/// <summary>
/// Target that we're trying to move to. If we have a path then this will be the first node on the path.
/// </summary>
[ViewVariables] public EntityCoordinates CurrentTarget;
/// <summary>
/// How close are we trying to get to the coordinates before being considered in range.
/// </summary>
@@ -36,9 +36,18 @@ public sealed class NPCSteeringComponent : Component
/// <summary>
/// How far does the last node in the path need to be before considering re-pathfinding.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)] public float RepathRange = 1.5f;
[ViewVariables(VVAccess.ReadWrite)] public float RepathRange = 1.2f;
public const int FailedPathLimit = 3;
/// <summary>
/// How many times we've failed to pathfind. Once this hits the limit we'll stop steering.
/// </summary>
[ViewVariables] public int FailedPathCount;
[ViewVariables] public SteeringStatus Status = SteeringStatus.Moving;
[ViewVariables(VVAccess.ReadWrite)] public PathFlags Flags = PathFlags.None;
}
public enum SteeringStatus : byte

View File

@@ -42,4 +42,6 @@ public sealed class HTNComponent : NPCComponent
/// Is this NPC currently planning?
/// </summary>
[ViewVariables] public bool Planning => PlanningJob != null;
}

View File

@@ -131,7 +131,7 @@ public sealed class HTNPlanJob : Job<HTNPlan>
return false;
}
var (valid, effects) = await primitive.Operator.Plan(blackboard);
var (valid, effects) = await primitive.Operator.Plan(blackboard, Cancellation);
if (!valid)
return false;

View File

@@ -151,8 +151,9 @@ public sealed class HTNSystem : EntitySystem
{
_sawmill.Fatal($"Received exception on planning job for {comp.Owner}!");
_npc.SleepNPC(comp.Owner);
var exc = comp.PlanningJob.Exception;
RemComp<HTNComponent>(comp.Owner);
throw comp.PlanningJob.Exception;
throw exc;
}
// If a new planning job has finished then handle it.

View File

@@ -1,11 +1,13 @@
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
namespace Content.Server.NPC.HTN.PrimitiveTasks;
/// <summary>
/// Concrete code that gets run for an NPC task.
/// </summary>
[ImplicitDataDefinitionForInheritors]
[ImplicitDataDefinitionForInheritors, MeansImplicitUse]
public abstract class HTNOperator
{
/// <summary>
@@ -20,9 +22,11 @@ public abstract class HTNOperator
/// Called during planning.
/// </summary>
/// <param name="blackboard">The blackboard for the NPC.</param>
/// <param name="cancelToken"></param>
/// <returns>Whether the plan is still valid and the effects to apply to the blackboard.
/// These get re-applied during execution and are up to the operator to use or discard.</returns>
public virtual async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard)
public virtual async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
CancellationToken cancelToken)
{
return (true, null);
}

View File

@@ -1,3 +1,4 @@
using System.Threading;
using System.Threading.Tasks;
using Content.Server.MobState;
using Content.Server.NPC.Components;
@@ -34,7 +35,8 @@ public sealed class MeleeOperator : HTNOperator
melee.Target = blackboard.GetValue<EntityUid>(TargetKey);
}
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard)
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
CancellationToken cancelToken)
{
// Don't attack if they're already as wounded as we want them.
if (!blackboard.TryGetValue<EntityUid>(TargetKey, out var target))
@@ -62,7 +64,6 @@ public sealed class MeleeOperator : HTNOperator
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
{
base.Update(blackboard, frameTime);
// TODO:
var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
var status = HTNOperatorStatus.Continuing;
@@ -79,6 +80,7 @@ public sealed class MeleeOperator : HTNOperator
{
switch (combat.Status)
{
case CombatStatus.TargetOutOfRange:
case CombatStatus.Normal:
status = HTNOperatorStatus.Continuing;
break;

View File

@@ -1,32 +1,24 @@
using Robust.Shared.Map;
using JetBrains.Annotations;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Melee;
/// <summary>
/// Selects a target for melee.
/// </summary>
[MeansImplicitUse]
public sealed class PickMeleeTargetOperator : NPCCombatOperator
{
protected override float GetRating(NPCBlackboard blackboard, EntityUid uid, EntityUid existingTarget, bool canMove, EntityQuery<TransformComponent> xformQuery)
protected override float GetRating(NPCBlackboard blackboard, EntityUid uid, EntityUid existingTarget, float distance, bool canMove, EntityQuery<TransformComponent> xformQuery)
{
var ourCoordinates = blackboard.GetValueOrDefault<EntityCoordinates>(NPCBlackboard.OwnerCoordinates);
if (!xformQuery.TryGetComponent(uid, out var targetXform))
return -1f;
var targetCoordinates = targetXform.Coordinates;
if (!ourCoordinates.TryDistance(EntManager, targetCoordinates, out var distance))
return -1f;
var rating = 0f;
if (existingTarget == uid)
{
rating += 3f;
rating += 2f;
}
rating += 1f / distance * 4f;
if (distance > 0f)
rating += 50f / distance;
return rating;
}

View File

@@ -2,10 +2,11 @@ using System.Threading;
using System.Threading.Tasks;
using Content.Server.NPC.Components;
using Content.Server.NPC.Pathfinding;
using Content.Server.NPC.Pathfinding.Pathfinders;
using Content.Server.NPC.Systems;
using Content.Shared.NPC;
using Robust.Shared.Map;
using Robust.Shared.Physics.Components;
using YamlDotNet.Core.Tokens;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators;
@@ -58,7 +59,8 @@ public sealed class MoveToOperator : HTNOperator
_steering = sysManager.GetEntitySystem<NPCSteeringSystem>();
}
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard)
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
CancellationToken cancelToken)
{
if (!blackboard.TryGetValue<EntityCoordinates>(TargetKey, out var targetCoordinates))
{
@@ -72,8 +74,7 @@ public sealed class MoveToOperator : HTNOperator
return (false, null);
if (!_mapManager.TryGetGrid(xform.GridUid, out var ownerGrid) ||
!_mapManager.TryGetGrid(targetCoordinates.GetGridUid(_entManager), out var targetGrid) ||
ownerGrid != targetGrid)
!_mapManager.TryGetGrid(targetCoordinates.GetGridUid(_entManager), out var targetGrid))
{
return (false, null);
}
@@ -97,30 +98,25 @@ public sealed class MoveToOperator : HTNOperator
});
}
var cancelToken = new CancellationTokenSource();
var access = blackboard.GetValueOrDefault<ICollection<string>>(NPCBlackboard.Access) ?? new List<string>();
var path = await _pathfind.GetPath(
blackboard.GetValue<EntityUid>(NPCBlackboard.Owner),
xform.Coordinates,
targetCoordinates,
range,
cancelToken,
_pathfind.GetFlags(blackboard));
var job = _pathfind.RequestPath(
new PathfindingArgs(
blackboard.GetValue<EntityUid>(NPCBlackboard.Owner),
access,
body.CollisionMask,
ownerGrid.GetTileRef(xform.Coordinates),
ownerGrid.GetTileRef(targetCoordinates),
range), cancelToken.Token);
job.Run();
await job.AsTask.WaitAsync(cancelToken.Token);
if (job.Result == null)
if (path.Result != PathResult.Path)
{
return (false, null);
}
return (true, new Dictionary<string, object>()
{
{NPCBlackboard.OwnerCoordinates, targetCoordinates},
{PathfindKey, job.Result}
{PathfindKey, path}
});
}
// Given steering is complicated we'll hand it off to a dedicated system rather than this singleton operator.
@@ -131,23 +127,25 @@ public sealed class MoveToOperator : HTNOperator
// Need to remove the planning value for execution.
blackboard.Remove<EntityCoordinates>(NPCBlackboard.OwnerCoordinates);
var targetCoordinates = blackboard.GetValue<EntityCoordinates>(TargetKey);
// Re-use the path we may have if applicable.
var comp = _steering.Register(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner), blackboard.GetValue<EntityCoordinates>(TargetKey));
var comp = _steering.Register(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner), targetCoordinates);
if (blackboard.TryGetValue<float>(RangeKey, out var range))
{
comp.Range = range;
}
if (blackboard.TryGetValue<Queue<TileRef>>(PathfindKey, out var path))
if (blackboard.TryGetValue<PathResultEvent>(PathfindKey, out var result))
{
if (blackboard.TryGetValue<EntityCoordinates>(NPCBlackboard.OwnerCoordinates, out var coordinates))
{
_steering.PrunePath(coordinates, path);
var mapCoords = coordinates.ToMap(_entManager);
_steering.PrunePath(mapCoords, targetCoordinates.ToMapPos(_entManager) - mapCoords.Position, result.Path);
}
comp.CurrentPath = path;
comp.CurrentPath = result.Path;
}
}
@@ -163,7 +161,7 @@ public sealed class MoveToOperator : HTNOperator
}
// OwnerCoordinates is only used in planning so dump it.
blackboard.Remove<Queue<TileRef>>(PathfindKey);
blackboard.Remove<PathResultEvent>(PathfindKey);
if (RemoveKeyOnFinish)
{

Some files were not shown because too many files have changed in this diff Show More