Unstable v0.19.3.0
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace Barotrauma
|
||||
|
||||
public bool IgnoreInEditor { get; set; }
|
||||
|
||||
private Identifier[] excludedIdentifiers;
|
||||
private ImmutableHashSet<Identifier> excludedIdentifiers;
|
||||
|
||||
private RelationType type;
|
||||
|
||||
@@ -60,11 +61,11 @@ namespace Barotrauma
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
Identifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToArray();
|
||||
Identifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToImmutableHashSet();
|
||||
}
|
||||
}
|
||||
|
||||
public Identifier[] Identifiers { get; private set; }
|
||||
public ImmutableHashSet<Identifier> Identifiers { get; private set; }
|
||||
|
||||
public string JoinedExcludedIdentifiers
|
||||
{
|
||||
@@ -73,27 +74,53 @@ namespace Barotrauma
|
||||
{
|
||||
if (value == null) return;
|
||||
|
||||
excludedIdentifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToArray();
|
||||
excludedIdentifiers = value.Split(',').Select(s => s.Trim()).ToIdentifiers().ToImmutableHashSet();
|
||||
}
|
||||
}
|
||||
|
||||
public bool MatchesItem(Item item)
|
||||
{
|
||||
if (item == null) { return false; }
|
||||
if (excludedIdentifiers.Any(id => item.Prefab.Identifier == id || item.HasTag(id))) { return false; }
|
||||
return Identifiers.Any(id => item.Prefab.Identifier == id || item.HasTag(id) || (AllowVariants && !item.Prefab.VariantOf.IsEmpty && item.Prefab.VariantOf == id));
|
||||
if (excludedIdentifiers.Contains(item.Prefab.Identifier)) { return false; }
|
||||
foreach (var excludedIdentifier in excludedIdentifiers)
|
||||
{
|
||||
if (item.HasTag(excludedIdentifier)) { return false; }
|
||||
}
|
||||
if (Identifiers.Contains(item.Prefab.Identifier)) { return true; }
|
||||
foreach (var identifier in Identifiers)
|
||||
{
|
||||
if (item.HasTag(identifier)) { return true; }
|
||||
}
|
||||
if (AllowVariants && !item.Prefab.VariantOf.IsEmpty)
|
||||
{
|
||||
if (Identifiers.Contains(item.Prefab.VariantOf)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool MatchesItem(ItemPrefab itemPrefab)
|
||||
{
|
||||
if (itemPrefab == null) { return false; }
|
||||
if (excludedIdentifiers.Any(id => itemPrefab.Identifier == id || itemPrefab.Tags.Contains(id))) { return false; }
|
||||
return Identifiers.Any(id => itemPrefab.Identifier == id || itemPrefab.Tags.Contains(id) || (AllowVariants && !itemPrefab.VariantOf.IsEmpty && itemPrefab.VariantOf == id));
|
||||
if (excludedIdentifiers.Contains(itemPrefab.Identifier)) { return false; }
|
||||
foreach (var excludedIdentifier in excludedIdentifiers)
|
||||
{
|
||||
if (itemPrefab.Tags.Contains(excludedIdentifier)) { return false; }
|
||||
}
|
||||
if (Identifiers.Contains(itemPrefab.Identifier)) { return true; }
|
||||
foreach (var identifier in Identifiers)
|
||||
{
|
||||
if (itemPrefab.Tags.Contains(identifier)) { return true; }
|
||||
}
|
||||
if (AllowVariants && !itemPrefab.VariantOf.IsEmpty)
|
||||
{
|
||||
if (Identifiers.Contains(itemPrefab.VariantOf)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public RelatedItem(Identifier[] identifiers, Identifier[] excludedIdentifiers)
|
||||
{
|
||||
this.Identifiers = identifiers.Select(id => id.Value.Trim().ToIdentifier()).ToArray();
|
||||
this.excludedIdentifiers = excludedIdentifiers.Select(id => id.Value.Trim().ToIdentifier()).ToArray();
|
||||
this.Identifiers = identifiers.Select(id => id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
|
||||
this.excludedIdentifiers = excludedIdentifiers.Select(id => id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
|
||||
|
||||
statusEffects = new List<StatusEffect>();
|
||||
}
|
||||
@@ -161,7 +188,7 @@ namespace Barotrauma
|
||||
new XAttribute("targetslot", TargetSlot),
|
||||
new XAttribute("allowvariants", AllowVariants));
|
||||
|
||||
if (excludedIdentifiers.Length > 0)
|
||||
if (excludedIdentifiers.Count > 0)
|
||||
{
|
||||
element.Add(new XAttribute("excludedidentifiers", JoinedExcludedIdentifiers));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user