1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
42 private const int DefaultAmount = 5;
47 private const float DefaultMaxAvailabilityRelativeToMin = 1.2f;
54 private readonly Dictionary<Identifier, float> minReputation =
new Dictionary<Identifier, float>();
59 public IReadOnlyDictionary<Identifier, float>
MinReputation => minReputation;
68 Price = element.GetAttributeInt(
"buyprice", 0);
74 RequiresUnlock = element.GetAttributeBool(
"requiresunlock",
false);
80 int minAmount = 0,
int maxAmount = 0,
bool canBeSpecial =
true,
int minLevelDifficulty = 0,
float buyingPriceMultiplier = 1f,
81 bool displayNonEmpty =
false,
bool requiresUnlock =
false,
string storeIdentifier =
null)
97 private void LoadReputationRestrictions(XElement priceInfoElement)
99 foreach (XElement childElement
in priceInfoElement.GetChildElements(
"reputation"))
101 Identifier factionId = childElement.GetAttributeIdentifier(
"faction", Identifier.Empty);
102 float rep = childElement.GetAttributeFloat(
"min", 0.0f);
103 if (!factionId.IsEmpty && rep > 0)
105 minReputation.Add(factionId, rep);
112 var priceInfos =
new List<PriceInfo>();
114 int basePrice = element.GetAttributeInt(
"baseprice", 0);
115 int minAmount = GetMinAmount(element, defaultValue: DefaultAmount);
116 int maxAmount = GetMaxAmount(element, defaultValue: (
int)(DefaultAmount * DefaultMaxAvailabilityRelativeToMin));
117 int minLevelDifficulty = element.GetAttributeInt(
"minleveldifficulty", 0);
118 bool canBeSpecial = element.GetAttributeBool(
"canbespecial",
true);
119 float buyingPriceMultiplier = element.GetAttributeFloat(
"buyingpricemultiplier", 1f);
120 bool displayNonEmpty = element.GetAttributeBool(
"displaynonempty",
false);
121 bool soldByDefault = element.GetAttributeBool(
"sold", element.GetAttributeBool(
"soldbydefault",
true));
122 bool requiresUnlock = element.GetAttributeBool(
"requiresunlock",
false);
123 Identifier requiredFactionByDefault = element.GetAttributeIdentifier(nameof(
RequiredFaction), Identifier.Empty);
124 foreach (XElement childElement
in element.GetChildElements(
"price"))
126 float priceMultiplier = childElement.GetAttributeFloat(
"multiplier", 1.0f);
127 bool sold = childElement.GetAttributeBool(
"sold", soldByDefault);
128 int storeMinLevelDifficulty = childElement.GetAttributeInt(
"minleveldifficulty", minLevelDifficulty);
129 float storeBuyingMultiplier = childElement.GetAttributeFloat(
"buyingpricemultiplier", buyingPriceMultiplier);
130 string backwardsCompatibleIdentifier = childElement.GetAttributeString(
"locationtype",
"");
131 if (!
string.IsNullOrEmpty(backwardsCompatibleIdentifier))
133 backwardsCompatibleIdentifier = $
"merchant{backwardsCompatibleIdentifier}";
135 string storeIdentifier = childElement.GetAttributeString(
"storeidentifier", backwardsCompatibleIdentifier);
137 var priceInfo =
new PriceInfo(price: (
int)(priceMultiplier * basePrice),
139 minAmount: sold ? GetMinAmount(childElement, minAmount) : 0,
140 maxAmount: sold ? GetMaxAmount(childElement, maxAmount) : 0,
141 canBeSpecial: canBeSpecial,
142 minLevelDifficulty: storeMinLevelDifficulty,
143 buyingPriceMultiplier: storeBuyingMultiplier,
144 displayNonEmpty: displayNonEmpty,
145 requiresUnlock: requiresUnlock,
146 storeIdentifier: storeIdentifier)
150 priceInfo.LoadReputationRestrictions(childElement);
151 priceInfos.Add(priceInfo);
153 bool soldElsewhere = soldByDefault && element.GetAttributeBool(
"soldelsewhere", element.GetAttributeBool(
"soldeverywhere",
false));
154 defaultPrice =
new PriceInfo(price: basePrice,
155 canBeBought: soldElsewhere,
156 minAmount: soldElsewhere ? minAmount : 0,
157 maxAmount: soldElsewhere ? maxAmount : 0,
158 canBeSpecial: canBeSpecial,
159 minLevelDifficulty: minLevelDifficulty,
160 buyingPriceMultiplier: buyingPriceMultiplier,
161 displayNonEmpty: displayNonEmpty,
162 requiresUnlock: requiresUnlock)
166 defaultPrice.LoadReputationRestrictions(element);
170 private static int GetMinAmount(XElement element,
int defaultValue) => element !=
null ?
171 element.GetAttributeInt(
"minamount", element.GetAttributeInt(
"minavailable", defaultValue)) :
174 private static int GetMaxAmount(XElement element,
int defaultValue) => element !=
null ?
175 element.GetAttributeInt(
"maxamount", element.GetAttributeInt(
"maxavailable", defaultValue)) :
int MinAvailableAmount
Minimum number of items available at a given store
float BuyingPriceMultiplier
The cost of item when sold by the store. Higher modifier means the item costs more to buy from the st...
int MinLevelDifficulty
The item isn't available in stores unless the level's difficulty is above this value
PriceInfo(XElement element)
Support for the old style of determining item prices when there were individual Price elements for ea...
int MaxAvailableAmount
Maximum number of items available at a given store. Defaults to 20% more than the minimum amount.
PriceInfo(int price, bool canBeBought, int minAmount=0, int maxAmount=0, bool canBeSpecial=true, int minLevelDifficulty=0, float buyingPriceMultiplier=1f, bool displayNonEmpty=false, bool requiresUnlock=false, string storeIdentifier=null)
IReadOnlyDictionary< Identifier, float > MinReputation
Minimum reputation needed to buy the item (Key = faction ID, Value = min rep)
Identifier StoreIdentifier
bool CanBeSpecial
Can the item be a Daily Special or a Requested Good
static List< PriceInfo > CreatePriceInfos(XElement element, out PriceInfo defaultPrice)
Identifier RequiredFaction
If set, the item is only available in outposts with this faction.