mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-22 05:51:35 +01:00
fix bug with action mapping
This commit is contained in:
parent
03a80ec5cd
commit
b0cbdf5625
@ -2,11 +2,13 @@ import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
import { NetscriptContext } from "../Netscript/APIWrapper";
|
||||
import { myrian } from "./Helpers";
|
||||
import { MyrianSleeve } from "./Myrian";
|
||||
import { MyrianActionTypes } from "./Enums";
|
||||
|
||||
const move = async (ctx: NetscriptContext, sleeve: MyrianSleeve, x: number, y: number) => {
|
||||
const dist = Math.abs(sleeve.x - x) + Math.abs(sleeve.y - y);
|
||||
if (dist > 1) throw new Error("Invalid move");
|
||||
if (myrian.world[y][x] !== " ") throw new Error("Invalid move");
|
||||
if (dist > 1) throw new Error(`Invalid move, target must be 1 tile away, is ${dist}`);
|
||||
const tile = myrian.world[y][x];
|
||||
if (tile !== " ") throw new Error(`Invalid move, cannot enter tile [${x}, ${y}] because the content is ${tile}`);
|
||||
return helpers.netscriptDelay(ctx, 100).then(() => {
|
||||
sleeve.x = x;
|
||||
sleeve.y = y;
|
||||
@ -24,6 +26,6 @@ export const actions: Record<
|
||||
string,
|
||||
(ctx: NetscriptContext, sleeve: MyrianSleeve, x: number, y: number) => Promise<void>
|
||||
> = {
|
||||
move: move,
|
||||
drain: drain,
|
||||
[MyrianActionTypes.MOVE]: move,
|
||||
[MyrianActionTypes.DRAIN]: drain,
|
||||
};
|
||||
|
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
4
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -2722,7 +2722,7 @@ export interface MyrianSleeve {
|
||||
inside: boolean;
|
||||
}
|
||||
|
||||
export declare enum MyrianActions {
|
||||
export declare enum MyrianActionTypes {
|
||||
MOVE = "MOVE",
|
||||
DRAIN = "DRAIN",
|
||||
}
|
||||
@ -6973,7 +6973,7 @@ export type NSEnums = {
|
||||
LocationName: typeof LocationName;
|
||||
ToastVariant: typeof ToastVariant;
|
||||
UniversityClassType: typeof UniversityClassType;
|
||||
MyrianActions: typeof MyrianActions;
|
||||
MyrianActions: typeof MyrianActionTypes;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user