[feat] Species lock for jobs

This commit is contained in:
rhailrake
2023-04-27 22:57:51 +06:00
committed by Aviu00
parent d65bc9a0d0
commit df7aadd830
14 changed files with 140 additions and 0 deletions

View File

@@ -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<HumanoidCharacterProfile>().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;