Skip to content

Commit

Permalink
Modular landmines (#8351)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirrorcult authored Jun 1, 2022
1 parent 19778cc commit da07d91
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 28 deletions.
1 change: 1 addition & 0 deletions Content.Server/Destructible/DestructibleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed class DestructibleSystem : SharedDestructibleSystem
[Dependency] public readonly ConstructionSystem ConstructionSystem = default!;
[Dependency] public readonly ExplosionSystem ExplosionSystem = default!;
[Dependency] public readonly StackSystem StackSystem = default!;
[Dependency] public readonly TriggerSystem TriggerSystem = default!;
[Dependency] public readonly IPrototypeManager PrototypeManager = default!;
[Dependency] public readonly IComponentFactory ComponentFactory = default!;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server.Destructible.Thresholds.Behaviors;

[DataDefinition]
public sealed class TriggerBehavior : IThresholdBehavior
{
public void Execute(EntityUid owner, DestructibleSystem system)
{
system.TriggerSystem.Trigger(owner);
}
}
8 changes: 7 additions & 1 deletion Content.Server/Explosion/EntitySystems/TriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Content.Shared.Sound;
using Content.Shared.Trigger;
using Content.Shared.Database;
using Content.Shared.Explosion;
using Content.Shared.Interaction;

namespace Content.Server.Explosion.EntitySystems
Expand Down Expand Up @@ -60,19 +61,22 @@ public override void Initialize()
private void HandleExplodeTrigger(EntityUid uid, ExplodeOnTriggerComponent component, TriggerEvent args)
{
_explosions.TriggerExplosive(uid, user: args.User);
args.Handled = true;
}

#region Flash
private void HandleFlashTrigger(EntityUid uid, FlashOnTriggerComponent component, TriggerEvent args)
{
// TODO Make flash durations sane ffs.
_flashSystem.FlashArea(uid, args.User, component.Range, component.Duration * 1000f);
args.Handled = true;
}
#endregion

private void HandleDeleteTrigger(EntityUid uid, DeleteOnTriggerComponent component, TriggerEvent args)
{
EntityManager.QueueDeleteEntity(uid);
args.Handled = true;
}

private void OnTriggerCollide(EntityUid uid, TriggerOnCollideComponent component, StartCollideEvent args)
Expand All @@ -84,12 +88,14 @@ private void OnTriggerCollide(EntityUid uid, TriggerOnCollideComponent component
private void OnActivate(EntityUid uid, TriggerOnActivateComponent component, ActivateInWorldEvent args)
{
Trigger(component.Owner, args.User);
args.Handled = true;
}

public void Trigger(EntityUid trigger, EntityUid? user = null)
public bool Trigger(EntityUid trigger, EntityUid? user = null)
{
var triggerEvent = new TriggerEvent(trigger, user);
EntityManager.EventBus.RaiseLocalEvent(trigger, triggerEvent);
return triggerEvent.Handled;
}

public void HandleTimerTrigger(EntityUid uid, EntityUid? user, float delay , float beepInterval, float? initialBeepDelay, SoundSpecifier? beepSound, AudioParams beepParams)
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/GhostKick/GhostKickUserOnTriggerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ private void HandleMineTriggered(EntityUid uid, GhostKickUserOnTriggerComponent
_ghostKickManager.DoDisconnect(
actor.PlayerSession.ConnectedClient,
"Tripped over a kick mine, crashed through the fourth wall");

args.Handled = true;
}
}
3 changes: 2 additions & 1 deletion Content.Server/LandMines/LandMineComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
[RegisterComponent]
public sealed class LandMineComponent : Component
{

[DataField("deleteOnActivate")]
public bool DeleteOnActivate = true;
}
18 changes: 10 additions & 8 deletions Content.Server/LandMines/LandMineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ private static void HandleTriggerAttempt(

private void HandleTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredEvent args)
{
_popupSystem.PopupCoordinates(
Loc.GetString("land-mine-triggered", ("mine", uid)),
Transform(uid).Coordinates,
Filter.Entities(args.Tripper));

_trigger.Trigger(uid, args.Tripper);

QueueDel(uid);
if (_trigger.Trigger(uid, args.Tripper))
{
_popupSystem.PopupCoordinates(
Loc.GetString("land-mine-triggered", ("mine", uid)),
Transform(uid).Coordinates,
Filter.Entities(args.Tripper));
}

if (component.DeleteOnActivate)
QueueDel(uid);
}
}

