mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-16 15:22:31 +01:00
added batteries
This commit is contained in:
@ -13,6 +13,7 @@ export class Myrian {
|
||||
world: string[][] = [];
|
||||
resources = 0;
|
||||
sleeves: MyrianSleeve[] = [];
|
||||
storedCycles = 0;
|
||||
|
||||
constructor() {
|
||||
this.world = DefaultWorld;
|
||||
@ -31,6 +32,30 @@ export class Myrian {
|
||||
return [1, 1];
|
||||
}
|
||||
|
||||
/** Main process function called by the engine loop every game cycle */
|
||||
process(numCycles = 1): void {
|
||||
const CYCLE_CHUNK = 10;
|
||||
this.storedCycles += numCycles;
|
||||
if (this.storedCycles < CYCLE_CHUNK) return;
|
||||
|
||||
// Calculate how many cycles to actually process.
|
||||
const cycles = Math.min(this.storedCycles, CYCLE_CHUNK);
|
||||
|
||||
try {
|
||||
for (let x = 0; x < this.world.length; x++) {
|
||||
for (let y = 0; y < this.world[x].length; y++) {
|
||||
const tile = this.world[x][y];
|
||||
if (tile === "d" && Math.random() > 0.99) {
|
||||
this.world[x][y] = "b";
|
||||
}
|
||||
}
|
||||
}
|
||||
this.storedCycles -= cycles;
|
||||
} catch (e: unknown) {
|
||||
console.error(`Exception caught when processing Gang: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** Serialize the current object to a JSON save state. */
|
||||
toJSON(): IReviverValue {
|
||||
return Generic_toJSON("Myrian", this);
|
||||
|
@ -17,7 +17,10 @@ const move = async (ctx: NetscriptContext, sleeve: MyrianSleeve, x: number, y: n
|
||||
};
|
||||
|
||||
const drain = async (ctx: NetscriptContext, sleeve: MyrianSleeve, x: number, y: number) => {
|
||||
const tile = myrian.world[y][x];
|
||||
if (tile !== "b") throw new Error(`Invalid tile. Must be 'b' but is ${tile}`);
|
||||
return helpers.netscriptDelay(ctx, 100).then(() => {
|
||||
myrian.world[y][x] = "d";
|
||||
return Promise.resolve();
|
||||
});
|
||||
};
|
||||
|
@ -43,6 +43,7 @@ import React from "react";
|
||||
import { setupUncaughtPromiseHandler } from "./UncaughtPromiseHandler";
|
||||
import { Button, Typography } from "@mui/material";
|
||||
import { SnackbarEvents } from "./ui/React/Snackbar";
|
||||
import { myrian } from "./Myrian/Helpers";
|
||||
|
||||
/** Game engine. Handles the main game loop. */
|
||||
const Engine: {
|
||||
@ -101,6 +102,8 @@ const Engine: {
|
||||
// Staneks gift
|
||||
staneksGift.process(numCycles);
|
||||
|
||||
myrian.process(numCycles);
|
||||
|
||||
// Corporation
|
||||
if (Player.corporation) {
|
||||
Player.corporation.storeCycles(numCycles);
|
||||
|
Reference in New Issue
Block a user