diff --git a/Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs b/Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs index 21a36e7ad5..cf16617479 100644 --- a/Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs +++ b/Content.IntegrationTests/Tests/GameRules/NukeOpsTest.cs @@ -16,6 +16,7 @@ using Content.Shared.FixedPoint; using Content.Shared.GameTicking; using Content.Shared.Hands.Components; using Content.Shared.Inventory; +using Content.Shared.NPC.Prototypes; using Content.Shared.NPC.Systems; using Content.Shared.NukeOps; using Content.Shared.Pinpointer; @@ -23,12 +24,16 @@ using Content.Shared.Station.Components; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; namespace Content.IntegrationTests.Tests.GameRules; [TestFixture] public sealed class NukeOpsTest { + private static readonly ProtoId SyndicateFaction = "Syndicate"; + private static readonly ProtoId NanotrasenFaction = "NanoTrasen"; + /// /// Check that a nuke ops game mode can start without issue. I.e., that the nuke station and such all get loaded. /// @@ -119,8 +124,8 @@ public sealed class NukeOpsTest Assert.That(entMan.HasComponent(player)); Assert.That(roleSys.MindIsAntagonist(mind)); Assert.That(roleSys.MindHasRole(mind)); - Assert.That(factionSys.IsMember(player, "Syndicate"), Is.True); - Assert.That(factionSys.IsMember(player, "NanoTrasen"), Is.False); + Assert.That(factionSys.IsMember(player, SyndicateFaction), Is.True); + Assert.That(factionSys.IsMember(player, NanotrasenFaction), Is.False); var roles = roleSys.MindGetAllRoleInfo(mind); var cmdRoles = roles.Where(x => x.Prototype == "NukeopsCommander"); Assert.That(cmdRoles.Count(), Is.EqualTo(1)); @@ -130,8 +135,8 @@ public sealed class NukeOpsTest Assert.That(entMan.HasComponent(dummyEnts[1])); Assert.That(roleSys.MindIsAntagonist(dummyMind)); Assert.That(roleSys.MindHasRole(dummyMind)); - Assert.That(factionSys.IsMember(dummyEnts[1], "Syndicate"), Is.True); - Assert.That(factionSys.IsMember(dummyEnts[1], "NanoTrasen"), Is.False); + Assert.That(factionSys.IsMember(dummyEnts[1], SyndicateFaction), Is.True); + Assert.That(factionSys.IsMember(dummyEnts[1], NanotrasenFaction), Is.False); roles = roleSys.MindGetAllRoleInfo(dummyMind); cmdRoles = roles.Where(x => x.Prototype == "NukeopsMedic"); Assert.That(cmdRoles.Count(), Is.EqualTo(1)); @@ -146,8 +151,8 @@ public sealed class NukeOpsTest Assert.That(entMan.HasComponent(ent), Is.False); Assert.That(roleSys.MindIsAntagonist(mindCrew), Is.False); Assert.That(roleSys.MindHasRole(mindCrew), Is.False); - Assert.That(factionSys.IsMember(ent, "Syndicate"), Is.False); - Assert.That(factionSys.IsMember(ent, "NanoTrasen"), Is.True); + Assert.That(factionSys.IsMember(ent, SyndicateFaction), Is.False); + Assert.That(factionSys.IsMember(ent, NanotrasenFaction), Is.True); var nukeroles = new List() { "Nukeops", "NukeopsMedic", "NukeopsCommander" }; Assert.That(roleSys.MindGetAllRoleInfo(mindCrew).Any(x => nukeroles.Contains(x.Prototype)), Is.False); } diff --git a/Content.IntegrationTests/Tests/GameRules/TraitorRuleTest.cs b/Content.IntegrationTests/Tests/GameRules/TraitorRuleTest.cs index d2717521b2..97fe1c8762 100644 --- a/Content.IntegrationTests/Tests/GameRules/TraitorRuleTest.cs +++ b/Content.IntegrationTests/Tests/GameRules/TraitorRuleTest.cs @@ -8,6 +8,7 @@ using Content.Server.Roles; using Content.Shared.GameTicking; using Content.Shared.GameTicking.Components; using Content.Shared.Mind; +using Content.Shared.NPC.Prototypes; using Content.Shared.NPC.Systems; using Content.Shared.Objectives.Components; using Robust.Shared.GameObjects; @@ -20,6 +21,8 @@ public sealed class TraitorRuleTest { private const string TraitorGameRuleProtoId = "Traitor"; private const string TraitorAntagRoleName = "Traitor"; + private static readonly ProtoId SyndicateFaction = "Syndicate"; + private static readonly ProtoId NanotrasenFaction = "NanoTrasen"; [Test] public async Task TestTraitorObjectives() @@ -108,8 +111,8 @@ public sealed class TraitorRuleTest // Make sure the player is a traitor. var mind = mindSys.GetMind(player)!.Value; Assert.That(roleSys.MindIsAntagonist(mind)); - Assert.That(factionSys.IsMember(player, "Syndicate"), Is.True); - Assert.That(factionSys.IsMember(player, "NanoTrasen"), Is.False); + Assert.That(factionSys.IsMember(player, SyndicateFaction), Is.True); + Assert.That(factionSys.IsMember(player, NanotrasenFaction), Is.False); Assert.That(traitorRule.TotalTraitors, Is.EqualTo(1)); Assert.That(traitorRule.TraitorMinds[0], Is.EqualTo(mind)); diff --git a/Content.Server/Zombies/ZombieSystem.Transform.cs b/Content.Server/Zombies/ZombieSystem.Transform.cs index 479c56cd5e..03be40aad2 100644 --- a/Content.Server/Zombies/ZombieSystem.Transform.cs +++ b/Content.Server/Zombies/ZombieSystem.Transform.cs @@ -38,6 +38,7 @@ using Content.Shared.Ghost.Roles.Components; using Content.Shared.Tag; using Robust.Shared.Player; using Robust.Shared.Prototypes; +using Content.Shared.NPC.Prototypes; namespace Content.Server.Zombies; @@ -66,6 +67,8 @@ public sealed partial class ZombieSystem private static readonly ProtoId InvalidForGlobalSpawnSpellTag = "InvalidForGlobalSpawnSpell"; private static readonly ProtoId CannotSuicideTag = "CannotSuicide"; + private static readonly ProtoId ZombieFaction = "Zombie"; + /// /// Handles an entity turning into a zombie when they die or go into crit /// @@ -223,7 +226,7 @@ public sealed partial class ZombieSystem _mobState.ChangeMobState(target, MobState.Alive); _faction.ClearFactions(target, dirty: false); - _faction.AddFaction(target, "Zombie"); + _faction.AddFaction(target, ZombieFaction); //gives it the funny "Zombie ___" name. _nameMod.RefreshNameModifiers(target); diff --git a/Content.Shared/NPC/Systems/NpcFactionSystem.cs b/Content.Shared/NPC/Systems/NpcFactionSystem.cs index 0d684de80b..734cb1d0ff 100644 --- a/Content.Shared/NPC/Systems/NpcFactionSystem.cs +++ b/Content.Shared/NPC/Systems/NpcFactionSystem.cs @@ -73,7 +73,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Returns whether an entity is a member of a faction. /// - public bool IsMember(Entity ent, string faction) + public bool IsMember(Entity ent, [ForbidLiteral] string faction) { if (!Resolve(ent, ref ent.Comp, false)) return false; @@ -85,7 +85,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// Returns whether an entity is a member of any listed faction. /// If the list is empty this returns false. /// - public bool IsMemberOfAny(Entity ent, IEnumerable> factions) + public bool IsMemberOfAny(Entity ent, [ForbidLiteral] IEnumerable> factions) { if (!Resolve(ent, ref ent.Comp, false)) return false; @@ -102,7 +102,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Adds this entity to the particular faction. /// - public void AddFaction(Entity ent, string faction, bool dirty = true) + public void AddFaction(Entity ent, [ForbidLiteral] string faction, bool dirty = true) { if (!_proto.HasIndex(faction)) { @@ -121,7 +121,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Adds this entity to the particular faction. /// - public void AddFactions(Entity ent, HashSet> factions, bool dirty = true) + public void AddFactions(Entity ent, [ForbidLiteral] HashSet> factions, bool dirty = true) { ent.Comp ??= EnsureComp(ent); @@ -143,7 +143,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Removes this entity from the particular faction. /// - public void RemoveFaction(Entity ent, string faction, bool dirty = true) + public void RemoveFaction(Entity ent, [ForbidLiteral] string faction, bool dirty = true) { if (!_proto.HasIndex(faction)) { @@ -202,7 +202,7 @@ public sealed partial class NpcFactionSystem : EntitySystem return GetNearbyFactions(ent, range, ent.Comp.FriendlyFactions); } - private IEnumerable GetNearbyFactions(EntityUid entity, float range, HashSet> factions) + private IEnumerable GetNearbyFactions(EntityUid entity, float range, [ForbidLiteral] HashSet> factions) { var xform = Transform(entity); foreach (var ent in _lookup.GetEntitiesInRange(_xform.GetMapCoordinates((entity, xform)), range)) @@ -228,12 +228,12 @@ public sealed partial class NpcFactionSystem : EntitySystem return ent.Comp.Factions.Overlaps(other.Comp.Factions) || ent.Comp.FriendlyFactions.Overlaps(other.Comp.Factions); } - public bool IsFactionFriendly(string target, string with) + public bool IsFactionFriendly([ForbidLiteral] string target, [ForbidLiteral] string with) { return _factions[target].Friendly.Contains(with) && _factions[with].Friendly.Contains(target); } - public bool IsFactionFriendly(string target, Entity with) + public bool IsFactionFriendly([ForbidLiteral] string target, Entity with) { if (!Resolve(with, ref with.Comp, false)) return false; @@ -242,12 +242,12 @@ public sealed partial class NpcFactionSystem : EntitySystem with.Comp.FriendlyFactions.Contains(target); } - public bool IsFactionHostile(string target, string with) + public bool IsFactionHostile([ForbidLiteral] string target, [ForbidLiteral] string with) { return _factions[target].Hostile.Contains(with) && _factions[with].Hostile.Contains(target); } - public bool IsFactionHostile(string target, Entity with) + public bool IsFactionHostile([ForbidLiteral] string target, Entity with) { if (!Resolve(with, ref with.Comp, false)) return false; @@ -256,7 +256,7 @@ public sealed partial class NpcFactionSystem : EntitySystem with.Comp.HostileFactions.Contains(target); } - public bool IsFactionNeutral(string target, string with) + public bool IsFactionNeutral([ForbidLiteral] string target, [ForbidLiteral] string with) { return !IsFactionFriendly(target, with) && !IsFactionHostile(target, with); } @@ -264,7 +264,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Makes the source faction friendly to the target faction, 1-way. /// - public void MakeFriendly(string source, string target) + public void MakeFriendly([ForbidLiteral] string source, [ForbidLiteral] string target) { if (!_factions.TryGetValue(source, out var sourceFaction)) { @@ -286,7 +286,7 @@ public sealed partial class NpcFactionSystem : EntitySystem /// /// Makes the source faction hostile to the target faction, 1-way. /// - public void MakeHostile(string source, string target) + public void MakeHostile([ForbidLiteral] string source, [ForbidLiteral] string target) { if (!_factions.TryGetValue(source, out var sourceFaction)) {