Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -18,7 +18,7 @@ namespace Barotrauma
private readonly string Multiplier;
private readonly char[] prefixCharacters = { '=', '/', '*', 'x', '-', '+' };
private static readonly char[] prefixCharacters = { '=', '/', '*', 'x', '-', '+' };
private readonly Upgrade upgrade;
@@ -66,7 +66,7 @@ namespace Barotrauma
}
else
{
float multiplier = UpgradePrefab.ParsePercentage(Multiplier, Name, sourceElement, upgrade.Prefab.SupressWarnings);
float multiplier = UpgradePrefab.ParsePercentage(Multiplier, Name, sourceElement, upgrade.Prefab.SuppressWarnings);
return ApplyPercentage(value, multiplier, level);
}
}
@@ -79,6 +79,46 @@ namespace Barotrauma
return 0;
}
public static float CalculateUpgrade(object originalValue, int level, string Multiplier)
{
if (originalValue is float || originalValue is int || originalValue is double)
{
var value = (float)originalValue;
if (Multiplier[^1] != '%')
{
float multiplier = 1.0f;
if (Multiplier.Length > 1)
{
if (prefixCharacters.Contains(Multiplier[0]))
{
float.TryParse(Multiplier.Substring(1).Trim(), NumberStyles.Number, CultureInfo.InvariantCulture, out multiplier);
}
}
switch (Multiplier[0])
{
case '*':
case 'x':
return value * (multiplier * level);
case '/':
return value / (multiplier * level);
case '-':
return value - (multiplier * level);
case '+':
return value + (multiplier * level);
case '=':
return multiplier;
}
}
else
{
float multiplier = UpgradePrefab.ParsePercentage(Multiplier, "", suppressWarnings: true);
return ApplyPercentage(value, multiplier, level);
}
}
return float.NaN;
}
/// <summary>
/// Sets the OriginalValue to a value stored in the save XML element
/// </summary>
@@ -125,7 +165,7 @@ namespace Barotrauma
}
}
if (!upgrade.Prefab.SupressWarnings)
if (!upgrade.Prefab.SuppressWarnings)
{
DebugConsole.AddWarning($"Multiplier for {Name} is too short or does not contain proper prefix. \n" +
$"The value should start with {string.Join(",", prefixCharacters)} and contain a floating point value or another property. \n" +
@@ -305,7 +345,7 @@ namespace Barotrauma
subElement.Add(new XElement(propertyRef.Name,
new XAttribute("value", propertyRef.OriginalValue)));
}
else if (!Prefab.SupressWarnings)
else if (!Prefab.SuppressWarnings)
{
DebugConsole.AddWarning($"Failed to save upgrade \"{Prefab.Name}\" on {TargetEntity.Name} because property reference \"{propertyRef.Name}\" is missing original values. \n" +
"Upgrades should always call Upgrade.ApplyUpgrade() or manually set the original value in a property reference after they have been added. \n" +
@@ -340,22 +380,6 @@ namespace Barotrauma
propertyReference.SetOriginalValue(originalValue);
object newValue = Convert.ChangeType(propertyReference.CalculateUpgrade(Level, sourceElement), originalValue.GetType(), NumberFormatInfo.InvariantInfo);
property!.SetValue(entity, newValue);
#if SERVER
// if (TargetEntity is IServerSerializable clientSerializable && !IsEqual(originalValue, newValue))
// {
// GameMain.Server.CreateEntityEvent(clientSerializable, new object[] { NetEntityEvent.Type.ChangeProperty, property });
// }
//
// static bool IsEqual(object item1, object item2)
// {
// if (item1 is float float1 && item2 is float float2)
// {
// return MathUtils.NearlyEqual(float1, float2);
// }
//
// return item1 == item2;
// }
#endif
}
else
{
@@ -23,16 +23,16 @@ namespace Barotrauma
Prefab = prefab;
IncreaseLow = UpgradePrefab.ParsePercentage(element.GetAttributeString("increaselow", string.Empty),
"IncreaseLow", element, suppressWarnings: prefab.SupressWarnings);
"IncreaseLow", element, suppressWarnings: prefab.SuppressWarnings);
IncreaseHigh = UpgradePrefab.ParsePercentage(element.GetAttributeString("increasehigh", string.Empty),
"IncreaseHigh", element, suppressWarnings: prefab.SupressWarnings);
"IncreaseHigh", element, suppressWarnings: prefab.SuppressWarnings);
BasePrice = element.GetAttributeInt("baseprice", -1);
if (BasePrice == -1)
{
if (prefab.SupressWarnings)
if (prefab.SuppressWarnings)
{
DebugConsole.AddWarning($"Price attribute \"baseprice\" is not defined for {prefab?.Identifier}.\n " +
"The value has been assumed to be '1000'.");
@@ -85,17 +85,17 @@ namespace Barotrauma
Categories.Add(this);
}
public bool CanBeApplied(Item item, UpgradePrefab? upgradePrefab = null)
public bool CanBeApplied(Item item, UpgradePrefab? upgradePrefab)
{
if (IsWallUpgrade) { return false; }
if (upgradePrefab != null && item.disallowedUpgrades.Contains(upgradePrefab.Identifier)) { return false; }
if (upgradePrefab != null && upgradePrefab.IsDisallowed(item)) { return false; }
return item.prefab.GetAllowedUpgrades().Contains(Identifier) ||
ItemTags.Any(tag => item.Prefab.Tags.Contains(tag) || item.Prefab.Identifier.Equals(tag, StringComparison.OrdinalIgnoreCase));
}
public bool CanBeApplied(XElement element)
public bool CanBeApplied(XElement element, UpgradePrefab prefab)
{
if (string.Equals("Structure", element.Name.ToString(), StringComparison.OrdinalIgnoreCase)) { return IsWallUpgrade; }
@@ -105,6 +105,10 @@ namespace Barotrauma
ItemPrefab? item = ItemPrefab.Find(null, identifier);
if (item == null) { return false; }
string[] disallowedUpgrades = element.GetAttributeStringArray("disallowedupgrades", new string[0]);
if (disallowedUpgrades.Any(s => s.Equals(Identifier, StringComparison.OrdinalIgnoreCase) || s.Equals(prefab.Identifier, StringComparison.OrdinalIgnoreCase))) { return false; }
return item.GetAllowedUpgrades().Contains(Identifier) ||
ItemTags.Any(tag => item.Tags.Contains(tag) || item.Identifier.Equals(tag, StringComparison.OrdinalIgnoreCase));
}
@@ -143,7 +147,7 @@ namespace Barotrauma
private bool Disposed { get; set; }
public bool SupressWarnings { get; }
public bool SuppressWarnings { get; }
public bool HideInMenus { get; }
@@ -159,7 +163,7 @@ namespace Barotrauma
Description = element.GetAttributeString("description", string.Empty);
MaxLevel = element.GetAttributeInt("maxlevel", 1);
Identifier = element.GetAttributeString("identifier", "");
SupressWarnings = element.GetAttributeBool("supresswarnings", false);
SuppressWarnings = element.GetAttributeBool("supresswarnings", false);
HideInMenus = element.GetAttributeBool("hideinmenus", false);
FilePath = filePath;
SourceElement = element;
@@ -219,7 +223,7 @@ namespace Barotrauma
string[] categories = element.GetAttributeStringArray("categories", new string[] { });
UpgradeCategories = (from category in UpgradeCategory.Categories from identifier in categories where string.Equals(category.Identifier, identifier) select category).ToArray();
if (!SupressWarnings && !IsOverride)
if (!SuppressWarnings && !IsOverride)
{
foreach (UpgradePrefab matchingPrefab in Prefabs.Where(prefab => prefab.TargetItems.Any(s => TargetItems.Contains(s))))
{
@@ -243,9 +247,14 @@ namespace Barotrauma
Prefabs.Add(this, isOverride);
}
public static UpgradePrefab? Find(string idenfitier)
public bool IsDisallowed(Item item)
{
return !string.IsNullOrWhiteSpace(idenfitier) ? Prefabs.Find(prefab => prefab.Identifier == idenfitier) : null;
return item.disallowedUpgrades.Contains(Identifier);
}
public static UpgradePrefab? Find(string identifier)
{
return !string.IsNullOrWhiteSpace(identifier) ? Prefabs.Find(prefab => prefab.Identifier == identifier) : null;
}
public static void LoadAll(IEnumerable<ContentFile> files)