forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'space-wizards:master' into master
- Loading branch information
Showing
39 changed files
with
337 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Content.Shared.Whitelist; | ||
|
||
namespace Content.Server.GameTicking.Rules.VariationPass.Components; | ||
|
||
/// <summary> | ||
/// Handles cutting a random wire on random devices around the station. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class CutWireVariationPassComponent : Component | ||
{ | ||
/// <summary> | ||
/// Blacklist of hackable entities that should not be chosen to | ||
/// have wires cut. | ||
/// </summary> | ||
[DataField] | ||
public EntityWhitelist Blacklist = new(); | ||
|
||
/// <summary> | ||
/// Chance for an individual wire to be cut. | ||
/// </summary> | ||
[DataField] | ||
public float WireCutChance = 0.05f; | ||
|
||
/// <summary> | ||
/// Maximum number of wires that can be cut stationwide. | ||
/// </summary> | ||
[DataField] | ||
public int MaxWiresCut = 10; | ||
} |
39 changes: 39 additions & 0 deletions
39
Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Content.Server.GameTicking.Rules.VariationPass.Components; | ||
using Content.Server.Wires; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server.GameTicking.Rules.VariationPass; | ||
|
||
/// <summary> | ||
/// Handles cutting a random wire on random devices around the station. | ||
/// This system identifies target devices and adds <see cref="CutWireOnMapInitComponent"/> to them. | ||
/// The actual wire cutting is handled by <see cref="CutWireOnMapInitSystem"/>. | ||
/// </summary> | ||
public sealed class CutWireVariationPassSystem : VariationPassSystem<CutWireVariationPassComponent> | ||
{ | ||
protected override void ApplyVariation(Entity<CutWireVariationPassComponent> ent, ref StationVariationPassEvent args) | ||
{ | ||
var wiresCut = 0; | ||
var query = AllEntityQuery<WiresComponent, TransformComponent>(); | ||
while (query.MoveNext(out var uid, out _, out var transform)) | ||
{ | ||
// Ignore if not part of the station | ||
if (!IsMemberOfStation((uid, transform), ref args)) | ||
continue; | ||
|
||
// Check against blacklist | ||
if (ent.Comp.Blacklist.IsValid(uid)) | ||
continue; | ||
|
||
if (Random.Prob(ent.Comp.WireCutChance)) | ||
{ | ||
EnsureComp<CutWireOnMapInitComponent>(uid); | ||
wiresCut++; | ||
|
||
// Limit max wires cut | ||
if (wiresCut >= ent.Comp.MaxWiresCut) | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 41 additions & 27 deletions
68
Content.Server/Spawners/Components/TimedSpawnerComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,54 @@ | ||
using System.Threading; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Random; | ||
using Robust.Shared.Serialization; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; | ||
|
||
namespace Content.Server.Spawners.Components | ||
namespace Content.Server.Spawners.Components; | ||
|
||
/// <summary> | ||
/// Spawns entities at a set interval. | ||
/// Can configure the set of entities, spawn timing, spawn chance, | ||
/// and min/max number of entities to spawn. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class TimedSpawnerComponent : Component, ISerializationHooks | ||
{ | ||
[RegisterComponent] | ||
public sealed partial class TimedSpawnerComponent : Component, ISerializationHooks | ||
{ | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("prototypes", customTypeSerializer:typeof(PrototypeIdListSerializer<EntityPrototype>))] | ||
public List<string> Prototypes { get; set; } = new(); | ||
/// <summary> | ||
/// List of entities that can be spawned by this component. One will be randomly | ||
/// chosen for each entity spawned. When multiple entities are spawned at once, | ||
/// each will be randomly chosen separately. | ||
/// </summary> | ||
[DataField] | ||
public List<EntProtoId> Prototypes = []; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("chance")] | ||
public float Chance { get; set; } = 1.0f; | ||
/// <summary> | ||
/// Chance of an entity being spawned at the end of each interval. | ||
/// </summary> | ||
[DataField] | ||
public float Chance = 1.0f; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("intervalSeconds")] | ||
public int IntervalSeconds { get; set; } = 60; | ||
/// <summary> | ||
/// Length of the interval between spawn attempts. | ||
/// </summary> | ||
[DataField] | ||
public int IntervalSeconds = 60; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("MinimumEntitiesSpawned")] | ||
public int MinimumEntitiesSpawned { get; set; } = 1; | ||
/// <summary> | ||
/// The minimum number of entities that can be spawned when an interval elapses. | ||
/// </summary> | ||
[DataField] | ||
public int MinimumEntitiesSpawned = 1; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField("MaximumEntitiesSpawned")] | ||
public int MaximumEntitiesSpawned { get; set; } = 1; | ||
/// <summary> | ||
/// The maximum number of entities that can be spawned when an interval elapses. | ||
/// </summary> | ||
[DataField] | ||
public int MaximumEntitiesSpawned = 1; | ||
|
||
public CancellationTokenSource? TokenSource; | ||
public CancellationTokenSource? TokenSource; | ||
|
||
void ISerializationHooks.AfterDeserialization() | ||
{ | ||
if (MinimumEntitiesSpawned > MaximumEntitiesSpawned) | ||
throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!"); | ||
} | ||
void ISerializationHooks.AfterDeserialization() | ||
{ | ||
if (MinimumEntitiesSpawned > MaximumEntitiesSpawned) | ||
throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!"); | ||
} | ||
} |
Oops, something went wrong.