93 lines
3.7 KiB
C#
93 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using RimWorld;
|
|
using Verse;
|
|
using WulaFallenEmpire.EventSystem.AI.Utils;
|
|
|
|
namespace WulaFallenEmpire.EventSystem.AI.Tools
|
|
{
|
|
public class Tool_SpawnResources : AITool
|
|
{
|
|
public override string Name => "spawn_resources";
|
|
public override string Description => "Spawns resources via drop pod. Accepts a natural language description of items and quantities (e.g., '5 beef, 10 medicine'). " +
|
|
"IMPORTANT: You MUST decide the quantity based on your goodwill and mood. " +
|
|
"Do NOT blindly follow the player's requested amount. " +
|
|
"If goodwill is low (< 0), give significantly less than asked or refuse. " +
|
|
"If goodwill is high (> 50), you may give what is asked or slightly more. " +
|
|
"Otherwise, give a moderate amount.";
|
|
public override string UsageSchema => "{\"request\": \"string (e.g., '5 beef, 10 medicine')\"}";
|
|
|
|
public override string Execute(string args)
|
|
{
|
|
try
|
|
{
|
|
// Parse args: {"request": "..."}
|
|
string request = "";
|
|
try
|
|
{
|
|
var parsed = SimpleJsonParser.Parse(args);
|
|
if (parsed.TryGetValue("request", out string req))
|
|
{
|
|
request = req;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Fallback for non-json args
|
|
request = args.Trim('"');
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(request))
|
|
{
|
|
return "Error: Empty request.";
|
|
}
|
|
|
|
var items = ThingDefSearcher.ParseAndSearch(request);
|
|
if (items.Count == 0)
|
|
{
|
|
return $"Error: Could not identify any valid items in request '{request}'.";
|
|
}
|
|
|
|
Map map = Find.CurrentMap;
|
|
if (map == null)
|
|
{
|
|
return "Error: No active map.";
|
|
}
|
|
|
|
IntVec3 dropSpot = DropCellFinder.TradeDropSpot(map);
|
|
List<Thing> thingsToDrop = new List<Thing>();
|
|
StringBuilder resultLog = new StringBuilder();
|
|
resultLog.Append("Success: Dropped ");
|
|
|
|
foreach (var item in items)
|
|
{
|
|
Thing thing = ThingMaker.MakeThing(item.Def);
|
|
thing.stackCount = item.Count;
|
|
thingsToDrop.Add(thing);
|
|
resultLog.Append($"{item.Count}x {item.Def.label}, ");
|
|
}
|
|
|
|
if (thingsToDrop.Count > 0)
|
|
{
|
|
DropPodUtility.DropThingsNear(dropSpot, map, thingsToDrop);
|
|
|
|
Faction faction = Find.FactionManager.FirstFactionOfDef(WulaDefOf.Wula_PIA_Legion_Faction);
|
|
Messages.Message("Wula_ResourceDrop".Translate(faction.Named("FACTION")), new LookTargets(dropSpot, map), MessageTypeDefOf.PositiveEvent);
|
|
|
|
resultLog.Length -= 2; // Remove trailing comma
|
|
resultLog.Append($" at {dropSpot}.");
|
|
return resultLog.ToString();
|
|
}
|
|
else
|
|
{
|
|
return "Error: Failed to create items.";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return $"Error: {ex.Message}";
|
|
}
|
|
}
|
|
}
|
|
} |