]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make monkeys better (#19407)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sun, 10 Sep 2023 02:51:51 +0000 (03:51 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Sep 2023 02:51:51 +0000 (12:51 +1000)
Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs
Content.Server/GameTicking/Rules/TraitorRuleSystem.cs
Content.Server/Traitor/Components/AutoTraitorComponent.cs [new file with mode: 0644]
Content.Server/Traitor/Systems/AutoTraitorSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Resources/Prototypes/Entities/Mobs/NPCs/pets.yml

index 6aebd60e2e7dcc4c0847e3900a05cc90e482ba6f..ccd2778008647373027ddf732740b54756a7df6f 100644 (file)
@@ -2,6 +2,7 @@ using Content.Server.GameTicking.Rules;
 using Content.Server.Zombies;
 using Content.Shared.Administration;
 using Content.Shared.Database;
+using Content.Shared.Humanoid;
 using Content.Shared.Mind;
 using Content.Shared.Mind.Components;
 using Content.Shared.Verbs;
@@ -21,7 +22,7 @@ public sealed partial class AdminVerbSystem
     // All antag verbs have names so invokeverb works.
     private void AddAntagVerbs(GetVerbsEvent<Verb> args)
     {
-        if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
+        if (!TryComp<ActorComponent>(args.User, out var actor))
             return;
 
         var player = actor.PlayerSession;
@@ -29,8 +30,7 @@ public sealed partial class AdminVerbSystem
         if (!_adminManager.HasAdminFlag(player, AdminFlags.Fun))
             return;
 
-        var targetHasMind = TryComp(args.Target, out MindContainerComponent? targetMindComp);
-        if (!targetHasMind || targetMindComp == null)
+        if (!TryComp<MindContainerComponent>(args.Target, out var targetMindComp))
             return;
 
         Verb traitor = new()
@@ -43,7 +43,9 @@ public sealed partial class AdminVerbSystem
                 if (!_minds.TryGetSession(targetMindComp.Mind, out var session))
                     return;
 
-                _traitorRule.MakeTraitor(session);
+                // if its a monkey or mouse or something dont give uplink or objectives
+                var isHuman = HasComp<HumanoidAppearanceComponent>(args.Target);
+                _traitorRule.MakeTraitor(session, giveUplink: isHuman, giveObjectives: isHuman);
             },
             Impact = LogImpact.High,
             Message = Loc.GetString("admin-verb-make-traitor"),
index 5dffd35ad42bfcc0c89e7394e44019acdd7cb056..210425526c207b0b983ae6a0333fa1b4759facc3 100644 (file)
@@ -205,7 +205,7 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
         return results;
     }
 
