diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index 0cf71024..40ca427a 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_SpawnResources.cs b/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_SpawnResources.cs index a443b16d..74d37fc3 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_SpawnResources.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/Tools/Tool_SpawnResources.cs @@ -53,17 +53,33 @@ namespace WulaFallenEmpire.EventSystem.AI.Tools if (!countMatch.Success) continue; if (!int.TryParse(countMatch.Groups[1].Value, out int count)) continue; - // Search for ThingDef using fuzzy search + // Search for ThingDef ThingDef def = null; - var searchResult = ThingDefSearcher.ParseAndSearch(name); - if (searchResult.Count > 0) + + // 1. Try exact defName match + def = DefDatabase.GetNamed(name, false); + + // 2. Try exact label match (case-insensitive) + if (def == null) { - def = searchResult[0].Def; + foreach (var d in DefDatabase.AllDefs) + { + if (d.label != null && d.label.Equals(name, StringComparison.OrdinalIgnoreCase)) + { + def = d; + break; + } + } } - else + + // 3. Try fuzzy search + if (def == null) { - // Fallback: try exact defName match just in case - def = DefDatabase.GetNamed(name, false); + var searchResult = ThingDefSearcher.ParseAndSearch(name); + if (searchResult.Count > 0) + { + def = searchResult[0].Def; + } } if (def != null && count > 0) @@ -103,7 +119,7 @@ namespace WulaFallenEmpire.EventSystem.AI.Tools Faction faction = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Wula_PIA_Legion_Faction")); if (faction != null) { - Messages.Message("Wula_ResourceDrop".Translate(faction.Name.Named("FACTION_name")), new LookTargets(dropSpot, map), MessageTypeDefOf.PositiveEvent); + Messages.Message("Wula_ResourceDrop".Translate(faction.def.defName.Named("FACTION_name")), new LookTargets(dropSpot, map), MessageTypeDefOf.PositiveEvent); } resultLog.Length -= 2; // Remove trailing comma diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs index 4636a694..d2c4b017 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs @@ -27,7 +27,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI public static Dialog_AIConversation Instance { get; private set; } // Debug field to track current portrait ID - private int _currentPortraitId = 2; + private int _currentPortraitId = 0; // Default Persona (used if XML doesn't provide one) private const string DefaultPersona = @" @@ -242,7 +242,18 @@ When the player requests any form of resources, you MUST follow this multi-turn Log.Warning($"[WulaAI] Failed to load portrait: {path}"); } } - if (_portraits.ContainsKey(2)) + + // Use portraitPath from def as the initial portrait + if (this.portrait != null) + { + // Find the ID of the initial portrait + var initial = _portraits.FirstOrDefault(kvp => kvp.Value == this.portrait); + if (initial.Key != 0) + { + _currentPortraitId = initial.Key; + } + } + else if (_portraits.ContainsKey(2)) // Fallback to 2 if def has no portrait { this.portrait = _portraits[2]; _currentPortraitId = 2; @@ -337,7 +348,7 @@ When the player requests any form of resources, you MUST follow this multi-turn // REWRITTEN: Check for XML tool call format // Use regex to detect if the response contains any XML tags - if (Regex.IsMatch(response, @"<[a-zA-Z0-9_]+(?:>.*?|/>)", RegexOptions.Singleline)) + if (Regex.IsMatch(response, @"<([a-zA-Z0-9_]+)(?:>.*?|/>)", RegexOptions.Singleline)) { await HandleXmlToolUsage(response); } @@ -427,7 +438,7 @@ When the player requests any form of resources, you MUST follow this multi-turn _history.Add(("tool", combinedResults.ToString().Trim())); // Check if there is any text content in the response - string textContent = Regex.Replace(xml, @"<[a-zA-Z0-9_]+(?:>.*?|/>)", "", RegexOptions.Singleline).Trim(); + string textContent = Regex.Replace(xml, @"<([a-zA-Z0-9_]+)(?:>.*?|/>)", "", RegexOptions.Singleline).Trim(); if (!string.IsNullOrEmpty(textContent)) { @@ -599,7 +610,7 @@ When the player requests any form of resources, you MUST follow this multi-turn text = Regex.Replace(text, @"<([a-zA-Z0-9_]+)[^>]*>.*?", "", RegexOptions.Singleline); // Remove self-closing tags: - text = Regex.Replace(text, @"<[a-zA-Z0-9_]+[^>]*/>", ""); + text = Regex.Replace(text, @"<([a-zA-Z0-9_]+)[^>]*/>", ""); text = text.Trim();