Client LuaCsForBarotrauma
HireManager.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  class HireManager
8  {
9  public List<CharacterInfo> AvailableCharacters { get; set; }
10  public List<CharacterInfo> PendingHires = new List<CharacterInfo>();
11 
12  public const int MaxAvailableCharacters = 6;
13 
14  public HireManager()
15  {
16  AvailableCharacters = new List<CharacterInfo>();
17  }
18 
19  public void RemoveCharacter(CharacterInfo character)
20  {
21  AvailableCharacters.Remove(character);
22  }
23 
24  public static int GetSalaryFor(IReadOnlyCollection<CharacterInfo> hires)
25  {
26  return hires.Sum(hire => GetSalaryFor(hire));
27  }
28 
29  public static int GetSalaryFor(CharacterInfo hire)
30  {
31  IEnumerable<Character> crew = GameSession.GetSessionCrewCharacters(CharacterType.Both);
32  float multiplier = 0;
33  foreach (var character in crew)
34  {
35  multiplier += character?.Info?.GetSavedStatValueWithAll(StatTypes.HireCostMultiplier, hire.Job.Prefab.Identifier) ?? 0;
36  }
37  float finalMultiplier = 1f + MathF.Max(multiplier, -1f);
38  return (int)(hire.Salary * finalMultiplier);
39  }
40 
41  public void GenerateCharacters(Location location, int amount)
42  {
43  AvailableCharacters.ForEach(c => c.Remove());
44  AvailableCharacters.Clear();
45 
46  foreach (var missingJob in location.Type.GetHireablesMissingFromCrew())
47  {
48  AddCharacter(missingJob);
49  amount--;
50  }
51  for (int i = 0; i < amount; i++)
52  {
53  AddCharacter(location.Type.GetRandomHireable());
54  }
55  if (location.Faction != null) { GenerateFactionCharacters(location.Faction.Prefab); }
56  if (location.SecondaryFaction != null) { GenerateFactionCharacters(location.SecondaryFaction.Prefab); }
57 
58  void AddCharacter(JobPrefab job)
59  {
60  if (job == null) { return; }
61  int variant = Rand.Range(0, job.Variants, Rand.RandSync.ServerAndClient);
62  AvailableCharacters.Add(new CharacterInfo(CharacterPrefab.HumanSpeciesName, jobOrJobPrefab: job, variant: variant));
63  }
64  }
65 
66  private void GenerateFactionCharacters(FactionPrefab faction)
67  {
68  foreach (var character in faction.HireableCharacters)
69  {
70  HumanPrefab humanPrefab = NPCSet.Get(character.NPCSetIdentifier, character.NPCIdentifier);
71  if (humanPrefab == null)
72  {
73  DebugConsole.ThrowError($"Couldn't create a hireable for the location: character prefab \"{character.NPCIdentifier}\" not found in the NPC set \"{character.NPCSetIdentifier}\".");
74  continue;
75  }
76  var characterInfo = humanPrefab.CreateCharacterInfo(Rand.RandSync.ServerAndClient);
77  characterInfo.MinReputationToHire = (faction.Identifier, character.MinReputation);
78  AvailableCharacters.Add(characterInfo);
79  }
80  }
81 
82  public void Remove()
83  {
84  AvailableCharacters.ForEach(c => c.Remove());
85  AvailableCharacters.Clear();
86  }
87 
88  public void RenameCharacter(CharacterInfo characterInfo, string newName)
89  {
90  if (characterInfo == null || string.IsNullOrEmpty(newName)) { return; }
91  AvailableCharacters.FirstOrDefault(ci => ci == characterInfo)?.Rename(newName);
92  PendingHires.FirstOrDefault(ci => ci == characterInfo)?.Rename(newName);
93  }
94  }
95 }
Stores information about the Character that is needed between rounds in the menu etc....
static readonly Identifier HumanSpeciesName
static ImmutableHashSet< Character > GetSessionCrewCharacters(CharacterType type)
Returns a list of crew characters currently in the game with a given filter.
void RemoveCharacter(CharacterInfo character)
Definition: HireManager.cs:19
static int GetSalaryFor(CharacterInfo hire)
Definition: HireManager.cs:29
void GenerateCharacters(Location location, int amount)
Definition: HireManager.cs:41
static int GetSalaryFor(IReadOnlyCollection< CharacterInfo > hires)
Definition: HireManager.cs:24
const int MaxAvailableCharacters
Definition: HireManager.cs:12
List< CharacterInfo > PendingHires
Definition: HireManager.cs:10
void RenameCharacter(CharacterInfo characterInfo, string newName)
Definition: HireManager.cs:88
List< CharacterInfo > AvailableCharacters
Definition: HireManager.cs:9
CharacterInfo CreateCharacterInfo(Rand.RandSync randSync=Rand.RandSync.Unsynced)
Creates a character info from the human prefab. If there are custom character infos defined,...
Definition: HumanPrefab.cs:231
CharacterType
Definition: Enums.cs:711
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.
Definition: Enums.cs:195