1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
42 private const int DefaultAmount = 5;
47 private const float DefaultMaxAvailabilityRelativeToMin = 1.2f;
49 private readonly Dictionary<Identifier, float> minReputation =
new Dictionary<Identifier, float>();
54 public IReadOnlyDictionary<Identifier, float>
MinReputation => minReputation;
63 Price = element.GetAttributeInt(
"buyprice", 0);
69 RequiresUnlock = element.GetAttributeBool(
"requiresunlock",
false);
75 int minAmount = 0,
int maxAmount = 0,
bool canBeSpecial =
true,
int minLevelDifficulty = 0,
float buyingPriceMultiplier = 1f,
76 bool displayNonEmpty =
false,
bool requiresUnlock =
false,
string storeIdentifier =
null)
92 private void LoadReputationRestrictions(XElement priceInfoElement)
94 foreach (XElement childElement
in priceInfoElement.GetChildElements(
"reputation"))
96 Identifier factionId = childElement.GetAttributeIdentifier(
"faction", Identifier.Empty);
97 float rep = childElement.GetAttributeFloat(
"min", 0.0f);
98 if (!factionId.IsEmpty && rep > 0)
100 minReputation.Add(factionId, rep);
107 var priceInfos =
new List<PriceInfo>();
109 int basePrice = element.GetAttributeInt(
"baseprice", 0);
110 int minAmount = GetMinAmount(element, defaultValue: DefaultAmount);
111 int maxAmount = GetMaxAmount(element, defaultValue: (
int)(DefaultAmount * DefaultMaxAvailabilityRelativeToMin));
112 int minLevelDifficulty = element.GetAttributeInt(
"minleveldifficulty", 0);
113 bool canBeSpecial = element.GetAttributeBool(
"canbespecial",
true);
114 float buyingPriceMultiplier = element.GetAttributeFloat(
"buyingpricemultiplier", 1f);
115 bool displayNonEmpty = element.GetAttributeBool(
"displaynonempty",
false);
116 bool soldByDefault = element.GetAttributeBool(
"sold", element.GetAttributeBool(
"soldbydefault",
true));
117 bool requiresUnlock = element.GetAttributeBool(
"requiresunlock",
false);
118 foreach (XElement childElement
in element.GetChildElements(
"price"))
120 float priceMultiplier = childElement.GetAttributeFloat(
"multiplier", 1.0f);
121 bool sold = childElement.GetAttributeBool(
"sold", soldByDefault);
122 int storeMinLevelDifficulty = childElement.GetAttributeInt(
"minleveldifficulty", minLevelDifficulty);
123 float storeBuyingMultiplier = childElement.GetAttributeFloat(
"buyingpricemultiplier", buyingPriceMultiplier);
124 string backwardsCompatibleIdentifier = childElement.GetAttributeString(
"locationtype",
"");
125 if (!
string.IsNullOrEmpty(backwardsCompatibleIdentifier))
127 backwardsCompatibleIdentifier = $
"merchant{backwardsCompatibleIdentifier}";
129 string storeIdentifier = childElement.GetAttributeString(
"storeidentifier", backwardsCompatibleIdentifier);
131 var priceInfo =
new PriceInfo(price: (
int)(priceMultiplier * basePrice),
133 minAmount: sold ? GetMinAmount(childElement, minAmount) : 0,
134 maxAmount: sold ? GetMaxAmount(childElement, maxAmount) : 0,
135 canBeSpecial: canBeSpecial,
136 minLevelDifficulty: storeMinLevelDifficulty,
137 buyingPriceMultiplier: storeBuyingMultiplier,
138 displayNonEmpty: displayNonEmpty,
139 requiresUnlock: requiresUnlock,
140 storeIdentifier: storeIdentifier);
141 priceInfo.LoadReputationRestrictions(childElement);
142 priceInfos.Add(priceInfo);
144 bool soldElsewhere = soldByDefault && element.GetAttributeBool(
"soldelsewhere", element.GetAttributeBool(
"soldeverywhere",
false));
145 defaultPrice =
new PriceInfo(price: basePrice,
146 canBeBought: soldElsewhere,
147 minAmount: soldElsewhere ? minAmount : 0,
148 maxAmount: soldElsewhere ? maxAmount : 0,
149 canBeSpecial: canBeSpecial,
150 minLevelDifficulty: minLevelDifficulty,
151 buyingPriceMultiplier: buyingPriceMultiplier,
152 displayNonEmpty: displayNonEmpty,
153 requiresUnlock: requiresUnlock);
154 defaultPrice.LoadReputationRestrictions(element);
158 private static int GetMinAmount(XElement element,
int defaultValue) => element !=
null ?
159 element.GetAttributeInt(
"minamount", element.GetAttributeInt(
"minavailable", defaultValue)) :
162 private static int GetMaxAmount(XElement element,
int defaultValue) => element !=
null ?
163 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)