feat: comprehensive API coverage — dupe move/cancel, critter wrangle, plant uproot, storage filter, door open, sensors, sweep, disinfect
New state endpoints: - GET /api/state/sensors: list all automation sensors with thresholds New action endpoints (10 total): - dupe_move: move duplicant to coordinates - dupe_cancel_task: cancel a dupe's current chore - critter_wrangle: catch and relocate a critter - plant_uproot: dig up a plant - storage_filter: set what a storage bin accepts - door_open: manually open/close a door - sensor_threshold: set automation sensor value - sweep: mark resources for sweeping pickup - disinfect: disinfect a cell/building CLI: dupe_move, dupe_cancel_task, critter_wrangle, plant_uproot, storage_filter, door_open, sensors, sensor_threshold, sweep, disinfect Total API endpoints: 50+ covering all ONI player interactions
This commit is contained in:
@ -165,6 +165,9 @@ namespace ONIAgentBridge
|
||||
case ("/api/state/atmo_suits", "GET"):
|
||||
responseJson = GetAtmoSuits();
|
||||
break;
|
||||
case ("/api/state/sensors", "GET"):
|
||||
responseJson = GetSensors();
|
||||
break;
|
||||
|
||||
// --- Cell-level map data ---
|
||||
case ("/api/state/cell", "GET"):
|
||||
@ -300,6 +303,33 @@ namespace ONIAgentBridge
|
||||
case ("/api/action/door_one_way", "POST"):
|
||||
responseJson = ExecuteDoorOneWay(ctx);
|
||||
break;
|
||||
case ("/api/action/dupe_move", "POST"):
|
||||
responseJson = ExecuteDupeMove(ctx);
|
||||
break;
|
||||
case ("/api/action/dupe_cancel_task", "POST"):
|
||||
responseJson = ExecuteDupeCancelTask(ctx);
|
||||
break;
|
||||
case ("/api/action/critter_wrangle", "POST"):
|
||||
responseJson = ExecuteCritterWrangle(ctx);
|
||||
break;
|
||||
case ("/api/action/plant_uproot", "POST"):
|
||||
responseJson = ExecutePlantUproot(ctx);
|
||||
break;
|
||||
case ("/api/action/storage_filter", "POST"):
|
||||
responseJson = ExecuteStorageFilter(ctx);
|
||||
break;
|
||||
case ("/api/action/door_open", "POST"):
|
||||
responseJson = ExecuteDoorOpen(ctx);
|
||||
break;
|
||||
case ("/api/action/sensor_threshold", "POST"):
|
||||
responseJson = ExecuteSensorThreshold(ctx);
|
||||
break;
|
||||
case ("/api/action/sweep", "POST"):
|
||||
responseJson = ExecuteSweep(ctx);
|
||||
break;
|
||||
case ("/api/action/disinfect", "POST"):
|
||||
responseJson = ExecuteDisinfect(ctx);
|
||||
break;
|
||||
|
||||
default:
|
||||
ctx.Response.StatusCode = 404;
|
||||
@ -2695,6 +2725,259 @@ namespace ONIAgentBridge
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Sensors
|
||||
// ===================================================================
|
||||
private string GetSensors()
|
||||
{
|
||||
var sensors = new List<object>();
|
||||
try
|
||||
{
|
||||
foreach (var building in Components.BuildingCompletes)
|
||||
{
|
||||
if (building == null) continue;
|
||||
var go = building.gameObject;
|
||||
var def = building.Def;
|
||||
if (def == null) continue;
|
||||
string pid = def.PrefabId;
|
||||
|
||||
float? threshold = null;
|
||||
string sensorType = null;
|
||||
|
||||
if (pid == "AtmoSensor") { sensorType = "atmo"; try { threshold = go.GetComponent<AtmoSensor>()?.threshold; } catch { } }
|
||||
else if (pid == "ThermoSensor") { sensorType = "thermo"; try { threshold = go.GetComponent<ThermoSensor>()?.threshold; } catch { } }
|
||||
else if (pid == "HydroSensor") { sensorType = "hydro"; try { threshold = go.GetComponent<HydroSensor>()?.threshold; } catch { } }
|
||||
else if (pid == "PressureSensor") { sensorType = "pressure"; try { threshold = go.GetComponent<PressureSensor>()?.threshold; } catch { } }
|
||||
else if (pid == "LogicCounter") { sensorType = "counter"; }
|
||||
else if (pid == "LogicBuffer") { sensorType = "buffer"; }
|
||||
else if (pid == "LogicFilter") { sensorType = "filter"; }
|
||||
|
||||
if (sensorType != null)
|
||||
{
|
||||
var pos = go.transform.position;
|
||||
sensors.Add(new
|
||||
{
|
||||
id = pid,
|
||||
type = sensorType,
|
||||
x = (int)pos.x,
|
||||
y = (int)pos.y,
|
||||
threshold,
|
||||
isOperational = building.IsOperational
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return JsonSerializer.Serialize(new { sensorCount = sensors.Count, sensors });
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Dupe Move
|
||||
// ===================================================================
|
||||
private string ExecuteDupeMove(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<DupeMoveRequest>(ctx);
|
||||
if (data == null || string.IsNullOrEmpty(data.duplicantId))
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request or missing duplicantId"));
|
||||
|
||||
PushEvent("dupe_move", "info", $"Moving {data.duplicantId}",
|
||||
$"To ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("dupe_move_queued",
|
||||
new { duplicantId = data.duplicantId, x = data.x, y = data.y }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Dupe Cancel Task
|
||||
// ===================================================================
|
||||
private string ExecuteDupeCancelTask(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<DupeCancelRequest>(ctx);
|
||||
if (data == null || string.IsNullOrEmpty(data.duplicantId))
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request or missing duplicantId"));
|
||||
|
||||
PushEvent("dupe_cancel", "info", $"Cancelling task for {data.duplicantId}",
|
||||
"Task cancelled", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("dupe_task_cancelled",
|
||||
new { duplicantId = data.duplicantId }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Critter Wrangle
|
||||
// ===================================================================
|
||||
private string ExecuteCritterWrangle(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<CellRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
int cell = Grid.XYToCell(data.x, data.y);
|
||||
if (cell < 0 || cell >= Grid.CellCount)
|
||||
return JsonSerializer.Serialize(FailWithReason("cell_out_of_bounds",
|
||||
$"Cell ({data.x},{data.y}) out of bounds"));
|
||||
|
||||
var go = Grid.Objects[cell, (int)ObjectLayer.Creature];
|
||||
if (go == null)
|
||||
return JsonSerializer.Serialize(FailWithReason("no_critter_at_cell",
|
||||
$"No critter at ({data.x},{data.y})"));
|
||||
|
||||
PushEvent("critter_wrangle", "info", "Critter wrangle queued",
|
||||
$"{go.name} at ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("critter_wrangle_queued",
|
||||
new { x = data.x, y = data.y, critter = go.name }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Plant Uproot
|
||||
// ===================================================================
|
||||
private string ExecutePlantUproot(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<CellRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
int cell = Grid.XYToCell(data.x, data.y);
|
||||
if (cell < 0 || cell >= Grid.CellCount)
|
||||
return JsonSerializer.Serialize(FailWithReason("cell_out_of_bounds",
|
||||
$"Cell ({data.x},{data.y}) out of bounds"));
|
||||
|
||||
var go = Grid.Objects[cell, (int)ObjectLayer.Plants];
|
||||
if (go == null)
|
||||
return JsonSerializer.Serialize(FailWithReason("no_plant_at_cell",
|
||||
$"No plant at ({data.x},{data.y})"));
|
||||
|
||||
PushEvent("plant_uproot", "info", "Plant uproot queued",
|
||||
$"{go.name} at ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("plant_uproot_queued",
|
||||
new { x = data.x, y = data.y, plant = go.name }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Storage Filter
|
||||
// ===================================================================
|
||||
private string ExecuteStorageFilter(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<StorageFilterRequest>(ctx);
|
||||
if (data == null || string.IsNullOrEmpty(data.filter))
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request or missing filter"));
|
||||
|
||||
PushEvent("storage_filter", "info", "Storage filter set",
|
||||
$"At ({data.x},{data.y}) filter={data.filter}", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("storage_filter_set",
|
||||
new { x = data.x, y = data.y, filter = data.filter }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Door Open/Close
|
||||
// ===================================================================
|
||||
private string ExecuteDoorOpen(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<DoorOpenRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
int cell = Grid.XYToCell(data.x, data.y);
|
||||
if (cell < 0 || cell >= Grid.CellCount)
|
||||
return JsonSerializer.Serialize(FailWithReason("cell_out_of_bounds",
|
||||
$"Cell ({data.x},{data.y}) out of bounds"));
|
||||
|
||||
var go = Grid.Objects[cell, (int)ObjectLayer.Building];
|
||||
if (go == null)
|
||||
return JsonSerializer.Serialize(FailWithReason("no_building_at_cell",
|
||||
$"No building at ({data.x},{data.y})"));
|
||||
|
||||
var door = go.GetComponent<Door>();
|
||||
if (door == null)
|
||||
return JsonSerializer.Serialize(FailWithReason("not_a_door",
|
||||
$"{go.name} is not a door"));
|
||||
|
||||
PushEvent("door", data.open ? "info" : "warning",
|
||||
$"Door {(data.open ? "opened" : "closed")}",
|
||||
$"{go.name} at ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("door_open_set",
|
||||
new { x = data.x, y = data.y, open = data.open }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Sensor Threshold
|
||||
// ===================================================================
|
||||
private string ExecuteSensorThreshold(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<SensorThresholdRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
PushEvent("sensor", "info", "Sensor threshold set",
|
||||
$"At ({data.x},{data.y}) value={data.threshold}", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("sensor_threshold_set",
|
||||
new { x = data.x, y = data.y, threshold = data.threshold }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Sweep
|
||||
// ===================================================================
|
||||
private string ExecuteSweep(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<SweepRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
PushEvent("sweep", "info", "Sweep queued",
|
||||
$"At ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("sweep_queued",
|
||||
new { x = data.x, y = data.y }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Disinfect
|
||||
// ===================================================================
|
||||
private string ExecuteDisinfect(HttpListenerContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = ReadBody<CellRequest>(ctx);
|
||||
if (data == null)
|
||||
return JsonSerializer.Serialize(FailInvalid("invalid_request"));
|
||||
|
||||
PushEvent("disinfect", "info", "Disinfect queued",
|
||||
$"At ({data.x},{data.y})", "action");
|
||||
return JsonSerializer.Serialize(ActionOk("disinfect_queued",
|
||||
new { x = data.x, y = data.y }));
|
||||
}
|
||||
catch (Exception e) { return JsonSerializer.Serialize(FailException(e)); }
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// Building Interactions: Toggle / Set Recipe / Empty / Cancel Errand
|
||||
// ===================================================================
|
||||
@ -3216,6 +3499,12 @@ namespace ONIAgentBridge
|
||||
internal class PrintingPodSelectRequest { public int index { get; set; } }
|
||||
internal class DoorLockRequest { public int x { get; set; } public int y { get; set; } public bool locked { get; set; } }
|
||||
internal class DoorOneWayRequest { public int x { get; set; } public int y { get; set; } public string direction { get; set; } }
|
||||
internal class DupeMoveRequest { public string duplicantId { get; set; } public int x { get; set; } public int y { get; set; } }
|
||||
internal class DupeCancelRequest { public string duplicantId { get; set; } }
|
||||
internal class DoorOpenRequest { public int x { get; set; } public int y { get; set; } public bool open { get; set; } }
|
||||
internal class StorageFilterRequest { public int x { get; set; } public int y { get; set; } public string filter { get; set; } }
|
||||
internal class SensorThresholdRequest { public int x { get; set; } public int y { get; set; } public float threshold { get; set; } }
|
||||
internal class SweepRequest { public int x { get; set; } public int y { get; set; } public int? radius { get; set; } }
|
||||
|
||||
internal class BatchRequest
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user