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-07-09 12:15:57 +01:00
|
|
|
|
using System.Reflection;
|
2022-11-09 19:23:24 +00:00
|
|
|
|
using ItemAttribute = GClass2203;
|
2022-09-17 20:47:01 +01:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using UnityEngine;
|
2022-09-19 00:13:32 +01:00
|
|
|
|
using System.IO;
|
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;
|
2022-09-17 20:47:01 +01:00
|
|
|
|
|
|
|
|
|
ItemAttribute attr1 = new ItemAttribute(EItemAttributeId.MoneySum)
|
2022-05-14 20:06:24 +01:00
|
|
|
|
{
|
2022-09-17 20:47:01 +01:00
|
|
|
|
StringValue = new Func<string>(__instance.TraderPrice),
|
|
|
|
|
FullStringValue = new Func<string>(__instance.TraderName),
|
|
|
|
|
Name = "TRADER",
|
2022-05-14 20:06:24 +01:00
|
|
|
|
DisplayType = new Func<EItemAttributeDisplayType>(() => EItemAttributeDisplayType.Compact)
|
|
|
|
|
};
|
2022-09-17 20:47:01 +01:00
|
|
|
|
|
|
|
|
|
__instance.Attributes.Add(attr1);
|
2022-05-14 20:06:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ValueExtension
|
|
|
|
|
{
|
2022-09-17 20:47:01 +01:00
|
|
|
|
static public Dictionary<string, JsonClass> itemDictionary = new Dictionary<string, JsonClass>();
|
2022-06-25 22:30:13 +01:00
|
|
|
|
static object lockObject = new object();
|
|
|
|
|
|
2022-09-17 20:47:01 +01:00
|
|
|
|
public static JsonClass GetData(String itemId)
|
|
|
|
|
{
|
|
|
|
|
var json = RequestHandler.GetJson($"/cwx/seeitemvalue/{itemId}");
|
|
|
|
|
var jsonClass = Json.Deserialize<JsonClass>(json);
|
|
|
|
|
|
|
|
|
|
itemDictionary.Add(itemId, jsonClass);
|
|
|
|
|
|
|
|
|
|
return jsonClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string TraderPrice(this Item item)
|
2022-05-14 20:06:24 +01:00
|
|
|
|
{
|
2022-09-17 20:47:01 +01:00
|
|
|
|
string itemId = item.Template._id;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
JsonClass jsonClass;
|
2022-09-17 20:47:01 +01:00
|
|
|
|
bool lockWasTaken = false;
|
2022-09-19 00:13:32 +01:00
|
|
|
|
double alteredPrice = 1;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
|
2022-09-17 20:47:01 +01:00
|
|
|
|
try
|
2022-05-14 20:06:24 +01:00
|
|
|
|
{
|
2022-09-17 20:47:01 +01:00
|
|
|
|
Monitor.Enter(lockObject, ref lockWasTaken);
|
|
|
|
|
|
|
|
|
|
if(!itemDictionary.TryGetValue(itemId, out jsonClass))
|
2022-06-25 22:30:13 +01:00
|
|
|
|
{
|
2022-09-17 20:47:01 +01:00
|
|
|
|
jsonClass = GetData(item.Template._id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (WebException)
|
|
|
|
|
{
|
|
|
|
|
return $"[SeeItemValue] Issue happened whilst getting Item from server";
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (lockWasTaken)
|
|
|
|
|
{
|
|
|
|
|
Monitor.Exit(lockObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
if (jsonClass.price != 1)
|
|
|
|
|
{
|
|
|
|
|
alteredPrice = DurabilityCheck(item, jsonClass);
|
|
|
|
|
}
|
2022-09-17 20:47:01 +01:00
|
|
|
|
|
|
|
|
|
double _price = alteredPrice * jsonClass.multiplier;
|
|
|
|
|
|
|
|
|
|
return Math.Round(_price).ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string TraderName(this Item item)
|
|
|
|
|
{
|
|
|
|
|
string itemId = item.Template._id;
|
|
|
|
|
JsonClass jsonClass;
|
|
|
|
|
bool lockWasTaken = false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Monitor.Enter(lockObject, ref lockWasTaken);
|
|
|
|
|
|
|
|
|
|
if (!itemDictionary.TryGetValue(itemId, out jsonClass))
|
|
|
|
|
{
|
|
|
|
|
jsonClass = GetData(item.Template._id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (WebException)
|
|
|
|
|
{
|
|
|
|
|
return $"[SeeItemValue] Issue happened whilst getting Item from server";
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (lockWasTaken)
|
|
|
|
|
{
|
|
|
|
|
Monitor.Exit(lockObject);
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 20:47:01 +01:00
|
|
|
|
return jsonClass.traderName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double DurabilityCheck(this Item item, JsonClass jsonClass)
|
|
|
|
|
{
|
|
|
|
|
double editedPrice = jsonClass.price;
|
|
|
|
|
double originalMax = jsonClass.originalMax;
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" Entered DurabilityCheck() - starting price is: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
var medKit = item.GetItemComponent<MedKitComponent>();
|
|
|
|
|
if (medKit != null && medKit.HpResource != 0 && medKit.MaxHpResource != 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" Medkit Check - HpResource is: {medKit.HpResource}");
|
|
|
|
|
DebugMode($" Medkit Check - MaxHpResource is: {medKit.MaxHpResource}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= medKit.HpResource / medKit.MaxHpResource;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After Medkit Check - price is: {editedPrice}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var repair = item.GetItemComponent<RepairableComponent>();
|
|
|
|
|
if (repair != null)
|
|
|
|
|
{
|
|
|
|
|
if (repair.Durability > 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" repairable Check - Durability is: {repair.Durability}");
|
|
|
|
|
DebugMode($" Medkit Check - originalMax is: {originalMax}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= repair.Durability / originalMax;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
}
|
2022-07-09 12:15:57 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" repairable Check - Durability is 0");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After repairable Check - price is: {editedPrice}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var dogtag = item.GetItemComponent<DogtagComponent>();
|
|
|
|
|
if (dogtag != null && dogtag.Level != 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" dogtag Check - level is: {dogtag.Level}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= dogtag.Level;
|
2022-06-25 22:30:13 +01:00
|
|
|
|
}
|
2022-05-14 20:06:24 +01:00
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After dogtag Check - price is: {editedPrice}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var repairKit = item.GetItemComponent<RepairKitComponent>();
|
|
|
|
|
if (repairKit != null)
|
|
|
|
|
{
|
|
|
|
|
if (repairKit.Resource > 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" repairkit Check - Resource is: {repairKit.Resource}");
|
|
|
|
|
DebugMode($" repairkit Check - originalMax is: {originalMax}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= repairKit.Resource / originalMax;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" repairkit Check - Resource is 0");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After repairkit Check - price is: {editedPrice}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var resource = item.GetItemComponent<ResourceComponent>();
|
|
|
|
|
if (resource != null && resource.Value != 0 && resource.MaxResource != 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" resource Check - Resource is: {resource.Value}");
|
|
|
|
|
DebugMode($" resource Check - MaxResource is: {resource.MaxResource}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
|
|
|
|
editedPrice *= resource.Value / resource.MaxResource;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After resource Check - price is: {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-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" foodDrink Check - HpPercent is: {foodDrink.HpPercent}");
|
|
|
|
|
DebugMode($" foodDrink Check - MaxResource is: {ginterface208_0.MaxResource}");
|
|
|
|
|
|
2022-07-25 15:21:49 -04:00
|
|
|
|
editedPrice *= foodDrink.HpPercent / ginterface208_0.MaxResource;
|
2022-07-09 12:15:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After foodDrink Check - price is: {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
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" foodDrink Check - totalMinusUsed is: {totalMinusUsed}");
|
|
|
|
|
DebugMode($" foodDrink Check - multi is: {multi}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= multi;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After keys Check - price is: {editedPrice}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
var sideEffect = item.GetItemComponent<SideEffectComponent>();
|
|
|
|
|
if (sideEffect != null && sideEffect.Value != 0)
|
|
|
|
|
{
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" sideEffect Check - resource is: {sideEffect.Value}");
|
|
|
|
|
DebugMode($" sideEffect Check - MaxResource is: {sideEffect.MaxResource}");
|
|
|
|
|
|
2022-07-09 12:15:57 +01:00
|
|
|
|
editedPrice *= sideEffect.Value / sideEffect.MaxResource;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 00:13:32 +01:00
|
|
|
|
DebugMode($" After sideEffect Check - price is: {editedPrice}");
|
|
|
|
|
|
|
|
|
|
DebugMode($"Ending price: {editedPrice}");
|
2022-07-09 12:15:57 +01:00
|
|
|
|
|
2022-09-17 20:47:01 +01:00
|
|
|
|
return editedPrice;
|
2022-05-14 20:06:24 +01:00
|
|
|
|
}
|
2022-09-19 00:13:32 +01:00
|
|
|
|
|
|
|
|
|
public static void DebugMode(String str)
|
|
|
|
|
{
|
|
|
|
|
var directory = Directory.GetCurrentDirectory();
|
|
|
|
|
|
|
|
|
|
var modDirectory = new DirectoryInfo(directory + "/user/mods/");
|
|
|
|
|
DirectoryInfo[] dirsInDir = modDirectory.GetDirectories("*" + "SeeItemValue" + "*.*");
|
|
|
|
|
|
|
|
|
|
if (dirsInDir.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
var json = File.ReadAllText(dirsInDir[0].ToString() + "/src/config.json");
|
|
|
|
|
|
|
|
|
|
var configJson = Json.Deserialize<ConfigClass>(json);
|
|
|
|
|
|
|
|
|
|
if (configJson != null && configJson.DebugMode)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError(str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-14 20:06:24 +01:00
|
|
|
|
}
|
|
|
|
|
}
|