Misc ItemToggleSystem changes (#26489)
* Minor ItemToggleSystem tweaks * Update visuals on startup * Remove SetIgnited * Misc toggle fixes * Update ItemToggleHotComponent.cs
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
namespace Content.Server.Item;
|
||||
|
||||
/// <summary>
|
||||
/// Handles whether this item applies a disarm malus when active.
|
||||
/// Handles whether this item applies a disarm malus when active.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class ItemToggleDisarmMalusComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Item has this modifier to the chance to disarm when activated.
|
||||
/// If null, the value will be inferred from the current malus just before the malus is first deactivated.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly), DataField]
|
||||
public float? ActivatedDisarmMalus = null;
|
||||
|
||||
/// <summary>
|
||||
/// Item has this modifier to the chance to disarm when deactivated. If none is mentioned, it uses the item's default disarm modifier.
|
||||
/// If null, the value will be inferred from the current malus just before the malus is first activated.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly), DataField]
|
||||
public float? DeactivatedDisarmMalus = null;
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
namespace Content.Server.Item;
|
||||
|
||||
/// <summary>
|
||||
/// Handles whether this item is sharp when toggled on.
|
||||
/// Handles whether this item is sharp when toggled on.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class ItemToggleSharpComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Item can be used to butcher when activated.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly), DataField]
|
||||
public bool ActivatedSharp = true;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using Content.Shared.Item;
|
||||
using Content.Server.CombatMode.Disarm;
|
||||
using Content.Server.Kitchen.Components;
|
||||
using Content.Shared.Item.ItemToggle;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent;
|
||||
|
||||
namespace Content.Server.Item;
|
||||
|
||||
@@ -13,47 +11,34 @@ public sealed class ItemToggleSystem : SharedItemToggleSystem
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<ItemToggleComponent, ItemToggledEvent>(Toggle);
|
||||
SubscribeLocalEvent<ItemToggleSharpComponent, ItemToggledEvent>(ToggleSharp);
|
||||
SubscribeLocalEvent<ItemToggleDisarmMalusComponent, ItemToggledEvent>(ToggleMalus);
|
||||
}
|
||||
|
||||
private void Toggle(EntityUid uid, ItemToggleComponent comp, ref ItemToggledEvent args)
|
||||
private void ToggleSharp(Entity<ItemToggleSharpComponent> ent, ref ItemToggledEvent args)
|
||||
{
|
||||
if (args.Activated == true)
|
||||
{
|
||||
if (TryComp<ItemToggleSharpComponent>(uid, out var itemSharpness))
|
||||
{
|
||||
if (itemSharpness.ActivatedSharp)
|
||||
EnsureComp<SharpComponent>(uid);
|
||||
}
|
||||
|
||||
if (!TryComp<ItemToggleDisarmMalusComponent>(uid, out var itemToggleDisarmMalus) ||
|
||||
!TryComp<DisarmMalusComponent>(uid, out var malus))
|
||||
return;
|
||||
|
||||
//Default the deactivated DisarmMalus to the item's value before activation happens.
|
||||
itemToggleDisarmMalus.DeactivatedDisarmMalus ??= malus.Malus;
|
||||
|
||||
if (itemToggleDisarmMalus.ActivatedDisarmMalus != null)
|
||||
{
|
||||
malus.Malus = (float) itemToggleDisarmMalus.ActivatedDisarmMalus;
|
||||
}
|
||||
}
|
||||
// TODO generalize this into a "ToggleComponentComponent", though probably with a better name
|
||||
if (args.Activated)
|
||||
EnsureComp<SharpComponent>(ent);
|
||||
else
|
||||
RemCompDeferred<SharpComponent>(ent);
|
||||
}
|
||||
|
||||
private void ToggleMalus(Entity<ItemToggleDisarmMalusComponent> ent, ref ItemToggledEvent args)
|
||||
{
|
||||
if (!TryComp<DisarmMalusComponent>(ent, out var malus))
|
||||
return;
|
||||
|
||||
if (args.Activated)
|
||||
{
|
||||
if (TryComp<ItemToggleSharpComponent>(uid, out var itemSharpness))
|
||||
{
|
||||
if (itemSharpness.ActivatedSharp)
|
||||
RemCompDeferred<SharpComponent>(uid);
|
||||
}
|
||||
|
||||
if (!TryComp<ItemToggleDisarmMalusComponent>(uid, out var itemToggleDisarmMalus) ||
|
||||
!TryComp<DisarmMalusComponent>(uid, out var malus))
|
||||
return;
|
||||
|
||||
if (itemToggleDisarmMalus.DeactivatedDisarmMalus != null)
|
||||
{
|
||||
malus.Malus = (float) itemToggleDisarmMalus.DeactivatedDisarmMalus;
|
||||
}
|
||||
ent.Comp.DeactivatedDisarmMalus ??= malus.Malus;
|
||||
if (ent.Comp.ActivatedDisarmMalus is {} activatedMalus)
|
||||
malus.Malus = activatedMalus;
|
||||
return;
|
||||
}
|
||||
|
||||
ent.Comp.ActivatedDisarmMalus ??= malus.Malus;
|
||||
if (ent.Comp.DeactivatedDisarmMalus is {} deactivatedMalus)
|
||||
malus.Malus = deactivatedMalus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +58,7 @@ namespace Content.Server.Stunnable.Systems
|
||||
|
||||
private void ToggleDone(Entity<StunbatonComponent> entity, ref ItemToggledEvent args)
|
||||
{
|
||||
if (!TryComp<ItemComponent>(entity, out var item))
|
||||
return;
|
||||
|
||||
_item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off", component: item);
|
||||
_item.SetHeldPrefix(entity.Owner, args.Activated ? "on" : "off");
|
||||
}
|
||||
|
||||
private void TryTurnOn(Entity<StunbatonComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
||||
|
||||
@@ -7,7 +7,6 @@ using Content.Shared.DoAfter;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Item.ItemToggle;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Robust.Shared.GameStates;
|
||||
@@ -32,8 +31,8 @@ namespace Content.Server.Tools
|
||||
SubscribeLocalEvent<WelderComponent, DoAfterAttemptEvent<ToolDoAfterEvent>>(OnWelderToolUseAttempt);
|
||||
SubscribeLocalEvent<WelderComponent, ComponentShutdown>(OnWelderShutdown);
|
||||
SubscribeLocalEvent<WelderComponent, ComponentGetState>(OnWelderGetState);
|
||||
SubscribeLocalEvent<WelderComponent, ItemToggleActivateAttemptEvent>(TryTurnOn);
|
||||
SubscribeLocalEvent<WelderComponent, ItemToggleDeactivateAttemptEvent>(TurnOff);
|
||||
SubscribeLocalEvent<WelderComponent, ItemToggledEvent>(OnToggle);
|
||||
SubscribeLocalEvent<WelderComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
|
||||
}
|
||||
|
||||
public (FixedPoint2 fuel, FixedPoint2 capacity) GetWelderFuelAndCapacity(EntityUid uid, WelderComponent? welder = null, SolutionContainerManagerComponent? solutionContainer = null)
|
||||
@@ -45,55 +44,54 @@ namespace Content.Server.Tools
|
||||
return (fuelSolution.GetTotalPrototypeQuantity(welder.FuelReagent), fuelSolution.MaxVolume);
|
||||
}
|
||||
|
||||
public void TryTurnOn(Entity<WelderComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
||||
private void OnToggle(Entity<WelderComponent> entity, ref ItemToggledEvent args)
|
||||
{
|
||||
if (!_solutionContainer.ResolveSolution(entity.Owner, entity.Comp.FuelSolutionName, ref entity.Comp.FuelSolution, out var solution) ||
|
||||
!TryComp<TransformComponent>(entity, out var transform))
|
||||
if (args.Activated)
|
||||
TurnOn(entity, args.User);
|
||||
else
|
||||
TurnOff(entity, args.User);
|
||||
}
|
||||
|
||||
private void OnActivateAttempt(Entity<WelderComponent> entity, ref ItemToggleActivateAttemptEvent args)
|
||||
{
|
||||
if (!_solutionContainer.ResolveSolution(entity.Owner, entity.Comp.FuelSolutionName, ref entity.Comp.FuelSolution, out var solution))
|
||||
{
|
||||
args.Cancelled = true;
|
||||
args.Popup = Loc.GetString("welder-component-no-fuel-message");
|
||||
return;
|
||||
}
|
||||
|
||||
var fuel = solution.GetTotalPrototypeQuantity(entity.Comp.FuelReagent);
|
||||
|
||||
// Not enough fuel to lit welder.
|
||||
if (fuel == FixedPoint2.Zero || fuel < entity.Comp.FuelLitCost)
|
||||
{
|
||||
if (args.User != null)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("welder-component-no-fuel-message"), entity, (EntityUid) args.User);
|
||||
}
|
||||
args.Popup = Loc.GetString("welder-component-no-fuel-message");
|
||||
args.Cancelled = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void TurnOn(Entity<WelderComponent> entity, EntityUid? user)
|
||||
{
|
||||
if (!_solutionContainer.ResolveSolution(entity.Owner, entity.Comp.FuelSolutionName, ref entity.Comp.FuelSolution))
|
||||
return;
|
||||
|
||||
_solutionContainer.RemoveReagent(entity.Comp.FuelSolution.Value, entity.Comp.FuelReagent, entity.Comp.FuelLitCost);
|
||||
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low,
|
||||
$"{ToPrettyString(user):user} toggled {ToPrettyString(entity.Owner):welder} on");
|
||||
|
||||
// Logging
|
||||
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(args.User):user} toggled {ToPrettyString(entity.Owner):welder} on");
|
||||
|
||||
_ignitionSource.SetIgnited(entity.Owner);
|
||||
|
||||
if (transform.GridUid is { } gridUid)
|
||||
var xform = Transform(entity);
|
||||
if (xform.GridUid is { } gridUid)
|
||||
{
|
||||
var position = _transformSystem.GetGridOrMapTilePosition(entity.Owner, transform);
|
||||
var position = _transformSystem.GetGridOrMapTilePosition(entity.Owner, xform);
|
||||
_atmosphereSystem.HotspotExpose(gridUid, position, 700, 50, entity.Owner, true);
|
||||
}
|
||||
|
||||
Dirty(entity);
|
||||
|
||||
_activeWelders.Add(entity);
|
||||
}
|
||||
|
||||
public void TurnOff(Entity<WelderComponent> entity, ref ItemToggleDeactivateAttemptEvent args)
|
||||
public void TurnOff(Entity<WelderComponent> entity, EntityUid? user)
|
||||
{
|
||||
// Logging
|
||||
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(args.User):user} toggled {ToPrettyString(entity.Owner):welder} off");
|
||||
|
||||
_ignitionSource.SetIgnited(entity.Owner, false);
|
||||
|
||||
Dirty(entity);
|
||||
|
||||
AdminLogger.Add(LogType.InteractActivate, LogImpact.Low,
|
||||
$"{ToPrettyString(user):user} toggled {ToPrettyString(entity.Owner):welder} off");
|
||||
_activeWelders.Remove(entity);
|
||||
}
|
||||
|
||||
@@ -186,7 +184,9 @@ namespace Content.Server.Tools
|
||||
if (_welderTimer < WelderUpdateTimer)
|
||||
return;
|
||||
|
||||
// TODO Use an "active welder" component instead, EntityQuery over that.
|
||||
// TODO Serialization. _activeWelders is not serialized.
|
||||
// Need to use some "active" component, and EntityQuery over that.
|
||||
// Probably best to generalize it to a "ToggleableFuelDrain" component.
|
||||
foreach (var tool in _activeWelders.ToArray())
|
||||
{
|
||||
if (!TryComp(tool, out WelderComponent? welder)
|
||||
|
||||
Reference in New Issue
Block a user