Compare commits

..

1 Commits

Author SHA1 Message Date
CWX
d2f4f000f8 Archive these 2023-10-20 20:29:04 +01:00
3 changed files with 155 additions and 196 deletions

View File

@ -15,7 +15,7 @@ namespace itemValueMod
[PatchPostfix] [PatchPostfix]
private static void PatchPostFix(ref Item __instance, string id, ItemTemplate template) private static void PatchPostFix(ref Item __instance, string id, ItemTemplate template)
{ {
ItemValue.AddItemValue(ref __instance, id, template); ItemValue.AddItemValue(ref __instance, template);
} }
} }
@ -29,7 +29,7 @@ namespace itemValueMod
[PatchPostfix] [PatchPostfix]
private static void PatchPostFix(ref BulletClass __instance, string id, AmmoTemplate template) private static void PatchPostFix(ref BulletClass __instance, string id, AmmoTemplate template)
{ {
ItemValue.AddItemValue(ref __instance, id, template); ItemValue.AddItemValue(ref __instance, template);
} }
} }
@ -43,7 +43,7 @@ namespace itemValueMod
[PatchPostfix] [PatchPostfix]
private static void PatchPostFix(ref GrenadeClass __instance, string id, ThrowableWeaponClass template) private static void PatchPostFix(ref GrenadeClass __instance, string id, ThrowableWeaponClass template)
{ {
ItemValue.AddItemValue(ref __instance, id, template); ItemValue.AddItemValue(ref __instance, template);
} }
} }
@ -57,7 +57,7 @@ namespace itemValueMod
[PatchPostfix] [PatchPostfix]
private static void PatchPostFix(ref ItemContainerClass __instance, string id, SecureContainerTemplateClass template) private static void PatchPostFix(ref ItemContainerClass __instance, string id, SecureContainerTemplateClass template)
{ {
ItemValue.AddItemValue(ref __instance, id, template); ItemValue.AddItemValue(ref __instance, template);
} }
} }
} }

View File

