4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
7 using System.Collections.Generic;
8 using System.Collections.Immutable;
34 None, HideWhenVisible, HideWhenNotVisible
54 if (container ==
null) {
return false; }
60 partial class ItemPrefab : MapEntityPrefab, IImplementsVariants<ItemPrefab>
62 public ImmutableDictionary<Identifier, ImmutableArray<DecorativeSprite>>
UpgradeOverrideSprites {
get;
private set; }
63 public ImmutableArray<BrokenItemSprite>
BrokenSprites {
get;
private set; }
75 private IReadOnlyList<DamageModifier> wearableDamageModifiers;
76 private IReadOnlyDictionary<Identifier, float> wearableSkillModifiers;
100 var upgradeOverrideSprites =
new Dictionary<Identifier, List<DecorativeSprite>>();
101 var brokenSprites =
new List<BrokenItemSprite>();
102 var decorativeSprites =
new List<DecorativeSprite>();
103 var containedSprites =
new List<ContainedItemSprite>();
104 var decorativeSpriteGroups =
new Dictionary<int, List<DecorativeSprite>>();
106 var wearableDamageModifiers =
new List<DamageModifier>();
107 var wearableSkillModifiers =
new Dictionary<Identifier, float>();
109 foreach (var subElement
in element.
Elements())
111 switch (subElement.Name.LocalName.ToLowerInvariant())
113 case "upgradeoverride":
116 var sprites =
new List<DecorativeSprite>();
117 foreach (var decorSprite
in subElement.Elements())
119 if (decorSprite.NameAsIdentifier() ==
"decorativesprite")
124 upgradeOverrideSprites.Add(subElement.GetAttributeIdentifier(
"identifier",
Identifier.Empty), sprites);
127 case "upgradepreviewsprite":
129 string iconFolder = GetTexturePath(subElement, variantOf);
134 case "inventoryicon":
136 string iconFolder = GetTexturePath(subElement, variantOf);
142 string iconFolder = GetTexturePath(subElement, variantOf);
146 case "infectedsprite":
148 string iconFolder = GetTexturePath(subElement, variantOf);
153 case "damagedinfectedsprite":
155 string iconFolder = GetTexturePath(subElement, variantOf);
161 string brokenSpriteFolder = GetTexturePath(subElement, variantOf);
163 var brokenSprite =
new BrokenItemSprite(
164 new Sprite(subElement, brokenSpriteFolder, lazyLoad:
true),
165 subElement.GetAttributeFloat(
"maxcondition", 0.0f),
166 subElement.GetAttributeBool(
"fadein",
false),
167 subElement.GetAttributePoint(
"offset", Point.Zero));
170 for (
int i = 0; i < brokenSprites.Count && brokenSprites[i].MaxConditionPercentage < brokenSprite.MaxConditionPercentage; i++)
174 brokenSprites.Insert(spriteIndex, brokenSprite);
176 case "decorativesprite":
177 string decorativeSpriteFolder = GetTexturePath(subElement, variantOf);
180 DecorativeSprite decorativeSprite =
null;
181 if (subElement.GetAttribute(
"texture") ==
null)
183 groupID = subElement.GetAttributeInt(
"randomgroupid", 0);
187 decorativeSprite =
new DecorativeSprite(subElement, decorativeSpriteFolder, lazyLoad:
true);
188 decorativeSprites.Add(decorativeSprite);
189 groupID = decorativeSprite.RandomGroupID;
191 if (!decorativeSpriteGroups.ContainsKey(groupID))
193 decorativeSpriteGroups.Add(groupID,
new List<DecorativeSprite>());
195 decorativeSpriteGroups[groupID].Add(decorativeSprite);
198 case "containedsprite":
199 string containedSpriteFolder = GetTexturePath(subElement, variantOf);
200 var containedSprite =
new ContainedItemSprite(subElement, containedSpriteFolder, lazyLoad:
true);
201 if (containedSprite.Sprite !=
null)
203 containedSprites.Add(containedSprite);
207 foreach (ContentXElement wearableSubElement
in subElement.Elements())
209 switch (wearableSubElement.Name.LocalName.ToLowerInvariant())
211 case "damagemodifier":
212 wearableDamageModifiers.Add(
new DamageModifier(wearableSubElement,
Name.
Value +
", Wearable", checkErrors:
false));
214 case "skillmodifier":
215 Identifier skillIdentifier = wearableSubElement.GetAttributeIdentifier(
"skillidentifier",
Identifier.Empty);
216 float skillValue = wearableSubElement.GetAttributeFloat(
"skillvalue", 0f);
217 if (wearableSkillModifiers.ContainsKey(skillIdentifier))
219 wearableSkillModifiers[skillIdentifier] += skillValue;
223 wearableSkillModifiers.TryAdd(skillIdentifier, skillValue);
231 this.wearableDamageModifiers = wearableDamageModifiers.ToImmutableList();
232 this.wearableSkillModifiers = wearableSkillModifiers.ToImmutableDictionary();
234 UpgradeOverrideSprites = upgradeOverrideSprites.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableDictionary();
238 DecorativeSpriteGroups = decorativeSpriteGroups.Select(kvp => (kvp.Key, kvp.Value.ToImmutableArray())).ToImmutableDictionary();
241 foreach (Item item
in Item.ItemList)
243 if (item.Prefab ==
this)
245 item.InitSpriteStates();
259 LocalizedString tooltip = $
"‖color:{XMLExtensions.ToStringHex(GUIStyle.TextColorBright)}‖{Name}‖color:end‖";
262 tooltip += $
"\n{Description}";
264 if (wearableDamageModifiers.Any() || wearableSkillModifiers.Any())
296 item.GetComponent<Items.Components.Door>()?.RefreshLinkedGap();
343 if (potentialContainer !=
null)
345 potentialContainer.IsHighlighted =
true;
370 public override void DrawPlacing(SpriteBatch spriteBatch, Rectangle placeRect,
float scale = 1.0f,
float rotation = 0.0f, SpriteEffects spriteEffects = SpriteEffects.None)
375 spriteBatch: spriteBatch,
376 pos:
new Vector2(placeRect.Center.X,
377 -(placeRect.Y - placeRect.Height / 2)),
381 spriteEffect: spriteEffects ^ sprite.
effects);
385 Vector2 position = placeRect.Location.ToVector2();
386 Vector2 placeSize = placeRect.Size.ToVector2();
388 spriteBatch: spriteBatch,
389 position:
new Vector2(position.X, -position.Y),
390 targetSize: placeSize,
392 textureScale: Vector2.One * scale,
394 spriteEffects: spriteEffects ^ sprite.
effects);
403 Color orange = GUIStyle.Orange;
405 text =
"\n\n" + $
"‖color:{orange.ToStringHex()}‖{TextManager.Get("requiredrepairskills
")}‖color:end‖";
409 Color levelColor = GUIStyle.Yellow;
410 if (skillLevel >= hint.Level)
412 levelColor = GUIStyle.Green;
414 else if (skillLevel < hint.Level / 2)
416 levelColor = GUIStyle.Red;
418 text +=
"\n" + hint.GetFormattedText(skillLevel, levelColor.ToStringHex());
readonly float MaxConditionPercentage
BrokenItemSprite(Sprite sprite, float maxCondition, bool fadeIn, Point offset)
Vector2 ScreenToWorld(Vector2 coords)
float GetSkillLevel(string skillIdentifier)
bool HasStoreAccessForItem(ItemPrefab prefab)
static Character? Controlled
bool MatchesContainer(Item container)
readonly bool UseWhenAttached
readonly ImmutableHashSet< Identifier > AllowedContainerTags
readonly DecorativeSpriteBehaviorType DecorativeSpriteBehavior
ContainedItemSprite(ContentXElement element, string path="", bool lazyLoad=false)
DecorativeSpriteBehaviorType
readonly ImmutableHashSet< Identifier > AllowedContainerIdentifiers
string? GetAttributeString(string key, string? def)
Identifier[] GetAttributeIdentifierArray(Identifier[] def, params string[] keys)
IEnumerable< ContentXElement > Elements()
bool GetAttributeBool(string key, bool def)
Sprite DamagedInfectedSprite
ImmutableArray< DecorativeSprite > DecorativeSprites
ImmutableDictionary< int, ImmutableArray< DecorativeSprite > > DecorativeSpriteGroups
ImmutableArray< ContainedItemSprite > ContainedSprites
override void DrawPlacing(SpriteBatch spriteBatch, Camera cam)
ImmutableArray< SkillRequirementHint > SkillRequirementHints
override void DrawPlacing(SpriteBatch spriteBatch, Rectangle placeRect, float scale=1.0f, float rotation=0.0f, SpriteEffects spriteEffects=SpriteEffects.None)
LocalizedString GetTooltip(Character character)
ImmutableDictionary< Identifier, ImmutableArray< DecorativeSprite > > UpgradeOverrideSprites
LocalizedString GetSkillRequirementHints(Character character)
override LocalizedString Name
Sprite UpgradePreviewSprite
override ImmutableHashSet< Identifier > Tags
ImmutableArray< BrokenItemSprite > BrokenSprites
override void UpdatePlacing(Camera cam)
float UpgradePreviewScale
override void AddTooltipInfo(ref LocalizedString name, ref LocalizedString description)
static Item GetPotentialContainer(Vector2 position, HashSet< MapEntity > entities=null)
LocalizedString Description
static Vector2 placePosition
static MapEntityPrefab Selected
readonly Identifier Identifier
void Draw(ISpriteBatch spriteBatch, Vector2 pos, float rotate=0.0f, float scale=1.0f, SpriteEffects spriteEffect=SpriteEffects.None)
void DrawTiled(ISpriteBatch spriteBatch, Vector2 position, Vector2 targetSize, float rotation=0f, Vector2? origin=null, Color? color=null, Vector2? startOffset=null, Vector2? textureScale=null, float? depth=null, SpriteEffects? spriteEffects=null)
static void StoreCommand(Command command)
Submarine(SubmarineInfo info, bool showErrorMessages=true, Func< Submarine, List< MapEntity >> loadEntities=null, IdRemap linkedRemap=null)
static Vector2 MouseToWorldGrid(Camera cam, Submarine sub, Vector2? mousePos=null, bool round=false)
override Vector2? Position