2 using System.Collections.Generic;
3 using System.Collections.Immutable;
6 using Microsoft.Xna.Framework;
154 if (value ==
null)
return;
156 Identifiers = value.Split(
',').Select(s => s.Trim()).ToIdentifiers().ToImmutableHashSet();
163 public ImmutableHashSet<Identifier>
Identifiers {
get;
private set; }
170 if (value ==
null)
return;
172 ExcludedIdentifiers = value.Split(
',').Select(s => s.Trim()).ToIdentifiers().ToImmutableHashSet();
178 if (item ==
null) {
return false; }
182 if (item.HasTag(excludedIdentifier)) {
return false; }
188 if (
Identifiers.Contains(item.Prefab.Identifier)) {
return true; }
191 if (item.HasTag(identifier)) {
return true; }
195 if (
Identifiers.Contains(item.Prefab.VariantOf)) {
return true; }
201 if (itemPrefab ==
null) {
return false; }
205 if (itemPrefab.Tags.Contains(excludedIdentifier)) {
return false; }
207 if (
Identifiers.Contains(itemPrefab.Identifier)) {
return true; }
210 if (itemPrefab.Tags.Contains(identifier)) {
return true; }
214 if (
Identifiers.Contains(itemPrefab.VariantOf)) {
return true; }
219 public RelatedItem(Identifier[] identifiers, Identifier[] excludedIdentifiers)
221 this.
Identifiers = identifiers.Select(
id =>
id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
222 this.
ExcludedIdentifiers = excludedIdentifiers.Select(
id =>
id.Value.Trim().ToIdentifier()).ToImmutableHashSet();
227 Identifier[] identifiers;
231 DebugConsole.ThrowError($
"Error in RelatedItem config (" + (
string.IsNullOrEmpty(parentDebugName) ? element.ToString() : parentDebugName) +
") - use item tags or identifiers instead of names.", contentPackage: element.
ContentPackage);
234 List<Identifier> convertedIdentifiers =
new List<Identifier>();
235 foreach (Identifier itemName
in itemNames)
238 if (matchingItem !=
null)
240 convertedIdentifiers.Add(matchingItem.Identifier);
245 convertedIdentifiers.Add(itemName);
248 identifiers = convertedIdentifiers.ToArray();
253 if (identifiers ==
null)
256 if (identifiers ==
null)
262 this.
Identifiers = identifiers.ToImmutableHashSet();
265 if (excludedIdentifiers ==
null)
268 if (excludedIdentifiers ==
null)
294 if (
string.IsNullOrEmpty(typeStr))
296 switch (element.
Name.ToString().ToLowerInvariant())
299 typeStr =
"Contained";
301 case "suitablefertilizer":
307 if (!Enum.TryParse(typeStr,
true, out type))
309 DebugConsole.ThrowError(
"Error in RelatedItem config (" + parentDebugName +
") - \"" + typeStr +
"\" is not a valid relation type.", contentPackage: element.
ContentPackage);
324 msg = msg.
Replace(
"[" + inputType.ToString().ToLowerInvariant() +
"]", GameSettings.CurrentConfig.KeyMap.KeyBindText(inputType));
330 foreach (var subElement
in element.Elements())
332 if (!subElement.Name.ToString().Equals(
"statuseffect", StringComparison.OrdinalIgnoreCase)) {
continue; }
336 IsOptional = element.GetAttributeBool(
"optional",
false);
337 IgnoreInEditor = element.GetAttributeBool(
"ignoreineditor",
false);
338 MatchOnEmpty = element.GetAttributeBool(
"matchonempty",
false);
339 TargetSlot = element.GetAttributeInt(
"targetslot", -1);
348 if (parentItem ==
null) {
return false; }
349 return CheckContained(parentItem);
352 return CheckItem(parentItem.
Container,
this);
354 if (character ==
null) {
return false; }
356 if (RequireOrMatchOnEmpty && heldItems.None()) {
return true; }
357 foreach (
Item equippedItem
in heldItems)
359 if (equippedItem ==
null) {
continue; }
360 if (CheckItem(equippedItem,
this))
368 if (character ==
null) {
return false; }
371 if (RequireOrMatchOnEmpty && allItems.None()) {
return true; }
372 foreach (
Item pickedItem
in allItems)
374 if (pickedItem ==
null) {
continue; }
375 if (CheckItem(pickedItem,
this))
391 private bool CheckContained(
Item parentItem)
395 if (
TargetSlot == -1 && RequireOrMatchOnEmpty)
401 foreach (var container
in parentItem.GetComponents<Items.
Components.ItemContainer>())
405 var itemInSlot = container.Inventory.GetItemAt(
TargetSlot);
407 if (
MatchOnEmpty && itemInSlot ==
null) {
return true; }
409 foreach (Item contained
in container.Inventory.AllItems)
413 if (CheckContained(contained)) {
return true; }
419 public void Save(XElement element)
423 new XAttribute(
"type", type.ToString()),
432 new XAttribute(
"rotation",
Rotation),
437 element.Add(
new XAttribute(nameof(
Hide),
true));
449 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
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)