From 6e6ec381c3f2e95d873b86531a3cd96e50a39cc2 Mon Sep 17 00:00:00 2001 From: Erag0n001 <148992045+Erag0n001@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:15:40 -0400 Subject: [PATCH 1/4] Improved marketplace - Books are now fully compatible with marketplaces - Cleaner UI - Cleaner submenu --- .../Client/Dialogs/RT_Dialog_MarketListing.cs | 102 ++++++++++++++++-- Source/Client/Managers/DeepScribeManager.cs | 5 +- Source/Server/Managers/MarketManager.cs | 18 ++-- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs index fde9cbda..441baca3 100644 --- a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs +++ b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.Linq; +using System.Reflection; using RimWorld; using Shared; using UnityEngine; @@ -13,7 +15,7 @@ public class RT_Dialog_MarketListing : Window { //UI - public override Vector2 InitialSize => new Vector2(400f, 400f); + public override Vector2 InitialSize => new Vector2(600f, 400f); private Vector2 scrollPosition = Vector2.zero; @@ -35,7 +37,7 @@ public class RT_Dialog_MarketListing : Window //Variables - private readonly ThingDataFile[] elements; + private readonly Thing[] elements; private readonly Map settlementMap; @@ -45,8 +47,13 @@ public RT_Dialog_MarketListing(ThingDataFile[] elements, Map settlementMap, Acti title = "Global Market"; description = $"Silver available for trade: {RimworldManager.GetSpecificThingCountInMap(ThingDefOf.Silver, settlementMap)}"; - - this.elements = elements; + List things = new List(); + foreach (var element in elements) + { + Thing thing = ThingScribeManager.StringToItem(element); + things.Add(thing); + } + this.elements = things.ToArray(); this.actionClick = actionClick; this.actionCancel = actionCancel; this.settlementMap = settlementMap; @@ -124,8 +131,7 @@ private void FillMainRect(Rect mainRect) try { - Thing thing = ThingScribeManager.StringToItem(elements[i]); - if (thing.MarketValue > 0) DrawCustomRow(rect, thing, num4); + if (elements[i].MarketValue > 0) DrawCustomRow(rect, elements[i], num4); else continue; } catch { continue; } @@ -143,8 +149,12 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) Text.Font = GameFont.Small; Rect fixedRect = new Rect(new Vector2(rect.x, rect.y + 5f), new Vector2(rect.width - 16f, rect.height - 5f)); if (index % 2 == 0) Widgets.DrawHighlight(fixedRect); - - Widgets.Label(fixedRect, $"{toDisplay.Label.CapitalizeFirst()} > ${toDisplay.MarketValue}/u"); + + string[] names = GetDisplayNames(toDisplay); + string displayName = names[0]; + string displaySimple = names[1]; + Logger.Warning(displayName); + Widgets.Label(fixedRect, $"{displayName.CapitalizeFirst()}"); if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - selectButtonX, rect.yMax - selectButtonY), new Vector2(selectButtonX, selectButtonY)), "Select")) { DialogManager.dialogMarketListingResult = index; @@ -172,8 +182,82 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) else DialogManager.PushNewDialog(new RT_Dialog_Error("You do not have enough silver!")); } }; - DialogManager.PushNewDialog(new RT_Dialog_1Input("Quantity to request", "Type the quantity you want to request", toDo, null)); + DialogManager.PushNewDialog(new RT_Dialog_1Input($"{displaySimple} to request", $"Type the quantity you want to request\nCost per unit:{toDisplay.MarketValue} | Amount available:{toDisplay.stackCount}", toDo, null)); + } + } + + private string[] GetDisplayNames(Thing thing) + { + string text = thing.LabelCapNoCount.CapitalizeFirst() + " "; + string textSimple = thing.LabelCapNoCount.CapitalizeFirst(); + Type type; + FieldInfo fieldInfo; + ReadingOutcomeDoerGainResearch research; + QualityCategory qc; + switch (thing.def.defName) + { + case "TextBook": + Book book = (Book)thing; + text = book.def.defName + " "; + book.BookComp.TryGetDoer(out BookOutcomeDoerGainSkillExp xp); + if (xp != null) + { + foreach (KeyValuePair pair in xp.Values) text += $"{pair.Key.defName}, "; + } + thing.TryGetQuality(out qc); + text += QualityUtility.GetLabelShort(qc); + + textSimple = thing.def.defName + " "; + break; + case "Schematic": + book = (Book)thing; + text = book.def.defName + " "; + book.BookComp.TryGetDoer(out research); + if (research != null) + { + type = research.GetType(); + fieldInfo = type.GetField("values", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary researchDict = (Dictionary)fieldInfo.GetValue(research); + foreach (ResearchProjectDef key in researchDict.Keys) text += $"{key.defName}, "; + } + thing.TryGetQuality(out qc); + text += QualityUtility.GetLabelShort(qc); + + textSimple = thing.def.defName + " "; + break; + case "Novel": + book = (Book)thing; + text = book.def.defName + " "; + type = book.GetType(); + fieldInfo = type.GetField("joyFactor", BindingFlags.NonPublic | BindingFlags.Instance); + text += (float)fieldInfo.GetValue(book) * 100 + "% recreation, "; + thing.TryGetQuality(out qc); + text += QualityUtility.GetLabelShort(qc); + + textSimple = thing.def.defName + " "; + break; + case "Tome": + book = (Book)thing; + text = book.def.defName + " "; + book.BookComp.TryGetDoer(out research); + if (research != null) + { + type = research.GetType(); + fieldInfo = type.GetField("values", BindingFlags.NonPublic | BindingFlags.Instance); + Dictionary researchDict = (Dictionary)fieldInfo.GetValue(research); + foreach (ResearchProjectDef key in researchDict.Keys) text += $"{key.defName}, "; + + type = book.GetType(); + fieldInfo = type.GetField("mentalBreakChancePerHour", BindingFlags.NonPublic | BindingFlags.Instance); + text += "mental break:"+ ((float)fieldInfo.GetValue(book) * 100).ToStringDecimalIfSmall() +"% "; + thing.TryGetQuality(out qc); + text += QualityUtility.GetLabel(qc); + + textSimple = thing.def.defName + " "; + } + break; } + return new string[] {text,textSimple}; } } } diff --git a/Source/Client/Managers/DeepScribeManager.cs b/Source/Client/Managers/DeepScribeManager.cs index 3e75135d..5934e65d 100644 --- a/Source/Client/Managers/DeepScribeManager.cs +++ b/Source/Client/Managers/DeepScribeManager.cs @@ -983,7 +983,7 @@ public static Thing[] GetItemsFromString(TransferData transferData) public static ThingDataFile ItemToString(Thing thing, int thingCount) { ThingDataFile thingData = new ThingDataFile(); - + Logger.Message(thing.def.defName); Thing toUse = null; if (GetItemMinified(thing, thingData)) toUse = thing.GetInnerIfMinified(); else toUse = thing; @@ -1143,6 +1143,7 @@ private static void GetBookDetails(Thing thing, ThingDataFile thingData) } thingData.BookData = bookData; + Logger.Warning(bookData.title); } catch (Exception e) { Logger.Warning(e.ToString()); } } @@ -1754,8 +1755,6 @@ public static bool CheckIfThingIsMinified(Thing thing) public static bool CheckIfThingIsBook(Thing thing) { - if (!ModsConfig.AnomalyActive) return false; - if (thing.def.defName == ThingDefOf.TextBook.defName) return true; else if (thing.def.defName == ThingDefOf.Schematic.defName) return true; else if (thing.def.defName == ThingDefOf.Tome.defName) return true; diff --git a/Source/Server/Managers/MarketManager.cs b/Source/Server/Managers/MarketManager.cs index d169aba4..54656f13 100644 --- a/Source/Server/Managers/MarketManager.cs +++ b/Source/Server/Managers/MarketManager.cs @@ -55,7 +55,7 @@ private static void AddToMarket(ServerClient client, MarketData marketData) NetworkHelper.SendPacketToAllClients(packet, client); } - private static void RemoveFromMarket(ServerClient client, MarketData marketData) + private static void RemoveFromMarket(ServerClient client, MarketData marketData) { if (marketData._quantityToManage == 0) { @@ -82,7 +82,7 @@ private static void RemoveFromMarket(ServerClient client, MarketData marketData) client.listener.EnqueuePacket(packet); marketData._stepMode = MarketStepMode.Reload; marketData._transferThings = Master.marketValues.MarketStock; - + packet = Packet.CreatePacketFromObject(nameof(PacketHandler.MarketPacket), marketData); NetworkHelper.SendPacketToAllClients(packet, client); @@ -99,21 +99,23 @@ private static void SendMarketStock(ServerClient client, MarketData marketData) private static void TryCombineStackIfAvailable(ServerClient client, ThingDataFile thingData) { + Logger.Warning(thingData.BookData.title); if (thingData.Quantity <= 0) { ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); return; } - - foreach (ThingDataFile stockedItem in Master.marketValues.MarketStock.ToArray()) + if (thingData.BookData.title == "null") { - if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + foreach (ThingDataFile stockedItem in Master.marketValues.MarketStock.ToArray()) { - stockedItem.Quantity += thingData.Quantity; - return; + if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + { + stockedItem.Quantity += thingData.Quantity; + return; + } } } - Master.marketValues.MarketStock.Add(thingData); } } From 5f3957af9d4f1420b1055726ba1ac19f5c4a1602 Mon Sep 17 00:00:00 2001 From: Erag0n001 <148992045+Erag0n001@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:16:23 -0400 Subject: [PATCH 2/4] Fixed issues and added support for genepacks - Game will no longer shit itself when a mod is missing. - Added support for Genepack. --- .../Client/Dialogs/RT_Dialog_MarketListing.cs | 33 ++++++++++++++----- Source/Client/Managers/DeepScribeManager.cs | 13 +++++--- Source/Server/Managers/MarketManager.cs | 2 +- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs index 441baca3..70a20570 100644 --- a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs +++ b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs @@ -50,9 +50,17 @@ public RT_Dialog_MarketListing(ThingDataFile[] elements, Map settlementMap, Acti List things = new List(); foreach (var element in elements) { - Thing thing = ThingScribeManager.StringToItem(element); - things.Add(thing); + Logger.Warning(element.DefName); + Thing thing = null; + try { thing = ThingScribeManager.StringToItem(element); } catch{ continue; } + if (thing != null) + { + Logger.Warning(thing.def.defName); + things.Add(thing); + } + Logger.Error("-------------"); } + Logger.Error(things.Count().ToString()); this.elements = things.ToArray(); this.actionClick = actionClick; this.actionCancel = actionCancel; @@ -134,7 +142,7 @@ private void FillMainRect(Rect mainRect) if (elements[i].MarketValue > 0) DrawCustomRow(rect, elements[i], num4); else continue; } - catch { continue; } + catch { Logger.Message(elements[i].def.defName); continue; } } num += 30f; @@ -153,7 +161,6 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) string[] names = GetDisplayNames(toDisplay); string displayName = names[0]; string displaySimple = names[1]; - Logger.Warning(displayName); Widgets.Label(fixedRect, $"{displayName.CapitalizeFirst()}"); if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - selectButtonX, rect.yMax - selectButtonY), new Vector2(selectButtonX, selectButtonY)), "Select")) { @@ -182,7 +189,7 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) else DialogManager.PushNewDialog(new RT_Dialog_Error("You do not have enough silver!")); } }; - DialogManager.PushNewDialog(new RT_Dialog_1Input($"{displaySimple} to request", $"Type the quantity you want to request\nCost per unit:{toDisplay.MarketValue} | Amount available:{toDisplay.stackCount}", toDo, null)); + DialogManager.PushNewDialog(new RT_Dialog_1Input($"{displaySimple} request", $"Type the quantity you want to request\nCost per unit:{toDisplay.MarketValue} | Amount available:{toDisplay.stackCount}", toDo, null)); } } @@ -198,7 +205,7 @@ private string[] GetDisplayNames(Thing thing) { case "TextBook": Book book = (Book)thing; - text = book.def.defName + " "; + text = book.def.defName + ": "; book.BookComp.TryGetDoer(out BookOutcomeDoerGainSkillExp xp); if (xp != null) { @@ -211,7 +218,7 @@ private string[] GetDisplayNames(Thing thing) break; case "Schematic": book = (Book)thing; - text = book.def.defName + " "; + text = book.def.defName + ": "; book.BookComp.TryGetDoer(out research); if (research != null) { @@ -227,7 +234,7 @@ private string[] GetDisplayNames(Thing thing) break; case "Novel": book = (Book)thing; - text = book.def.defName + " "; + text = book.def.defName + ": "; type = book.GetType(); fieldInfo = type.GetField("joyFactor", BindingFlags.NonPublic | BindingFlags.Instance); text += (float)fieldInfo.GetValue(book) * 100 + "% recreation, "; @@ -238,7 +245,7 @@ private string[] GetDisplayNames(Thing thing) break; case "Tome": book = (Book)thing; - text = book.def.defName + " "; + text = book.def.defName + ": "; book.BookComp.TryGetDoer(out research); if (research != null) { @@ -256,6 +263,14 @@ private string[] GetDisplayNames(Thing thing) textSimple = thing.def.defName + " "; } break; + case "Genepack": + Genepack pack = (Genepack)thing; + text = pack.def.defName + ": "; + foreach (GeneDef gene in pack.GeneSet.GenesListForReading) + { + text += $"{gene.label}, "; + } + break; } return new string[] {text,textSimple}; } diff --git a/Source/Client/Managers/DeepScribeManager.cs b/Source/Client/Managers/DeepScribeManager.cs index 5934e65d..bfb8947d 100644 --- a/Source/Client/Managers/DeepScribeManager.cs +++ b/Source/Client/Managers/DeepScribeManager.cs @@ -1009,6 +1009,7 @@ public static ThingDataFile ItemToString(Thing thing, int thingCount) public static Thing StringToItem(ThingDataFile thingData) { + Thing thing = SetItem(thingData); SetItemQuantity(thing, thingData); @@ -1024,7 +1025,9 @@ public static Thing StringToItem(ThingDataFile thingData) SetItemMinified(thing, thingData); if (DeepScribeHelper.CheckIfThingIsGenepack(thing)) SetGenepackDetails(thing, thingData); - else if (DeepScribeHelper.CheckIfThingIsBook(thing)) SetBookDetails(thing, thingData); + + if (DeepScribeHelper.CheckIfThingIsBook(thing)) SetBookDetails(thing, thingData); + return thing; } @@ -1755,11 +1758,13 @@ public static bool CheckIfThingIsMinified(Thing thing) public static bool CheckIfThingIsBook(Thing thing) { + if (thing.def.defName == ThingDefOf.TextBook.defName) return true; else if (thing.def.defName == ThingDefOf.Schematic.defName) return true; - else if (thing.def.defName == ThingDefOf.Tome.defName) return true; else if (thing.def.defName == ThingDefOf.Novel.defName) return true; - else return false; + if (!ModsConfig.AnomalyActive) return false; + if (thing.def.defName == ThingDefOf.Tome.defName) return true; + return false; } public static bool CheckIfThingIsGenepack(Thing thing) @@ -1767,7 +1772,7 @@ public static bool CheckIfThingIsGenepack(Thing thing) if (!ModsConfig.BiotechActive) return false; if (thing.def.defName == ThingDefOf.Genepack.defName) return true; - else return false; + return false; } } } diff --git a/Source/Server/Managers/MarketManager.cs b/Source/Server/Managers/MarketManager.cs index 54656f13..324eb5f1 100644 --- a/Source/Server/Managers/MarketManager.cs +++ b/Source/Server/Managers/MarketManager.cs @@ -105,7 +105,7 @@ private static void TryCombineStackIfAvailable(ServerClient client, ThingDataFil ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); return; } - if (thingData.BookData.title == "null") + if (thingData.BookData.title == "null" && thingData.GenepackData.genepackDefs.Count == 0) { foreach (ThingDataFile stockedItem in Master.marketValues.MarketStock.ToArray()) { From 541bdc541d0b82b09f7cef19bd9c1c8cb9dc40ad Mon Sep 17 00:00:00 2001 From: Erag0n001 <148992045+Erag0n001@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:18:33 -0400 Subject: [PATCH 3/4] Removed debugging loggers --- Source/Client/Dialogs/RT_Dialog_MarketListing.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs index 70a20570..973537a7 100644 --- a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs +++ b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs @@ -50,17 +50,13 @@ public RT_Dialog_MarketListing(ThingDataFile[] elements, Map settlementMap, Acti List things = new List(); foreach (var element in elements) { - Logger.Warning(element.DefName); Thing thing = null; try { thing = ThingScribeManager.StringToItem(element); } catch{ continue; } if (thing != null) { - Logger.Warning(thing.def.defName); things.Add(thing); } - Logger.Error("-------------"); } - Logger.Error(things.Count().ToString()); this.elements = things.ToArray(); this.actionClick = actionClick; this.actionCancel = actionCancel; @@ -142,7 +138,7 @@ private void FillMainRect(Rect mainRect) if (elements[i].MarketValue > 0) DrawCustomRow(rect, elements[i], num4); else continue; } - catch { Logger.Message(elements[i].def.defName); continue; } + catch {; continue; } } num += 30f; From f1e3911e329c58f01aebb87df312d2e146e993ab Mon Sep 17 00:00:00 2001 From: Byte-Nova <159603018+Byte-Nova@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:05:54 +0200 Subject: [PATCH 4/4] Removed leftover logs, improved code readability --- Source/Client/Dialogs/RT_Dialog_1Input.cs | 12 +++--- .../Client/Dialogs/RT_Dialog_MarketListing.cs | 31 +++++++++------ Source/Client/Managers/DeepScribeManager.cs | 2 +- Source/Server/Managers/MarketManager.cs | 38 +++++++++++++------ 4 files changed, 53 insertions(+), 30 deletions(-) diff --git a/Source/Client/Dialogs/RT_Dialog_1Input.cs b/Source/Client/Dialogs/RT_Dialog_1Input.cs index 5afb62e3..a18b1bea 100644 --- a/Source/Client/Dialogs/RT_Dialog_1Input.cs +++ b/Source/Client/Dialogs/RT_Dialog_1Input.cs @@ -2,6 +2,7 @@ using RimWorld; using UnityEngine; using Verse; +using static GameClient.DialogManagerHelper; namespace GameClient { @@ -54,7 +55,7 @@ public override void DoWindowContents(Rect rect) float horizontalLineDif = Text.CalcSize(title).y + StandardMargin / 2; float inputOneLabelDif = Text.CalcSize(inputOneLabel).y + StandardMargin; - float inputOneDif = inputOneLabelDif + 30f; + float inputOneDif = inputOneLabelDif + 28f; Text.Font = GameFont.Medium; Widgets.Label(new Rect(centeredX - Text.CalcSize(title).x / 2, rect.y, Text.CalcSize(title).x, Text.CalcSize(title).y), title); @@ -62,17 +63,16 @@ public override void DoWindowContents(Rect rect) DrawInputOne(centeredX, inputOneLabelDif, inputOneDif); - if (Widgets.ButtonText(new Rect(new Vector2(rect.xMin, rect.yMax - buttonY), new Vector2(buttonX, buttonY)), "Confirm")) + if (Widgets.ButtonText(GetRectForLocation(rect, defaultButtonSize, RectLocation.BottomLeft), "Confirm")) { DialogManager.dialog1ResultOne = inputOneResult; - - if (actionYes != null) actionYes.Invoke(); + actionYes?.Invoke(); Close(); } - if (Widgets.ButtonText(new Rect(new Vector2(rect.xMax - buttonX, rect.yMax - buttonY), new Vector2(buttonX, buttonY)), "Cancel")) + if (Widgets.ButtonText(GetRectForLocation(rect, defaultButtonSize, RectLocation.BottomRight), "Cancel")) { - if (actionNo != null) actionNo.Invoke(); + actionNo?.Invoke(); Close(); } } diff --git a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs index 973537a7..4b8edc35 100644 --- a/Source/Client/Dialogs/RT_Dialog_MarketListing.cs +++ b/Source/Client/Dialogs/RT_Dialog_MarketListing.cs @@ -185,18 +185,25 @@ private void DrawCustomRow(Rect rect, Thing toDisplay, int index) else DialogManager.PushNewDialog(new RT_Dialog_Error("You do not have enough silver!")); } }; - DialogManager.PushNewDialog(new RT_Dialog_1Input($"{displaySimple} request", $"Type the quantity you want to request\nCost per unit:{toDisplay.MarketValue} | Amount available:{toDisplay.stackCount}", toDo, null)); + + string title = $"{displaySimple} request"; + string description = $"Max ammount to request: {toDisplay.stackCount} | Price per unit: {toDisplay.MarketValue}"; + DialogManager.PushNewDialog(new RT_Dialog_1Input(title, description, toDo, null)); } } private string[] GetDisplayNames(Thing thing) { - string text = thing.LabelCapNoCount.CapitalizeFirst() + " "; + string text = thing.LabelCapNoCount.CapitalizeFirst() + $" x{thing.stackCount} "; string textSimple = thing.LabelCapNoCount.CapitalizeFirst(); + Type type; FieldInfo fieldInfo; ReadingOutcomeDoerGainResearch research; QualityCategory qc; + + //Exceptions of things that must be handled differently + switch (thing.def.defName) { case "TextBook": @@ -208,10 +215,11 @@ private string[] GetDisplayNames(Thing thing) foreach (KeyValuePair pair in xp.Values) text += $"{pair.Key.defName}, "; } thing.TryGetQuality(out qc); - text += QualityUtility.GetLabelShort(qc); + text += QualityUtility.GetLabelShort(qc); textSimple = thing.def.defName + " "; break; + case "Schematic": book = (Book)thing; text = book.def.defName + ": "; @@ -224,10 +232,11 @@ private string[] GetDisplayNames(Thing thing) foreach (ResearchProjectDef key in researchDict.Keys) text += $"{key.defName}, "; } thing.TryGetQuality(out qc); - text += QualityUtility.GetLabelShort(qc); + text += QualityUtility.GetLabelShort(qc); textSimple = thing.def.defName + " "; break; + case "Novel": book = (Book)thing; text = book.def.defName + ": "; @@ -235,10 +244,11 @@ private string[] GetDisplayNames(Thing thing) fieldInfo = type.GetField("joyFactor", BindingFlags.NonPublic | BindingFlags.Instance); text += (float)fieldInfo.GetValue(book) * 100 + "% recreation, "; thing.TryGetQuality(out qc); - text += QualityUtility.GetLabelShort(qc); + text += QualityUtility.GetLabelShort(qc); textSimple = thing.def.defName + " "; break; + case "Tome": book = (Book)thing; text = book.def.defName + ": "; @@ -254,21 +264,20 @@ private string[] GetDisplayNames(Thing thing) fieldInfo = type.GetField("mentalBreakChancePerHour", BindingFlags.NonPublic | BindingFlags.Instance); text += "mental break:"+ ((float)fieldInfo.GetValue(book) * 100).ToStringDecimalIfSmall() +"% "; thing.TryGetQuality(out qc); - text += QualityUtility.GetLabel(qc); + text += QualityUtility.GetLabel(qc); textSimple = thing.def.defName + " "; } break; + case "Genepack": Genepack pack = (Genepack)thing; text = pack.def.defName + ": "; - foreach (GeneDef gene in pack.GeneSet.GenesListForReading) - { - text += $"{gene.label}, "; - } + foreach (GeneDef gene in pack.GeneSet.GenesListForReading) text += $"{gene.label}, "; break; } - return new string[] {text,textSimple}; + + return new string[] {text, textSimple}; } } } diff --git a/Source/Client/Managers/DeepScribeManager.cs b/Source/Client/Managers/DeepScribeManager.cs index f6c9c21a..a41c4cd8 100644 --- a/Source/Client/Managers/DeepScribeManager.cs +++ b/Source/Client/Managers/DeepScribeManager.cs @@ -983,8 +983,8 @@ public static Thing[] GetItemsFromString(TransferData transferData) public static ThingDataFile ItemToString(Thing thing, int thingCount) { ThingDataFile thingData = new ThingDataFile(); - Logger.Message(thing.def.defName); Thing toUse = null; + if (GetItemMinified(thing, thingData)) toUse = thing.GetInnerIfMinified(); else toUse = thing; diff --git a/Source/Server/Managers/MarketManager.cs b/Source/Server/Managers/MarketManager.cs index 29ae7179..64886d0b 100644 --- a/Source/Server/Managers/MarketManager.cs +++ b/Source/Server/Managers/MarketManager.cs @@ -99,24 +99,38 @@ private static void SendMarketStock(ServerClient client, MarketData marketData) private static void TryCombineStackIfAvailable(ServerClient client, ThingDataFile thingData) { - Logger.Warning(thingData.BookData.title); - if (thingData.Quantity <= 0) - { - ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); - return; - } - if (thingData.BookData.title == "null" && thingData.GenepackData.genepackDefs.Count == 0) + if (thingData.Quantity <= 0) ResponseShortcutManager.SendIllegalPacket(client, "Tried to sell illegal quantity at market"); + else { - foreach (ThingDataFile stockedItem in Master.marketValues.MarketStock.ToArray()) + //Check if thing is book to handle differently + if (thingData.BookData.title != "null") Master.marketValues.MarketStock.Add(thingData); + + //Check if thing is genepack to handle differently + else if (thingData.GenepackData.genepackDefs.Count != 0) Master.marketValues.MarketStock.Add(thingData); + + //Act as if normal thing + else { - if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + foreach (ThingDataFile stockedItem in MarketManagerHelper.GetMarketStockSafe()) { - stockedItem.Quantity += thingData.Quantity; - return; + if (stockedItem.DefName == thingData.DefName && stockedItem.MaterialDefName == thingData.MaterialDefName) + { + stockedItem.Quantity += thingData.Quantity; + return; + } } + + Master.marketValues.MarketStock.Add(thingData); } } - Master.marketValues.MarketStock.Add(thingData); + } + } + + public static class MarketManagerHelper + { + public static ThingDataFile[] GetMarketStockSafe() + { + return Master.marketValues.MarketStock.ToArray(); } } }