2 using System.Collections.Generic;
3 using System.Collections.Immutable;
6 using Microsoft.Xna.Framework;
152 set =>
Identifiers = value.ToIdentifiers().ToImmutableHashSet();
158 public ImmutableHashSet<Identifier>
Identifiers {
get;
private set; }
168 if (item ==
null) {
return false; }
172 if (item.HasTag(excludedIdentifier)) {
return false; }
178 if (
Identifiers.Contains(item.Prefab.Identifier)) {
return true; }
181 if (item.HasTag(identifier)) {
return true; }
185 if (
Identifiers.Contains(item.Prefab.VariantOf)) {
return true; }
191 if (itemPrefab ==
null) {
return false; }
195 if (itemPrefab.Tags.Contains(excludedIdentifier)) {
return false; }
197 if (
Identifiers.Contains(itemPrefab.Identifier)) {
return true; }
200 if (itemPrefab.Tags.Contains(identifier)) {
return true; }
204 if (
Identifiers.Contains(itemPrefab.VariantOf)) {
return true; }
209 public RelatedItem(Identifier[] identifiers, Identifier[] excludedIdentifiers)
211 this.
Identifiers = identifiers.Select(
id =>
id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
212 this.
ExcludedIdentifiers = excludedIdentifiers.Select(
id =>
id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
217 Identifier[] identifiers;
221 DebugConsole.ThrowError($
"Error in RelatedItem config (" + (
string.IsNullOrEmpty(parentDebugName) ? element.ToString() : parentDebugName) +
") - use item tags or identifiers instead of names.", contentPackage: element.
ContentPackage);
224 List<Identifier> convertedIdentifiers =
new List<Identifier>();
225 foreach (Identifier itemName
in itemNames)
228 if (matchingItem !=
null)
230 convertedIdentifiers.Add(matchingItem.Identifier);
235 convertedIdentifiers.Add(itemName);
238 identifiers = convertedIdentifiers.ToArray();
243 if (identifiers ==
null)
246 if (identifiers ==
null)
252 this.
Identifiers = identifiers.ToImmutableHashSet();
255 if (excludedIdentifiers ==
null)
258 if (excludedIdentifiers ==
null)
284 if (
string.IsNullOrEmpty(typeStr))
286 switch (element.
Name.ToString().ToLowerInvariant())
289 typeStr =
"Contained";
291 case "suitablefertilizer":
297 if (!Enum.TryParse(typeStr,
true, out type))
299 DebugConsole.ThrowError(
"Error in RelatedItem config (" + parentDebugName +
") - \"" + typeStr +
"\" is not a valid relation type.", contentPackage: element.
ContentPackage);
314 string inputTag = $
"[{inputType.ToString().ToLowerInvariant()}]";
315 if (!msg.
Contains(inputTag)) {
continue; }
316 msg = msg.
Replace(inputTag, GameSettings.CurrentConfig.KeyMap.KeyBindText(inputType));
322 foreach (var subElement
in element.Elements())
324 if (!subElement.Name.ToString().Equals(
"statuseffect", StringComparison.OrdinalIgnoreCase)) {
continue; }
328 IsOptional = element.GetAttributeBool(
"optional",
false);
329 IgnoreInEditor = element.GetAttributeBool(
"ignoreineditor",
false);
330 MatchOnEmpty = element.GetAttributeBool(
"matchonempty",
false);
331 TargetSlot = element.GetAttributeInt(
"targetslot", -1);
340 if (parentItem ==
null) {
return false; }
341 return CheckContained(parentItem);
344 return CheckItem(parentItem.
Container,
this);
346 if (character ==
null) {
return false; }
348 if (RequireOrMatchOnEmpty && heldItems.None()) {
return true; }
349 foreach (
Item equippedItem
in heldItems)
351 if (equippedItem ==
null) {
continue; }
352 if (CheckItem(equippedItem,
this))
360 if (character ==
null) {
return false; }
363 if (RequireOrMatchOnEmpty && allItems.None()) {
return true; }
364 foreach (
Item pickedItem
in allItems)
366 if (pickedItem ==
null) {
continue; }
367 if (CheckItem(pickedItem,
this))
383 private bool CheckContained(
Item parentItem)
387 if (
TargetSlot == -1 && RequireOrMatchOnEmpty)
393 foreach (var container
in parentItem.GetComponents<Items.
Components.ItemContainer>())
397 var itemInSlot = container.Inventory.GetItemAt(
TargetSlot);
399 if (
MatchOnEmpty && itemInSlot ==
null) {
return true; }
401 foreach (Item contained
in container.Inventory.AllItems)
405 if (CheckContained(contained)) {
return true; }
411 public void Save(XElement element)
415 new XAttribute(
"type", type.ToString()),
424 new XAttribute(
"rotation",
Rotation),
429 element.Add(
new XAttribute(nameof(
Hide),
true));
441 if (!
Msg.IsNullOrWhiteSpace()) { element.Add(
new XAttribute(
"msg",
MsgTag.IsEmpty ?
Msg :
MsgTag.Value)); }
CharacterInventory Inventory
IEnumerable< Item >?? HeldItems
Items the character has in their hand slots. Doesn't return nulls and only returns items held in both...
string? GetAttributeString(string key, string? def)
Identifier[] GetAttributeIdentifierArray(Identifier[] def, params string[] keys)
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
Vector2 GetAttributeVector2(string key, in Vector2 def)
bool GetAttributeBool(string key, bool def)
XAttribute? GetAttribute(string name)
Identifier GetAttributeIdentifier(string key, string def)
virtual IEnumerable< Item > AllItems
All items contained in the inventory. Stacked items are returned as individual instances....
int FindIndex(Item item)
Find the index of the first slot the item is contained in.
ItemInventory OwnInventory
List< ItemComponent > Components
static readonly PrefabCollection< ItemPrefab > Prefabs
bool Contains(string subStr, StringComparison comparison=StringComparison.Ordinal)
LocalizedString Replace(Identifier find, LocalizedString replace, StringComparison stringComparison=StringComparison.Ordinal)
readonly Identifier Identifier
StatusEffects can be used to execute various kinds of effects: modifying the state of some entity in ...
static StatusEffect Load(ContentXElement element, string parentDebugName)