From c6c2b3ba99e4555806415ad4aaf888288de7e3f6 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Wed, 5 Jun 2024 20:45:37 -0400 Subject: [PATCH] vWhatever.0 --- src/Factory/Factory.ts | 31 +++- src/Factory/Helper.tsx | 193 ++++++++++----------- src/Factory/formulas/formulas.ts | 34 ++++ src/Factory/ui/EntityIcon.tsx | 23 +-- src/Factory/ui/FactoryRoot.tsx | 39 ++++- src/Netscript/NetscriptHelpers.tsx | 28 ++- src/NetscriptFunctions/Factory.ts | 116 ++++++++----- src/ScriptEditor/NetscriptDefinitions.d.ts | 101 +++++++++-- 8 files changed, 385 insertions(+), 180 deletions(-) diff --git a/src/Factory/Factory.ts b/src/Factory/Factory.ts index 58a70cc32..2cd9e8019 100644 --- a/src/Factory/Factory.ts +++ b/src/Factory/Factory.ts @@ -1,4 +1,17 @@ -import { Bot, Entity, EntityType, Item } from "@nsdefs"; +import { + Bot, + Entity, + EntityType, + ContainerEntity, + Item, + Dispenser, + Dock, + Crafter, + Chest, + Wall, + BaseEntity, + EntityID, +} from "@nsdefs"; import { factory } from "./Helper"; export interface Factory { @@ -24,3 +37,19 @@ export const bitsMap: Record = { [Item.ComplexG]: 4, [Item.ComplexB]: 4, }; + +export const isEntityContainer = (entity: BaseEntity): entity is ContainerEntity => "inventory" in entity; + +export const isEntityBot = (e: Entity): e is Bot => e.type === EntityType.Bot; +export const isEntityDispenser = (e: Entity): e is Dispenser => e.type === EntityType.Dispenser; +export const isEntityDock = (e: Entity): e is Dock => e.type === EntityType.Dock; +export const isEntityCrafter = (e: Entity): e is Crafter => e.type === EntityType.Crafter; +export const isEntityChest = (e: Entity): e is Chest => e.type === EntityType.Chest; +export const isEntityWall = (e: Entity): e is Wall => e.type === EntityType.Wall; + +export const findEntity = (id: EntityID, type?: EntityType): Entity | undefined => + factory.entities.find( + typeof id === "string" + ? (e) => e.name === id && (!type || type === e.type) + : (e) => e.x === id[0] && e.y === id[1] && (!type || type === e.type), + ); diff --git a/src/Factory/Helper.tsx b/src/Factory/Helper.tsx index 076ced2e7..e724ffa60 100644 --- a/src/Factory/Helper.tsx +++ b/src/Factory/Helper.tsx @@ -5,115 +5,11 @@ export const factorySize = 12; const defaultFactory: Factory = { bits: 0, - entities: [ - { - type: EntityType.Dispenser, - dispensing: Item.BasicR, - x: Math.floor(factorySize / 4), - y: 0, - cooldown: 10000, - cooldownUntil: 0, - inventory: [Item.BasicR], - maxInventory: 1, - }, - { - type: EntityType.Dispenser, - dispensing: Item.BasicG, - x: Math.floor(factorySize / 2), - y: 0, - cooldown: 10000, - cooldownUntil: 0, - inventory: [Item.BasicG], - maxInventory: 1, - }, - { - type: EntityType.Dispenser, - dispensing: Item.BasicB, - x: Math.floor((factorySize * 3) / 4), - y: 0, - cooldown: 10000, - cooldownUntil: 0, - inventory: [Item.BasicB], - maxInventory: 1, - }, - { - type: EntityType.Dock, - x: Math.floor(factorySize / 4), - y: Math.floor(factorySize - 1), - potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], - potentialRequestCount: 1, - currentRequest: [Item.BasicR], - inventory: [], - maxInventory: 1, - }, - { - type: EntityType.Dock, - x: Math.floor(factorySize / 2), - y: Math.floor(factorySize - 1), - potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], - potentialRequestCount: 1, - currentRequest: [Item.BasicG], - inventory: [], - maxInventory: 1, - }, - { - type: EntityType.Dock, - x: Math.floor((factorySize * 3) / 4), - y: Math.floor(factorySize - 1), - potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], - potentialRequestCount: 1, - currentRequest: [Item.BasicB], - inventory: [], - maxInventory: 1, - }, - { - type: EntityType.Dock, - x: 0, - y: Math.floor(factorySize - 1), - potentialRequest: [Item.ComplexR], - potentialRequestCount: 1, - currentRequest: [Item.ComplexR], - inventory: [], - maxInventory: 1, - }, - { - type: EntityType.Bot, - x: Math.floor(factorySize / 2), - y: Math.floor(factorySize / 2), - inventory: [], - energy: 16, - name: "alice", - maxInventory: 1, - }, - { - type: EntityType.Crafter, - x: 2, - y: 2, - inventory: [], - maxInventory: 3, - recipe: { - input: [Item.BasicR], - output: [Item.ComplexR], - }, - }, - { - type: EntityType.Chest, - inventory: [Item.BasicR], - maxInventory: 3, - x: Math.floor(factorySize / 2) + 1, - y: Math.floor(factorySize / 2), - }, - ], + entities: [], }; export const factory: Factory = defaultFactory; -export const loadFactory = (save: string) => { - if (!save) return; - // const savedFactory = JSON.parse(save); - // Object.assign(factory, savedFactory); -}; - export const NewBot = (name: string, x: number, y: number) => { factory.entities.push({ type: EntityType.Bot, @@ -125,3 +21,90 @@ export const NewBot = (name: string, x: number, y: number) => { maxInventory: 1, }); }; + +export const NewChest = (name: string, x: number, y: number) => { + factory.entities.push({ + name, + type: EntityType.Chest, + inventory: [], + maxInventory: 1, + x, + y, + }); +}; + +export const NewCrafter = (name: string, x: number, y: number) => { + factory.entities.push({ + name, + type: EntityType.Crafter, + x, + y, + inventory: [], + maxInventory: 2, + recipe: { + input: [Item.BasicR, Item.BasicR], + output: [Item.ComplexR], + }, + }); +}; + +export const NewDispenser = (name: string, x: number, y: number, dispensing: Item) => { + factory.entities.push({ + name, + type: EntityType.Dispenser, + x, + y, + dispensing, + cooldown: 10000, + cooldownUntil: 0, + inventory: [dispensing], + maxInventory: 1, + }); +}; + +export const NewDock = (name: string, x: number, y: number) => { + const potential = [Item.BasicR, Item.BasicG, Item.BasicB]; + factory.entities.push({ + name, + type: EntityType.Dock, + x, + y, + potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], + potentialRequestCount: 1, + currentRequest: [potential[Math.floor(Math.random() * potential.length)]], + inventory: [], + maxInventory: 1, + }); +}; + +export const NewWall = (name: string, x: number, y: number) => { + factory.entities.push({ + name, + type: EntityType.Wall, + x, + y, + }); +}; + +export const loadFactory = (save: string) => { + if (!save) return; + // const savedFactory = JSON.parse(save); + // Object.assign(factory, savedFactory); +}; + +export const resetFactory = () => { + factory.bits = 0; + factory.entities = []; + Object.assign(factory, defaultFactory); + NewBot("alice", Math.floor(factorySize / 2), Math.floor(factorySize / 2)); + NewDispenser("disp0", Math.floor(factorySize / 4), 0, Item.BasicR); + NewDispenser("disp1", Math.floor(factorySize / 2), 0, Item.BasicG); + NewDispenser("disp2", Math.floor((factorySize * 3) / 4), 0, Item.BasicB); + + NewDock("dock0", Math.floor(factorySize / 4), Math.floor(factorySize - 1)); + NewDock("dock1", Math.floor(factorySize / 2), Math.floor(factorySize - 1)); + NewDock("dock2", Math.floor((factorySize * 3) / 4), Math.floor(factorySize - 1)); + NewWall("wall0", 2, 2); +}; + +resetFactory(); diff --git a/src/Factory/formulas/formulas.ts b/src/Factory/formulas/formulas.ts index 92490083d..aeac2a0e4 100644 --- a/src/Factory/formulas/formulas.ts +++ b/src/Factory/formulas/formulas.ts @@ -1 +1,35 @@ +import { EntityType } from "@nsdefs"; + +export type FactoryFormulaParams = [number, number, number, number]; + +export const inventoryScale: Record = { + [EntityType.Bot]: [8, 0.5, 2, 0], + [EntityType.Dispenser]: [4, 1, 5, 0], + [EntityType.Dock]: [Infinity, Infinity, Infinity, Infinity], + [EntityType.Crafter]: [Infinity, 1, -1, 4095], + [EntityType.Chest]: [1.2, 10, 0, 63], + [EntityType.Wall]: [Infinity, Infinity, Infinity, Infinity], +}; + +// a^(b*X+c)+d +const exp = (p: FactoryFormulaParams, x: number): number => Math.floor(Math.pow(p[0], p[1] * x + p[2]) + p[3]); + +export const upgradeMaxInventoryCost = (type: EntityType, currentMaxInventory: number): number => + exp(inventoryScale[type], currentMaxInventory); + export const botPrice = (currentBots: number): number => Math.pow(2, currentBots + 3); + +/** +glitches: + +1 - moving dock & dispensers +2 - energy consumption +3 - ugrade degradation +4 - power hinderance (speed & transfer) +5 - dexterity hinderance (craft & build) +6 - dock complexity +7 - random walls + + + + */ diff --git a/src/Factory/ui/EntityIcon.tsx b/src/Factory/ui/EntityIcon.tsx index 16482134c..df5926a9a 100644 --- a/src/Factory/ui/EntityIcon.tsx +++ b/src/Factory/ui/EntityIcon.tsx @@ -7,7 +7,9 @@ import MoveToInboxIcon from "@mui/icons-material/MoveToInbox"; import OutboxIcon from "@mui/icons-material/Outbox"; import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank"; import PrecisionManufacturingIcon from "@mui/icons-material/PrecisionManufacturing"; +import BlockIcon from "@mui/icons-material/Block"; import { Tooltip, Typography } from "@mui/material"; +import { isEntityContainer } from "../Factory"; export const cellSize = 48; @@ -30,23 +32,18 @@ const itemColorMap: Record = { [Item.ComplexG]: colorGreen, }; +const WallIcon = styled(BlockIcon)(defaultIconStyle); const BotIcon = styled(SmartToyIcon)(defaultIconStyle); const DispenserIcon = styled(OutboxIcon)((props: { dispenser: Dispenser; col: string }) => ({ ...defaultIconStyle, color: new Date().getTime() > props.dispenser.cooldownUntil ? props.col : "gray", })); -const DockIcon = styled(MoveToInboxIcon)({ - ...defaultIconStyle, -}); +const DockIcon = styled(MoveToInboxIcon)(defaultIconStyle); -const CrafterIcon = styled(PrecisionManufacturingIcon)({ - ...defaultIconStyle, -}); +const CrafterIcon = styled(PrecisionManufacturingIcon)(defaultIconStyle); -const ChestIcon = styled(CheckBoxOutlineBlankIcon)({ - ...defaultIconStyle, -}); +const ChestIcon = styled(CheckBoxOutlineBlankIcon)(defaultIconStyle); interface ITooltipContentProps { entity: Entity; @@ -55,13 +52,16 @@ interface ITooltipContentProps { const TooltipContent = ({ entity, content }: ITooltipContentProps): React.ReactElement => { return ( <> - {entity.type} + + {entity.name} ({entity.type}) + {content} ); }; const TooltipInventory = ({ entity }: { entity: Entity }): React.ReactElement => { + if (!isEntityContainer(entity)) return <>; return ( {entity.inventory.map((item) => ( @@ -75,6 +75,9 @@ const TooltipInventory = ({ entity }: { entity: Entity }): React.ReactElement => export const EntityIcon = ({ entity }: { entity: Entity }): React.ReactElement => { switch (entity.type) { + case EntityType.Wall: { + return ; + } case EntityType.Chest: { return ( } />}> diff --git a/src/Factory/ui/FactoryRoot.tsx b/src/Factory/ui/FactoryRoot.tsx index 6675110a5..99814be1c 100644 --- a/src/Factory/ui/FactoryRoot.tsx +++ b/src/Factory/ui/FactoryRoot.tsx @@ -33,9 +33,18 @@ interface IColProps { const Col = ({ x }: IColProps): React.ReactElement => { return ( - {new Array(factorySize).fill(null).map((_, y) => ( - - ))} + {new Array(factorySize + 1).fill(null).map((_, y) => { + if (y === 0) + return ( + + {x - 1} + + ); + return ; + })} ); }; @@ -50,6 +59,23 @@ const Table = styled("div")({ paddingRight: "2px", }); +const YHeader = () => { + return ( + + {new Array(factorySize + 1).fill(null).map((_, y) => { + return ( + + {y === 0 ? "Y\\X" : y - 1} + + ); + })} + + ); +}; + interface IProps {} export const FactoryRoot = (__props: IProps): React.ReactElement => { @@ -59,9 +85,10 @@ export const FactoryRoot = (__props: IProps): React.ReactElement => { Factory
- {new Array(factorySize).fill(null).map((_, index) => ( - - ))} + {new Array(factorySize + 1).fill(null).map((_, x) => { + if (x === 0) return ; + return ; + })}
diff --git a/src/Netscript/NetscriptHelpers.tsx b/src/Netscript/NetscriptHelpers.tsx index 045a42e0b..2e05594b3 100644 --- a/src/Netscript/NetscriptHelpers.tsx +++ b/src/Netscript/NetscriptHelpers.tsx @@ -1,5 +1,11 @@ import type { NetscriptContext } from "./APIWrapper"; -import type { RunningScript as IRunningScript, Person as IPerson, Server as IServer, ScriptArg } from "@nsdefs"; +import type { + RunningScript as IRunningScript, + Person as IPerson, + Server as IServer, + ScriptArg, + EntityID, +} from "@nsdefs"; import React from "react"; import { killWorkerScript } from "./killWorkerScript"; @@ -74,6 +80,8 @@ export const helpers = { gangMember, gangTask, log, + coord2d, + entityID, filePath, scriptPath, getRunningScript, @@ -152,6 +160,24 @@ function scriptArgs(ctx: NetscriptContext, args: unknown) { return args; } +function isCoord2D(v: unknown): v is [number, number] { + return Array.isArray(v) && v.length === 2 && typeof v[0] === "number" && typeof v[1] === "number"; +} + +function coord2d(ctx: NetscriptContext, argName: string, v: unknown): [number, number] { + if (!isCoord2D(v)) throw errorMessage(ctx, `${argName} should be a [number, number], was ${v}`, "TYPE"); + return v; +} + +function isEntityID(v: unknown): v is EntityID { + return typeof v === "string" || isCoord2D(v); +} + +function entityID(ctx: NetscriptContext, argName: string, v: unknown): EntityID { + if (!isEntityID(v)) throw errorMessage(ctx, `${argName} should be string | [number, number], was ${v}`, "TYPE"); + return v; +} + function runOptions(ctx: NetscriptContext, threadOrOption: unknown): CompleteRunOptions { const result: CompleteRunOptions = { threads: 1 as PositiveInteger, diff --git a/src/NetscriptFunctions/Factory.ts b/src/NetscriptFunctions/Factory.ts index bef59d470..060471653 100644 --- a/src/NetscriptFunctions/Factory.ts +++ b/src/NetscriptFunctions/Factory.ts @@ -1,9 +1,9 @@ import { Bot, Factory as IFactory, EntityType, Item, Crafter } from "@nsdefs"; import { InternalAPI } from "../Netscript/APIWrapper"; import { helpers } from "../Netscript/NetscriptHelpers"; -import { NewBot, factory, factorySize } from "../Factory/Helper"; -import { adjacent, bitsMap, findBot, findEntityAt } from "../Factory/Factory"; -import { botPrice } from "../Factory/formulas/formulas"; +import { NewBot, factory, factorySize, resetFactory } from "../Factory/Helper"; +import { adjacent, bitsMap, findEntity, isEntityContainer } from "../Factory/Factory"; +import { botPrice, upgradeMaxInventoryCost } from "../Factory/formulas/formulas"; export function NetscriptFactory(): InternalAPI { return { @@ -12,10 +12,9 @@ export function NetscriptFactory(): InternalAPI { const botCount = factory.entities.reduce((acc, e) => (e.type === EntityType.Bot ? acc + 1 : acc), 0); return botPrice(botCount); }, - purchaseBot: (ctx) => (_name, _x, _y) => { + purchaseBot: (ctx) => (_name, _coord) => { const name = helpers.string(ctx, "name", _name); - const x = helpers.number(ctx, "x", _x); - const y = helpers.number(ctx, "y", _y); + const [x, y] = helpers.coord2d(ctx, "coord", _coord); const another = factory.entities.find((e): e is Bot => e.type === EntityType.Bot && e.name === name); if (another) { helpers.log(ctx, () => `bot "${name}" already exists`); @@ -41,10 +40,9 @@ export function NetscriptFactory(): InternalAPI { }, moveBot: (ctx) => - async (_name, _x, _y): Promise => { + async (_name, _coord): Promise => { const name = helpers.string(ctx, "name", _name); - const x = helpers.number(ctx, "x", _x); - const y = helpers.number(ctx, "y", _y); + const [x, y] = helpers.coord2d(ctx, "coord", _coord); const bot = factory.entities.find((e) => e.type === EntityType.Bot && e.name === name); if (!bot) return Promise.resolve(false); @@ -57,40 +55,37 @@ export function NetscriptFactory(): InternalAPI { return Promise.resolve(true); }); }, - getBot: - (ctx) => - (_name): Bot | undefined => { - const name = helpers.string(ctx, "name", _name); - const bot = factory.entities.find((e): e is Bot => e.type === EntityType.Bot && e.name === name); - if (!bot) return; - return JSON.parse(JSON.stringify(bot)); - }, - entityAt: (ctx) => (_x, _y) => { - const x = helpers.number(ctx, "x", _x); - const y = helpers.number(ctx, "y", _y); - return factory.entities.find((e) => e.x === x && e.y === y); + getEntity: (ctx) => (_id) => { + const id = helpers.entityID(ctx, "id", _id); + return findEntity(id); }, entities: (__ctx) => () => JSON.parse(JSON.stringify(factory.entities)), transfer: (ctx) => - async (_name, _x, _y, _pickup, _drop): Promise => { - const name = helpers.string(ctx, "name", _name); - const x = helpers.number(ctx, "x", _x); - const y = helpers.number(ctx, "y", _y); + async (_from, _to, _pickup, _drop): Promise => { + const botID = helpers.entityID(ctx, "from", _from); + const containerID = helpers.entityID(ctx, "to", _to); const pickup = _pickup as Item[]; - const drop = _drop as Item[]; + const drop = (_drop ?? []) as Item[]; - const bot = findBot(name); + const bot = findEntity(botID, EntityType.Bot) as Bot; if (!bot) { - helpers.log(ctx, () => `bot "${name}" not found`); + helpers.log(ctx, () => `bot ${botID} not found`); return Promise.resolve(false); } - const container = findEntityAt(x, y); + + const container = findEntity(containerID); if (!container) { - helpers.log(ctx, () => `container not found at [${x}, ${y}]`); + helpers.log(ctx, () => `container ${containerID} not found`); + return Promise.resolve(false); + } + + if (!isEntityContainer(container)) { + helpers.log(ctx, () => `entity ${containerID} is not a container`); return Promise.resolve(false); } + if (!adjacent(bot, container)) { helpers.log(ctx, () => "bot is not adjacent to container"); return Promise.resolve(false); @@ -121,7 +116,7 @@ export function NetscriptFactory(): InternalAPI { container.cooldownUntil = Date.now() + container.cooldown; setTimeout(() => { if (container.inventory.length < container.maxInventory) { - container.inventory.push(container.dispensing); + container.inventory = new Array(container.maxInventory).fill(container.dispensing); } }, container.cooldown); break; @@ -138,6 +133,7 @@ export function NetscriptFactory(): InternalAPI { .fill(null) .map(() => container.potentialRequest[Math.floor(Math.random() * container.potentialRequest.length)]); container.currentRequest = newRequest; + container.maxInventory = newRequest.length; } break; } @@ -147,18 +143,19 @@ export function NetscriptFactory(): InternalAPI { }, craft: (ctx) => - async (_name, _x, _y): Promise => { - const name = helpers.string(ctx, "name", _name); - const x = helpers.number(ctx, "x", _x); - const y = helpers.number(ctx, "y", _y); - const bot = findBot(name); + async (_botID, _crafterID): Promise => { + const botID = helpers.entityID(ctx, "bot", _botID); + const crafterID = helpers.entityID(ctx, "crafter", _crafterID); + + const bot = findEntity(botID, EntityType.Bot) as Bot; if (!bot) { - helpers.log(ctx, () => `bot "${name}" not found`); + helpers.log(ctx, () => `bot ${botID} not found`); return Promise.resolve(false); } - const crafter = findEntityAt(x, y, EntityType.Crafter); + + const crafter = findEntity(crafterID, EntityType.Crafter) as Crafter; if (!crafter) { - helpers.log(ctx, () => `crafter not found at [${x}, ${y}]`); + helpers.log(ctx, () => `crafter ${crafterID} not found`); return Promise.resolve(false); } @@ -180,5 +177,46 @@ export function NetscriptFactory(): InternalAPI { return Promise.resolve(true); }); }, + upgradeMaxInventory: (ctx) => (_id) => { + const id = helpers.entityID(ctx, "id", _id); + const container = findEntity(id); + if (!container) { + helpers.log(ctx, () => `container ${id} not found`); + return false; + } + + if (!isEntityContainer(container)) { + helpers.log(ctx, () => `entity ${id} is not a container`); + return false; + } + + const cost = upgradeMaxInventoryCost(container.type, container.maxInventory); + if (factory.bits < cost) { + helpers.log(ctx, () => `not enough bits to upgrade container`); + return false; + } + + factory.bits -= cost; + container.maxInventory++; + + return true; + }, + + getUpgradeMaxInventoryCost: (ctx) => (_id) => { + const id = helpers.entityID(ctx, "id", _id); + const container = findEntity(id); + if (!container) { + helpers.log(ctx, () => `container ${id} not found`); + return -1; + } + + if (!isEntityContainer(container)) { + helpers.log(ctx, () => `entity ${id} is not a container`); + return -1; + } + + return upgradeMaxInventoryCost(container.type, container.maxInventory); + }, + reset: () => resetFactory, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d0c469d80..97dc0aecf 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5153,6 +5153,7 @@ export enum EntityType { Dock = "dock", Crafter = "crafter", Chest = "chest", + Wall = "wall", } export enum Item { @@ -5165,51 +5166,57 @@ export enum Item { } export interface BaseEntity { + name: string; type: EntityType; x: number; y: number; } -export interface Bot extends InventoryEntity { +export interface Bot extends ContainerEntity { type: EntityType.Bot; - name: string; energy: number; } -export interface InventoryEntity extends BaseEntity { +export interface ContainerEntity extends BaseEntity { inventory: Item[]; maxInventory: number; } -export interface Dispenser extends InventoryEntity { +export interface Dispenser extends ContainerEntity { type: EntityType.Dispenser; dispensing: Item; cooldown: number; cooldownUntil: number; } -export interface Dock extends InventoryEntity { +export interface Dock extends ContainerEntity { type: EntityType.Dock; potentialRequest: Item[]; potentialRequestCount: number; currentRequest: Item[]; } -export interface Chest extends InventoryEntity { +export interface Chest extends ContainerEntity { type: EntityType.Chest; } -export interface Crafter extends InventoryEntity { +export interface Crafter extends ContainerEntity { type: EntityType.Crafter; recipe: Recipe; } +export interface Wall extends BaseEntity { + type: EntityType.Wall; +} + export interface Recipe { input: Item[]; output: Item[]; } -export type Entity = Bot | Dispenser | Dock | Crafter | Chest; +export type EntityID = string | [number, number]; + +export type Entity = Bot | Dispenser | Dock | Crafter | Chest | Wall; interface Factory { /** @@ -5218,28 +5225,86 @@ interface Factory { * RAM cost: 0 GB * @returns true if the move succeeded, false otherwise. */ - moveBot(name: string, x: number, y: number): Promise; + moveBot(name: EntityID, coord: [number, number]): Promise; /** - * Get information about a bot + * Get entity * @remarks - * RAM cost: 0 GB - * @returns bot information + * RAM cost: 0GB + * @returns entity with this ID */ - getBot(name: string): Bot | undefined; - - entityAt(x: number, y: number): Entity | undefined; + getEntity(entity: EntityID): Entity | undefined; + /** + * Get all entities + * @remarks + * RAM cost: 0 GB + * @returns all entities + */ entities(): Entity[]; - transfer(name: string, x: number, y: number, pickup: Item[], drop: Item[]): Promise; + /** + * Transfer items between entities + * @remarks + * RAM cost: 0 GB + * @returns true if the transfer succeeded, false otherwise. + */ + transfer(from: EntityID, to: EntityID, pickup: Item[], drop?: Item[]): Promise; - craft(name: string, x: number, y: number): Promise; + /** + * Make a bot use a crafter in order to craft an item. + * @remarks + * RAM cost: 0 GB + * @returns true if the crafting succeeded, false otherwise. + */ + craft(bot: EntityID, crafter: EntityID): Promise; + /** + * get number of bits available + * @remarks + * RAM cost: 0 GB + * @returns number of bits available + */ getBits(): number; + /** + * Get the price of the next bot + * @remarks + * RAM cost: 0 GB + * @returns price of the next bot + */ getBotPrice(): number; - purchaseBot(name: string, x: number, y: number): boolean; + + /** + * Purchase a new bot and place it at location [x, y] + * @remarks + * RAM cost: 0 GB + * @returns true if the purchase succeeded, false otherwise. + */ + purchaseBot(name: string, coord: [number, number]): boolean; + + /** + * Upgrade the inventory of an entity + * @remarks + * RAM cost: 0 GB + * @returns true if the upgrade succeeded, false otherwise. + */ + upgradeMaxInventory(entity: EntityID): boolean; + + /** + * Get the cost of upgrading the inventory of an entity + * @remarks + * RAM cost: 0 GB + * @returns cost of upgrading the inventory of an entity, -1 on failure. + */ + getUpgradeMaxInventoryCost(entity: EntityID): number; + + /** + * Completely reset the factory, for debug purposes + * @remarks + * RAM cost: 0 GB + */ + reset(): void; } /** @public */