Faction Test v1.0.1.0

This commit is contained in:
Regalis11
2023-02-16 15:01:28 +02:00
parent caa5a2f762
commit 2c5a7923b0
309 changed files with 7502 additions and 4335 deletions
@@ -1,16 +1,33 @@
using Barotrauma.IO;
using Barotrauma.Extensions;
using Barotrauma.IO;
using Barotrauma.Items.Components;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Barotrauma.Extensions;
using System.Security.Cryptography;
using System.Xml.Linq;
namespace Barotrauma
{
readonly struct SkillRequirementHint
{
public readonly Identifier Skill;
public readonly float Level;
public readonly LocalizedString SkillName;
public LocalizedString GetFormattedText(int skillLevel, string levelColorTag) =>
$"{SkillName} {Level} (‖color:{levelColorTag}‖{skillLevel}‖color:end‖)";
public SkillRequirementHint(ContentXElement element)
{
Skill = element.GetAttributeIdentifier("identifier", Identifier.Empty);
Level = element.GetAttributeFloat("level", 0);
SkillName = TextManager.Get("skillname." + Skill);
}
}
readonly struct DeconstructItem
{
public readonly Identifier ItemIdentifier;
@@ -443,6 +460,8 @@ namespace Barotrauma
//Containers (by identifiers or tags) that this item should be placed in. These are preferences, which are not enforced.
public ImmutableArray<PreferredContainer> PreferredContainers { get; private set; }
public ImmutableArray<SkillRequirementHint> SkillRequirementHints { get; private set; }
public SwappableItem SwappableItem
{
get;
@@ -568,9 +587,11 @@ namespace Barotrauma
public ImmutableDictionary<Identifier, FixedQuantityResourceInfo> LevelQuantity { get; private set; }
public bool CanSpriteFlipX { get; private set; }
private bool canSpriteFlipX;
public override bool CanSpriteFlipX => canSpriteFlipX;
public bool CanSpriteFlipY { get; private set; }
private bool canSpriteFlipY;
public override bool CanSpriteFlipY => canSpriteFlipY;
/// <summary>
/// Can the item be chosen as extra cargo in multiplayer. If not set, the item is available if it can be bought from outposts in the campaign.
@@ -658,6 +679,9 @@ namespace Barotrauma
[Serialize(1f, IsPropertySaveable.No)]
public float ExplosionDamageMultiplier { get; private set; }
[Serialize(1f, IsPropertySaveable.No)]
public float ItemDamageMultiplier { get; private set; }
[Serialize(false, IsPropertySaveable.No)]
public bool DamagedByProjectiles { get; private set; }
@@ -767,6 +791,21 @@ namespace Barotrauma
[Serialize(true, IsPropertySaveable.No)]
public bool ShowHealthBar { get; private set; }
[Serialize(1f, IsPropertySaveable.No, description: "How much the bots prioritize this item when they seek for items. For example, bots prioritize less exosuit than the other diving suits. Defaults to 1. Note that there's also a specific CombatPriority for items that can be used as weapons.")]
public float BotPriority { get; private set; }
[Serialize(true, IsPropertySaveable.No)]
public bool ShowNameInHealthBar { get; private set; }
[Serialize(false, IsPropertySaveable.No, description:"Should the bots shoot at this item with turret or not? Disabled by default.")]
public bool IsAITurretTarget { get; private set; }
[Serialize(1.0f, IsPropertySaveable.No, description: "How much the bots prioritize shooting this item with turrets? Defaults to 1. Distance to the target affects the decision making.")]
public float AITurretPriority { get; private set; }
[Serialize(1.0f, IsPropertySaveable.No, description: "How much the bots prioritize shooting this item with slow turrets, like railguns? Defaults to 1. Not used if AITurretPriority is 0. Distance to the target affects the decision making.")]
public float AISlowTurretPriority { get; private set; }
protected override Identifier DetermineIdentifier(XElement element)
{
Identifier identifier = base.DetermineIdentifier(element);
@@ -869,6 +908,15 @@ namespace Barotrauma
SerializableProperty.DeserializeProperties(this, ConfigElement);
LoadDescription(ConfigElement);
var skillRequirementHints = new List<SkillRequirementHint>();
foreach (var skillRequirementHintElement in ConfigElement.GetChildElements("SkillRequirementHint"))
{
skillRequirementHints.Add(new SkillRequirementHint(skillRequirementHintElement));
}
if (skillRequirementHints.Any())
{
SkillRequirementHints = skillRequirementHints.ToImmutableArray();
}
var allowDroppingOnSwapWith = ConfigElement.GetAttributeIdentifierArray("allowdroppingonswapwith", Array.Empty<Identifier>());
AllowDroppingOnSwapWith = allowDroppingOnSwapWith.ToImmutableHashSet();
@@ -884,8 +932,8 @@ namespace Barotrauma
case "sprite":
string spriteFolder = GetTexturePath(subElement, variantOf);
CanSpriteFlipX = subElement.GetAttributeBool("canflipx", true);
CanSpriteFlipY = subElement.GetAttributeBool("canflipy", true);
canSpriteFlipX = subElement.GetAttributeBool("canflipx", true);
canSpriteFlipY = subElement.GetAttributeBool("canflipy", true);
sprite = new Sprite(subElement, spriteFolder, lazyLoad: true);
if (subElement.GetAttribute("sourcerect") == null &&
@@ -936,14 +984,20 @@ namespace Barotrauma
AllowDeconstruct = true;
RandomDeconstructionOutput = subElement.GetAttributeBool("chooserandom", false);
RandomDeconstructionOutputAmount = subElement.GetAttributeInt("amount", 1);
foreach (XElement deconstructItem in subElement.Elements())
foreach (XElement itemElement in subElement.Elements())
{
if (deconstructItem.Attribute("name") != null)
if (itemElement.Attribute("name") != null)
{
DebugConsole.ThrowError($"Error in item config \"{ToString()}\" - use item identifiers instead of names to configure the deconstruct items.");
continue;
}
deconstructItems.Add(new DeconstructItem(deconstructItem, Identifier));
var deconstructItem = new DeconstructItem(itemElement, Identifier);
if (deconstructItem.ItemIdentifier.IsEmpty)
{
DebugConsole.ThrowError($"Error in item config \"{ToString()}\" - deconstruction output contains an item with no identifier.");
continue;
}
deconstructItems.Add(deconstructItem);
}
RandomDeconstructionOutputAmount = Math.Min(RandomDeconstructionOutputAmount, deconstructItems.Count);
break;
@@ -1336,11 +1390,43 @@ namespace Barotrauma
}
public Identifier VariantOf { get; }
public ItemPrefab ParentPrefab { get; set; }
public void InheritFrom(ItemPrefab parent)
{
ConfigElement = originalElement.CreateVariantXML(parent.ConfigElement).FromPackage(ConfigElement.ContentPackage);
ConfigElement = originalElement.CreateVariantXML(parent.ConfigElement, CheckXML).FromPackage(ConfigElement.ContentPackage);
ParseConfigElement(parent);
void CheckXML(XElement originalElement, XElement variantElement, XElement result)
{
if (result == null) { return; }
if (result.Name.ToIdentifier() == "RequiredItem" &&
result.Parent?.Name.ToIdentifier() == "Fabricate")
{
int originalAmount = originalElement.GetAttributeInt("amount", 1);
Identifier originalIdentifier = originalElement.GetAttributeIdentifier("identifier", Identifier.Empty);
if (variantElement == null)
{
//if the variant defines some fabrication requirements, we probably don't want to inherit anything extra from the base item?
if (this.originalElement.GetChildElement("Fabricate")?.GetChildElement("RequiredItem") != null)
{
DebugConsole.AddWarning($"Potential error in item variant \"{Identifier}\": " +
$"the item inherits the fabrication requirement of x{originalAmount} \"{originalIdentifier}\" from the base item \"{parent.Identifier}\". " +
$"If this is not intentional, you can use empty <RequiredItem /> elements in the item variant to remove any excess inherited fabrication requirements.");
}
return;
}
Identifier resultIdentifier = result.GetAttributeIdentifier("identifier", Identifier.Empty);
if (originalAmount > 1 && variantElement.GetAttribute("amount") == null)
{
DebugConsole.AddWarning($"Potential error in item variant \"{Identifier}\": " +
$"the base item \"{parent.Identifier}\" requires x{originalAmount} \"{originalIdentifier}\" to fabricate. " +
$"The variant only overrides the required item, not the amount, resulting in a requirement of x{originalAmount} \"{resultIdentifier}\". "+
"Specify the amount in the variant to fix this.");
}
}
}
}
public override string ToString()