44 changes: 39 additions & 5 deletions Content.Server/Payload/EntitySystems/PayloadSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Explosion.EntitySystems;
using Content.Shared.Chemistry.Components;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Payload.Components;
using Content.Shared.Tag;
using Robust.Shared.Containers;
Expand All @@ -27,25 +29,37 @@ public override void Initialize()
SubscribeLocalEvent<PayloadTriggerComponent, TriggerEvent>(OnTriggerTriggered);
SubscribeLocalEvent<PayloadCaseComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
SubscribeLocalEvent<PayloadCaseComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
SubscribeLocalEvent<PayloadCaseComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ChemicalPayloadComponent, TriggerEvent>(HandleChemicalPayloadTrigger);
}

private void OnCaseTriggered(EntityUid uid, PayloadCaseComponent component, TriggerEvent args)
public IEnumerable<EntityUid> GetAllPayloads(EntityUid uid, ContainerManagerComponent? contMan=null)
{
if (!TryComp(uid, out ContainerManagerComponent? contMan))
return;
if (!Resolve(uid, ref contMan, false))
yield break;

// Pass trigger event onto all contained payloads. Payload capacity configurable by construction graphs.
foreach (var container in contMan.Containers.Values)
{
foreach (var entity in container.ContainedEntities)
{
if (_tagSystem.HasTag(entity, "Payload"))
RaiseLocalEvent(entity, args, false);
yield return entity;
}
}
}

private void OnCaseTriggered(EntityUid uid, PayloadCaseComponent component, TriggerEvent args)
{
if (!TryComp(uid, out ContainerManagerComponent? contMan))
return;

// Pass trigger event onto all contained payloads. Payload capacity configurable by construction graphs.
foreach (var ent in GetAllPayloads(uid, contMan))
{
RaiseLocalEvent(ent, args, false);
}
}