@ -4,261 +4,220 @@ using EFT.InventoryLogic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Net;
using System.Threading;
using UnityEngine; using UnityEngine;
using System.IO; using System.IO;
using System.Linq;
using Comfort.Common;
namespace itemValueMod namespace itemValueMod
{ {
public class ItemValue public class ItemValue
{ {
public static void AddItemValue<T>(ref T __instance, string id, ItemTemplate template) where T : Item public static void AddItemValue<T>(ref T __instance, ItemTemplate template) where T : Item
{ {
var atts = new List<ItemAttributeClass>();
atts.AddRange(__instance.Attributes);
__instance.Attributes = atts;
ItemAttributeClass attr1 = new ItemAttributeClass(EItemAttributeId.MoneySum) __instance.SetupShit();
{ //var atts = new List<ItemAttributeClass>();
StringValue = new Func<string>(__instance.TraderPrice), //atts.AddRange(__instance.Attributes);
FullStringValue = new Func<string>(__instance.TraderName), //__instance.Attributes = atts;
Name = "TRADER",
DisplayType = new Func<EItemAttributeDisplayType>(() => EItemAttributeDisplayType.Compact)
};
__instance.Attributes.Add(attr1); //var attr1 = new ItemAttributeClass(EItemAttributeId.MoneySum)
//{
// StringValue = __instance.TraderPrice(template),
// FullStringValue = __instance.TraderName,
// Name = "TRADER",
// DisplayType = () => EItemAttributeDisplayType.Compact
//};
//__instance.Attributes.Add(attr1);
} }
} }
public static class ValueExtension public static class ValueExtension
{ {
static public Dictionary<string, JsonClass> itemDictionary = new Dictionary<string, JsonClass>(); public static ItemFactory ItemFactoryInstance;
static object lockObject = new object();
public static JsonClass GetData(String itemId) public static void SetupShit(this Item item)
{ {
var json = RequestHandler.GetJson($"/cwx/seeitemvalue/{itemId}"); ItemFactoryInstance = Singleton<ItemFactory>.Instance;
var jsonClass = Json.Deserialize<JsonClass>(json); var itemTemplate = ItemFactoryInstance.ItemTemplates.Values.First(x => x._id == item.TemplateId).Name;
itemDictionary.Add(itemId, jsonClass);
return jsonClass;
Debug.LogError($"[itemTemplate] {itemTemplate}");
} }
public static string TraderPrice(this Item item) //public static Func<string> TraderPrice(this Item item, ItemTemplate template)
{ //{
string itemId = item.Template._id; // string itemId = item.Template._id;
JsonClass jsonClass; // JsonClass jsonClass;
bool lockWasTaken = false; // double alteredPrice = 1;
double alteredPrice = 1;
try // if (jsonClass.price != 1)
{ // {
Monitor.Enter(lockObject, ref lockWasTaken); // alteredPrice = DurabilityCheck(item, jsonClass);
// }
if(!itemDictionary.TryGetValue(itemId, out jsonClass)) // double _price = alteredPrice * jsonClass.multiplier;
{
jsonClass = GetData(item.Template._id); // return Math.Round(_price).ToString();
} //}
}
catch (WebException) //public static string TraderName(this Item item)
{ //{
return $"[SeeItemValue] Issue happened whilst getting Item from server"; // string itemId = item.Template._id;
} // JsonClass jsonClass;
finally
{ // return jsonClass.traderName;
if (lockWasTaken) //}
{
Monitor.Exit(lockObject); //public static double DurabilityCheck(this Item item, JsonClass jsonClass)
} //{
} // double editedPrice = jsonClass.price;
// double originalMax = jsonClass.originalMax;
if (jsonClass.price != 1)
{ // DebugMode($" Entered DurabilityCheck() - starting price is: {editedPrice}");
alteredPrice = DurabilityCheck(item, jsonClass);
} // var medKit = item.GetItemComponent<MedKitComponent>();
// if (medKit != null && medKit.HpResource != 0 && medKit.MaxHpResource != 0)
double _price = alteredPrice * jsonClass.multiplier; // {
// DebugMode($" Medkit Check - HpResource is: {medKit.HpResource}");
return Math.Round(_price).ToString(); // DebugMode($" Medkit Check - MaxHpResource is: {medKit.MaxHpResource}");
}
// editedPrice *= medKit.HpResource / medKit.MaxHpResource;
public static string TraderName(this Item item) // }
{
string itemId = item.Template._id; // DebugMode($" After Medkit Check - price is: {editedPrice}");
JsonClass jsonClass;
bool lockWasTaken = false; // var repair = item.GetItemComponent<RepairableComponent>();
// if (repair != null)
try // {
{ // if (repair.Durability > 0)
Monitor.Enter(lockObject, ref lockWasTaken); // {
// DebugMode($" repairable Check - Durability is: {repair.Durability}");
if (!itemDictionary.TryGetValue(itemId, out jsonClass)) // DebugMode($" Medkit Check - originalMax is: {originalMax}");
{
jsonClass = GetData(item.Template._id); // editedPrice *= repair.Durability / originalMax;
} // }
} // else
catch (WebException) // {
{ // DebugMode($" repairable Check - Durability is 0");
return $"[SeeItemValue] Issue happened whilst getting Item from server";
} // editedPrice = 1;
finally // }
{ // }
if (lockWasTaken)
{ // DebugMode($" After repairable Check - price is: {editedPrice}");
Monitor.Exit(lockObject);
} // var dogtag = item.GetItemComponent<DogtagComponent>();
} // if (dogtag != null && dogtag.Level != 0)
// {
return jsonClass.traderName; // DebugMode($" dogtag Check - level is: {dogtag.Level}");
}
// editedPrice *= dogtag.Level;
public static double DurabilityCheck(this Item item, JsonClass jsonClass) // }
{
double editedPrice = jsonClass.price; // DebugMode($" After dogtag Check - price is: {editedPrice}");
double originalMax = jsonClass.originalMax;
// var repairKit = item.GetItemComponent<RepairKitComponent>();
DebugMode($" Entered DurabilityCheck() - starting price is: {editedPrice}"); // if (repairKit != null)
// {
var medKit = item.GetItemComponent<MedKitComponent>(); // if (repairKit.Resource > 0)
if (medKit != null && medKit.HpResource != 0 && medKit.MaxHpResource != 0) // {
{ // DebugMode($" repairkit Check - Resource is: {repairKit.Resource}");
DebugMode($" Medkit Check - HpResource is: {medKit.HpResource}"); // DebugMode($" repairkit Check - originalMax is: {originalMax}");
DebugMode($" Medkit Check - MaxHpResource is: {medKit.MaxHpResource}");
// editedPrice *= repairKit.Resource / originalMax;
editedPrice *= medKit.HpResource / medKit.MaxHpResource; // }
} // else
// {
DebugMode($" After Medkit Check - price is: {editedPrice}"); // DebugMode($" repairkit Check - Resource is 0");
var repair = item.GetItemComponent<RepairableComponent>(); // editedPrice = 1;
if (repair != null) // }
{ // }
if (repair.Durability > 0)
{ // DebugMode($" After repairkit Check - price is: {editedPrice}");
DebugMode($" repairable Check - Durability is: {repair.Durability}");
DebugMode($" Medkit Check - originalMax is: {originalMax}"); // var resource = item.GetItemComponent<ResourceComponent>();
// if (resource != null && resource.Value != 0 && resource.MaxResource != 0)
editedPrice *= repair.Durability / originalMax; // {
} // DebugMode($" resource Check - Resource is: {resource.Value}");
else // DebugMode($" resource Check - MaxResource is: {resource.MaxResource}");
{
DebugMode($" repairable Check - Durability is 0"); // editedPrice *= resource.Value / resource.MaxResource;
// }
editedPrice = 1;
} // DebugMode($" After resource Check - price is: {editedPrice}");
}
// var foodDrink = item.GetItemComponent<FoodDrinkComponent>();
DebugMode($" After repairable Check - price is: {editedPrice}"); // if (foodDrink != null && foodDrink.HpPercent != 0)
// {
var dogtag = item.GetItemComponent<DogtagComponent>(); // GInterface234 ginterface234_0 = (GInterface234)foodDrink.GetType().GetField("ginterface234_0", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(foodDrink);
if (dogtag != null && dogtag.Level != 0)
{ // DebugMode($" foodDrink Check - HpPercent is: {foodDrink.HpPercent}");
DebugMode($" dogtag Check - level is: {dogtag.Level}"); // DebugMode($" foodDrink Check - MaxResource is: {ginterface234_0.MaxResource}");
editedPrice *= dogtag.Level; // editedPrice *= foodDrink.HpPercent / ginterface234_0.MaxResource;
} // }
DebugMode($" After dogtag Check - price is: {editedPrice}"); // DebugMode($" After foodDrink Check - price is: {editedPrice}");
var repairKit = item.GetItemComponent<RepairKitComponent>(); // var keys = item.GetItemComponent<KeyComponent>();
if (repairKit != null) // if (keys != null)
{ // {
if (repairKit.Resource > 0) // GInterface238 template = (GInterface238)keys.GetType().GetField("Template", BindingFlags.Public | BindingFlags.Instance).GetValue(keys);
{
DebugMode($" repairkit Check - Resource is: {repairKit.Resource}"); // if (keys.NumberOfUsages > 0)
DebugMode($" repairkit Check - originalMax is: {originalMax}"); // {
// double totalMinusUsed = Convert.ToDouble(template.MaximumNumberOfUsage - keys.NumberOfUsages);
editedPrice *= repairKit.Resource / originalMax; // double multi = totalMinusUsed / template.MaximumNumberOfUsage;
}
else // DebugMode($" foodDrink Check - totalMinusUsed is: {totalMinusUsed}");
{ // DebugMode($" foodDrink Check - multi is: {multi}");
DebugMode($" repairkit Check - Resource is 0");
// editedPrice *= multi;
editedPrice = 1; // }
} // }
}
// DebugMode($" After keys Check - price is: {editedPrice}");
DebugMode($" After repairkit Check - price is: {editedPrice}");
// var sideEffect = item.GetItemComponent<SideEffectComponent>();
var resource = item.GetItemComponent<ResourceComponent>(); // if (sideEffect != null && sideEffect.Value != 0)
if (resource != null && resource.Value != 0 && resource.MaxResource != 0) // {
{ // DebugMode($" sideEffect Check - resource is: {sideEffect.Value}");
DebugMode($" resource Check - Resource is: {resource.Value}"); // DebugMode($" sideEffect Check - MaxResource is: {sideEffect.MaxResource}");
DebugMode($" resource Check - MaxResource is: {resource.MaxResource}");
// editedPrice *= sideEffect.Value / sideEffect.MaxResource;
editedPrice *= resource.Value / resource.MaxResource; // }
}
// DebugMode($" After sideEffect Check - price is: {editedPrice}");
DebugMode($" After resource Check - price is: {editedPrice}");
// DebugMode($"Ending price: {editedPrice}");
var foodDrink = item.GetItemComponent<FoodDrinkComponent>();
if (foodDrink != null && foodDrink.HpPercent != 0) // return editedPrice;
{ //}
GInterface234 ginterface234_0 = (GInterface234)foodDrink.GetType().GetField("ginterface234_0", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(foodDrink);
//public static void DebugMode(String str)
DebugMode($" foodDrink Check - HpPercent is: {foodDrink.HpPercent}"); //{
DebugMode($" foodDrink Check - MaxResource is: {ginterface234_0.MaxResource}"); // var directory = Directory.GetCurrentDirectory();
editedPrice *= foodDrink.HpPercent / ginterface234_0.MaxResource; // var modDirectory = new DirectoryInfo(directory + "/user/mods/");
} // DirectoryInfo[] dirsInDir = modDirectory.GetDirectories("*" + "SeeItemValue" + "*.*");
DebugMode($" After foodDrink Check - price is: {editedPrice}"); // if (dirsInDir.Length == 1)
// {
var keys = item.GetItemComponent<KeyComponent>(); // var json = File.ReadAllText(dirsInDir[0].ToString() + "/src/config.json");
if (keys != null)
{ // var configJson = Json.Deserialize<ConfigClass>(json);
GInterface238 template = (GInterface238)keys.GetType().GetField("Template", BindingFlags.Public | BindingFlags.Instance).GetValue(keys);
// if (configJson != null && configJson.DebugMode)
if (keys.NumberOfUsages > 0) // {
{ // Debug.LogError(str);
double totalMinusUsed = Convert.ToDouble(template.MaximumNumberOfUsage - keys.NumberOfUsages); // }
double multi = totalMinusUsed / template.MaximumNumberOfUsage; // }
//}
DebugMode($" foodDrink Check - totalMinusUsed is: {totalMinusUsed}");
DebugMode($" foodDrink Check - multi is: {multi}");
editedPrice *= multi;
}
}
DebugMode($" After keys Check - price is: {editedPrice}");
var sideEffect = item.GetItemComponent<SideEffectComponent>();
if (sideEffect != null && sideEffect.Value != 0)
{
DebugMode($" sideEffect Check - resource is: {sideEffect.Value}");
DebugMode($" sideEffect Check - MaxResource is: {sideEffect.MaxResource}");
editedPrice *= sideEffect.Value / sideEffect.MaxResource;
}
DebugMode($" After sideEffect Check - price is: {editedPrice}");
DebugMode($"Ending price: {editedPrice}");
return editedPrice;
}
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);
}
}
}
} }
} }