v0.11.0.9

This commit is contained in:
Joonas Rikkonen
2020-12-09 16:34:16 +02:00
parent bbf06f0984
commit f433a7ba10
325 changed files with 13947 additions and 3652 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'.");
@@ -143,7 +143,7 @@ namespace Barotrauma
private bool Disposed { get; set; }
public bool SupressWarnings { get; }
public bool SuppressWarnings { get; }
public bool HideInMenus { get; }
@@ -159,7 +159,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 +219,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 +243,9 @@ namespace Barotrauma
Prefabs.Add(this, isOverride);
}
public static UpgradePrefab? Find(string idenfitier)
public static UpgradePrefab? Find(string identifier)
{
return !string.IsNullOrWhiteSpace(idenfitier) ? Prefabs.Find(prefab => prefab.Identifier == idenfitier) : null;
return !string.IsNullOrWhiteSpace(identifier) ? Prefabs.Find(prefab => prefab.Identifier == identifier) : null;
}
public static void LoadAll(IEnumerable<ContentFile> files)