private void OnTriggerTriggered(EntityUid uid, PayloadTriggerComponent component, TriggerEvent args)
{
if (!component.Active)
Expand Down Expand Up @@ -106,6 +120,24 @@ private void OnEntityRemoved(EntityUid uid, PayloadCaseComponent component, EntR
trigger.GrantedComponents.Clear();
}

private void OnExamined(EntityUid uid, PayloadCaseComponent component, ExaminedEvent args)
{
if (!args.IsInDetailsRange)
{
args.PushMarkup(Loc.GetString("payload-case-not-close-enough", ("ent", uid)));
return;
}

if (GetAllPayloads(uid).Any())
{
args.PushMarkup(Loc.GetString("payload-case-has-payload", ("ent", uid)));
}
else
{
args.PushMarkup(Loc.GetString("payload-case-does-not-have-payload", ("ent", uid)));
}
}

private void HandleChemicalPayloadTrigger(EntityUid uid, ChemicalPayloadComponent component, TriggerEvent args)
{
if (component.BeakerSlotA.Item is not EntityUid beakerA
Expand Down Expand Up @@ -135,5 +167,7 @@ private void HandleChemicalPayloadTrigger(EntityUid uid, ChemicalPayloadComponen
_solutionSystem.TryAddSolution(beakerB, solutionB, tmpSol);
solutionA.MaxVolume -= solutionB.MaxVolume;
_solutionSystem.UpdateChemicals(beakerA, solutionA, false);

args.Handled = true;
}
}
1 change: 1 addition & 0 deletions Content.Server/Sound/EmitSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override void Initialize()
private void HandleEmitSoundOnTrigger(EntityUid uid, EmitSoundOnTriggerComponent component, TriggerEvent args)
{
TryEmitSound(component);
args.Handled = true;
}

private void HandleEmitSoundOnLand(EntityUid eUI, BaseEmitSoundComponent component, LandEvent arg)
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/payload/payload-case.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
payload-case-not-close-enough = You need to get closer to determine if {THE($ent)} has a payload installed.
payload-case-has-payload = {CAPITALIZE(THE($ent))} has a payload installed!
payload-case-does-not-have-payload = {CAPITALIZE(THE($ent))} does not have a payload installed.
28 changes: 27 additions & 1 deletion Resources/Prototypes/Entities/Objects/Misc/land_mine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
components:
- type: Clickable
- type: InteractionOutline
- type: Anchorable
- type: Pullable
- type: MovedByPressure
- type: Physics
bodyType: Static
Expand All @@ -18,9 +20,20 @@
layer:
- LowImpassable
- type: Sprite
drawdepth: FloorObjects
drawdepth: Items
sprite: Objects/Misc/uglymine.rsi
state: uglymine
- type: Damageable
damageContainer: Inorganic
- type: Destructible
thresholds:
- trigger:
!type:DamageTrigger
damage: 50
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: LandMine
- type: StepTrigger
requiredTriggeredSpeed: 0
Expand All @@ -32,6 +45,19 @@
components:
- type: GhostKickUserOnTrigger

- type: entity
name: modular mine
description: This bad boy could be packing any number of dangers. Or a bike horn.
parent: BaseLandMine
id: LandMineModular
components:
- type: PayloadCase
- type: Construction
graph: ModularMineGraph
node: emptyCase
- type: LandMine
deleteOnActivate: false

- type: entity
name: explosive mine
parent: BaseLandMine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO probably needs a base grenade

- type: entity
name: explosive grenade
description: Grenade that creates a small but devastating explosion.
Expand Down Expand Up @@ -32,6 +34,7 @@
!type:DamageTrigger
damage: 10
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: ["Destruction"]
- type: Appearance
Expand Down Expand Up @@ -71,6 +74,7 @@
!type:DamageTrigger
damage: 10
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: ["Destruction"]
- type: Appearance
Expand Down Expand Up @@ -108,13 +112,15 @@
!type:DamageTrigger
damage: 10
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: ["Destruction"]
- type: Appearance
visuals:
- type: TimerTriggerVisualizer
countdown_sound:
path: /Audio/Effects/minibombcountdown.ogg

- type: entity
name: the nuclear option
description: Please don't throw it, think of the children.
Expand Down Expand Up @@ -144,6 +150,7 @@
!type:DamageTrigger
damage: 50
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: ["Destruction"]
- type: Appearance
Expand Down Expand Up @@ -175,6 +182,7 @@
!type:DamageTrigger
damage: 50
behaviors:
- !type:TriggerBehavior
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: Appearance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
- type: constructionGraph
id: ModularMineGraph
start: start
graph:

- node: start
edges:
- to: emptyCase
steps:
- material: Steel
amount: 5
doAfter: 1

- node: emptyCase
entity: LandMineModular
edges:
- to: wiredCase
steps:
- material: Cable
doAfter: 0.5

- node: wiredCase
entity: LandMineModular
actions:
- !type:PlaySound
sound: /Audio/Machines/button.ogg
edges:
- to: emptyCase
steps:
- tool: Cutting
doAfter: 0.5
completed:
- !type:SpawnPrototype
prototype: CableApcStack1
- to: mine
steps:
- tag: Payload
store: payload
name: Payload
doAfter: 0.5

- node: mine
actions:
- !type:PlaySound
sound: /Audio/Machines/button.ogg
- !type:AdminLog
message: "A mine was crafted"
edges:
- to: wiredCase
steps:
- tool: Prying
doAfter: 0.5
completed:
- !type:EmptyContainer
container: payload
25 changes: 25 additions & 0 deletions Resources/Prototypes/Recipes/Construction/modular.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- type: construction
name: Modular Grenade
id: ModularGrenadeRecipe
graph: ModularGrenadeGraph
startNode: start
targetNode: grenade
category: Weapons
description: Construct a grenade using a trigger and a payload.
icon:
sprite: Objects/Weapons/Grenades/modular.rsi
state: complete
objectType: Item

- type: construction
name: Modular Mine
id: ModularMineRecipe
graph: ModularMineGraph
startNode: start
targetNode: mine
category: Weapons
description: Construct a landmine using a payload.
icon:
sprite: Objects/Misc/uglymine.rsi
state: uglymine
objectType: Item
Loading

0 comments on commit da07d91

Please sign in to comment.