eft-lootvalueex/Plugin/Utils/EconomyUtils.cs

45 lines
1.7 KiB
C#
Raw Permalink Normal View History

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 static class EconomyUtils
{
internal 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);
}
internal 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;
}
}
}