Make sell to flea on shift alt click
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -399,3 +399,4 @@ FodyWeavers.xsd
|
|||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
/libs
|
/libs
|
||||||
|
.idea
|
||||||
|
@@ -13,9 +13,11 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UIFixes.util;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using FleaRequirement = GClass1859;
|
||||||
|
|
||||||
namespace UIFixes;
|
namespace UIFixes;
|
||||||
|
|
||||||
@@ -174,6 +176,8 @@ public static class MultiSelectPatches
|
|||||||
|
|
||||||
public class ItemViewClickPatch : ModulePatch
|
public class ItemViewClickPatch : ModulePatch
|
||||||
{
|
{
|
||||||
|
private static ISession Session => ClientAppUtils.GetMainApp().GetClientBackEndSession();
|
||||||
|
|
||||||
protected override MethodBase GetTargetMethod()
|
protected override MethodBase GetTargetMethod()
|
||||||
{
|
{
|
||||||
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.OnClick));
|
return AccessTools.Method(typeof(GridItemView), nameof(GridItemView.OnClick));
|
||||||
@@ -191,6 +195,10 @@ public static class MultiSelectPatches
|
|||||||
bool shiftDown = Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift);
|
bool shiftDown = Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.RightShift);
|
||||||
bool altDown = Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt);
|
bool altDown = Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt);
|
||||||
|
|
||||||
|
if (shiftDown && altDown) {
|
||||||
|
SellAllToFlea();
|
||||||
|
}
|
||||||
|
|
||||||
if (ctrlDown && !shiftDown && !altDown)
|
if (ctrlDown && !shiftDown && !altDown)
|
||||||
{
|
{
|
||||||
QuickMove(__instance, ___ItemUiContext, ___ItemController);
|
QuickMove(__instance, ___ItemUiContext, ___ItemController);
|
||||||
@@ -274,6 +282,32 @@ public static class MultiSelectPatches
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SellAllToFlea() {
|
||||||
|
foreach (DragItemContext selectedItemContext in MultiSelect.SortedItemContexts()) {
|
||||||
|
try {
|
||||||
|
SellToFlea(selectedItemContext.Item);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
Console.WriteLine("Oopsie!");
|
||||||
|
Console.WriteLine(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SellToFlea(Item item) {
|
||||||
|
double? fleaPrice = FleaPriceCache.FetchPrice(item.TemplateId);
|
||||||
|
Console.WriteLine("Flea price for " + item.Name + ":" + fleaPrice);
|
||||||
|
|
||||||
|
if (fleaPrice.HasValue) {
|
||||||
|
var req = new FleaRequirement {
|
||||||
|
count = (int)(fleaPrice.Value * 1.4),
|
||||||
|
_tpl = "5449016a4bdc2d6f028b456f"
|
||||||
|
};
|
||||||
|
Console.WriteLine("Selling " + item.Name + " for " + req.count + " roubl");
|
||||||
|
Session.RagFair.AddOffer(false, [item.Id], [req], null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ContextActionsPatch : ModulePatch
|
public class ContextActionsPatch : ModulePatch
|
||||||
|
@@ -15,8 +15,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PathToSPT Condition="'$(Configuration)'=='Debug'">..\..\..\..\SPT\3.9.2-debug</PathToSPT>
|
<PathToSPT>C:\Games\Escape from Tarkov\Escape from Tarkov</PathToSPT>
|
||||||
<PathToSPT Condition="'$(Configuration)'=='Release'">..\..\..\..\SPT\3.9.2</PathToSPT>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -83,6 +82,18 @@
|
|||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="lib\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Remove="lib\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="lib\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command='if $(ConfigurationName) == Debug (
|
<Exec Command='if $(ConfigurationName) == Debug (
|
||||||
xcopy /F /Y "$(TargetPath)" "$(ProjectDir)$(PathToSPT)\BepInEx\plugins\"
|
xcopy /F /Y "$(TargetPath)" "$(ProjectDir)$(PathToSPT)\BepInEx\plugins\"
|
||||||
|
65
util/FleaCache.cs
Normal file
65
util/FleaCache.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SPT.Common.Http;
|
||||||
|
|
||||||
|
namespace UIFixes.util {
|
||||||
|
internal static class FleaPriceCache {
|
||||||
|
static Dictionary<string, CachePrice> cache = new Dictionary<string, CachePrice>();
|
||||||
|
|
||||||
|
public static double? FetchPrice(string templateId) {
|
||||||
|
if (cache.ContainsKey(templateId)) {
|
||||||
|
double secondsSinceLastUpdate = (DateTime.Now - cache[templateId].lastUpdate).TotalSeconds;
|
||||||
|
if (secondsSinceLastUpdate > 300)
|
||||||
|
return QueryAndTryUpsertPrice(templateId, true);
|
||||||
|
return cache[templateId].price;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QueryAndTryUpsertPrice(templateId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string QueryPrice(string templateId) {
|
||||||
|
return RequestHandler.PostJson("/LootValue/GetItemLowestFleaPrice",
|
||||||
|
JsonConvert.SerializeObject(new FleaPriceRequest(templateId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double? QueryAndTryUpsertPrice(string templateId, bool update) {
|
||||||
|
string response = QueryPrice(templateId);
|
||||||
|
|
||||||
|
bool hasPlayerFleaPrice = !(string.IsNullOrEmpty(response) || response == "null");
|
||||||
|
|
||||||
|
if (hasPlayerFleaPrice) {
|
||||||
|
double price = double.Parse(response);
|
||||||
|
|
||||||
|
if (update)
|
||||||
|
cache[templateId].Update(price);
|
||||||
|
else
|
||||||
|
cache[templateId] = new CachePrice(price);
|
||||||
|
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FleaPriceRequest {
|
||||||
|
public string templateId;
|
||||||
|
public FleaPriceRequest(string templateId) => this.templateId = templateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class CachePrice {
|
||||||
|
public double price { get; private set; }
|
||||||
|
public DateTime lastUpdate { get; private set; }
|
||||||
|
|
||||||
|
public CachePrice(double price) {
|
||||||
|
this.price = price;
|
||||||
|
lastUpdate = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(double price) {
|
||||||
|
this.price = price;
|
||||||
|
lastUpdate = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user