Handle flea item prices as doubles
This commit is contained in:
@@ -126,7 +126,7 @@ public class RagfairOfferGenerator(
|
||||
itemHelper.AddCartridgesToAmmoBox(itemsClone, itemHelper.GetItem(rootItem.Template).Value);
|
||||
}
|
||||
|
||||
var roubleListingPrice = Math.Round((double) ConvertOfferRequirementsIntoRoubles(offerRequirements));
|
||||
var roubleListingPrice = Math.Round(ConvertOfferRequirementsIntoRoubles(offerRequirements));
|
||||
var singleItemListingPrice = isPackOffer ? roubleListingPrice / itemStackCount : roubleListingPrice;
|
||||
|
||||
var offer = new RagfairOffer
|
||||
@@ -209,14 +209,14 @@ public class RagfairOfferGenerator(
|
||||
* @param offerRequirements barter requirements for offer
|
||||
* @returns rouble cost of offer
|
||||
*/
|
||||
protected int ConvertOfferRequirementsIntoRoubles(List<OfferRequirement> offerRequirements)
|
||||
protected double ConvertOfferRequirementsIntoRoubles(IEnumerable<OfferRequirement> offerRequirements)
|
||||
{
|
||||
var roublePrice = 0;
|
||||
var roublePrice = 0d;
|
||||
foreach (var requirement in offerRequirements)
|
||||
{
|
||||
roublePrice += (int) (paymentHelper.IsMoneyTpl(requirement.Template)
|
||||
? Math.Round((double) CalculateRoublePrice((int) requirement.Count, requirement.Template))
|
||||
: ragfairPriceService.GetFleaPriceForItem(requirement.Template) * requirement.Count); // get flea price for barter offer items
|
||||
roublePrice += (paymentHelper.IsMoneyTpl(requirement.Template)
|
||||
? Math.Round(CalculateRoublePrice(requirement.Count.Value, requirement.Template))
|
||||
: ragfairPriceService.GetFleaPriceForItem(requirement.Template) * requirement.Count.Value); // Get flea price for barter offer items
|
||||
}
|
||||
|
||||
return roublePrice;
|
||||
@@ -244,7 +244,7 @@ public class RagfairOfferGenerator(
|
||||
* @param currencyType Type of currency (euro/dollar/rouble)
|
||||
* @returns count of roubles
|
||||
*/
|
||||
protected int CalculateRoublePrice(int currencyCount, string currencyType)
|
||||
protected double CalculateRoublePrice(double currencyCount, string currencyType)
|
||||
{
|
||||
if (currencyType == Money.ROUBLES)
|
||||
{
|
||||
|
||||
@@ -166,11 +166,11 @@ public class HandbookHelper(
|
||||
/// <param name="nonRoubleCurrencyCount">Currency count to convert</param>
|
||||
/// <param name="currencyTypeFrom">What current currency is</param>
|
||||
/// <returns>Count in roubles</returns>
|
||||
public int InRUB(double nonRoubleCurrencyCount, string currencyTypeFrom)
|
||||
public double InRUB(double nonRoubleCurrencyCount, string currencyTypeFrom)
|
||||
{
|
||||
return (int) (currencyTypeFrom == Money.ROUBLES
|
||||
return currencyTypeFrom == Money.ROUBLES
|
||||
? nonRoubleCurrencyCount
|
||||
: Math.Round(nonRoubleCurrencyCount * GetTemplatePrice(currencyTypeFrom)));
|
||||
: Math.Round(nonRoubleCurrencyCount * GetTemplatePrice(currencyTypeFrom));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -179,7 +179,7 @@ public class HandbookHelper(
|
||||
/// <param name="roubleCurrencyCount">roubles to convert</param>
|
||||
/// <param name="currencyTypeTo">Currency to convert roubles into</param>
|
||||
/// <returns>currency count in desired type</returns>
|
||||
public int FromRUB(double roubleCurrencyCount, string currencyTypeTo)
|
||||
public double FromRUB(double roubleCurrencyCount, string currencyTypeTo)
|
||||
{
|
||||
if (currencyTypeTo == Money.ROUBLES)
|
||||
{
|
||||
@@ -188,7 +188,9 @@ public class HandbookHelper(
|
||||
|
||||
// Get price of currency from handbook
|
||||
var price = GetTemplatePrice(currencyTypeTo);
|
||||
return (int) (price > 0 ? Math.Max(1, Math.Round(roubleCurrencyCount / price)) : 0);
|
||||
return price > 0
|
||||
? Math.Max(1, Math.Round(roubleCurrencyCount / price))
|
||||
: 0;
|
||||
}
|
||||
|
||||
public HandbookCategory GetCategoryById(string handbookId)
|
||||
|
||||
@@ -479,6 +479,7 @@ public record TraderAssort
|
||||
|
||||
public record BarterScheme
|
||||
{
|
||||
// Confirmed in client
|
||||
[JsonPropertyName("count")]
|
||||
public double? Count
|
||||
{
|
||||
|
||||
@@ -998,7 +998,7 @@ public class FenceService(
|
||||
|
||||
// Multiply item cost by desired multiplier
|
||||
var basePrice = barterSchemes[itemRoot.Id][0][0].Count;
|
||||
barterSchemes[itemRoot.Id][0][0].Count = Math.Round((double) (basePrice * multipler));
|
||||
barterSchemes[itemRoot.Id][0][0].Count = Math.Round(basePrice.Value * multiplier.Value);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -300,15 +300,14 @@ public class RagfairPriceService(
|
||||
price = RandomiseOfferPrice(price, range);
|
||||
|
||||
// Convert to different currency if required.
|
||||
var roublesId = Money.ROUBLES;
|
||||
if (desiredCurrency != roublesId)
|
||||
if (desiredCurrency != Money.ROUBLES)
|
||||
{
|
||||
price = _handbookHelper.FromRUB(price, desiredCurrency);
|
||||
}
|
||||
|
||||
if (price < 1)
|
||||
if (price <= 0)
|
||||
{
|
||||
return 1;
|
||||
return 0.1d;
|
||||
}
|
||||
|
||||
return price;
|
||||
|
||||
Reference in New Issue
Block a user