Faction Test 100.4.0.0

This commit is contained in:
Markus Isberg
2022-11-14 18:28:28 +02:00
parent 87426b68b2
commit c772b61fc1
412 changed files with 16984 additions and 5530 deletions
@@ -8,19 +8,14 @@ namespace Barotrauma
{
internal partial class CampaignMetadata
{
public CampaignMode Campaign { get; }
private readonly Dictionary<Identifier, object> data = new Dictionary<Identifier, object>();
public CampaignMetadata(CampaignMode campaign)
public CampaignMetadata()
{
Campaign = campaign;
}
public CampaignMetadata(CampaignMode campaign, XElement element)
public CampaignMetadata(XElement element)
{
Campaign = campaign;
foreach (var subElement in element.Elements())
{
if (string.Equals(subElement.Name.ToString(), "data", StringComparison.InvariantCultureIgnoreCase))
@@ -1,9 +1,17 @@
#nullable enable
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Barotrauma
{
public enum FactionAffiliation
{
Positive,
Neutral,
Negative
}
class Faction
{
public Reputation Reputation { get; }
@@ -14,6 +22,42 @@ namespace Barotrauma
Prefab = prefab;
Reputation = new Reputation(metadata, this, prefab.MinReputation, prefab.MaxReputation, prefab.InitialReputation);
}
/// <summary>
/// Get what kind of affiliation this faction has towards the player depending on who they chose to side with via talents
/// </summary>
/// <returns></returns>
public static FactionAffiliation GetPlayerAffiliationStatus(Identifier identifier, ImmutableHashSet<Character>? characterList = null)
{
if (GameMain.GameSession?.Campaign?.Factions is not { } factions) { return FactionAffiliation.Neutral; }
characterList ??= GameSession.GetSessionCrewCharacters(CharacterType.Both);
foreach (Character character in characterList)
{
if (character.Info is not { } info) { continue; }
foreach (Faction faction in factions)
{
Identifier factionIdentifier = faction.Prefab.Identifier;
if (info.GetSavedStatValue(StatTypes.Affiliation, factionIdentifier) > 0f)
{
return factionIdentifier == identifier
? FactionAffiliation.Positive
: FactionAffiliation.Negative;
}
}
}
return FactionAffiliation.Neutral;
}
public static FactionAffiliation GetPlayerAffiliationStatus(Faction faction, ImmutableHashSet<Character>? characterList = null) => GetPlayerAffiliationStatus(faction.Prefab.Identifier, characterList);
public override string ToString()
{
return $"{base.ToString()} ({Prefab?.Identifier.ToString() ?? "null"})";
}
}
internal class FactionPrefab : Prefab
@@ -25,6 +69,50 @@ namespace Barotrauma
public LocalizedString Description { get; }
public LocalizedString ShortDescription { get; }
public class HireableCharacter
{
public readonly Identifier NPCSetIdentifier;
public readonly Identifier NPCIdentifier;
public readonly float MinReputation;
public HireableCharacter(ContentXElement element)
{
NPCSetIdentifier = element.GetAttributeIdentifier("from", element.GetAttributeIdentifier("npcsetidentifier", Identifier.Empty));
NPCIdentifier = element.GetAttributeIdentifier("identifier", element.GetAttributeIdentifier("npcidentifier", Identifier.Empty));
MinReputation = element.GetAttributeFloat("minreputation", 0.0f);
}
}
public ImmutableArray<HireableCharacter> HireableCharacters;
public class AutomaticMission
{
public readonly Identifier MissionTag;
public readonly LevelData.LevelType LevelType;
public readonly float MinReputation, MaxReputation;
public readonly float MinProbability, MaxProbability;
public AutomaticMission(ContentXElement element, string parentDebugName)
{
MissionTag = element.GetAttributeIdentifier("missiontag", Identifier.Empty);
LevelType = element.GetAttributeEnum("leveltype", LevelData.LevelType.LocationConnection);
MinReputation = element.GetAttributeFloat("minreputation", 0.0f);
MaxReputation = element.GetAttributeFloat("maxreputation", 0.0f);
if (MinReputation > MaxReputation)
{
DebugConsole.ThrowError($"Error in faction prefab \"{parentDebugName}\": MinReputation cannot be larger than MaxReputation.");
}
float probability = element.GetAttributeFloat("probability", 0.0f);
MinProbability = element.GetAttributeFloat("minprobability", probability);
MaxProbability = element.GetAttributeFloat("maxprobability", probability);
}
}
public ImmutableArray<AutomaticMission> AutomaticMissions;
public bool StartOutpost { get; }
public int MenuOrder { get; }
/// <summary>
@@ -42,38 +130,73 @@ namespace Barotrauma
/// </summary>
public int InitialReputation { get; }
public float ControlledOutpostPercentage { get; }
public float SecondaryControlledOutpostPercentage { get; }
#if CLIENT
public Sprite? Icon { get; private set; }
public Sprite? IconSmall { get; private set; }
public Sprite? BackgroundPortrait { get; private set; }
#endif
public Color IconColor { get; }
#endif
public FactionPrefab(ContentXElement element, FactionsFile file) : base(file, element.GetAttributeIdentifier("identifier", string.Empty))
{
MenuOrder = element.GetAttributeInt("menuorder", 0);
StartOutpost = element.GetAttributeBool("startoutpost", false);
MinReputation = element.GetAttributeInt("minreputation", -100);
MaxReputation = element.GetAttributeInt("maxreputation", 100);
InitialReputation = element.GetAttributeInt("initialreputation", 0);
ControlledOutpostPercentage = element.GetAttributeFloat("controlledoutpostpercentage", 0);
SecondaryControlledOutpostPercentage = element.GetAttributeFloat("secondarycontrolledoutpostpercentage", 0);
Name = element.GetAttributeString("name", null) ?? TextManager.Get($"faction.{Identifier}").Fallback("Unnamed");
Description = element.GetAttributeString("description", null) ?? TextManager.Get($"faction.{Identifier}.description").Fallback("");
ShortDescription = element.GetAttributeString("shortdescription", null) ?? TextManager.Get($"faction.{Identifier}.shortdescription").Fallback("");
#if CLIENT
List<HireableCharacter> hireableCharacters = new List<HireableCharacter>();
List<AutomaticMission> automaticMissions = new List<AutomaticMission>();
foreach (var subElement in element.Elements())
{
if (subElement.Name.ToString().Equals("icon", StringComparison.OrdinalIgnoreCase))
var subElementId = subElement.NameAsIdentifier();
if (subElementId == "icon")
{
IconColor = subElement.GetAttributeColor("color", Color.White);
#if CLIENT
Icon = new Sprite(subElement);
#endif
}
else if (subElement.Name.ToString().Equals("portrait", StringComparison.OrdinalIgnoreCase))
else if (subElementId == "iconsmall")
{
#if CLIENT
IconSmall = new Sprite(subElement);
#endif
}
else if (subElementId == "portrait")
{
#if CLIENT
BackgroundPortrait = new Sprite(subElement);
#endif
}
else if (subElementId == "hireable")
{
hireableCharacters.Add(new HireableCharacter(subElement));
}
else if (subElementId == "mission" || subElementId == "automaticmission")
{
automaticMissions.Add(new AutomaticMission(subElement, Identifier.ToString()));
}
}
#endif
HireableCharacters = hireableCharacters.ToImmutableArray();
AutomaticMissions = automaticMissions.ToImmutableArray();
}
public override string ToString()
{
return $"{base.ToString()} ({Identifier})";
}
public override void Dispose()
@@ -1,17 +1,16 @@
using Microsoft.Xna.Framework;
using System;
using System.Linq;
namespace Barotrauma
{
class Reputation
{
public const float HostileThreshold = 0.2f;
public const float ReputationLossPerNPCDamage = 0.1f;
public const float ReputationLossPerStolenItemPrice = 0.01f;
public const float ReputationLossPerWallDamage = 0.1f;
public const float MinReputationLossPerStolenItem = 0.5f;
public const float MaxReputationLossPerStolenItem = 10.0f;
public const float ReputationLossPerNPCDamage = 0.05f;
public const float ReputationLossPerWallDamage = 0.05f;
public const float ReputationLossPerStolenItemPrice = 0.005f;
public const float MinReputationLossPerStolenItem = 0.05f;
public const float MaxReputationLossPerStolenItem = 1.0f;
public Identifier Identifier { get; }
public int MinReputation { get; }
@@ -66,10 +65,21 @@ namespace Barotrauma
float reputationGainMultiplier = 1f;
foreach (Character character in GameSession.GetSessionCrewCharacters(CharacterType.Both))
{
reputationGainMultiplier += character.GetStatValue(StatTypes.ReputationGainMultiplier);
reputationGainMultiplier *= 1f + character.GetStatValue(StatTypes.ReputationGainMultiplier);
reputationGainMultiplier *= 1f + character.Info?.GetSavedStatValue(StatTypes.ReputationGainMultiplier, Identifier) ?? 0;
}
reputationChange *= reputationGainMultiplier;
}
else if (reputationChange < 0f)
{
float reputationLossMultiplier = 1f;
foreach (Character character in GameSession.GetSessionCrewCharacters(CharacterType.Both))
{
reputationLossMultiplier *= 1f + character.GetStatValue(StatTypes.ReputationLossMultiplier);
reputationLossMultiplier *= 1f + character.Info?.GetSavedStatValue(StatTypes.ReputationLossMultiplier, Identifier) ?? 0;
}
reputationChange *= reputationLossMultiplier;
}
Value += reputationChange;
}