Remove async from buyCoffee and throwParty

This commit is contained in:
Staszek Welsh 2022-06-01 23:28:14 +01:00
parent ffaa38d086
commit 04efd899a0
3 changed files with 13 additions and 17 deletions

@ -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 {

@ -769,7 +769,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
},
throwParty:
(ctx: NetscriptContext) =>
async (_divisionName: unknown, _cityName: unknown, _costPerEmployee: unknown): Promise<number> => {
(_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<void> => {
(_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) =>

@ -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<number>;
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<void>;
buyCoffee(divisionName: string, cityName: string): boolean;
/**
* Hire AdVert.
* @param divisionName - Name of the division