Unstable 0.17.0.0

This commit is contained in:
Markus Isberg
2022-02-26 02:43:01 +09:00
parent a83f375681
commit 3974067915
913 changed files with 32472 additions and 32364 deletions
@@ -9,87 +9,87 @@ namespace Barotrauma
{
private readonly JobPrefab prefab;
private readonly Dictionary<string, Skill> skills;
private readonly Dictionary<Identifier, Skill> skills;
public string Name
{
get { return prefab.Name; }
}
public LocalizedString Name => prefab.Name;
public string Description
{
get { return prefab.Description; }
}
public LocalizedString Description => prefab.Description;
public JobPrefab Prefab
{
get { return prefab; }
}
public List<Skill> Skills
{
get { return skills.Values.ToList(); }
}
public JobPrefab Prefab => prefab;
public List<Skill> Skills => skills.Values.ToList();
public int Variant;
public Skill PrimarySkill { get; }
public Job(JobPrefab jobPrefab, Rand.RandSync randSync = Rand.RandSync.Unsynced, int variant = 0)
public Job(JobPrefab jobPrefab) : this(jobPrefab, randSync: Rand.RandSync.Unsynced, variant: 0) { }
public Job(JobPrefab jobPrefab, Rand.RandSync randSync, int variant, params Skill[] s)
{
prefab = jobPrefab;
Variant = variant;
skills = new Dictionary<string, Skill>();
skills = new Dictionary<Identifier, Skill>();
foreach (var skill in s) { skills.Add(skill.Identifier, skill); }
foreach (SkillPrefab skillPrefab in prefab.Skills)
{
var skill = new Skill(skillPrefab, randSync);
skills.Add(skillPrefab.Identifier, skill);
Skill skill;
if (skills.ContainsKey(skillPrefab.Identifier))
{
skill = skills[skillPrefab.Identifier];
skills[skillPrefab.Identifier] = new Skill(skill.Identifier, skill.Level);
}
else
{
skill = new Skill(skillPrefab, randSync);
skills.Add(skillPrefab.Identifier, skill);
}
if (skillPrefab.IsPrimarySkill) { PrimarySkill = skill; }
}
}
public Job(XElement element)
{
string identifier = element.GetAttributeString("identifier", "").ToLowerInvariant();
Identifier identifier = element.GetAttributeIdentifier("identifier", "");
JobPrefab p;
if (!JobPrefab.Prefabs.ContainsKey(identifier))
{
DebugConsole.ThrowError($"Could not find the job {identifier}. Giving the character a random job.");
p = JobPrefab.Random();
p = JobPrefab.Random(Rand.RandSync.Unsynced);
}
else
{
p = JobPrefab.Prefabs[identifier];
}
prefab = p;
skills = new Dictionary<string, Skill>();
foreach (XElement subElement in element.Elements())
skills = new Dictionary<Identifier, Skill>();
foreach (var subElement in element.Elements())
{
if (!subElement.Name.ToString().Equals("skill", System.StringComparison.OrdinalIgnoreCase)) { continue; }
string skillIdentifier = subElement.GetAttributeString("identifier", "");
if (string.IsNullOrEmpty(skillIdentifier)) { continue; }
if (subElement.NameAsIdentifier() != "skill") { continue; }
Identifier skillIdentifier = subElement.GetAttributeIdentifier("identifier", "");
if (skillIdentifier.IsEmpty) { continue; }
var skill = new Skill(skillIdentifier, subElement.GetAttributeFloat("level", 0));
skills.Add(skillIdentifier, skill);
if (skillIdentifier == prefab.PrimarySkill?.Identifier) { PrimarySkill = skill; }
}
}
public static Job Random(Rand.RandSync randSync = Rand.RandSync.Unsynced)
public static Job Random(Rand.RandSync randSync)
{
var prefab = JobPrefab.Random(randSync);
var variant = Rand.Range(0, prefab.Variants, randSync);
return new Job(prefab, randSync, variant);
}
public float GetSkillLevel(string skillIdentifier)
public float GetSkillLevel(Identifier skillIdentifier)
{
if (string.IsNullOrWhiteSpace(skillIdentifier)) { return 0.0f; }
if (skillIdentifier.IsEmpty) { return 0.0f; }
skills.TryGetValue(skillIdentifier, out Skill skill);
return (skill == null) ? 0.0f : skill.Level;
return skill?.Level ?? 0.0f;
}
public void IncreaseSkillLevel(string skillIdentifier, float increase, bool increasePastMax)
public void IncreaseSkillLevel(Identifier skillIdentifier, float increase, bool increasePastMax)
{
if (skills.TryGetValue(skillIdentifier, out Skill skill))
{
@@ -130,7 +130,7 @@ namespace Barotrauma
else
{
string itemIdentifier = itemElement.GetAttributeString("identifier", "");
itemPrefab = MapEntityPrefab.Find(null, itemIdentifier) as ItemPrefab;
itemPrefab = MapEntityPrefab.FindByIdentifier(itemIdentifier.ToIdentifier()) as ItemPrefab;
if (itemPrefab == null)
{
DebugConsole.ThrowError("Tried to spawn \"" + Name + "\" with the item \"" + itemIdentifier + "\". Matching item prefab not found.");
@@ -192,27 +192,16 @@ namespace Barotrauma
if (item.Prefab.Identifier == "idcard")
{
if (spawnPoint != null)
{
foreach (string s in spawnPoint.IdCardTags)
{
item.AddTag(s);
if (!string.IsNullOrWhiteSpace(spawnPoint.IdCardDesc)) { item.Description = spawnPoint.IdCardDesc; }
}
}
item.AddTag("name:" + character.Name);
item.AddTag("job:" + Name);
IdCard idCardComponent = item.GetComponent<IdCard>();
idCardComponent?.Initialize(character.Info);
idCardComponent?.Initialize(spawnPoint, character);
}
foreach (WifiComponent wifiComponent in item.GetComponents<WifiComponent>())
{
wifiComponent.TeamID = character.TeamID;
}
if (parentItem != null) parentItem.Combine(item, user: null);
if (parentItem != null) { parentItem.Combine(item, user: null); }
foreach (XElement childItemElement in itemElement.Elements())
{
@@ -227,7 +216,7 @@ namespace Barotrauma
jobElement.Add(new XAttribute("name", Name));
jobElement.Add(new XAttribute("identifier", prefab.Identifier));
foreach (KeyValuePair<string, Skill> skill in skills)
foreach (KeyValuePair<Identifier, Skill> skill in skills)
{
jobElement.Add(new XElement("skill", new XAttribute("identifier", skill.Value.Identifier), new XAttribute("level", skill.Value.Level)));
}
@@ -2,6 +2,7 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Xml.Linq;
@@ -9,54 +10,78 @@ namespace Barotrauma
{
public class AutonomousObjective
{
public string identifier;
public string option;
public readonly float priorityModifier;
public readonly bool ignoreAtOutpost;
public readonly Identifier Identifier;
public readonly Identifier Option;
public readonly float PriorityModifier;
public readonly bool IgnoreAtOutpost;
public AutonomousObjective(XElement element)
{
identifier = element.GetAttributeString("identifier", null);
Identifier = element.GetAttributeIdentifier("identifier", Identifier.Empty);
//backwards compatibility
if (string.IsNullOrEmpty(identifier))
if (Identifier == Identifier.Empty)
{
identifier = element.GetAttributeString("aitag", null);
Identifier = element.GetAttributeIdentifier("aitag", Identifier.Empty);
}
option = element.GetAttributeString("option", null);
priorityModifier = element.GetAttributeFloat("prioritymodifier", 1);
priorityModifier = MathHelper.Max(priorityModifier, 0);
ignoreAtOutpost = element.GetAttributeBool("ignoreatoutpost", false);
Option = element.GetAttributeIdentifier("option", Identifier.Empty);
PriorityModifier = element.GetAttributeFloat("prioritymodifier", 1);
PriorityModifier = MathHelper.Max(PriorityModifier, 0);
IgnoreAtOutpost = element.GetAttributeBool("ignoreatoutpost", false);
}
}
partial class JobPrefab : IPrefab, IDisposable
class ItemRepairPriority : Prefab
{
public static readonly PrefabCollection<ItemRepairPriority> Prefabs = new PrefabCollection<ItemRepairPriority>();
public readonly float Priority;
public ItemRepairPriority(XElement element, JobsFile file) : base(file, element.GetAttributeIdentifier("tag", Identifier.Empty))
{
Priority = element.GetAttributeFloat("priority", -1f);
if (Priority < 0)
{
DebugConsole.AddWarning($"The 'priority' attribute is missing from the the item repair priorities definition in {element} of {file.Path}.");
}
}
public override void Dispose() { }
}
class JobVariant
{
public JobPrefab Prefab;
public int Variant;
public JobVariant(JobPrefab prefab, int variant)
{
Prefab = prefab;
Variant = variant;
}
}
partial class JobPrefab : PrefabWithUintIdentifier
{
public static readonly PrefabCollection<JobPrefab> Prefabs = new PrefabCollection<JobPrefab>();
private bool disposed = false;
public void Dispose()
public override void Dispose()
{
if (disposed) { return; }
disposed = true;
Prefabs.Remove(this);
}
private static readonly Dictionary<string, float> _itemRepairPriorities = new Dictionary<string, float>();
private static readonly Dictionary<Identifier, float> _itemRepairPriorities = new Dictionary<Identifier, float>();
/// <summary>
/// Tag -> priority.
/// </summary>
public static IReadOnlyDictionary<string, float> ItemRepairPriorities => _itemRepairPriorities;
public static IReadOnlyDictionary<Identifier, float> ItemRepairPriorities => _itemRepairPriorities;
public static XElement NoJobElement;
public static ContentXElement NoJobElement;
public static JobPrefab Get(string identifier)
{
if (Prefabs == null)
{
DebugConsole.ThrowError("Issue in the code execution order: job prefabs not loaded.");
return null;
}
if (Prefabs.ContainsKey(identifier))
{
return Prefabs[identifier];
@@ -70,62 +95,41 @@ namespace Barotrauma
public class PreviewItem
{
public readonly string ItemIdentifier;
public readonly Identifier ItemIdentifier;
public readonly bool ShowPreview;
public PreviewItem(string itemIdentifier, bool showPreview)
public PreviewItem(Identifier itemIdentifier, bool showPreview)
{
ItemIdentifier = itemIdentifier;
ShowPreview = showPreview;
}
}
public readonly Dictionary<int, XElement> ItemSets = new Dictionary<int, XElement>();
public readonly Dictionary<int, List<PreviewItem>> PreviewItems = new Dictionary<int, List<PreviewItem>>();
public readonly Dictionary<int, ContentXElement> ItemSets = new Dictionary<int, ContentXElement>();
public readonly ImmutableDictionary<int, ImmutableArray<PreviewItem>> PreviewItems;
public readonly List<SkillPrefab> Skills = new List<SkillPrefab>();
public readonly List<AutonomousObjective> AutonomousObjectives = new List<AutonomousObjective>();
public readonly List<string> AppropriateOrders = new List<string>();
public readonly List<Identifier> AppropriateOrders = new List<Identifier>();
[Serialize("1,1,1,1", false)]
[Serialize("1,1,1,1", IsPropertySaveable.No)]
public Color UIColor
{
get;
private set;
}
[Serialize("notfound", false)]
public string Identifier
{
get;
private set;
}
public readonly LocalizedString Name;
[Serialize("notfound", false)]
public string Name
{
get;
private set;
}
[Serialize(AIObjectiveIdle.BehaviorType.Passive, false)]
[Serialize(AIObjectiveIdle.BehaviorType.Passive, IsPropertySaveable.No)]
public AIObjectiveIdle.BehaviorType IdleBehavior
{
get;
private set;
}
public string OriginalName { get { return Identifier; } }
public readonly LocalizedString Description;
public ContentPackage ContentPackage { get; private set; }
[Serialize("", false)]
public string Description
{
get;
private set;
}
[Serialize(false, false)]
[Serialize(false, IsPropertySaveable.No)]
public bool OnlyJobSpecificDialog
{
get;
@@ -133,7 +137,7 @@ namespace Barotrauma
}
//the number of these characters in the crew the player starts with in the single player campaign
[Serialize(0, false)]
[Serialize(0, IsPropertySaveable.No)]
public int InitialCount
{
get;
@@ -141,7 +145,7 @@ namespace Barotrauma
}
//if set to true, a client that has chosen this as their preferred job will get it no matter what
[Serialize(false, false)]
[Serialize(false, IsPropertySaveable.No)]
public bool AllowAlways
{
get;
@@ -149,7 +153,7 @@ namespace Barotrauma
}
//how many crew members can have the job (only one captain etc)
[Serialize(100, false)]
[Serialize(100, IsPropertySaveable.No)]
public int MaxNumber
{
get;
@@ -158,21 +162,21 @@ namespace Barotrauma
//how many crew members are REQUIRED to have the job
//(i.e. if one captain is required, one captain is chosen even if all the players have set captain to lowest preference)
[Serialize(0, false)]
[Serialize(0, IsPropertySaveable.No)]
public int MinNumber
{
get;
private set;
}
[Serialize(0.0f, false)]
[Serialize(0.0f, IsPropertySaveable.No)]
public float MinKarma
{
get;
private set;
}
[Serialize(1.0f, false)]
[Serialize(1.0f, IsPropertySaveable.No)]
public float PriceMultiplier
{
get;
@@ -180,7 +184,7 @@ namespace Barotrauma
}
// TODO: not used
[Serialize(10.0f, false)]
[Serialize(10.0f, IsPropertySaveable.No)]
public float Commonness
{
get;
@@ -188,7 +192,7 @@ namespace Barotrauma
}
//how much the vitality of the character is increased/reduced from the default value
[Serialize(0.0f, false)]
[Serialize(0.0f, IsPropertySaveable.No)]
public float VitalityModifier
{
get;
@@ -196,7 +200,7 @@ namespace Barotrauma
}
//whether the job should be available to NPCs
[Serialize(false, false)]
[Serialize(false, IsPropertySaveable.No)]
public bool HiddenJob
{
get;
@@ -208,35 +212,33 @@ namespace Barotrauma
public SkillPrefab PrimarySkill => Skills?.FirstOrDefault(s => s.IsPrimarySkill);
public string FilePath { get; private set; }
public XElement Element { get; private set; }
public XElement ClothingElement { get; private set; }
public ContentXElement Element { get; private set; }
public ContentXElement ClothingElement { get; private set; }
public int Variants { get; private set; }
public JobPrefab(XElement element, string filePath)
public JobPrefab(ContentXElement element, JobsFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
{
FilePath = filePath;
SerializableProperty.DeserializeProperties(this, element);
Name = TextManager.Get("JobName." + Identifier);
Description = TextManager.Get("JobDescription." + Identifier, returnNull: true) ?? string.Empty;
Identifier = Identifier.ToLowerInvariant();
Description = TextManager.Get("JobDescription." + Identifier);
Element = element;
var previewItems = new Dictionary<int, List<PreviewItem>>();
int variant = 0;
foreach (XElement subElement in element.Elements())
foreach (var subElement in element.Elements())
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "itemset":
ItemSets.Add(variant, subElement);
PreviewItems[variant] = new List<PreviewItem>();
previewItems[variant] = new List<PreviewItem>();
loadItemIdentifiers(subElement, variant);
variant++;
break;
case "skills":
foreach (XElement skillElement in subElement.Elements())
foreach (var skillElement in subElement.Elements())
{
Skills.Add(new SkillPrefab(skillElement));
}
@@ -246,7 +248,7 @@ namespace Barotrauma
break;
case "appropriateobjectives":
case "appropriateorders":
subElement.Elements().ForEach(order => AppropriateOrders.Add(order.GetAttributeString("identifier", "").ToLowerInvariant()));
subElement.Elements().ForEach(order => AppropriateOrders.Add(order.GetAttributeIdentifier("identifier", "")));
break;
case "jobicon":
Icon = new Sprite(subElement.FirstElement());
@@ -267,19 +269,22 @@ namespace Barotrauma
continue;
}
string itemIdentifier = itemElement.GetAttributeString("identifier", "");
if (string.IsNullOrWhiteSpace(itemIdentifier))
Identifier itemIdentifier = itemElement.GetAttributeIdentifier("identifier", Identifier.Empty);
if (itemIdentifier.IsEmpty)
{
DebugConsole.ThrowError("Error in job config \"" + Name + "\" - item with no identifier.");
}
else
{
PreviewItems[variant].Add(new PreviewItem(itemIdentifier, itemElement.GetAttributeBool("showpreview", true)));
previewItems[variant].Add(new PreviewItem(itemIdentifier, itemElement.GetAttributeBool("showpreview", true)));
}
loadItemIdentifiers(itemElement, variant);
}
}
PreviewItems = previewItems.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray()))
.ToImmutableDictionary();
Variants = variant;
Skills.Sort((x,y) => y.LevelRange.Start.CompareTo(x.LevelRange.Start));
@@ -287,77 +292,7 @@ namespace Barotrauma
// Disabled on purpose, TODO: remove all references?
//ClothingElement = element.GetChildElement("PortraitClothing");
}
public static JobPrefab Random(Rand.RandSync sync = Rand.RandSync.Unsynced) => Prefabs.GetRandom(p => !p.HiddenJob, sync);
public static void LoadAll(IEnumerable<ContentFile> files)
{
foreach (ContentFile file in files)
{
LoadFromFile(file);
}
}
public static void LoadFromFile(ContentFile file)
{
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
if (doc == null) { return; }
var mainElement = doc.Root.IsOverride() ? doc.Root.FirstElement() : doc.Root;
if (doc.Root.IsOverride())
{
DebugConsole.ThrowError($"Error in '{file.Path}': Cannot override all job prefabs, because many of them are required by the main game! Please try overriding jobs one by one.");
}
foreach (XElement element in mainElement.Elements())
{
if (element.IsOverride())
{
var job = new JobPrefab(element.FirstElement(), file.Path)
{
ContentPackage = file.ContentPackage
};
Prefabs.Add(job, true);
}
else
{
if (!element.Name.ToString().Equals("job", StringComparison.OrdinalIgnoreCase)) { continue; }
var job = new JobPrefab(element, file.Path)
{
ContentPackage = file.ContentPackage
};
Prefabs.Add(job, false);
}
}
NoJobElement ??= mainElement.GetChildElement("nojob");
var itemRepairPrioritiesElement = mainElement.GetChildElement("ItemRepairPriorities");
if (itemRepairPrioritiesElement != null)
{
foreach (var subElement in itemRepairPrioritiesElement.Elements())
{
string tag = subElement.GetAttributeString("tag", null);
if (tag != null)
{
float priority = subElement.GetAttributeFloat("priority", -1f);
if (priority >= 0)
{
_itemRepairPriorities.TryAdd(tag, priority);
}
else
{
DebugConsole.AddWarning($"The 'priority' attribute is missing from the the item repair priorities definition in {subElement} of {file.Path}.");
}
}
else
{
DebugConsole.AddWarning($"The 'tag' attribute is missing from the the item repair priorities definition in {subElement} of {file.Path}.");
}
}
}
}
public static void RemoveByFile(string filePath)
{
Prefabs.RemoveByFile(filePath);
}
public static JobPrefab Random(Rand.RandSync sync) => Prefabs.GetRandom(p => !p.HiddenJob, sync);
}
}
@@ -4,12 +4,12 @@ namespace Barotrauma
{
class Skill
{
private float level;
public string Identifier { get; }
public readonly Identifier Identifier;
public const float MaximumSkill = 100.0f;
private float level;
public float Level
{
get { return level; }
@@ -21,18 +21,11 @@ namespace Barotrauma
level = MathHelper.Clamp(level + value, 0.0f, increasePastMax ? SkillSettings.Current.MaximumSkillWithTalents : MaximumSkill);
}
private Sprite icon;
public Sprite Icon
{
get
{
if (icon == null)
{
icon = GetIcon();
}
return icon;
}
}
private Identifier iconJobId;
public Sprite Icon => !iconJobId.IsEmpty && JobPrefab.Prefabs.TryGet(iconJobId, out var jobPrefab)
? jobPrefab.Icon
: null;
public readonly float PriceMultiplier = 1.0f;
@@ -40,39 +33,42 @@ namespace Barotrauma
{
Identifier = prefab.Identifier;
level = Rand.Range(prefab.LevelRange.Start, prefab.LevelRange.End, randSync);
icon = GetIcon();
iconJobId = GetIconJobId();
PriceMultiplier = prefab.PriceMultiplier;
}
public Skill(string identifier, float level)
public Skill(Identifier identifier, float level)
{
Identifier = identifier;
this.level = level;
icon = GetIcon();
iconJobId = GetIconJobId();
}
private Sprite GetIcon()
private Identifier GetIconJobId()
{
string jobId = null;
switch (Identifier.ToLowerInvariant())
Identifier jobId = Identifier.Empty;
if (Identifier == "electrical")
{
case "electrical":
jobId = "engineer";
break;
case "helm":
jobId = "captain";
break;
case "mechanical":
jobId = "mechanic";
break;
case "medical":
jobId = "medicaldoctor";
break;
case "weapons":
jobId = "securityofficer";
break;
jobId = "engineer".ToIdentifier();
}
return jobId != null && JobPrefab.Prefabs.ContainsKey(jobId) ? JobPrefab.Prefabs[jobId].IconSmall : null;
else if (Identifier == "helm")
{
jobId = "captain".ToIdentifier();
}
else if (Identifier == "mechanical")
{
jobId = "mechanic".ToIdentifier();
}
else if (Identifier == "medical")
{
jobId = "medicaldoctor".ToIdentifier();
}
else if (Identifier == "weapons")
{
jobId = "securityofficer".ToIdentifier();
}
return jobId;
}
}
}
@@ -5,7 +5,7 @@ namespace Barotrauma
{
class SkillPrefab
{
public readonly string Identifier;
public readonly Identifier Identifier;
public Range<float> LevelRange { get; private set; }
@@ -16,9 +16,9 @@ namespace Barotrauma
public bool IsPrimarySkill { get; }
public SkillPrefab(XElement element)
public SkillPrefab(ContentXElement element)
{
Identifier = element.GetAttributeString("identifier", "");
Identifier = element.GetAttributeIdentifier("identifier", "");
PriceMultiplier = element.GetAttributeFloat("pricemultiplier", 25.0f);
var levelString = element.GetAttributeString("level", "");
if (levelString.Contains(","))