Thirdly, I do not want to run from rats - it’s a waste of time. In earlier versions, there was an algorithm for killing rats. We use it partially.
In the ship I have 2 drones and a ShieldBooster. We will configure the drones for the aggressive mode and we will release them on arrival to asteroid belt. Before the warp it is necessary to scope the drones to the drone bay.
Let’s write the functions for working with drones:
// our window with drones
IWindowDroneView WindowDrones =>
Measurement?.WindowDroneView?.FirstOrDefault();
// drones in bay
DroneViewEntryGroup DronesInBayListEntry =>
WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in bay", RegexOptions.IgnoreCase));
// drones in space
DroneViewEntryGroup DronesInSpaceListEntry =>
WindowDrones?.ListView?.Entry?.OfType<DroneViewEntryGroup>()?.FirstOrDefault(Entry => null != Entry?.Caption?.Text?.RegexMatchIfSuccess(@"Drones in Local Space", RegexOptions.IgnoreCase));
int? DronesInSpaceCount => DronesInSpaceListEntry?.Caption?.Text?.AsDroneLabel()?.Status?.TryParseInt();
int? DronesInBayListEntryCount => DronesInBayListEntry?.Caption?.Text?.AsDroneLabel()?.Status?.TryParseInt();
// check our drones and scope them
void DroneEnsureInBay()
{
if(0 == DronesInSpaceCount)
return;
DroneReturnToBay();
Host.Delay(4444);
}
// scope our drones
void DroneReturnToBay()
{
Host.Log("return drones to bay.");
Sanderling.MouseClickRight(DronesInSpaceListEntry);
Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("return.*bay", RegexOptions.IgnoreCase));
}
// launch our drones
void DroneLaunch()
{
Host.Log("launch drones.");
Sanderling.MouseClickRight(DronesInBayListEntry);
Sanderling.MouseClickLeft(Menu?.FirstOrDefault()?.EntryFirstMatchingRegexPattern("launch", RegexOptions.IgnoreCase));
}
Now we need to make sure that the drones are scoped before our ship warp to anywhere.
Func<object> MainStep()
{
// ...
if(ReadyForManeuver)
{
DroneEnsureInBay();
// ...
}
}
In belt we should launch our drones and activate our shield booster if the rats attacked us.
Func<object> InBeltMineStep()
{if(ShouldSwitchMiningSite)
return MainStep;
EnsureWindowInventoryOreContainerIsOpen();
EnsureOverviewTypeSelectionLoaded();
if(OreContainerFilledForOffload)
return null;
if (!(ReadyForManeuver))
{
DelayWhileUpdatingMemory(6000);
return InBeltMineStep;
}
if (!(DronesInSpaceCount > 0) && (DronesInBayListEntryCount > 0))
DroneLaunch();
bool ShouldTurnOnShieldBooster = ShieldHpPercent <90;
ToggleShieldBooster(ShouldTurnOnShieldBooster);
// the rest of the code is unchanged...
return InBeltMineStep;
}
Now we’ll write a function to turn on / off the shield booster.
// get all shield boosters in one array
Sanderling.Accumulation.IShipUiModule[] SetModuleShieldBoosters =>
Sanderling.MemoryMeasurementAccu?.Value?.ShipUiModule?.Where(module => module?.TooltipLast?.Value?.IsShieldBooster ?? false)?.ToArray();
// if true then we should turn on shield booster if false - turn off
void ToggleShieldBooster(bool turnOn = true)
{
var shieldBooster = SetModuleShieldBoosters?.FirstOrDefault();
if((shieldBooster?.RampActive ?? false) !=turnOn)
{
Host.Log("toggle Shield Booster.");
ModuleToggle(shieldBooster);
}
}
Now we will collect all the changes in one script and test it in practice.
PS: I’m testing on the old version of Sanderling ((v17.11.19 - it’s free), so local chat checking is disabled.