3 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
10 internal class CampaignSettings : INetSerializableStruct, ISerializableEntity
12 public static CampaignSettings
Empty =>
new CampaignSettings(element:
null);
15 public static CampaignSettings CurrentSettings =
new CampaignSettings(GameSettings.CurrentConfig.SavedCampaignSettings);
17 public string Name =>
"CampaignSettings";
19 public const string LowerCaseSaveElementName =
"campaignsettings";
22 public string PresetName {
get;
set; } =
string.Empty;
25 public bool TutorialEnabled {
get;
set; }
28 public bool RadiationEnabled {
get;
set; }
30 public const int DefaultMaxMissionCount = 2;
31 public const int MaxMissionCountLimit = 10;
32 public const int MinMissionCountLimit = 1;
34 private int maxMissionCount;
36 [Serialize(DefaultMaxMissionCount,
IsPropertySaveable.Yes), NetworkSerialize(MinValueInt = MinMissionCountLimit, MaxValueInt = MaxMissionCountLimit)]
37 public int MaxMissionCount
39 get => maxMissionCount;
40 set => maxMissionCount = MathHelper.Clamp(value, MinMissionCountLimit, MaxMissionCountLimit);
43 public int TotalMaxMissionCount => MaxMissionCount + GetAddedMissionCount();
49 public Identifier StartItemSet {
get;
set; }
54 private int? _initialMoney;
55 public const int DefaultInitialMoney = 8000;
57 public int InitialMoney
61 if (_initialMoney is
int alreadyCachedValue)
63 return alreadyCachedValue;
67 _initialMoney = DefaultInitialMoney;
68 Identifier settingDefinitionIdentifier = nameof(StartingBalanceAmount).ToIdentifier();
69 Identifier attributeIdentifier = StartingBalanceAmount.ToIdentifier();
70 if (CampaignModePresets.TryGetAttribute(settingDefinitionIdentifier, attributeIdentifier, out XAttribute? attribute))
72 _initialMoney = attribute.GetAttributeInt(DefaultInitialMoney);
76 DebugConsole.ThrowError($
"CampaignSettings: Can't find value for {attributeIdentifier} in {settingDefinitionIdentifier}");
78 return _initialMoney ?? DefaultInitialMoney;
83 private float? _extraEventManagerDifficulty;
84 private const float defaultExtraEventManagerDifficulty = 0;
86 public float ExtraEventManagerDifficulty
90 if (_extraEventManagerDifficulty is
float alreadyCachedValue)
92 return alreadyCachedValue;
96 _extraEventManagerDifficulty = defaultExtraEventManagerDifficulty;
97 Identifier settingDefinitionIdentifier = nameof(ExtraEventManagerDifficulty).ToIdentifier();
98 Identifier attributeIdentifier = WorldHostility.ToIdentifier();
99 if (CampaignModePresets.TryGetAttribute(settingDefinitionIdentifier, attributeIdentifier, out XAttribute? attribute))
101 _extraEventManagerDifficulty = attribute.GetAttributeFloat(defaultExtraEventManagerDifficulty);
105 DebugConsole.ThrowError($
"CampaignSettings: Can't find value for {attributeIdentifier} in {settingDefinitionIdentifier}");
107 return _extraEventManagerDifficulty ?? defaultExtraEventManagerDifficulty;
112 private float? _levelDifficultyMultiplier;
113 private const float defaultLevelDifficultyMultiplier = 1.0f;
115 public float LevelDifficultyMultiplier
119 if (_levelDifficultyMultiplier is
float alreadyCachedValue)
121 return alreadyCachedValue;
125 _levelDifficultyMultiplier = defaultLevelDifficultyMultiplier;
126 Identifier settingDefinitionIdentifier = nameof(LevelDifficultyMultiplier).ToIdentifier();
127 Identifier attributeIdentifier = WorldHostility.ToIdentifier();
128 if (CampaignModePresets.TryGetAttribute(settingDefinitionIdentifier, attributeIdentifier, out XAttribute? attribute))
130 _levelDifficultyMultiplier = attribute.GetAttributeFloat(defaultLevelDifficultyMultiplier);
134 DebugConsole.ThrowError($
"CampaignSettings: Can't find value for {attributeIdentifier} in {settingDefinitionIdentifier}");
136 return _levelDifficultyMultiplier ?? defaultLevelDifficultyMultiplier;
141 private static readonly Dictionary<string, MultiplierSettings> _multiplierSettings =
new Dictionary<string, MultiplierSettings>
143 {
"default",
new MultiplierSettings { Min = 0.2f, Max = 2.0f, Step = 0.1f } },
144 { nameof(CrewVitalityMultiplier),
new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
145 { nameof(NonCrewVitalityMultiplier),
new MultiplierSettings { Min = 0.5f, Max = 3.0f, Step = 0.1f } },
146 { nameof(MissionRewardMultiplier),
new MultiplierSettings { Min = 0.5f, Max = 2.0f, Step = 0.1f } },
147 { nameof(RepairFailMultiplier),
new MultiplierSettings { Min = 0.5f, Max = 5.0f, Step = 0.5f } },
148 { nameof(ShopPriceMultiplier),
new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } },
149 { nameof(ShipyardPriceMultiplier),
new MultiplierSettings { Min = 0.1f, Max = 3.0f, Step = 0.1f } }
154 public float CrewVitalityMultiplier {
get;
set; }
157 public float NonCrewVitalityMultiplier {
get;
set; }
160 public float OxygenMultiplier {
get;
set; }
163 public float FuelMultiplier {
get;
set; }
166 public float MissionRewardMultiplier {
get;
set; }
169 public float ShopPriceMultiplier {
get;
set; }
172 public float ShipyardPriceMultiplier {
get;
set; }
175 public float RepairFailMultiplier {
get;
set; }
178 public bool ShowHuskWarning {
get;
set; }
183 private float? _minPatdownProbability;
184 private float? _maxPatdownProbability;
185 public const float DefaultMinPatdownProbability = 0.2f;
186 public const float DefaultMaxPatdownProbability = 0.9f;
188 public float PatdownProbabilityMin
192 if (_minPatdownProbability is
float alreadyCachedValue)
194 return alreadyCachedValue;
198 _minPatdownProbability = DefaultMinPatdownProbability;
199 Identifier settingDefinitionIdentifier = nameof(PatdownProbabilityMin).ToIdentifier();
200 Identifier attributeIdentifier = PatdownProbability.ToIdentifier();
201 if (CampaignModePresets.TryGetAttribute(settingDefinitionIdentifier, attributeIdentifier, out XAttribute? attribute))
203 _minPatdownProbability = attribute.GetAttributeFloat(DefaultMinPatdownProbability);
207 DebugConsole.ThrowError($
"CampaignSettings: Can't find value for {attributeIdentifier} in {settingDefinitionIdentifier}");
209 return _minPatdownProbability ?? DefaultMinPatdownProbability;
214 public float PatdownProbabilityMax
218 if (_maxPatdownProbability is
float alreadyCachedValue)
220 return alreadyCachedValue;
224 _maxPatdownProbability = DefaultMaxPatdownProbability;
225 Identifier settingDefinitionIdentifier = nameof(PatdownProbabilityMax).ToIdentifier();
226 Identifier attributeIdentifier = PatdownProbability.ToIdentifier();
227 if (CampaignModePresets.TryGetAttribute(settingDefinitionIdentifier, attributeIdentifier, out XAttribute? attribute))
229 _maxPatdownProbability = attribute.GetAttributeFloat(DefaultMaxPatdownProbability);
233 DebugConsole.ThrowError($
"CampaignSettings: Can't find value for {attributeIdentifier} in {settingDefinitionIdentifier}");
235 return _maxPatdownProbability ?? DefaultMaxPatdownProbability;
240 public Dictionary<Identifier, SerializableProperty> SerializableProperties {
get;
private set; }
243 public CampaignSettings()
245 SerializableProperties = SerializableProperty.GetProperties(
this);
248 public CampaignSettings(XElement? element =
null)
250 SerializableProperties = SerializableProperty.DeserializeProperties(
this, element);
253 public XElement Save()
255 XElement saveElement =
new XElement(LowerCaseSaveElementName);
256 SerializableProperty.SerializeProperties(
this, saveElement, saveIfDefault:
true);
260 private static int GetAddedMissionCount()
262 var characters = GameSession.GetSessionCrewCharacters(
CharacterType.Both);
263 if (!characters.Any()) {
return 0; }
264 return characters.Max(
static character => (
int)character.GetStatValue(
StatTypes.ExtraMissionCount));
269 public float Min {
get;
set; }
270 public float Max {
get;
set; }
271 public float Step {
get;
set; }
274 public static MultiplierSettings GetMultiplierSettings(
string multiplierName)
276 if (_multiplierSettings.TryGetValue(multiplierName, out MultiplierSettings value))
281 return _multiplierSettings[
"default"];
StartingBalanceAmountOption
StatTypes
StatTypes are used to alter several traits of a character. They are mostly used by talents.