eft-lootvalueex/Plugin/Utils/EconomyUtils.cs
Yui db4003caa7
feat: get best trader offer for items
TODO: Make a better conversion for USD/EUR to RUB
2024-11-08 17:17:10 -03:00

45 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Comfort.Common;
using EFT.InventoryLogic;
using SPT.Reflection.Utils;
using EFTCurrencyUtils = GClass2531;
namespace LootValueEX.Utils
{
internal class EconomyUtils
{
public static float ConvertToRuble(string id, float amount)
{
if (!EFTCurrencyUtils.TryGetCurrencyType(id, out ECurrencyType currencyType))
return 0f;
if (currencyType.Equals(ECurrencyType.RUB))
return amount;
return amount * (float)Singleton<HandbookClass>.Instance.GetBasePrice(id);
}
public static Structs.TradeOfferStruct GetTraderItemOffer(TraderClass trader, Item item)
{
Plugin.Log.LogDebug($"GetTraderItemOffer: {item.LocalizedName()} - {trader.LocalizedName}");
TraderClass.GStruct244? tradeOffer = trader.GetUserItemPrice(item);
if (tradeOffer == null)
{
Plugin.Log.LogDebug("GetTraderItemOffer: tradeOffer == null");
return default;
}
if(tradeOffer.Value.Amount > 0)
{
Plugin.Log.LogDebug($"{trader.LocalizedName}\n\tCurrencyID: {tradeOffer.Value.CurrencyId}\n\tValue: {tradeOffer.Value.Amount}\n\tPrice in RB: {EconomyUtils.ConvertToRuble(tradeOffer.Value.CurrencyId, tradeOffer.Value.Amount)}");
return new Structs.TradeOfferStruct(trader.Id, tradeOffer.Value.CurrencyId, tradeOffer.Value.Amount, EconomyUtils.ConvertToRuble(tradeOffer.Value.CurrencyId, tradeOffer.Value.Amount));
}
Plugin.Log.LogDebug("GetTraderItemOffer: no value");
return default;
}
}
}