From 04efd899a087e7c6c96c3be6567206c8dcbe6849 Mon Sep 17 00:00:00 2001 From: Staszek Welsh Date: Wed, 1 Jun 2022 23:28:14 +0100 Subject: [PATCH] Remove async from buyCoffee and throwParty --- src/Corporation/Actions.ts | 8 +++++--- src/NetscriptFunctions/Corporation.ts | 14 ++++---------- src/ScriptEditor/NetscriptDefinitions.d.ts | 8 ++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 71e59eaad..fa4d383a4 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -333,12 +333,14 @@ export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size: corp.funds = corp.funds - cost; } -export function BuyCoffee(corp: ICorporation, office: OfficeSpace): void { +export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean { const cost = 500e3 * office.employees.length; - if (corp.funds < cost) { return; } + if (corp.funds < cost) { return false; } - if (!office.setCoffee()) { return; } + if (!office.setCoffee()) { return false; } corp.funds -= cost; + + return true; } export function ThrowParty(corp: ICorporation, office: OfficeSpace, costPerEmployee: number): number { diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 1f7bd94c7..0fc8804fc 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -769,7 +769,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript }, throwParty: (ctx: NetscriptContext) => - async (_divisionName: unknown, _cityName: unknown, _costPerEmployee: unknown): Promise => { + (_divisionName: unknown, _cityName: unknown, _costPerEmployee: unknown): number => { checkAccess(ctx, 8); const divisionName = ctx.helper.string("divisionName", _divisionName); const cityName = ctx.helper.city("cityName", _cityName); @@ -782,14 +782,11 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript const corporation = getCorporation(); const office = getOffice(divisionName, cityName); - return netscriptDelay(0, workerScript).then(function () { - return Promise.resolve(ThrowParty(corporation, office, costPerEmployee)); - }); - //return ThrowParty(corporation, office, costPerEmployee) + return ThrowParty(corporation, office, costPerEmployee) }, buyCoffee: (ctx: NetscriptContext) => - async (_divisionName: unknown, _cityName: unknown): Promise => { + (_divisionName: unknown, _cityName: unknown): boolean => { checkAccess(ctx, 8); const divisionName = ctx.helper.string("divisionName", _divisionName); const cityName = ctx.helper.city("cityName", _cityName); @@ -797,10 +794,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript const corporation = getCorporation(); const office = getOffice(divisionName, cityName); - return netscriptDelay(0, workerScript).then(function () { - return Promise.resolve(BuyCoffee(corporation, office)); - }); - //BuyCoffee(corporation, getOffice(divisionName, cityName); + return BuyCoffee(corporation, office); }, hireAdVert: (ctx: NetscriptContext) => diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index e4be6a507..cf0e12a82 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -6639,16 +6639,16 @@ export interface OfficeAPI { * @param divisionName - Name of the division * @param cityName - Name of the city * @param costPerEmployee - Amount to spend per employee. - * @returns Amount of happiness increased. + * @returns Multiplier for happiness and morale, or zero on failure */ - throwParty(divisionName: string, cityName: string, costPerEmployee: number): Promise; + throwParty(divisionName: string, cityName: string, costPerEmployee: number): number; /** * Buy coffee for your employees * @param divisionName - Name of the division * @param cityName - Name of the city - * @returns A promise that is fulfilled when the coffee is served. + * @returns true if buying coffee was successful, false otherwise */ - buyCoffee(divisionName: string, cityName: string): Promise; + buyCoffee(divisionName: string, cityName: string): boolean; /** * Hire AdVert. * @param divisionName - Name of the division