From 2cdf178447d60dc54c3e0ad9166e7337e717d293 Mon Sep 17 00:00:00 2001 From: RinKeeper <161238702+RinKeeper@users.noreply.github.com> Date: Thu, 27 Jun 2024 08:59:13 +0300 Subject: [PATCH] wizard admin verb (#374) * done * oops * some wizard rule tweaks * Update WizardRuleSystem.cs resolve --- .../Systems/AdminVerbSystem.Antags.cs | 19 ++++- .../_White/Wizard/WizardRuleSystem.cs | 76 ++++++++++++++++++- .../Locale/en-US/administration/antag.ftl | 2 + .../Locale/ru-RU/administration/antag.ftl | 2 + 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs index 1e7c32851a..604a6f922f 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Antags.cs @@ -9,6 +9,7 @@ using Content.Shared.Verbs; using Robust.Shared.Player; using Robust.Shared.Utility; using Content.Server._White.Cult.GameRule; +using Content.Server._White.Wizard; namespace Content.Server.Administration.Systems; @@ -22,6 +23,7 @@ public sealed partial class AdminVerbSystem [Dependency] private readonly PiratesRuleSystem _piratesRule = default!; [Dependency] private readonly RevolutionaryRuleSystem _revolutionaryRule = default!; [Dependency] private readonly CultRuleSystem _cultRule = default!; + [Dependency] private readonly WizardRuleSystem _wizardRule = default!; // All antag verbs have names so invokeverb works. private void AddAntagVerbs(GetVerbsEvent args) @@ -150,8 +152,21 @@ public sealed partial class AdminVerbSystem Impact = LogImpact.High, Message = Loc.GetString("admin-verb-make-changeling"), }; - args.Verbs.Add(changeling); - //WD edit end + + Verb wizard = new() + { + Text = Loc.GetString("admin-verb-text-make-wizard"), + Category = VerbCategory.Antag, + Icon = new SpriteSpecifier.Texture(new ResPath("/Textures/Clothing/Head/Hats/wizardhat.rsi/icon.png")), + Act = () => + { + _wizardRule.AdminMakeWizard(args.Target); + }, + Impact = LogImpact.High, + Message = Loc.GetString("admin-verb-make-wizard"), + }; + args.Verbs.Add(wizard); } + //WD edit end } diff --git a/Content.Server/_White/Wizard/WizardRuleSystem.cs b/Content.Server/_White/Wizard/WizardRuleSystem.cs index 46ef0bcbcb..0f511c52b8 100644 --- a/Content.Server/_White/Wizard/WizardRuleSystem.cs +++ b/Content.Server/_White/Wizard/WizardRuleSystem.cs @@ -300,10 +300,10 @@ public sealed class WizardRuleSystem : GameRuleSystem _npcFaction.AddFaction(mob, "Wizard"); } - private void SpawnWizard(ICommonSession? session, WizardRuleComponent component, bool spawnGhostRoles = true) + private EntityCoordinates WizardSpawnPoint(WizardRuleComponent component) { if (component.ShuttleMap is not {Valid: true} mapUid) - return; + return EntityCoordinates.Invalid; var spawn = new EntityCoordinates(); foreach (var (_, meta, xform) in EntityQuery(true)) @@ -318,13 +318,25 @@ public sealed class WizardRuleSystem : GameRuleSystem break; } - //Fallback, spawn at the centre of the map + // Fallback, spawn at the centre of the map if (spawn == new EntityCoordinates()) { spawn = Transform(mapUid).Coordinates; _sawmill.Warning("Fell back to default spawn for wizard!"); } + return spawn; + } + + private void SpawnWizard(ICommonSession? session, WizardRuleComponent component, bool spawnGhostRoles = true) + { + var spawn = WizardSpawnPoint(component); + if (spawn == EntityCoordinates.Invalid) + { + _sawmill.Error("Failed to calculate wizard spawn point"); + return; + } + var wizardAntag = _prototypeManager.Index(component.WizardRoleProto); //If a session is available, spawn mob and transfer mind into it @@ -395,4 +407,62 @@ public sealed class WizardRuleSystem : GameRuleSystem ICommonSession? session = null; SpawnWizard(session, component, true); } + + /// + /// Makes mob a wizard through admin verb button + /// + public void AdminMakeWizard(EntityUid uid) + { + var rule = EntityQuery().FirstOrDefault(); + + if (rule == null) + { + GameTicker.StartGameRule("Wizard", out var ruleEntity); + rule = Comp(ruleEntity); + } + + if (HasComp(uid)) + return; + + MakeWizard(uid, rule, true); + } + + private bool MakeWizard(EntityUid wizard, WizardRuleComponent rule, + bool giveObjectives = true) + { + if (!_mind.TryGetMind(wizard, out var mindId, out var mind)) + { + Log.Info("Failed getting mind for picked wizard."); + return false; + } + + if (HasComp(mindId)) + { + Log.Error($"Player {mind.CharacterName} is already a wizard."); + return false; + } + + HumanoidCharacterProfile? profile = null; + if (TryComp(wizard, out ActorComponent? actor)) + profile = _prefs.GetPreferences(actor.PlayerSession.UserId).SelectedCharacter as HumanoidCharacterProfile; + + if (giveObjectives) + { + AddRole(mindId, mind, rule); + } + + if (!_prototypeManager.TryIndex(rule.StartingGear, out var gear)) + { + _sawmill.Error("Failed to load wizard gear prototype"); + return false; + } + + SetupWizardEntity(wizard, rule.Points, gear, profile); + + var spawnpoint = WizardSpawnPoint(rule); + var transform = EnsureComp(wizard); + transform.Coordinates = spawnpoint; + + return true; + } } diff --git a/Resources/Locale/en-US/administration/antag.ftl b/Resources/Locale/en-US/administration/antag.ftl index 1375969e79..09dc3980d5 100644 --- a/Resources/Locale/en-US/administration/antag.ftl +++ b/Resources/Locale/en-US/administration/antag.ftl @@ -6,6 +6,7 @@ admin-verb-make-nuclear-operative = Make target into a lone Nuclear Operative. admin-verb-make-pirate = Make the target into a pirate. Note this doesn't configure the game rule. admin-verb-make-head-rev = Make the target into a Head Revolutionary. admin-verb-make-thief = Make the target into a thief. +admin-verb-make-wizard = Make the target into a wizard. admin-verb-text-make-traitor = Make Traitor admin-verb-text-make-changeling = Make Changeling @@ -14,3 +15,4 @@ admin-verb-text-make-nuclear-operative = Make Nuclear Operative admin-verb-text-make-pirate = Make Pirate admin-verb-text-make-head-rev = Make Head Rev admin-verb-text-make-thief = Make Thief +admin-verb-text-make-wizard = Make wizard diff --git a/Resources/Locale/ru-RU/administration/antag.ftl b/Resources/Locale/ru-RU/administration/antag.ftl index b444bf66fc..6bcbafe193 100644 --- a/Resources/Locale/ru-RU/administration/antag.ftl +++ b/Resources/Locale/ru-RU/administration/antag.ftl @@ -6,6 +6,7 @@ admin-verb-make-nuclear-operative = Сделать цель одиноким Я admin-verb-make-pirate = Сделать цель пиратом\капером. Учтите, что это не меняет игровой режим. admin-verb-make-head-rev = Сделать цель главой революции. admin-verb-make-thief = Сделать цель вором. +admin-verb-make-wizard = Сделать цель магом. admin-verb-text-make-traitor = Сделать предателем admin-verb-text-make-changeling = Сделать генокрадом @@ -14,3 +15,4 @@ admin-verb-text-make-nuclear-operative = Сделать одиноким яде admin-verb-text-make-pirate = Сделать пиратом admin-verb-text-make-head-rev = Сделать главой революции admin-verb-text-make-thief = Сделать вором +admin-verb-text-make-wizard = Сделать магом