Node passes
NodePassed tells your mod each time a drone reaches an air node.
Drones drone events
Add a handler to NodePassed. Every handler gets the same args object, so read it and change nothing.
public static class Drones
{
public static event Action<DroneNodePassedArgs> NodePassed;
}
| Event | Gives you | When it fires |
|---|---|---|
NodePassed | DroneNodePassedArgs | A drone reached an air node. |
DroneNodePassedArgs what you get when a drone passes a node
NodePassed gives you one of these for each node a drone reaches. IsRouteEnd marks the last node of a route, and DroneId can be null, so check it before you use it.
public sealed class DroneNodePassedArgs
{
public string NodeId { get; }
public string DroneId { get; }
public bool IsRouteEnd { get; }
}
| Property | Type | What it means |
|---|---|---|
NodeId | string | The id of the node that was reached. |
DroneId | string | The id of the drone that reached it. null when the framework cannot tell. |
IsRouteEnd | bool | true when the node has no next node, so this is the end of the route. |
Things to know
NodePassedfires once for each node a drone reaches. Every handler receives the sameDroneNodePassedArgsobject. It fires just before the game runs that node’s own outputs and moves the drone on. (It is raised at the start ofAir_Node.Pass, from a Harmony prefix (a change that runs before the game method), insideDrone.Update. At that moment the drone’stargetNodeis still the node it just reached.)- To stop the drone from your
NodePassedhandler, callSetActive(id, false). That does work, and the drone stops on its next update. DroneIdis the drone that reached the node. The game’s pass call does not say which drone it was, so the framework notes which drone is updating and reads that note. (Air_Node.Passtakes no drone. A prefix onDrone.Updatestores the running drone in a static field, andDrone.Updateis the only caller ofPassin the game code.)IsRouteEndistrueat the last node of a route. If the drone is set to switch off at the end of its path,Changedfires too, a moment later. (It is true whenAir_Node.NextNodeis null. The game then turns the drone off whenDrone.deActivateOnPathEndis set.)
Limits
- A new target set from inside a
NodePassedhandler is overwritten straight away. The game then picks the drone’s next target itself, or switches the drone off at the end of its route. (The game movestargetNodeto the next node, or turns the drone off at the route end, after the handlers run. Because of that,Drones.Getread inside the handler still shows the node that was just passed as the target.) DroneIdis null when the pass did not come from a drone’s own update, or when that drone is not heading for this node. The game never does this by itself, but a scene output or aSendMessagecall can trigger a pass by name. (DroneIdis null whenPassruns outside a drone’sUpdate, or when the stored drone’stargetNodeis not this node.)