2 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
4 using System.Collections.Immutable;
20 public Faction(CampaignMetadata? metadata, FactionPrefab prefab)
23 Reputation =
new Reputation(metadata,
this, prefab.MinReputation, prefab.MaxReputation, prefab.InitialReputation);
34 bool isHighest =
true;
35 foreach (
Faction otherFaction
in factions)
37 if (otherFaction == faction || otherFaction.
Reputation.
Value < faction.Reputation.Value) {
continue; }
48 return $
"{base.ToString()} ({Prefab?.Identifier.ToString() ?? "null"})";
52 internal class FactionPrefab : Prefab
54 public readonly
static PrefabCollection<FactionPrefab> Prefabs =
new PrefabCollection<FactionPrefab>();
56 public LocalizedString Name {
get; }
58 public LocalizedString Description {
get; }
59 public LocalizedString ShortDescription {
get; }
77 public ImmutableArray<HireableCharacter> HireableCharacters;
96 DebugConsole.ThrowError($
"Error in faction prefab \"{parentDebugName}\": MinReputation cannot be larger than MaxReputation.");
106 public ImmutableArray<AutomaticMission> AutomaticMissions;
108 public bool StartOutpost {
get; }
111 public int MenuOrder {
get; }
116 public int MinReputation {
get; }
121 public int MaxReputation {
get; }
126 public int InitialReputation {
get; }
128 public float ControlledOutpostPercentage {
get; }
130 public float SecondaryControlledOutpostPercentage {
get; }
133 public Sprite? Icon {
get;
private set; }
135 public Sprite? IconSmall {
get;
private set; }
137 public Sprite? BackgroundPortrait {
get;
private set; }
140 public Color IconColor {
get; }
142 public FactionPrefab(ContentXElement element, FactionsFile file) : base(file, element.GetAttributeIdentifier(
"identifier", string.
Empty))
144 MenuOrder = element.GetAttributeInt(
"menuorder", 0);
145 StartOutpost = element.GetAttributeBool(
"startoutpost",
false);
146 MinReputation = element.GetAttributeInt(
"minreputation", -100);
147 MaxReputation = element.GetAttributeInt(
"maxreputation", 100);
148 InitialReputation = element.GetAttributeInt(
"initialreputation", 0);
149 ControlledOutpostPercentage = element.GetAttributeFloat(
"controlledoutpostpercentage", 0);
150 SecondaryControlledOutpostPercentage = element.GetAttributeFloat(
"secondarycontrolledoutpostpercentage", 0);
151 Name = element.GetAttributeString(
"name",
null) ?? TextManager.Get($
"faction.{Identifier}").Fallback(
"Unnamed");
152 Description = element.GetAttributeString(
"description",
null) ?? TextManager.Get($
"faction.{Identifier}.description").Fallback(
"");
153 ShortDescription = element.GetAttributeString(
"shortdescription",
null) ?? TextManager.Get($
"faction.{Identifier}.shortdescription").Fallback(
"");
154 OpposingFaction = element.GetAttributeIdentifier(nameof(OpposingFaction),
Identifier.Empty);
156 List<HireableCharacter> hireableCharacters =
new List<HireableCharacter>();
157 List<AutomaticMission> automaticMissions =
new List<AutomaticMission>();
158 foreach (var subElement
in element.Elements())
160 var subElementId = subElement.NameAsIdentifier();
161 if (subElementId ==
"icon")
163 IconColor = subElement.GetAttributeColor(
"color", Color.White);
165 Icon =
new Sprite(subElement);
168 else if (subElementId ==
"iconsmall")
171 IconSmall =
new Sprite(subElement);
174 else if (subElementId ==
"portrait")
177 BackgroundPortrait =
new Sprite(subElement);
180 else if (subElementId ==
"hireable")
182 hireableCharacters.Add(
new HireableCharacter(subElement));
184 else if (subElementId ==
"mission" || subElementId ==
"automaticmission")
186 automaticMissions.Add(
new AutomaticMission(subElement,
Identifier.ToString()));
189 HireableCharacters = hireableCharacters.ToImmutableArray();
190 AutomaticMissions = automaticMissions.ToImmutableArray();
193 public override string ToString()
195 return $
"{base.ToString()} ({Identifier})";
198 public override void Dispose()
IReadOnlyList< Faction > Factions
float GetAttributeFloat(string key, float def)
bool GetAttributeBool(string key, bool def)
int GetAttributeInt(string key, int def)
Identifier GetAttributeIdentifier(string key, string def)
override string ToString()
Faction(CampaignMetadata? metadata, FactionPrefab prefab)
static FactionAffiliation GetPlayerAffiliationStatus(Faction faction)
Get what kind of affiliation this faction has towards the player depending on who they chose to side ...
readonly float MinProbability
readonly LevelData.LevelType LevelType
readonly bool DisallowBetweenOtherFactionOutposts
readonly float MinReputation
readonly Identifier MissionTag
readonly int MaxDistanceFromFactionOutpost
AutomaticMission(ContentXElement element, string parentDebugName)
HireableCharacter(ContentXElement element)
readonly Identifier NPCSetIdentifier
readonly float MinReputation
readonly Identifier NPCIdentifier
static GameSession?? GameSession
readonly Identifier Identifier