From 7366da899b48266041d54dcff8835117772be01e Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 3 Feb 2025 15:02:03 +0000 Subject: [PATCH 1/4] Renamed `IsSameItem` --- Libraries/Core/Helpers/ItemHelper.cs | 6 +++--- Libraries/Core/Services/FenceService.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Libraries/Core/Helpers/ItemHelper.cs b/Libraries/Core/Helpers/ItemHelper.cs index 48242ccf..0b068f48 100644 --- a/Libraries/Core/Helpers/ItemHelper.cs +++ b/Libraries/Core/Helpers/ItemHelper.cs @@ -98,7 +98,7 @@ public class ItemHelper( * @param compareUpdProperties Upd properties to compare between the items * @returns true if they are the same, false if they aren't */ - public bool isSameItems(List item1, List item2, HashSet compareUpdProperties = null) + public bool IsSameItems(List item1, List item2, HashSet compareUpdProperties = null) { if (item1.Count() != item2.Count) { @@ -113,7 +113,7 @@ public class ItemHelper( return false; } - if (!this.isSameItem(itemOf1, itemOf2, compareUpdProperties)) + if (!this.IsSameItem(itemOf1, itemOf2, compareUpdProperties)) { return false; } @@ -130,7 +130,7 @@ public class ItemHelper( * @param compareUpdProperties Upd properties to compare between the items * @returns true if they are the same, false if they aren't */ - public bool isSameItem(Item item1, Item item2, HashSet compareUpdProperties = null) + public bool IsSameItem(Item item1, Item item2, HashSet compareUpdProperties = null) { if (item1.Template != item2.Template) { diff --git a/Libraries/Core/Services/FenceService.cs b/Libraries/Core/Services/FenceService.cs index 42093548..35efb603 100644 --- a/Libraries/Core/Services/FenceService.cs +++ b/Libraries/Core/Services/FenceService.cs @@ -405,7 +405,7 @@ public class FenceService( existingFenceAssorts.Items, existingRootItem.Id ); - if (itemHelper.isSameItems(itemWithChildren, existingFullItemTree, fenceItemUpdCompareProperties)) + if (itemHelper.IsSameItems(itemWithChildren, existingFullItemTree, fenceItemUpdCompareProperties)) { // Guard against a missing stack count if (existingRootItem.Upd?.StackObjectsCount == null) From ab414ad264dbd8c886fdf94f15f888f8cf99e565 Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 3 Feb 2025 15:02:22 +0000 Subject: [PATCH 2/4] Re-implemented `IsSameItem` --- Libraries/Core/Helpers/ItemHelper.cs | 131 ++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 15 deletions(-) diff --git a/Libraries/Core/Helpers/ItemHelper.cs b/Libraries/Core/Helpers/ItemHelper.cs index 0b068f48..987cc7e8 100644 --- a/Libraries/Core/Helpers/ItemHelper.cs +++ b/Libraries/Core/Helpers/ItemHelper.cs @@ -113,7 +113,7 @@ public class ItemHelper( return false; } - if (!this.IsSameItem(itemOf1, itemOf2, compareUpdProperties)) + if (!IsSameItem(itemOf1, itemOf2, compareUpdProperties)) { return false; } @@ -130,29 +130,130 @@ public class ItemHelper( * @param compareUpdProperties Upd properties to compare between the items * @returns true if they are the same, false if they aren't */ - public bool IsSameItem(Item item1, Item item2, HashSet compareUpdProperties = null) + public bool IsSameItem(Item item1, Item item2, HashSet? compareUpdProperties = null) { + // Different tpl == different item if (item1.Template != item2.Template) { return false; } - var props = typeof(Upd).GetProperties(); - if (compareUpdProperties is not null) + // Both lack upd object + same tpl = same + if (item1.Upd is null && item2.Upd is null) { - return compareUpdProperties.ToArray() - .All( - (p) => - { - var item1p = props.FirstOrDefault(prop => prop.Name.ToLower() == p.ToLower()).GetValue(item1.Upd); - var item2p = props.FirstOrDefault(prop => prop.Name.ToLower() == p.ToLower()).GetValue(item2.Upd); - ; - return _compareUtil.RecursiveCompare(item1p, item2p); - } - ); // TODO: please refactor this is you know how + return true; } - return _compareUtil.RecursiveCompare(item1.Upd, item2.Upd); + // item1 lacks upd, item2 has one + if (item1.Upd is null && item2.Upd is not null) + { + return false; + } + + // item1 has upd, item2 lacks one + if (item1.Upd is not null && item2.Upd is null) + { + return false; + } + + // Key + if (compareUpdProperties is null || compareUpdProperties.Contains("Key")) + { + if (item1.Upd?.Key?.NumberOfUsages != item2.Upd?.Key?.NumberOfUsages) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("Buff")) + { + // Buffed armor/weapon + if (item1.Upd?.Buff.Value != item2.Upd?.Buff.Value + && item1.Upd?.Buff.BuffType != item2.Upd?.Buff.BuffType) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("CultistAmulet")) + { + // Amulet + if (item1.Upd?.CultistAmulet?.NumberOfUsages != item2.Upd?.CultistAmulet?.NumberOfUsages) + { + return false; + } + } + + + if (compareUpdProperties is null || compareUpdProperties.Contains("Dogtag")) + { + if (item1.Upd.Dogtag.ProfileId != item2.Upd.Dogtag.ProfileId) + { + return false; + } + } + + + + // Faceshield + if (compareUpdProperties is null || compareUpdProperties.Contains("FaceShield")) + { + if (item1.Upd?.FaceShield?.Hits != item2.Upd?.FaceShield?.Hits) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("Foldable")) + { + if (item1.Upd?.Foldable?.Folded.GetValueOrDefault(false) != + item2.Upd?.Foldable?.Folded.GetValueOrDefault(false)) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("FoodDrink")) + { + if (item1.Upd?.FoodDrink?.HpPercent != item2.Upd?.FoodDrink?.HpPercent) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("MedKit")) + { + if (item1.Upd.MedKit.HpResource != item2.Upd.MedKit.HpResource) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("RecodableComponent")) + { + if (item1.Upd?.RecodableComponent?.IsEncoded != item2.Upd?.RecodableComponent?.IsEncoded) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("RepairKit")) + { + if (item1.Upd?.RepairKit?.Resource != item2.Upd?.RepairKit?.Resource) + { + return false; + } + } + + if (compareUpdProperties is null || compareUpdProperties.Contains("Resource")) + { + if (item1.Upd?.Resource?.UnitsConsumed != item2.Upd?.Resource?.UnitsConsumed) + { + return false; + } + } + + return true; } /** From a4bb2e8f25a67c2098da3e51738e1e674d4b6d34 Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 3 Feb 2025 15:05:51 +0000 Subject: [PATCH 3/4] fix prestigeRequestTypes and getting items transfered --- Libraries/Core/Callbacks/PrestigeCallbacks.cs | 2 +- Libraries/Core/Controllers/PrestigeController.cs | 4 ++-- .../Core/Models/Eft/Prestige/ObtainPrestigeRequest.cs | 11 ++++++++++- Libraries/Core/Routers/Static/PrestigeStaticRouter.cs | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Libraries/Core/Callbacks/PrestigeCallbacks.cs b/Libraries/Core/Callbacks/PrestigeCallbacks.cs index 51310fa8..b6000b6b 100644 --- a/Libraries/Core/Callbacks/PrestigeCallbacks.cs +++ b/Libraries/Core/Callbacks/PrestigeCallbacks.cs @@ -31,7 +31,7 @@ public class PrestigeCallbacks( /// /// /// - public string ObtainPrestige(string url, List info, string sessionID) + public string ObtainPrestige(string url, ObtainPrestigeRequestList info, string sessionID) { _prestigeController.ObtainPrestige(sessionID, info); diff --git a/Libraries/Core/Controllers/PrestigeController.cs b/Libraries/Core/Controllers/PrestigeController.cs index b58d6c55..3854ef8a 100644 --- a/Libraries/Core/Controllers/PrestigeController.cs +++ b/Libraries/Core/Controllers/PrestigeController.cs @@ -52,7 +52,7 @@ public class PrestigeController( /// public void ObtainPrestige( string sessionId, - List request) + ObtainPrestigeRequestList request) { var prePrestigeProfileClone = _cloner.Clone(_profileHelper.GetFullProfile(sessionId)); var prePrestigePmc = prePrestigeProfileClone.CharacterData.PmcData; @@ -123,7 +123,7 @@ public class PrestigeController( // Flag profile as having achieved this prestige level newProfile.CharacterData.PmcData.Prestige[currentPrestigeData.Id] = _timeUtil.GetTimeStamp(); - newProfile.CharacterData.PmcData.Info.PrestigeLevel++; + newProfile.CharacterData.PmcData.Info.PrestigeLevel = indexOfPrestigeObtained; if (request is not null) { diff --git a/Libraries/Core/Models/Eft/Prestige/ObtainPrestigeRequest.cs b/Libraries/Core/Models/Eft/Prestige/ObtainPrestigeRequest.cs index 44ae3ab1..1af2ab6a 100644 --- a/Libraries/Core/Models/Eft/Prestige/ObtainPrestigeRequest.cs +++ b/Libraries/Core/Models/Eft/Prestige/ObtainPrestigeRequest.cs @@ -1,8 +1,14 @@ using System.Text.Json.Serialization; +using Core.Models.Utils; namespace Core.Models.Eft.Prestige { - public record ObtainPrestigeRequest + public class ObtainPrestigeRequestList : List, IRequestData + { + + } + + public record ObtainPrestigeRequest : IRequestData { [JsonPropertyName("id")] public string Id { get; set; } @@ -21,5 +27,8 @@ namespace Core.Models.Eft.Prestige [JsonPropertyName("z")] public int Z { get; set; } + + [JsonPropertyName("r")] + public string R { get; set; } } } diff --git a/Libraries/Core/Routers/Static/PrestigeStaticRouter.cs b/Libraries/Core/Routers/Static/PrestigeStaticRouter.cs index 3e13f09c..aebdba68 100644 --- a/Libraries/Core/Routers/Static/PrestigeStaticRouter.cs +++ b/Libraries/Core/Routers/Static/PrestigeStaticRouter.cs @@ -33,7 +33,8 @@ public class PrestigeStaticRouter : StaticRouter info, sessionID, output - ) => _presetCallbacks.ObtainPrestige(url, info as List, sessionID)) + ) => _presetCallbacks.ObtainPrestige(url, info as ObtainPrestigeRequestList, sessionID) + , typeof(ObtainPrestigeRequestList)) ] ) { From d2e04ff877e833fa9b0f26798569450f933d04fc Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 3 Feb 2025 15:29:34 +0000 Subject: [PATCH 4/4] Improved `IsSameItem` --- .../Core/Generators/RagfairOfferGenerator.cs | 2 +- Libraries/Core/Helpers/ItemHelper.cs | 111 ++++-------------- .../Core/Models/Eft/Common/Tables/Item.cs | 3 +- 3 files changed, 26 insertions(+), 90 deletions(-) diff --git a/Libraries/Core/Generators/RagfairOfferGenerator.cs b/Libraries/Core/Generators/RagfairOfferGenerator.cs index 3dc27ec7..985472d7 100644 --- a/Libraries/Core/Generators/RagfairOfferGenerator.cs +++ b/Libraries/Core/Generators/RagfairOfferGenerator.cs @@ -703,7 +703,7 @@ public class RagfairOfferGenerator( if (rootItem.Upd?.Key != null && itemDetails.Properties.MaximumNumberOfUsage > 1) { // Randomize key uses - rootItem.Upd.Key.NumberOfUsages = Math.Round((double) itemDetails.Properties.MaximumNumberOfUsage * (1 - maxMultiplier)); + rootItem.Upd.Key.NumberOfUsages = (int?)Math.Round(itemDetails.Properties.MaximumNumberOfUsage.Value * (1 - maxMultiplier)); return; } diff --git a/Libraries/Core/Helpers/ItemHelper.cs b/Libraries/Core/Helpers/ItemHelper.cs index 987cc7e8..72b74de3 100644 --- a/Libraries/Core/Helpers/ItemHelper.cs +++ b/Libraries/Core/Helpers/ItemHelper.cs @@ -156,98 +156,33 @@ public class ItemHelper( return false; } - // Key - if (compareUpdProperties is null || compareUpdProperties.Contains("Key")) + // key = Upd property Type as string, value = comparison function that returns bool + var comparers = new Dictionary> { - if (item1.Upd?.Key?.NumberOfUsages != item2.Upd?.Key?.NumberOfUsages) + { "Key", (upd1, upd2) => upd1.Key?.NumberOfUsages == upd2.Key?.NumberOfUsages }, + { "Buff", (upd1, upd2) => upd1.Buff?.Value == upd2.Buff?.Value && upd1.Buff?.BuffType == upd2.Buff?.BuffType }, + { "CultistAmulet", (upd1, upd2) => upd1.CultistAmulet?.NumberOfUsages == upd2.CultistAmulet?.NumberOfUsages }, + { "Dogtag", (upd1, upd2) => upd1.Dogtag?.ProfileId == upd2.Dogtag?.ProfileId }, + { "FaceShield", (upd1, upd2) => upd1.FaceShield?.Hits == upd2.FaceShield?.Hits }, + { "Foldable", (upd1, upd2) => upd1.Foldable?.Folded.GetValueOrDefault(false) == upd2.Foldable?.Folded.GetValueOrDefault(false) }, + { "FoodDrink", (upd1, upd2) => upd1.FoodDrink?.HpPercent == upd2.FoodDrink?.HpPercent }, + { "MedKit", (upd1, upd2) => upd1.MedKit?.HpResource == upd2.MedKit?.HpResource }, + { "RecodableComponent", (upd1, upd2) => upd1.RecodableComponent?.IsEncoded == upd2.RecodableComponent?.IsEncoded }, + { "RepairKit", (upd1, upd2) => upd1.RepairKit?.Resource == upd2.RepairKit?.Resource }, + { "Resource", (upd1, upd2) => upd1.Resource?.UnitsConsumed == upd2.Resource?.UnitsConsumed } + }; + + // Choose above keys or passed in keys to compare items with + var valuesToCompare = compareUpdProperties?.Count > 0 ? compareUpdProperties : comparers.Keys.ToHashSet(); + foreach (var propertyName in valuesToCompare) + { + if (!comparers.TryGetValue(propertyName, out var comparer)) { - return false; + // Key not found, skip + continue; } - } - if (compareUpdProperties is null || compareUpdProperties.Contains("Buff")) - { - // Buffed armor/weapon - if (item1.Upd?.Buff.Value != item2.Upd?.Buff.Value - && item1.Upd?.Buff.BuffType != item2.Upd?.Buff.BuffType) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("CultistAmulet")) - { - // Amulet - if (item1.Upd?.CultistAmulet?.NumberOfUsages != item2.Upd?.CultistAmulet?.NumberOfUsages) - { - return false; - } - } - - - if (compareUpdProperties is null || compareUpdProperties.Contains("Dogtag")) - { - if (item1.Upd.Dogtag.ProfileId != item2.Upd.Dogtag.ProfileId) - { - return false; - } - } - - - - // Faceshield - if (compareUpdProperties is null || compareUpdProperties.Contains("FaceShield")) - { - if (item1.Upd?.FaceShield?.Hits != item2.Upd?.FaceShield?.Hits) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("Foldable")) - { - if (item1.Upd?.Foldable?.Folded.GetValueOrDefault(false) != - item2.Upd?.Foldable?.Folded.GetValueOrDefault(false)) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("FoodDrink")) - { - if (item1.Upd?.FoodDrink?.HpPercent != item2.Upd?.FoodDrink?.HpPercent) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("MedKit")) - { - if (item1.Upd.MedKit.HpResource != item2.Upd.MedKit.HpResource) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("RecodableComponent")) - { - if (item1.Upd?.RecodableComponent?.IsEncoded != item2.Upd?.RecodableComponent?.IsEncoded) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("RepairKit")) - { - if (item1.Upd?.RepairKit?.Resource != item2.Upd?.RepairKit?.Resource) - { - return false; - } - } - - if (compareUpdProperties is null || compareUpdProperties.Contains("Resource")) - { - if (item1.Upd?.Resource?.UnitsConsumed != item2.Upd?.Resource?.UnitsConsumed) + if (!comparer(item1.Upd, item2.Upd)) { return false; } diff --git a/Libraries/Core/Models/Eft/Common/Tables/Item.cs b/Libraries/Core/Models/Eft/Common/Tables/Item.cs index fc6e344a..c3225246 100644 --- a/Libraries/Core/Models/Eft/Common/Tables/Item.cs +++ b/Libraries/Core/Models/Eft/Common/Tables/Item.cs @@ -244,8 +244,9 @@ public record UpdFoodDrink public record UpdKey { + // Checked in client [JsonPropertyName("NumberOfUsages")] - public double? NumberOfUsages { get; set; } + public int? NumberOfUsages { get; set; } } public record UpdResource