Land mine armament (#33883)
* Land Mine is now armable, it will not explode unless armed. * Land Mine is now armable, it will not explode unless armed. * Explicitly have Armed as false * SharedLandMineSystem.cs adds the "Arm"-verb in "Content.Shared" with the Arming logic being implemented in "Content.Server" * Land Mines now blink only when armed. * Added prediction components, moved logic to SharedLandMineSystem.cs and inherit it in client content. * Accessing the datafield directly instead of using methods * Mines are now armed by default with a unarmed prototype * Land mine now shows if it is armed when examined and in range. * Landmine is unarmed by default with an armed variant for mapping purposes. * Removed properties that were already defined by inheritance. * Access the bool directly from the component * Add booleans to change if the Arm-verb is showed and if examining the mine shows the status. * Added status message for unarmed mine, removed using PushGroup since only one string is displayed. * Added properties to the explosive floor sign to ensure that it is armed, not showing neither status nor arm-verb. * The prototypes work now as before with added unarmed versions. Sprite is now only one toggable layer. * Make the craftable land mine unarmed. * Refactored the arming mechanic into own component and system. * Reverted the explosive wet floor sign to previous prototype and added the Armable component and ItemToggle to the landmines. * Moved the examination strings from land-mines.ftl to armable.ftl. * Removed unused property. * Formatting and fixing imports * Added prefixes to the ftl naming. Moved LocId from system to component * Added documentation. Moved check for armable to HandleStepTriggerAttempt. Moved the LocId to component. * Removed the TryArming method. Added documentation. * Removed unnecessary TryComp * Simplified the logic for the trigger attempt * HasComp instead of TryComp on logic * EmoGarbage Review --------- Co-authored-by: Franz - Josef Björck <kaiserbirch@proton.me> Co-authored-by: EmoGarbage404 <retron404@gmail.com>
This commit is contained in:
@@ -1,13 +0,0 @@
|
|||||||
using Robust.Shared.Audio;
|
|
||||||
|
|
||||||
namespace Content.Server.LandMines;
|
|
||||||
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed partial class LandMineComponent : Component
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Trigger sound effect when stepping onto landmine
|
|
||||||
/// </summary>
|
|
||||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
|
||||||
public SoundSpecifier? Sound;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using Content.Server.Explosion.EntitySystems;
|
using Content.Server.Explosion.EntitySystems;
|
||||||
|
using Content.Shared.Armable;
|
||||||
|
using Content.Shared.Item.ItemToggle.Components;
|
||||||
|
using Content.Shared.LandMines;
|
||||||
using Content.Shared.Popups;
|
using Content.Shared.Popups;
|
||||||
using Content.Shared.StepTrigger.Systems;
|
using Content.Shared.StepTrigger.Systems;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
|
|
||||||
namespace Content.Server.LandMines;
|
namespace Content.Server.LandMines;
|
||||||
@@ -14,30 +16,46 @@ public sealed class LandMineSystem : EntitySystem
|
|||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<LandMineComponent, StepTriggeredOnEvent>(HandleStepOnTriggered);
|
SubscribeLocalEvent<LandMineComponent, StepTriggeredOnEvent>(HandleStepOnTriggered);
|
||||||
SubscribeLocalEvent<LandMineComponent, StepTriggeredOffEvent>(HandleStepOffTriggered);
|
SubscribeLocalEvent<LandMineComponent, StepTriggeredOffEvent>(HandleStepOffTriggered);
|
||||||
|
|
||||||
SubscribeLocalEvent<LandMineComponent, StepTriggerAttemptEvent>(HandleStepTriggerAttempt);
|
SubscribeLocalEvent<LandMineComponent, StepTriggerAttemptEvent>(HandleStepTriggerAttempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Warns the player when stepped on.
|
||||||
|
/// </summary>
|
||||||
private void HandleStepOnTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOnEvent args)
|
private void HandleStepOnTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOnEvent args)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(component.TriggerText))
|
||||||
{
|
{
|
||||||
_popupSystem.PopupCoordinates(
|
_popupSystem.PopupCoordinates(
|
||||||
Loc.GetString("land-mine-triggered", ("mine", uid)),
|
Loc.GetString(component.TriggerText, ("mine", uid)),
|
||||||
Transform(uid).Coordinates,
|
Transform(uid).Coordinates,
|
||||||
args.Tripper,
|
args.Tripper,
|
||||||
PopupType.LargeCaution);
|
PopupType.LargeCaution);
|
||||||
|
}
|
||||||
_audioSystem.PlayPvs(component.Sound, uid);
|
_audioSystem.PlayPvs(component.Sound, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sends a trigger when stepped off.
|
||||||
|
/// </summary>
|
||||||
private void HandleStepOffTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOffEvent args)
|
private void HandleStepOffTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOffEvent args)
|
||||||
{
|
{
|
||||||
_trigger.Trigger(uid, args.Tripper);
|
_trigger.Trigger(uid, args.Tripper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args)
|
/// <summary>
|
||||||
|
/// Presumes that the landmine isn't armable and should be treated as always armed.
|
||||||
|
/// If Armable and ItemToggle is present the event will continue only if the mine is activated.
|
||||||
|
/// </summary>
|
||||||
|
private void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args)
|
||||||
{
|
{
|
||||||
args.Continue = true;
|
args.Continue = true;
|
||||||
|
|
||||||
|
if (HasComp<ArmableComponent>(uid) && TryComp<ItemToggleComponent>(uid, out var itemToggle))
|
||||||
|
args.Continue = itemToggle.Activated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
Content.Shared/Armable/ArmableComponent.cs
Normal file
35
Content.Shared/Armable/ArmableComponent.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Armable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes an item armable, needs ItemToggleComponent to work.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
[Access(typeof(ArmableSystem))]
|
||||||
|
public sealed partial class ArmableComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Does it show its status on examination?
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool ShowStatusOnExamination = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Does it change appearance when activated?
|
||||||
|
/// </summary>
|
||||||
|
[DataField, AutoNetworkedField]
|
||||||
|
public bool ChangeAppearance = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Text to show on examination when the entity is armed.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public LocId? ExamineTextArmed = "armable-examine-armed";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Text to show on examination when the entity is not armed
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public LocId? ExamineTextNotArmed ="armable-examine-not-armed";
|
||||||
|
}
|
||||||
54
Content.Shared/Armable/ArmableSystem.cs
Normal file
54
Content.Shared/Armable/ArmableSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
using Content.Shared.Examine;
|
||||||
|
using Content.Shared.Item.ItemToggle;
|
||||||
|
using Content.Shared.Item.ItemToggle.Components;
|
||||||
|
|
||||||
|
namespace Content.Shared.Armable;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When used together with ItemToggle this will make the ItemToggle one way which is then used to represent an armed
|
||||||
|
/// state. If ItemComponent.Activated is true then the item is considered to be armed and should be able to be
|
||||||
|
/// triggered.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ArmableSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly ItemToggleSystem _itemToggle = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<ArmableComponent, ExaminedEvent>(OnExamine);
|
||||||
|
SubscribeLocalEvent<ArmableComponent, ItemToggledEvent>(ArmingDone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the status of the armable entity on examination.
|
||||||
|
/// </summary>
|
||||||
|
private void OnExamine(EntityUid uid, ArmableComponent comp, ExaminedEvent args)
|
||||||
|
{
|
||||||
|
if (!args.IsInDetailsRange || !comp.ShowStatusOnExamination || !TryComp<ItemToggleComponent>(uid, out var itemToggle))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (itemToggle.Activated)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(comp.ExamineTextArmed))
|
||||||
|
args.PushMarkup(Loc.GetString(comp.ExamineTextArmed, ("name", uid)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(comp.ExamineTextNotArmed))
|
||||||
|
args.PushMarkup(Loc.GetString(comp.ExamineTextNotArmed,("name", uid)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the appearance and disables the ItemToggleComponent as to not show the deactivate verb.
|
||||||
|
/// Whatever is armed should probably not be trivially disarmed.
|
||||||
|
/// </summary>
|
||||||
|
private void ArmingDone(Entity<ArmableComponent> entity, ref ItemToggledEvent args)
|
||||||
|
{
|
||||||
|
if (!args.Activated)
|
||||||
|
return;
|
||||||
|
_itemToggle.SetOnActivate(entity.Owner, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ public sealed partial class ItemToggleComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Can the entity be activated in the world.
|
/// Can the entity be activated in the world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool OnActivate = true;
|
public bool OnActivate = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -263,6 +263,21 @@ public sealed class ItemToggleSystem : EntitySystem
|
|||||||
RaiseLocalEvent(uid, ref toggleUsed);
|
RaiseLocalEvent(uid, ref toggleUsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets if this toggleable item can be activated in world by pressing "e"
|
||||||
|
/// </summary>
|
||||||
|
public void SetOnActivate(Entity<ItemToggleComponent?> ent, bool val)
|
||||||
|
{
|
||||||
|
if (!Resolve(ent, ref ent.Comp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ent.Comp.OnActivate == val)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ent.Comp.OnActivate = val;
|
||||||
|
Dirty(ent);
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateVisuals(Entity<ItemToggleComponent> ent)
|
private void UpdateVisuals(Entity<ItemToggleComponent> ent)
|
||||||
{
|
{
|
||||||
if (TryComp(ent, out AppearanceComponent? appearance))
|
if (TryComp(ent, out AppearanceComponent? appearance))
|
||||||
|
|||||||
23
Content.Shared/LandMines/LandMineComponent.cs
Normal file
23
Content.Shared/LandMines/LandMineComponent.cs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
using Robust.Shared.Audio;
|
||||||
|
|
||||||
|
namespace Content.Shared.LandMines;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Give a warning if stepped on and will execute a trigger on step off. When used together with ArmableComponent and
|
||||||
|
/// ItemToggleComponent it will only trigger if "ItemToggle.Activated" is true.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed partial class LandMineComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The text that popups when the landmine is stepped on.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public LocId? TriggerText = "land-mine-triggered";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger sound effect when stepping onto landmine
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public SoundSpecifier? Sound;
|
||||||
|
}
|
||||||
2
Resources/Locale/en-US/armable/armable.ftl
Normal file
2
Resources/Locale/en-US/armable/armable.ftl
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
armable-examine-armed = {CAPITALIZE(THE($name))} is [color=red]armed[/color].
|
||||||
|
armable-examine-not-armed = {CAPITALIZE(THE($name))} needs to be armed.
|
||||||
@@ -1 +1,2 @@
|
|||||||
land-mine-triggered = You step on the { $mine }!
|
land-mine-triggered = You step on the { $mine }!
|
||||||
|
land-mine-verb-begin = Arm
|
||||||
|
|||||||
@@ -4,7 +4,11 @@
|
|||||||
components:
|
components:
|
||||||
- type: Clickable
|
- type: Clickable
|
||||||
- type: InteractionOutline
|
- type: InteractionOutline
|
||||||
- type: Anchorable
|
- type: ItemToggle
|
||||||
|
soundActivate:
|
||||||
|
path: /Audio/Weapons/click.ogg
|
||||||
|
params:
|
||||||
|
maxDistance: 1
|
||||||
- type: Pullable
|
- type: Pullable
|
||||||
- type: MovedByPressure
|
- type: MovedByPressure
|
||||||
- type: Physics
|
- type: Physics
|
||||||
@@ -22,7 +26,16 @@
|
|||||||
- type: Sprite
|
- type: Sprite
|
||||||
drawdepth: Items
|
drawdepth: Items
|
||||||
sprite: Objects/Misc/landmine.rsi
|
sprite: Objects/Misc/landmine.rsi
|
||||||
state: landmine
|
layers:
|
||||||
|
- state: landmine-inactive
|
||||||
|
map: [ "enum.ToggleVisuals.Layer" ]
|
||||||
|
- type: Appearance
|
||||||
|
- type: GenericVisualizer
|
||||||
|
visuals:
|
||||||
|
enum.ToggleVisuals.Toggled:
|
||||||
|
enum.ToggleVisuals.Layer:
|
||||||
|
True: {state: landmine}
|
||||||
|
False: {state: landmine-inactive}
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Inorganic
|
damageContainer: Inorganic
|
||||||
- type: Destructible
|
- type: Destructible
|
||||||
@@ -39,33 +52,60 @@
|
|||||||
path: /Audio/Effects/beep_landmine.ogg
|
path: /Audio/Effects/beep_landmine.ogg
|
||||||
params:
|
params:
|
||||||
maxDistance: 10
|
maxDistance: 10
|
||||||
|
- type: Armable
|
||||||
- type: StepTrigger
|
- type: StepTrigger
|
||||||
requiredTriggeredSpeed: 0
|
requiredTriggeredSpeed: 0
|
||||||
stepOn: true
|
stepOn: true
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
|
id: LandMineKickUnarmed
|
||||||
name: kick mine
|
name: kick mine
|
||||||
parent: BaseLandMine
|
parent: BaseLandMine
|
||||||
id: LandMineKick
|
|
||||||
components:
|
components:
|
||||||
- type: GhostKickUserOnTrigger
|
- type: GhostKickUserOnTrigger
|
||||||
- type: DeleteOnTrigger
|
- type: DeleteOnTrigger
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: LandMineKick
|
||||||
|
suffix: armed
|
||||||
|
parent: LandMineKickUnarmed
|
||||||
|
components:
|
||||||
|
- type: ItemToggle
|
||||||
|
activated: true
|
||||||
|
onActivate: false
|
||||||
|
- type: Armable
|
||||||
|
- type: Sprite
|
||||||
|
layers:
|
||||||
|
- state: landmine
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
name: modular mine
|
name: modular mine
|
||||||
description: This bad boy could be packing any number of dangers. Or a bike horn.
|
description: This bad boy could be packing any number of dangers. Or a bike horn.
|
||||||
parent: BaseLandMine
|
parent: BaseLandMine
|
||||||
id: LandMineModular
|
id: LandMineModularUnarmed
|
||||||
components:
|
components:
|
||||||
- type: PayloadCase
|
- type: PayloadCase
|
||||||
- type: Construction
|
- type: Construction
|
||||||
graph: ModularMineGraph
|
graph: ModularMineGraph
|
||||||
node: emptyCase
|
node: emptyCase
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
id: LandMineModular
|
||||||
|
suffix: armed
|
||||||
|
parent: LandMineModularUnarmed
|
||||||
|
components:
|
||||||
|
- type: ItemToggle
|
||||||
|
activated: true
|
||||||
|
onActivate: false
|
||||||
|
- type: Armable
|
||||||
|
- type: Sprite
|
||||||
|
layers:
|
||||||
|
- state: landmine
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
name: explosive mine
|
name: explosive mine
|
||||||
parent: BaseLandMine
|
parent: BaseLandMine
|
||||||
id: LandMineExplosive
|
id: LandMineExplosiveUnarmed
|
||||||
components:
|
components:
|
||||||
- type: ExplodeOnTrigger
|
- type: ExplodeOnTrigger
|
||||||
- type: Explosive
|
- type: Explosive
|
||||||
@@ -74,3 +114,16 @@
|
|||||||
intensitySlope: 3
|
intensitySlope: 3
|
||||||
totalIntensity: 120 # about a ~4 tile radius
|
totalIntensity: 120 # about a ~4 tile radius
|
||||||
canCreateVacuum: false
|
canCreateVacuum: false
|
||||||
|
|
||||||
|
- type: entity
|
||||||
|
suffix: armed
|
||||||
|
parent: LandMineExplosiveUnarmed
|
||||||
|
id: LandMineExplosive
|
||||||
|
components:
|
||||||
|
- type: ItemToggle
|
||||||
|
activated: true
|
||||||
|
onActivate: false
|
||||||
|
- type: Armable
|
||||||
|
- type: Sprite
|
||||||
|
layers:
|
||||||
|
- state: landmine
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
doAfter: 1
|
doAfter: 1
|
||||||
|
|
||||||
- node: emptyCase
|
- node: emptyCase
|
||||||
entity: LandMineModular
|
entity: LandMineModularUnarmed
|
||||||
edges:
|
edges:
|
||||||
- to: wiredCase
|
- to: wiredCase
|
||||||
steps:
|
steps:
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
doAfter: 2
|
doAfter: 2
|
||||||
|
|
||||||
- node: wiredCase
|
- node: wiredCase
|
||||||
entity: LandMineModular
|
entity: LandMineModularUnarmed
|
||||||
actions:
|
actions:
|
||||||
- !type:PlaySound
|
- !type:PlaySound
|
||||||
sound: /Audio/Machines/button.ogg
|
sound: /Audio/Machines/button.ogg
|
||||||
|
|||||||
Reference in New Issue
Block a user