From df7aadd8308e987e9c21c4badb42a339e03cd67f Mon Sep 17 00:00:00 2001 From: rhailrake <49613070+rhailrake@users.noreply.github.com> Date: Thu, 27 Apr 2023 22:57:51 +0600 Subject: [PATCH] [feat] Species lock for jobs --- .github/workflows/update-wiki.yml | 72 +++++++++++++++++++ .../GameTicking/GameTicker.Spawning.cs | 31 ++++++++ Content.Shared/Roles/JobPrototype.cs | 5 ++ .../Roles/Jobs/Cargo/quartermaster.yml | 3 + .../Prototypes/Roles/Jobs/Command/captain.yml | 3 + .../Roles/Jobs/Command/head_of_personnel.yml | 2 + .../Roles/Jobs/Engineering/chief_engineer.yml | 3 + .../Jobs/Medical/chief_medical_officer.yml | 3 + .../Roles/Jobs/Science/research_director.yml | 3 + .../Roles/Jobs/Security/detective.yml | 3 + .../Roles/Jobs/Security/head_of_security.yml | 3 + .../Roles/Jobs/Security/security_cadet.yml | 3 + .../Roles/Jobs/Security/security_officer.yml | 3 + .../Prototypes/Roles/Jobs/Security/warden.yml | 3 + 14 files changed, 140 insertions(+) create mode 100644 .github/workflows/update-wiki.yml diff --git a/.github/workflows/update-wiki.yml b/.github/workflows/update-wiki.yml new file mode 100644 index 0000000000..a42b6dac4d --- /dev/null +++ b/.github/workflows/update-wiki.yml @@ -0,0 +1,72 @@ +name: Update Wiki + +on: + workflow_dispatch: + push: + branches: [ master, jsondump ] + paths: + - '.github/workflows/update-wiki.yml' + - 'Content.Shared/Chemistry/**.cs' + - 'Content.Server/Chemistry/**.cs' + - 'Content.Server/GuideGenerator/**.cs' + - 'Resources/Prototypes/Reagents/**.yml' + - 'Resources/Prototypes/Chemistry/**.yml' + - 'Resources/Prototypes/Recipes/Reactions/**.yml' + - 'RobustToolbox/' + +jobs: + update-wiki: + name: Build and Publish JSON blobs to wiki + runs-on: ubuntu-latest + + steps: + - name: Checkout Master + uses: actions/checkout@v2 + + - name: Setup Submodule + run: | + git submodule update --init --recursive + + - name: Pull Engine Updates + uses: space-wizards/submodule-dependency@v0.1.5 + + - name: Update Engine Submodules + run: | + cd RobustToolbox/ + git submodule update --init --recursive + + - name: Setup .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.100 + + - name: Install Dependencies + run: dotnet restore + + - name: Build Project + run: dotnet build --configuration Release --no-restore /p:WarningsAsErrors=nullable /m + + - name: Generate JSON blobs for prototypes + run: dotnet ./bin/Content.Server/Content.Server.dll --cvar autogen.destination_file=prototypes.json + continue-on-error: true + + - name: Upload chem_prototypes.json to wiki + uses: jtmullen/mediawiki-edit-action@v0.1.1 + with: + wiki_text_file: ./bin/Content.Server/data/chem_prototypes.json + edit_summary: Update chem_prototypes.json via GitHub Actions + page_name: "${{ secrets.WIKI_PAGE_ROOT }}/chem_prototypes.json" + api_url: https://wiki.ss14.su/api.php + username: ${{ secrets.WIKI_BOT_USER }} + password: ${{ secrets.WIKI_BOT_PASS }} + + - name: Upload react_prototypes.json to wiki + uses: jtmullen/mediawiki-edit-action@v0.1.1 + with: + wiki_text_file: ./bin/Content.Server/data/react_prototypes.json + edit_summary: Update react_prototypes.json via GitHub Actions + page_name: "${{ secrets.WIKI_PAGE_ROOT }}/react_prototypes.json" + api_url: https://wiki.ss14.su/api.php + username: ${{ secrets.WIKI_BOT_USER }} + password: ${{ secrets.WIKI_BOT_PASS }} + diff --git a/Content.Server/GameTicking/GameTicker.Spawning.cs b/Content.Server/GameTicking/GameTicker.Spawning.cs index 7ace73e86f..3902845004 100644 --- a/Content.Server/GameTicking/GameTicker.Spawning.cs +++ b/Content.Server/GameTicking/GameTicker.Spawning.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using System.Numerics; using Content.Server.Administration.Managers; +using System.Text; using Content.Server.Ghost; using Content.Server.Spawners.Components; using Content.Server.Speech.Components; @@ -210,6 +211,36 @@ namespace Content.Server.GameTicking _playTimeTrackings.PlayerRolesChanged(player); + var whitelistedSpecies = jobPrototype.WhitelistedSpecies; + + if (whitelistedSpecies.Count > 0 && !whitelistedSpecies.Contains(character.Species)) + { + var playerProfiles = _prefsManager.GetPreferences(player.UserId).Characters.Values.Cast().ToList(); + + var existedAllowedProfile = playerProfiles.FindAll(x => whitelistedSpecies.Contains(x.Species)); + + if (existedAllowedProfile.Count == 0) + { + character = HumanoidCharacterProfile.RandomWithSpecies(_robustRandom.Pick(whitelistedSpecies)); + _chatManager.DispatchServerMessage(player, "Данному виду запрещено играть на этой профессии. Вам была выдана случайная внешность."); + } + else + { + character = _robustRandom.Pick(existedAllowedProfile); + _chatManager.DispatchServerMessage(player, "Данному виду запрещено играть на этой профессии. Вам была выдана случайная внешность с подходящим видом из вашего профиля."); + } + + StringBuilder availableSpeciesLoc = new StringBuilder(); + foreach (var specie in whitelistedSpecies) + { + availableSpeciesLoc.AppendLine("-" + Loc.GetString($"species-name-{specie.ToLower()}")); + } + + _chatManager.DispatchServerMessage(player, $"Доступные виды: \n {availableSpeciesLoc}"); + } + + + var mobMaybe = _stationSpawning.SpawnPlayerCharacterOnStation(station, job, character); DebugTools.AssertNotNull(mobMaybe); var mob = mobMaybe!.Value; diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index 64cd2c6643..3348557571 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -1,4 +1,5 @@ using Content.Shared.Access; +using Content.Shared.Humanoid.Prototypes; using Content.Shared.Players.PlayTimeTracking; using Content.Shared.StatusIcon; using Robust.Shared.Prototypes; @@ -98,5 +99,9 @@ namespace Content.Shared.Roles [DataField("extendedAccessGroups", customTypeSerializer: typeof(PrototypeIdListSerializer))] public IReadOnlyCollection ExtendedAccessGroups { get; private set; } = Array.Empty(); + + [DataField("whitelistedSpecies", customTypeSerializer: typeof(PrototypeIdListSerializer))] + public IReadOnlyCollection WhitelistedSpecies { get; private set; } = Array.Empty(); + } } diff --git a/Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml b/Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml index 95fdf2b674..42cab23dde 100644 --- a/Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml +++ b/Resources/Prototypes/Roles/Jobs/Cargo/quartermaster.yml @@ -19,6 +19,9 @@ startingGear: QuartermasterGear icon: "JobIconQuarterMaster" supervisors: job-supervisors-captain + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Cargo diff --git a/Resources/Prototypes/Roles/Jobs/Command/captain.yml b/Resources/Prototypes/Roles/Jobs/Command/captain.yml index b72a718697..f3e9f41037 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/captain.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/captain.yml @@ -22,6 +22,9 @@ requireAdminNotify: true joinNotifyCrew: true supervisors: job-supervisors-centcom + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false accessGroups: - AllAccess diff --git a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml index 744b6013fc..79936c86c8 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/head_of_personnel.yml @@ -21,6 +21,8 @@ icon: "JobIconHeadOfPersonnel" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistedSpecies: + - Human canBeAntag: false access: - Command diff --git a/Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml b/Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml index 24f96207e7..af7f118de4 100644 --- a/Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml +++ b/Resources/Prototypes/Roles/Jobs/Engineering/chief_engineer.yml @@ -20,6 +20,9 @@ icon: "JobIconChiefEngineer" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Maintenance diff --git a/Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml b/Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml index 4635bbcc39..86951ee98b 100644 --- a/Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml +++ b/Resources/Prototypes/Roles/Jobs/Medical/chief_medical_officer.yml @@ -22,6 +22,9 @@ icon: "JobIconChiefMedicalOfficer" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Medical diff --git a/Resources/Prototypes/Roles/Jobs/Science/research_director.yml b/Resources/Prototypes/Roles/Jobs/Science/research_director.yml index fed002977d..7441e7f0fd 100644 --- a/Resources/Prototypes/Roles/Jobs/Science/research_director.yml +++ b/Resources/Prototypes/Roles/Jobs/Science/research_director.yml @@ -14,6 +14,9 @@ icon: "JobIconResearchDirector" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Research diff --git a/Resources/Prototypes/Roles/Jobs/Security/detective.yml b/Resources/Prototypes/Roles/Jobs/Security/detective.yml index e8d6299f48..e76b7e5815 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/detective.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/detective.yml @@ -10,6 +10,9 @@ startingGear: DetectiveGear icon: "JobIconDetective" supervisors: job-supervisors-hos + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Security diff --git a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml index 7f6017b619..db88e6dbab 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml @@ -20,6 +20,9 @@ icon: "JobIconHeadOfSecurity" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - HeadOfSecurity diff --git a/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml b/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml index a4a5889ca1..b6d105d45a 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml @@ -13,6 +13,9 @@ startingGear: SecurityCadetGear icon: "JobIconSecurityCadet" supervisors: job-supervisors-security + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Security diff --git a/Resources/Prototypes/Roles/Jobs/Security/security_officer.yml b/Resources/Prototypes/Roles/Jobs/Security/security_officer.yml index 886e40b151..898e207c09 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/security_officer.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/security_officer.yml @@ -10,6 +10,9 @@ startingGear: SecurityOfficerGear icon: "JobIconSecurityOfficer" supervisors: job-supervisors-hos + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Security diff --git a/Resources/Prototypes/Roles/Jobs/Security/warden.yml b/Resources/Prototypes/Roles/Jobs/Security/warden.yml index 2b8d15b9e2..2d17865c56 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/warden.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/warden.yml @@ -10,6 +10,9 @@ startingGear: WardenGear icon: "JobIconWarden" supervisors: job-supervisors-hos + whitelistedSpecies: + - Human + - Dwarf canBeAntag: false access: - Security