2024-11-08 21:17:10 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-11-23 01:30:48 +01:00
|
|
|
|
internal static class EconomyUtils
|
2024-11-08 21:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
2024-11-23 01:30:48 +01:00
|
|
|
|
internal static float ConvertToRuble(string id, float amount)
|
2024-11-08 21:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
if (!EFTCurrencyUtils.TryGetCurrencyType(id, out ECurrencyType currencyType))
|
|
|
|
|
return 0f;
|
|
|
|
|
if (currencyType.Equals(ECurrencyType.RUB))
|
|
|
|
|
return amount;
|
|
|
|
|
return amount * (float)Singleton<HandbookClass>.Instance.GetBasePrice(id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-23 01:30:48 +01:00
|
|
|
|
internal static Structs.TradeOfferStruct GetTraderItemOffer(TraderClass trader, Item item)
|
2024-11-08 21:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|