-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor and add log * add api needed for objective * backport LastProfileLoaded * fix midround antag rule * evil twin spawning code * evil twin yml and stuff * m * hopefully fully rename it * fixy --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
02b1352
commit 9985ee9
Showing
18 changed files
with
325 additions
and
25 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Content.Server/DeltaV/ParadoxAnomaly/Components/ParadoxAnomalySpawner.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,17 @@ | ||
using Content.Server.DeltaV.ParadoxAnomaly.Systems; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.DeltaV.ParadoxAnomaly.Components; | ||
|
||
/// <summary> | ||
/// Creates a random paradox anomaly and tranfers mind to it when taken by a player. | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(ParadoxAnomalySystem))] | ||
public sealed partial class ParadoxAnomalySpawnerComponent : Component | ||
{ | ||
/// <summary> | ||
/// Antag game rule to start for the paradox anomaly. | ||
/// </summary> | ||
[DataField] | ||
public EntProtoId Rule = "ParadoxAnomaly"; | ||
} |
164 changes: 164 additions & 0 deletions
164
Content.Server/DeltaV/ParadoxAnomaly/Systems/ParadoxAnomalySystem.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,164 @@ | ||
using Content.Server.DeltaV.ParadoxAnomaly.Components; | ||
using Content.Server.DetailExaminable; | ||
using Content.Server.GenericAntag; | ||
using Content.Server.Ghost.Roles; | ||
using Content.Server.Ghost.Roles.Components; | ||
using Content.Server.Psionics; | ||
using Content.Server.Spawners.Components; | ||
using Content.Server.Station.Systems; | ||
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.DeltaV.ParadoxAnomaly.Systems; | ||
|
||
/// <summary> | ||
/// 90% of the work is done by exterminator since its a reskin. | ||
/// All the logic here is spawning since thats tricky. | ||
/// </summary> | ||
public sealed class ParadoxAnomalySystem : EntitySystem | ||
{ | ||
[Dependency] private readonly GenericAntagSystem _genericAntag = default!; | ||
[Dependency] private readonly GhostRoleSystem _ghostRole = default!; | ||
[Dependency] private readonly IPrototypeManager _proto = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly MetaDataSystem _metaData = default!; | ||
[Dependency] private readonly PsionicsSystem _psionics = default!; | ||
[Dependency] private readonly SharedHumanoidAppearanceSystem _humanoid = 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<ParadoxAnomalySpawnerComponent, TakeGhostRoleEvent>(OnTakeGhostRole); | ||
} | ||
|
||
private void OnTakeGhostRole(Entity<ParadoxAnomalySpawnerComponent> ent, ref TakeGhostRoleEvent args) | ||
{ | ||
Log.Info($"Using paradox anomaly spawner {ent}"); | ||
if (!TrySpawnParadoxAnomaly(ent.Comp.Rule, out var twin)) | ||
return; | ||
|
||
Log.Info($"Created paradox anomaly {ToPrettyString(twin):twin}"); | ||
var role = Comp<GhostRoleComponent>(ent); | ||
_ghostRole.GhostRoleInternalCreateMindAndTransfer(args.Player, ent, twin.Value, role); | ||
_ghostRole.UnregisterGhostRole((ent.Owner, role)); | ||
|
||
args.TookRole = true; | ||
QueueDel(ent); | ||
} | ||
|
||
private bool TrySpawnParadoxAnomaly(string rule, [NotNullWhen(true)] out EntityUid? twin) | ||
{ | ||
twin = null; | ||
|
||
// Get a list of potential candidates | ||
var candidates = new List<(EntityUid, EntityUid, SpeciesPrototype, HumanoidCharacterProfile)>(); | ||
var query = EntityQueryEnumerator<MindContainerComponent, HumanoidAppearanceComponent>(); | ||
while (query.MoveNext(out var uid, out var mindContainer, out var humanoid)) | ||
{ | ||
if (humanoid.LastProfileLoaded is not {} profile) | ||
continue; | ||
|
||
if (!_proto.TryIndex<SpeciesPrototype>(humanoid.Species, out var species)) | ||
continue; | ||
|
||
if (_mind.GetMind(uid, mindContainer) is not {} mindId || !HasComp<JobComponent>(mindId)) | ||
continue; | ||
|
||
if (_role.MindIsAntagonist(mindId)) | ||
continue; | ||
|
||
// TODO: when metempsychosis real skip whoever has Karma | ||
|
||
candidates.Add((uid, mindId, species, profile)); | ||
} | ||
|
||
twin = SpawnParadoxAnomaly(candidates, rule); | ||
return twin != null; | ||
} | ||
|
||
private EntityUid? SpawnParadoxAnomaly(List<(EntityUid, EntityUid, SpeciesPrototype, HumanoidCharacterProfile)> candidates, string rule) | ||
{ | ||
// Select a candidate. | ||
if (candidates.Count == 0) | ||
return null; | ||
|
||
var (uid, mindId, species, profile) = _random.Pick(candidates); | ||
var jobId = Comp<JobComponent>(mindId).Prototype; | ||
var job = _proto.Index<JobPrototype>(jobId!); | ||
|
||
// Find a suitable spawn point. | ||
var station = _station.GetOwningStation(uid); | ||
var latejoins = new List<EntityUid>(); | ||
var query = EntityQueryEnumerator<SpawnPointComponent>(); | ||
while (query.MoveNext(out var spawnUid, out var spawnPoint)) | ||
{ | ||
if (spawnPoint.SpawnType != SpawnPointType.LateJoin) | ||
continue; | ||
|
||
if (_station.GetOwningStation(spawnUid) == station) | ||
latejoins.Add(spawnUid); | ||
} | ||
|
||
if (latejoins.Count == 0) | ||
return null; | ||
|
||
// Spawn the twin. | ||
var destination = Transform(_random.Pick(latejoins)).Coordinates; | ||
var spawned = Spawn(species.Prototype, destination); | ||
|
||
// Set the kill target to the chosen player | ||
_terminator.SetTarget(spawned, mindId); | ||
_genericAntag.MakeAntag(spawned, rule); | ||
|
||
////////////////////////// | ||
// /!\ WARNING /!\ // | ||
// MAJOR SHITCODE BELOW // | ||
// /!\ WARNING /!\ // | ||
////////////////////////// | ||
|
||
// Copy the details. | ||
_humanoid.LoadProfile(spawned, profile); | ||
_metaData.SetEntityName(spawned, Name(uid)); | ||
|
||
if (TryComp<DetailExaminableComponent>(uid, out var detail)) | ||
{ | ||
var detailCopy = EnsureComp<DetailExaminableComponent>(spawned); | ||
detailCopy.Content = detail.Content; | ||
} | ||
|
||
if (job.StartingGear != null && _proto.TryIndex<StartingGearPrototype>(job.StartingGear, out var gear)) | ||
{ | ||
_stationSpawning.EquipStartingGear(spawned, gear, profile); | ||
_stationSpawning.EquipIdCard(spawned, | ||
profile.Name, | ||
job, | ||
station); | ||
} | ||
|
||
foreach (var special in job.Special) | ||
{ | ||
special.AfterEquip(spawned); | ||
} | ||
|
||
var psi = EnsureComp<PotentialPsionicComponent>(spawned); | ||
_psionics.RollPsionics(spawned, psi, false, 100); | ||
|
||
return spawned; | ||
} | ||
} |
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
9 changes: 5 additions & 4 deletions
9
Content.Server/Nyanotrasen/StationEvents/Components/MidRoundAntagRuleComponent.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,16 +1,17 @@ | ||
using Content.Server.StationEvents.Events; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Server.StationEvents.Components; | ||
|
||
[RegisterComponent, Access(typeof(MidRoundAntagRule))] | ||
public sealed partial class MidRoundAntagRuleComponent : Component | ||
{ | ||
[DataField("antags")] | ||
public IReadOnlyList<string> MidRoundAntags = new[] | ||
public List<EntProtoId> MidRoundAntags = new() | ||
{ | ||
"SpawnPointGhostRatKing", | ||
"SpawnPointGhostVampSpider", | ||
"SpawnPointGhostFugitive", | ||
"MobEvilTwinSpawn" | ||
//"SpawnPointGhostVampSpider", | ||
//"SpawnPointGhostFugitive", | ||
"SpawnPointGhostParadoxAnomaly" | ||
}; | ||
} |
27 changes: 12 additions & 15 deletions
27
Content.Server/Nyanotrasen/StationEvents/Events/MidRoundAntagRule.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,41 +1,38 @@ | ||
using System.Linq; | ||
using Robust.Shared.Random; | ||
using Content.Server.GameTicking.Rules.Components; | ||
using Content.Server.StationEvents.Components; | ||
using Robust.Shared.Random; | ||
using System.Linq; | ||
|
||
namespace Content.Server.StationEvents.Events; | ||
|
||
internal sealed class MidRoundAntagRule : StationEventSystem<MidRoundAntagRuleComponent> | ||
public sealed class MidRoundAntagRule : StationEventSystem<MidRoundAntagRuleComponent> | ||
{ | ||
[Dependency] private readonly IRobustRandom _robustRandom = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
protected override void Started(EntityUid uid, MidRoundAntagRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) | ||
{ | ||
base.Started(uid, component, gameRule, args); | ||
|
||
var spawnLocations = EntityManager.EntityQuery<MidRoundAntagSpawnLocationComponent, TransformComponent>().ToList(); | ||
var backupSpawnLocations = EntityManager.EntityQuery<VentCritterSpawnLocationComponent, TransformComponent>().ToList(); | ||
var spawnLocations = EntityQuery<MidRoundAntagSpawnLocationComponent, TransformComponent>().ToList(); | ||
var backupSpawnLocations = EntityQuery<VentCritterSpawnLocationComponent, TransformComponent>().ToList(); | ||
|
||
TransformComponent? spawn = new(); | ||
|
||
if (spawnLocations.Count > 0) | ||
{ | ||
var spawnLoc = _robustRandom.Pick(spawnLocations); | ||
var spawnLoc = _random.Pick(spawnLocations); | ||
spawn = spawnLoc.Item2; | ||
} else if (backupSpawnLocations.Count > 0) | ||
{ | ||
var spawnLoc = _robustRandom.Pick(backupSpawnLocations); | ||
var spawnLoc = _random.Pick(backupSpawnLocations); | ||
spawn = spawnLoc.Item2; | ||
} | ||
|
||
if (spawn == null) | ||
if (spawn?.GridUid == null) | ||
return; | ||
|
||
if (spawn.GridUid == null) | ||
{ | ||
return; | ||
} | ||
|
||
Spawn(_robustRandom.Pick(component.MidRoundAntags), spawn.Coordinates); | ||
var proto = _random.Pick(component.MidRoundAntags); | ||
Log.Info($"Spawning midround antag {proto} at {spawn.Coordinates}"); | ||
Spawn(proto, spawn.Coordinates); | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
Resources/Locale/en-US/deltav/game-ticking/game-rules/rule-paradox-anomaly.ftl
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,5 @@ | ||
paradox-anomaly-round-end-agent-name = Paradox Anomaly | ||
objective-issuer-self = [color=#1708EC]Self[/color] | ||
# briefing is in terminator ftl |
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
2 changes: 2 additions & 0 deletions
2
Resources/Locale/en-US/deltav/objectives/conditions/paradox-anomaly.ftl
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,2 @@ | ||
objective-paradox-anomaly-kill-title = Kill this universe's {$targetName} | ||
objective-paradox-anomaly-friend-title = Keep your new friend {$targetName} alive |
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
Oops, something went wrong.