MCPcopy
hub / github.com/FreezingMoon/AncientBeast / tryMovementAbility

Method tryMovementAbility

src/bot.ts:1191–1233  ·  view source on GitHub ↗

* Try to use an ability flagged as `isMovementAbility` (teleport, flying dash, etc.) * to reposition the creature. * Returns true if an ability was triggered.

(opts: { requireTrapSafe?: boolean } = {})

Source from the content-addressed store, hash-verified

1189 * Returns true if an ability was triggered.
1190 */
1191 tryMovementAbility(opts: { requireTrapSafe?: boolean } = {}): boolean {
1192 const creature = this.game.activeCreature;
1193 if (!creature) return false;
1194 const requireTrapSafe = opts.requireTrapSafe ?? false;
1195
1196 const strategy = this.getStrategyFor(creature);
1197 const abilityOrder =
1198 strategy?.getAbilityPriority?.(creature, this) ?? creature.abilities.map((_, i) => i);
1199
1200 for (const i of abilityOrder) {
1201 const ability = creature.abilities[i];
1202 if (
1203 !ability ||
1204 !ability.isMovementAbility ||
1205 (requireTrapSafe && ability.isMovementAbility !== 'safe') ||
1206 this.failedAbilityIds.has(i) ||
1207 ability.getTrigger() !== 'onQuery' ||
1208 ability.used ||
1209 typeof ability.require !== 'function'
1210 ) {
1211 continue;
1212 }
1213 try {
1214 if (!ability.require()) continue;
1215 } catch {
1216 continue;
1217 }
1218 this.setPendingAction({ type: 'ability', abilityIndex: i });
1219 const previousQueryOpt = this.game.grid?.lastQueryOpt;
1220 ability.use();
1221 if (this.pendingAction === null) {
1222 continue;
1223 }
1224 if (this.game.grid?.lastQueryOpt === previousQueryOpt) {
1225 this.clearPendingAction();
1226 this.failedAbilityIds.add(i);
1227 continue;
1228 }
1229 return true;
1230 }
1231
1232 return false;
1233 }
1234
1235 private setPendingAction(action: BotPendingAction) {
1236 this.pendingAction = action;

Callers 1

takeTurnMethod · 0.95

Calls 8

getStrategyForMethod · 0.95
setPendingActionMethod · 0.95
clearPendingActionMethod · 0.95
getAbilityPriorityMethod · 0.80
hasMethod · 0.80
getTriggerMethod · 0.80
useMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected