2022-07-09 12:15:57 +01:00
|
|
|
|
using Aki.Common.Http;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
using Aki.Common.Utils;
|
|
|
|
|
using EFT.InventoryLogic;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
using UnityEngine;
|
2022-07-09 12:15:57 +01:00
|
|
|
|
using System.Reflection;
|
2022-07-25 15:21:49 -04:00
|
|
|
|
using ItemAttribute = GClass2185;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
|
|
|
|
|
namespace itemValueMod
|
|
|
|
|
{
|
|
|
|
|
public class ItemValue
|
|
|
|
|
{
|
|
|
|
|
public static void AddItemValue<T>(ref T __instance, string id, ItemTemplate template) where T : Item
|
|
|
|
|
{
|
|
|
|
|
var atts = new List<ItemAttribute>();
|
|
|
|
|
atts.AddRange(__instance.Attributes);
|
|
|
|
|
__instance.Attributes = atts;
|
|
|
|
|
ItemAttribute attr = new ItemAttribute(EItemAttributeId.MoneySum)
|
|
|
|
|
{
|
2022-07-09 12:15:57 +01:00
|
|
|
|
StringValue = new Func<string>(__instance.ValueStr),
|
|
|
|
|
Name = "RUB ₽",
|
2022-05-14 20:06:24 +01:00
|
|
|
|
DisplayType = new Func<EItemAttributeDisplayType>(() => EItemAttributeDisplayType.Compact)
|
|
|
|
|
};
|
|
|
|
|
__instance.Attributes.Add(attr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ValueExtension
|
|
|
|
|
{
|
2022-07-09 12:15:57 +01:00
|
|
|
|
static public Dictionary<string, JsonClass> dict = new Dictionary<string, JsonClass>();
|
2022-06-25 22:30:13 +01:00
|
|
|
|
static object lockObject = new object();
|
|
|
|
|
|
2022-05-14 20:06:24 +01:00
|
|
|
|
public static double Value(this Item item)
|
|
|
|
|
{
|
|
|
|
|
var template = item.Template;
|
|
|
|
|
string itemId = template._id;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
JsonClass jsonClass;
|
2022-07-09 12:15:57 +01:00
|
|
|
|
double _price;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
double editedPrice;
|
|
|
|
|
double editedMulti;
|
2022-07-09 12:15:57 +01:00
|
|
|
|
double originalMax;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
|
2022-06-25 22:30:13 +01:00
|
|
|
|
lock (lockObject)
|
2022-05-14 20:06:24 +01:00
|
|
|
|
{
|
2022-07-09 12:15:57 +01:00
|
|
|
|
if (!dict.TryGetValue(template._id, out jsonClass))
|
2022-06-25 22:30:13 +01:00
|
|
|
|
{
|
|
|
|
|
var json = RequestHandler.GetJson($"/cwx/seeitemvalue/{itemId}");
|
|
|
|
|
jsonClass = Json.Deserialize<JsonClass>(json);
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
dict.Add(template._id, jsonClass);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
editedPrice = jsonClass.price;
|
|
|
|
|
editedMulti = jsonClass.multiplier;
|
|
|
|
|
originalMax = jsonClass.originalMax;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" editedPrice: {editedPrice}");
|
|
|
|
|
Debug.LogError($" editedMulti: {editedMulti}");
|
|
|
|
|
Debug.LogError($" originalMax: {originalMax}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
var medKit = item.GetItemComponent<MedKitComponent>();
|
|
|
|
|
if (medKit != null && medKit.HpResource != 0 && medKit.MaxHpResource != 0)
|
|
|
|
|
{
|
|
|
|
|
editedPrice *= medKit.HpResource / medKit.MaxHpResource;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" MedKitComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var repair = item.GetItemComponent<RepairableComponent>();
|
|
|
|
|
if (repair != null)
|
|
|
|
|
{
|
|
|
|
|
if (repair.Durability > 0)
|
|
|
|
|
{
|
|
|
|
|
editedPrice *= repair.Durability / originalMax;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" RepairableComponent: {editedPrice}");
|
2022-06-25 22:30:13 +01:00
|
|
|
|
}
|
2022-07-09 12:15:57 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
editedPrice = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dogtag = item.GetItemComponent<DogtagComponent>();
|
|
|
|
|
if (dogtag != null && dogtag.Level != 0)
|
|
|
|
|
{
|
|
|
|
|
editedPrice *= dogtag.Level;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" DogtagComponent: {editedPrice}");
|
2022-06-25 22:30:13 +01:00
|
|
|
|
}
|
2022-05-14 20:06:24 +01:00
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var repairKit = item.GetItemComponent<RepairKitComponent>();
|
|
|
|
|
if (repairKit != null)
|
|
|
|
|
{
|
|
|
|
|
if (repairKit.Resource > 0)
|
|
|
|
|
{
|
|
|
|
|
editedPrice *= repairKit.Resource / originalMax;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" RepairKitComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
editedPrice = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var resource = item.GetItemComponent<ResourceComponent>();
|
|
|
|
|
if (resource != null && resource.Value != 0 && resource.MaxResource != 0)
|
|
|
|
|
{
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" ResourceComponent.value: {resource.Value}");
|
|
|
|
|
Debug.LogError($" ResourceComponent.MaxResource: {resource.MaxResource}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
editedPrice *= resource.Value / resource.MaxResource;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" ResourceComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var foodDrink = item.GetItemComponent<FoodDrinkComponent>();
|
|
|
|
|
if (foodDrink != null && foodDrink.HpPercent != 0)
|
|
|
|
|
{
|
2022-07-25 15:21:49 -04:00
|
|
|
|
GInterface208 ginterface208_0 = (GInterface208)foodDrink.GetType().GetField("ginterface208_0", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(foodDrink);
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
2022-07-25 15:21:49 -04:00
|
|
|
|
editedPrice *= foodDrink.HpPercent / ginterface208_0.MaxResource;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" FoodDrinkComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var keys = item.GetItemComponent<KeyComponent>();
|
|
|
|
|
if (keys != null)
|
|
|
|
|
{
|
2022-07-25 15:21:49 -04:00
|
|
|
|
GInterface212 ginterface212_0 = (GInterface212)keys.GetType().GetField("Template", BindingFlags.Public | BindingFlags.Instance).GetValue(keys);
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
if (keys.NumberOfUsages > 0)
|
|
|
|
|
{
|
2022-07-25 15:21:49 -04:00
|
|
|
|
double totalMinusUsed = Convert.ToDouble(ginterface212_0.MaximumNumberOfUsage - keys.NumberOfUsages);
|
|
|
|
|
double multi = totalMinusUsed / ginterface212_0.MaximumNumberOfUsage;
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
editedPrice *= multi;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" KeyComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sideEffect = item.GetItemComponent<SideEffectComponent>();
|
|
|
|
|
if (sideEffect != null && sideEffect.Value != 0)
|
|
|
|
|
{
|
|
|
|
|
editedPrice *= sideEffect.Value / sideEffect.MaxResource;
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($" SideEffectComponent: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_price = editedPrice * editedMulti;
|
|
|
|
|
Debug.LogError($"ENDING PRICE: {_price}");
|
|
|
|
|
|
2022-05-14 20:06:24 +01:00
|
|
|
|
return _price;
|
|
|
|
|
}
|
|
|
|
|
public static string ValueStr(this Item item)
|
|
|
|
|
{
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var result = Math.Round(item.Value()).ToString();
|
2022-07-11 20:58:04 +01:00
|
|
|
|
Debug.LogError($"price, rounded to string: {result}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
return result;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|