Skip to content

Commit

Permalink
paradox anomaly antag rework (DeltaV-Station#1206)
Browse files Browse the repository at this point in the history
* move paradox code around and update it

* make MidRoundAntagRule just give spawn locations

* update the yaml

* give anom and listening post raffles

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: Null <[email protected]>
  • Loading branch information
deltanedas and NullWanderer authored May 18, 2024
1 parent 6a1749a commit 94d3fda
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 250 deletions.

This file was deleted.

164 changes: 0 additions & 164 deletions Content.Server/DeltaV/ParadoxAnomaly/Systems/ParadoxAnomalySystem.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.StationEvents.Components;

/// <summary>
/// Creates a paradox anomaly of a random person when taken by a player.
/// </summary>
[RegisterComponent]
public sealed partial class ParadoxClonerRuleComponent : Component;
104 changes: 104 additions & 0 deletions Content.Server/DeltaV/StationEvents/Events/ParadoxClonerRule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using Content.Server.Antag;
using Content.Server.GameTicking.Rules;
using Content.Server.Psionics;
using Content.Server.Station.Systems;
using Content.Server.StationEvents.Components;
using Content.Server.StationEvents.Events;
using Content.Server.Terminator.Systems;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Diagnostics.CodeAnalysis;

namespace Content.Server.StationEvents.Events;

/// <summary>
/// Creates clones of random players to make into selected antags.
/// 90% of the actual antag's work is done by exterminator (rip) since its a reskin.
/// </summary>
public sealed class ParadoxClonerRule : StationEventSystem<ParadoxClonerRuleComponent>
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly PsionicsSystem _psionics = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly SharedRoleSystem _role = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
[Dependency] private readonly TerminatorSystem _terminator = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<ParadoxClonerRuleComponent, AntagSelectEntityEvent>(OnSelectEntity);
}

private void OnSelectEntity(Entity<ParadoxClonerRuleComponent> ent, ref AntagSelectEntityEvent args)
{
if (args.Session?.AttachedEntity is not {} spawner)
return;

Log.Debug($"Rule {ToPrettyString(ent)} creating a paradox anomaly using spawner {spawner}");
if (!TrySpawnParadoxAnomaly(spawner, out var clone))
return;

Log.Info($"Created paradox anomaly {ToPrettyString(clone):clone}");
args.Entity = clone;
}

private bool TrySpawnParadoxAnomaly(EntityUid spawner, [NotNullWhen(true)] out EntityUid? clone)
{
clone = null;

// Get a list of potential candidates
var candidates = new List<(EntityUid, Entity<JobComponent>, HumanoidCharacterProfile)>();
var query = EntityQueryEnumerator<MindContainerComponent, HumanoidAppearanceComponent>();
while (query.MoveNext(out var uid, out var mindContainer, out var humanoid))
{
if (humanoid.LastProfileLoaded is {} profile &&
_mind.GetMind(uid, mindContainer) is {} mindId &&
TryComp<JobComponent>(mindId, out var job) &&
!_role.MindIsAntagonist(mindId))
{
candidates.Add((uid, (mindId, job), profile));
}
}

if (candidates.Count == 0)
{
Log.Warning("Found no eligible players to paradox clone!");
return false;
}

clone = SpawnParadoxAnomaly(spawner, candidates);
return true;
}

private EntityUid SpawnParadoxAnomaly(EntityUid spawner, List<(EntityUid, Entity<JobComponent>, HumanoidCharacterProfile)> candidates)
{
// Select a candidate.
var (uid, (mindId, job), profile) = _random.Pick(candidates);

// Spawn the clone.
var coords = Transform(spawner).Coordinates;
var station = _station.GetOwningStation(uid);
var spawned = _stationSpawning.SpawnPlayerMob(coords, job, profile, station);

// Set the kill target to the chosen player
_terminator.SetTarget(spawned, mindId);

// guaranteed psionic power
var psi = EnsureComp<PotentialPsionicComponent>(spawned);
_psionics.RollPsionics(spawned, psi, false, 100);

return spawned;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
using Content.Server.Nyanotrasen.StationEvents.Events;
using Content.Server.StationEvents.Events;
using Robust.Shared.Prototypes;

namespace Content.Server.StationEvents.Components;

[RegisterComponent, Access(typeof(MidRoundAntagRule))]
public sealed partial class MidRoundAntagRuleComponent : Component
{
/// <summary>
/// Spawner to create at a random mid round antag marker.
/// </summary>
[DataField(required: true)]
public EntProtoId Spawner = string.Empty;
}
/// <summary>
/// Spawns any antags at random midround antag spawnpoints, falls back to vent critter spawners.
/// Requires <c>AntagSelection</c>.
/// </summary>
[RegisterComponent]
public sealed partial class MidRoundAntagRuleComponent : Component;
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
namespace Content.Server.StationEvents
{
[RegisterComponent]
public sealed partial class MidRoundAntagSpawnLocationComponent : Component
{
namespace Content.Server.StationEvents;

}
}
[RegisterComponent]
public sealed partial class MidRoundAntagSpawnLocationComponent : Component;
Loading

0 comments on commit 94d3fda

Please sign in to comment.