-    public bool MakeTraitor(ICommonSession traitor)
+    public bool MakeTraitor(ICommonSession traitor, bool giveUplink = true, bool giveObjectives = true)
     {
         var traitorRule = EntityQuery<TraitorRuleComponent>().FirstOrDefault();
         if (traitorRule == null)
@@ -240,19 +240,25 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
         if (_jobs.MindTryGetJob(mindId, out _, out var prototype))
             startingBalance = Math.Max(startingBalance - prototype.AntagAdvantage, 0);
 
-        // creadth: we need to create uplink for the antag.
-        // PDA should be in place already
-        var pda = _uplink.FindUplinkTarget(mind.OwnedEntity!.Value);
-        if (pda == null || !_uplink.AddUplink(mind.OwnedEntity.Value, startingBalance))
-            return false;
-
-        // Add the ringtone uplink and get its code for greeting
-        var code = EnsureComp<RingerUplinkComponent>(pda.Value).Code;
+        // Give traitors their codewords and uplink code to keep in their character info menu
+        var briefing = Loc.GetString("traitor-role-codewords-short", ("codewords", string.Join(", ", traitorRule.Codewords)));
+        Note[]? code = null;
+        if (giveUplink)
+        {
+            // creadth: we need to create uplink for the antag.
+            // PDA should be in place already
+            var pda = _uplink.FindUplinkTarget(mind.OwnedEntity!.Value);
+            if (pda == null || !_uplink.AddUplink(mind.OwnedEntity.Value, startingBalance))
+                return false;
+
+            // Give traitors their codewords and uplink code to keep in their character info menu
+            code = EnsureComp<RingerUplinkComponent>(pda.Value).Code;
+            // If giveUplink is false the uplink code part is omitted
+            briefing = string.Format("{0}\n{1}", briefing,
+                Loc.GetString("traitor-role-uplink-code-short", ("code", string.Join("-", code).Replace("sharp","#"))));
+        }
 
         // Prepare traitor role
-        // Give traitors their codewords and uplink code to keep in their character info menu
-        var briefing =
-            $"{Loc.GetString("traitor-role-codewords-short", ("codewords", string.Join(", ", traitorRule.Codewords)))}\n{Loc.GetString("traitor-role-uplink-code-short", ("code", string.Join("-", code).Replace("sharp", "#")))}";
         var traitorRole = new TraitorRoleComponent
         {
             PrototypeId = traitorRule.TraitorPrototypeId,
@@ -282,17 +288,20 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
         _npcFaction.AddFaction(entity, "Syndicate");
 
         // Give traitors their objectives
-        var maxDifficulty = _cfg.GetCVar(CCVars.TraitorMaxDifficulty);
-        var maxPicks = _cfg.GetCVar(CCVars.TraitorMaxPicks);
-        var difficulty = 0f;
-        for (var pick = 0; pick < maxPicks && maxDifficulty > difficulty; pick++)
+        if (giveObjectives)
         {
-            var objective = _objectives.GetRandomObjective(mindId, mind, "TraitorObjectiveGroups");
+            var maxDifficulty = _cfg.GetCVar(CCVars.TraitorMaxDifficulty);
+            var maxPicks = _cfg.GetCVar(CCVars.TraitorMaxPicks);
+            var difficulty = 0f;
+            for (var pick = 0; pick < maxPicks && maxDifficulty > difficulty; pick++)
+            {
+                var objective = _objectives.GetRandomObjective(mindId, mind, "TraitorObjectiveGroups");
+                if (objective == null)
+                    continue;
 
-            if (objective == null)
-                continue;
-            if (_mindSystem.TryAddObjective(mindId, mind, objective))
-                difficulty += objective.Difficulty;
+                if (_mindSystem.TryAddObjective(mindId, mind, objective))
+                    difficulty += objective.Difficulty;
+            }
         }
 
         return true;
@@ -304,14 +313,15 @@ public sealed class TraitorRuleSystem : GameRuleSystem<TraitorRuleComponent>
     /// <param name="mind">A mind (player)</param>
     /// <param name="codewords">Codewords</param>
     /// <param name="code">Uplink codes</param>
-    private void SendTraitorBriefing(EntityUid mind, string[] codewords, Note[] code)
+    private void SendTraitorBriefing(EntityUid mind, string[] codewords, Note[]? code)
     {
-        if (_mindSystem.TryGetSession(mind, out var session))
-        {
-           _chatManager.DispatchServerMessage(session, Loc.GetString("traitor-role-greeting"));
-           _chatManager.DispatchServerMessage(session, Loc.GetString("traitor-role-codewords", ("codewords", string.Join(", ", codewords))));
+        if (!_mindSystem.TryGetSession(mind, out var session))
+            return;
+
+       _chatManager.DispatchServerMessage(session, Loc.GetString("traitor-role-greeting"));
+       _chatManager.DispatchServerMessage(session, Loc.GetString("traitor-role-codewords", ("codewords", string.Join(", ", codewords))));
+       if (code != null)
            _chatManager.DispatchServerMessage(session, Loc.GetString("traitor-role-uplink-code", ("code", string.Join("-", code).Replace("sharp","#"))));
-        }
     }
 
     private void HandleLatejoin(PlayerSpawnCompleteEvent ev)
diff --git a/Content.Server/Traitor/Components/AutoTraitorComponent.cs b/Content.Server/Traitor/Components/AutoTraitorComponent.cs
new file mode 100644 (file)
index 0000000..ab4bee2
--- /dev/null
@@ -0,0 +1,22 @@
+using Content.Server.Traitor.Systems;
+
+namespace Content.Server.Traitor.Components;
+
+/// <summary>
+/// Makes the entity a traitor either instantly if it has a mind or when a mind is added.
+/// </summary>
+[RegisterComponent, Access(typeof(AutoTraitorSystem))]
+public sealed partial class AutoTraitorComponent : Component
+{
+    /// <summary>
+    /// Whether to give the traitor an uplink or not.
+    /// </summary>
+    [DataField("giveUplink"), ViewVariables(VVAccess.ReadWrite)]
+    public bool GiveUplink = true;
+
+    /// <summary>
+    /// Whether to give the traitor objectives or not.
+    /// </summary>
+    [DataField("giveObjectives"), ViewVariables(VVAccess.ReadWrite)]
+    public bool GiveObjectives = true;
+}
diff --git a/Content.Server/Traitor/Systems/AutoTraitorSystem.cs b/Content.Server/Traitor/Systems/AutoTraitorSystem.cs
new file mode 100644 (file)
index 0000000..70fefd4
--- /dev/null
@@ -0,0 +1,76 @@
+using Content.Server.GameTicking.Rules;
+using Content.Server.Traitor.Components;
+using Content.Shared.Mind;
+using Content.Shared.Mind.Components;
+
+namespace Content.Server.Traitor.Systems;
+
+/// <summary>
+/// Makes entities with <see cref="AutoTraitorComponent"/> a traitor either immediately if they have a mind or when a mind is added.
+/// </summary>
+public sealed class AutoTraitorSystem : EntitySystem
+{
+    [Dependency] private readonly TraitorRuleSystem _traitorRule = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<AutoTraitorComponent, MapInitEvent>(OnMapInit);
+        SubscribeLocalEvent<AutoTraitorComponent, MindAddedMessage>(OnMindAdded);
+    }
+
+    private void OnMapInit(EntityUid uid, AutoTraitorComponent comp, MapInitEvent args)
+    {
+        TryMakeTraitor(uid, comp);
+    }
+
+    private void OnMindAdded(EntityUid uid, AutoTraitorComponent comp, MindAddedMessage args)
+    {
+        TryMakeTraitor(uid, comp);
+    }
+
+    /// <summary>
+    /// Sets the GiveUplink field.
+    /// </summary>
+    public void SetGiveUplink(EntityUid uid, bool giveUplink, AutoTraitorComponent? comp = null)
+    {
+        if (!Resolve(uid, ref comp))
+            return;
+
+        comp.GiveUplink = giveUplink;
+    }
+
+    /// <summary>
+    /// Sets the GiveObjectives field.
+    /// </summary>
+    public void SetGiveObjectives(EntityUid uid, bool giveObjectives, AutoTraitorComponent? comp = null)
+    {
+        if (!Resolve(uid, ref comp))
+            return;
+
+        comp.GiveObjectives = giveObjectives;
+    }
+
+    /// <summary>
+    /// Checks if there is a mind, then makes it a traitor using the options.
+    /// </summary>
+    public bool TryMakeTraitor(EntityUid uid, AutoTraitorComponent? comp = null)
+    {
+        if (!Resolve(uid, ref comp))
+            return false;
+
+        if (!TryComp<MindContainerComponent>(uid, out var mindContainer) || mindContainer.Mind == null)
+            return false;
+
+        var mindId = mindContainer.Mind.Value;
+        if (!TryComp<MindComponent>(mindId, out var mind) || mind.Session == null)
+            return false;
+
+        var session = mind.Session;
+        _traitorRule.MakeTraitor(session, giveUplink: comp.GiveUplink, giveObjectives: comp.GiveObjectives);
+        // prevent spamming anything if it fails
+        RemComp<AutoTraitorComponent>(uid);
+        return true;
+    }
+}
index add77172989e6a1f4d8806213917ec6993a128f3..7ff922bc0128018fd4982e8db8a3c002ad0b20be 100644 (file)
         - MobMask
         layer:
         - MobLayer
+  - type: Stripping
   - type: Strippable
   - type: UserInterface
     interfaces:
     - Trash
     - VimPilot
     - Mouse
+    - DoorBumpOpener
   - type: Respirator
     damage:
       types:
   - type: Tag
     tags:
     - VimPilot
+    - DoorBumpOpener
+  # make the player a traitor once its taken
+  - type: AutoTraitor
+    giveUplink: false
+    giveObjectives: false
 
   # I have included a snake_hiss.ogg sound file so if you want to use that be my guest
 - type: entity
index f401a75fae739a75e1f9f7a37ab24ac570c2751b..4fedd7f1a6455dfae67503f8e34f0fcfa48fe68b 100644 (file)
     tags:
     - CannotSuicide
     - DoorBumpOpener
+    - VimPilot
   - type: Loadout
     prototypes: [ MobMonkeyGear ]