Fix the job overflow crash (#5560)

* Fix the overflow crash

* localization fail
This commit is contained in:
Moony
2021-11-26 16:51:00 -06:00
committed by GitHub
parent 1f09f7f055
commit ef89af1a0c
3 changed files with 12 additions and 5 deletions

View File

@@ -106,7 +106,7 @@ namespace Content.Server.GameTicking
return assigned;
}
private string PickBestAvailableJob(HumanoidCharacterProfile profile, StationId station)
private string? PickBestAvailableJob(HumanoidCharacterProfile profile, StationId station)
{
var available = _stationSystem.StationInfo[station].JobList;
@@ -148,7 +148,7 @@ namespace Content.Server.GameTicking
}
var overflows = _stationSystem.StationInfo[station].MapPrototype.OverflowJobs.Clone().ToList();
return _robustRandom.Pick(overflows);
return overflows.Count != 0 ? _robustRandom.Pick(overflows) : null;
}
[Conditional("DEBUG")]

View File

@@ -81,6 +81,15 @@ namespace Content.Server.GameTicking
return;
}
// Pick best job best on prefs.
jobId ??= PickBestAvailableJob(character, station);
// If no job available, just bail out.
if (jobId is null)
{
_chatManager.DispatchServerMessage(player, Loc.GetString("game-ticker-player-no-jobs-available-when-joining"));
return;
}
PlayerJoinGame(player);
var data = player.ContentData();
@@ -94,9 +103,6 @@ namespace Content.Server.GameTicking
};
newMind.ChangeOwningPlayer(data.UserId);
// Pick best job best on prefs.
jobId ??= PickBestAvailableJob(character, station);
var jobPrototype = _prototypeManager.Index<JobPrototype>(jobId);
var job = new Job(newMind, jobPrototype);
newMind.AddRole(job);