|
| 1 | +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt |
| 2 | +using System.Linq; |
| 3 | +using Content.Server.Administration; |
| 4 | +using Content.Server.Antag; |
| 5 | +using Content.Server.GameTicking; |
| 6 | +using Content.Server.GameTicking.Rules.Components; |
| 7 | +using Content.Shared.Administration; |
| 8 | +using Content.Shared.GameTicking; |
| 9 | +using Content.Shared.IdentityManagement; |
| 10 | +using Robust.Server.Player; |
| 11 | +using Robust.Shared.Console; |
| 12 | +using Robust.Shared.Random; |
| 13 | +using Content.Shared.Ghost; |
| 14 | +using Content.Server.Administration.Managers; |
| 15 | +using Content.Server.Roles; |
| 16 | +using Content.Shared.Mind; |
| 17 | +using Content.Shared.Mindshield.Components; |
| 18 | +using Content.Shared.Preferences; |
| 19 | +using Content.Server.Preferences.Managers; |
| 20 | + |
| 21 | +namespace Content.Server.SS220.Commands |
| 22 | +{ |
| 23 | + [AdminCommand(AdminFlags.VarEdit)] // Only for admins |
| 24 | + public sealed class MakeAntagCommand : IConsoleCommand |
| 25 | + { |
| 26 | + [Dependency] private readonly IEntityManager _entityManager = default!; |
| 27 | + [Dependency] private readonly IServerPreferencesManager _pref = default!; |
| 28 | + |
| 29 | + public string Command => "makerandomantag"; |
| 30 | + public string Description => Loc.GetString("command-makerandomantag-description"); |
| 31 | + public string Help => $"Usage: {Command}"; |
| 32 | + |
| 33 | + private readonly List<string> _antagTypes = new() // TODO: When will add a cult add a cultist there |
| 34 | + { |
| 35 | + "Traitor", |
| 36 | + "Thief", |
| 37 | + "InitialInfected", |
| 38 | + }; |
| 39 | + |
| 40 | + public void Execute(IConsoleShell shell, string argStr, string[] args) |
| 41 | + { |
| 42 | + if (args.Length == 0 || !_antagTypes.Contains(args[0])) |
| 43 | + { |
| 44 | + shell.WriteLine(Loc.GetString("command-makerandomantag-objective")); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + var successEntityUid = AdminMakeRandomAntagCommand(args[0]); |
| 49 | + |
| 50 | + if (successEntityUid != null) |
| 51 | + { |
| 52 | + shell.WriteLine(Loc.GetString("command-makerandomantag-sucess", |
| 53 | + ("Entityname", Identity.Name(successEntityUid.Value, _entityManager)), ("antag", args[0]))); |
| 54 | + } |
| 55 | + else |
| 56 | + shell.WriteLine(Loc.GetString("command-makerandomantag-negative")); |
| 57 | + } |
| 58 | + |
| 59 | + private EntityUid? AdminMakeRandomAntagCommand(string defaultRule) |
| 60 | + { |
| 61 | + var antag = _entityManager.System<AntagSelectionSystem>(); |
| 62 | + var playerManager = IoCManager.Resolve<IPlayerManager>(); |
| 63 | + var gameTicker = _entityManager.System<GameTicker>(); |
| 64 | + var random = IoCManager.Resolve<IRobustRandom>(); |
| 65 | + var mindSystem = _entityManager.System<SharedMindSystem>(); |
| 66 | + var roleSystem = _entityManager.System<RoleSystem>(); |
| 67 | + var banSystem = IoCManager.Resolve<IBanManager>(); |
| 68 | + |
| 69 | + var players = playerManager.Sessions |
| 70 | + .Where(x => gameTicker.PlayerGameStatuses[x.UserId] == PlayerGameStatus.JoinedGame) |
| 71 | + .ToList(); |
| 72 | + |
| 73 | + random.Shuffle(players); // Shuffle player list to be more randomly |
| 74 | + |
| 75 | + foreach (var player in players) |
| 76 | + { |
| 77 | + |
| 78 | + var pref = (HumanoidCharacterProfile)_pref.GetPreferences(player.UserId).SelectedCharacter; |
| 79 | + |
| 80 | + if (!mindSystem.TryGetMind(player.UserId, out var mindId)) // Is it player or a cow? |
| 81 | + continue; |
| 82 | + |
| 83 | + if (banSystem.GetRoleBans(player.UserId) is { } roleBans && |
| 84 | + roleBans.Contains("Job:" + defaultRule)) // Do he have a roleban on THIS antag? |
| 85 | + continue; |
| 86 | + |
| 87 | + if (roleSystem.MindIsAntagonist(mindId) || |
| 88 | + _entityManager.HasComponent<GhostComponent>(player.AttachedEntity) || |
| 89 | + _entityManager.HasComponent<MindShieldComponent>(player.AttachedEntity)) // Is he already lucky boy or he is ghost or he is CAPTIAN? |
| 90 | + continue; |
| 91 | + |
| 92 | + if (!pref.AntagPreferences.Contains(defaultRule)) // Do he want to be a chosen antag or no? |
| 93 | + continue; |
| 94 | + |
| 95 | + switch (defaultRule) // TODO: When will add a cult add a cultist there too. U can add more for fun if u want. |
| 96 | + { |
| 97 | + case "Traitor": |
| 98 | + antag.ForceMakeAntag<TraitorRuleComponent>(player, defaultRule); |
| 99 | + break; |
| 100 | + case "Thief": |
| 101 | + antag.ForceMakeAntag<ThiefRuleComponent>(player, defaultRule); |
| 102 | + break; |
| 103 | + case "InitialInfected": |
| 104 | + antag.ForceMakeAntag<ZombieRuleComponent>(player, defaultRule); |
| 105 | + break; |
| 106 | + } |
| 107 | + if (roleSystem.MindIsAntagonist(mindId)) // If he sucessfuly passed all checks and get his antag? |
| 108 | + return player.AttachedEntity; |
| 109 | + } |
| 110 | + return null; |
| 111 | + } |
| 112 | + |
| 113 | + |
| 114 | + public CompletionResult GetCompletion(IConsoleShell shell, string[] args) |
| 115 | + { |
| 116 | + if (args.Length == 1) |
| 117 | + { |
| 118 | + return CompletionResult.FromOptions(_antagTypes); |
| 119 | + } |
| 120 | + return CompletionResult.Empty; |
| 121 | + } |
| 122 | + } |
| 123 | +} |
0 commit comments