mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 17:43:48 +01:00
Added better job assignment function, and fix docs
This commit is contained in:
parent
abdc786403
commit
1384b86810
@ -173,6 +173,40 @@ export class OfficeSpace {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setEmployeeToJob(job: string, amount: number): boolean {
|
||||||
|
let unassignedCount = 0;
|
||||||
|
let jobCount = 0;
|
||||||
|
for (let i = 0; i < this.employees.length; ++i) {
|
||||||
|
if (this.employees[i].pos === EmployeePositions.Unassigned) {
|
||||||
|
unassignedCount++;
|
||||||
|
} else if (this.employees[i].pos === job) {
|
||||||
|
jobCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((jobCount + unassignedCount) < amount) return false;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.employees.length; ++i) {
|
||||||
|
if (this.employees[i].pos === EmployeePositions.Unassigned) {
|
||||||
|
if (jobCount <= amount) {
|
||||||
|
this.employees[i].pos = job;
|
||||||
|
jobCount++;
|
||||||
|
unassignedCount--;
|
||||||
|
}
|
||||||
|
if (jobCount === amount) break;
|
||||||
|
} else if (this.employees[i].pos === job) {
|
||||||
|
if (jobCount >= amount) {
|
||||||
|
this.employees[i].pos = EmployeePositions.Unassigned;
|
||||||
|
jobCount--;
|
||||||
|
unassignedCount++;
|
||||||
|
}
|
||||||
|
if (jobCount === amount) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (jobCount !== amount) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
toJSON(): any {
|
toJSON(): any {
|
||||||
return Generic_toJSON("OfficeSpace", this);
|
return Generic_toJSON("OfficeSpace", this);
|
||||||
}
|
}
|
||||||
|
@ -508,6 +508,21 @@ export function NetscriptCorporation(
|
|||||||
const researchName = helper.string("hasResearched", "researchName", aresearchName);
|
const researchName = helper.string("hasResearched", "researchName", aresearchName);
|
||||||
return hasResearched(getDivision(divisionName), researchName);
|
return hasResearched(getDivision(divisionName), researchName);
|
||||||
},
|
},
|
||||||
|
setAutoJobAssignment: function (adivisionName: any, acityName: any, ajob: any, aamount: any): Promise<boolean> {
|
||||||
|
checkAccess("setAutoJobAssignment", 8);
|
||||||
|
const divisionName = helper.string("setAutoJobAssignment", "divisionName", adivisionName);
|
||||||
|
const cityName = helper.string("setAutoJobAssignment", "cityName", acityName);
|
||||||
|
const amount = helper.number("setAutoJobAssignment", "amount", aamount);
|
||||||
|
const job = helper.string("setAutoJobAssignment", "job", ajob);
|
||||||
|
const office = getOffice(divisionName, cityName);
|
||||||
|
if (!Object.values(EmployeePositions).includes(job)) throw new Error(`'${job}' is not a valid job.`);
|
||||||
|
return netscriptDelay(1000, workerScript).then(function () {
|
||||||
|
if (workerScript.env.stopFlag) {
|
||||||
|
return Promise.reject(workerScript);
|
||||||
|
}
|
||||||
|
return Promise.resolve(office.setEmployeeToJob(job, amount));
|
||||||
|
});
|
||||||
|
},
|
||||||
assignJob: function (adivisionName: any, acityName: any, aemployeeName: any, ajob: any): Promise<void> {
|
assignJob: function (adivisionName: any, acityName: any, aemployeeName: any, ajob: any): Promise<void> {
|
||||||
checkAccess("assignJob", 8);
|
checkAccess("assignJob", 8);
|
||||||
const divisionName = helper.string("assignJob", "divisionName", adivisionName);
|
const divisionName = helper.string("assignJob", "divisionName", adivisionName);
|
||||||
|
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
19
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -6086,7 +6086,7 @@ export interface OfficeAPI {
|
|||||||
*/
|
*/
|
||||||
assignJob(divisionName: string, cityName: string, employeeName: string, job: string): Promise<void>;
|
assignJob(divisionName: string, cityName: string, employeeName: string, job: string): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Assign an employee to a job.
|
* Hire an employee.
|
||||||
* @param divisionName - Name of the division
|
* @param divisionName - Name of the division
|
||||||
* @param cityName - Name of the city
|
* @param cityName - Name of the city
|
||||||
* @returns The newly hired employee, if any
|
* @returns The newly hired employee, if any
|
||||||
@ -6100,7 +6100,7 @@ export interface OfficeAPI {
|
|||||||
*/
|
*/
|
||||||
upgradeOfficeSize(divisionName: string, cityName: string, size: number): void;
|
upgradeOfficeSize(divisionName: string, cityName: string, size: number): void;
|
||||||
/**
|
/**
|
||||||
* Assign an employee to a job.
|
* Throw a party for your employees
|
||||||
* @param divisionName - Name of the division
|
* @param divisionName - Name of the division
|
||||||
* @param cityName - Name of the city
|
* @param cityName - Name of the city
|
||||||
* @param costPerEmployee - Amount to spend per employee.
|
* @param costPerEmployee - Amount to spend per employee.
|
||||||
@ -6120,7 +6120,7 @@ export interface OfficeAPI {
|
|||||||
*/
|
*/
|
||||||
hireAdVert(divisionName: string): void;
|
hireAdVert(divisionName: string): void;
|
||||||
/**
|
/**
|
||||||
* Hire AdVert.
|
* purchace a research
|
||||||
* @param divisionName - Name of the division
|
* @param divisionName - Name of the division
|
||||||
* @param researchName - Name of the research
|
* @param researchName - Name of the research
|
||||||
*/
|
*/
|
||||||
@ -6166,6 +6166,15 @@ export interface OfficeAPI {
|
|||||||
* @returns true is unlocked, false if not
|
* @returns true is unlocked, false if not
|
||||||
*/
|
*/
|
||||||
hasResearched(divisionName: string, researchName: string): boolean;
|
hasResearched(divisionName: string, researchName: string): boolean;
|
||||||
|
/**
|
||||||
|
* Set the auto job assignment for a job
|
||||||
|
* @param divisionName - Name of the division
|
||||||
|
* @param cityName - Name of the city
|
||||||
|
* @param job - Name of the job
|
||||||
|
* @param amount - Number of employees to assign to that job
|
||||||
|
* @returns A promise that is fulfilled when the assignment is complete.
|
||||||
|
*/
|
||||||
|
setAutoJobAssignment(divisionName: string, cityName: string, job: string, amount: number): Promise<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -6411,7 +6420,7 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
|||||||
acceptInvestmentOffer(): boolean;
|
acceptInvestmentOffer(): boolean;
|
||||||
/**
|
/**
|
||||||
* Go public
|
* Go public
|
||||||
* @param numShares number of shares you would like to issue for your IPO
|
* @param numShares - number of shares you would like to issue for your IPO
|
||||||
* @returns true if you successfully go public, false if not
|
* @returns true if you successfully go public, false if not
|
||||||
*/
|
*/
|
||||||
goPublic(numShares: number): boolean;
|
goPublic(numShares: number): boolean;
|
||||||
@ -6439,7 +6448,7 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
|||||||
*/
|
*/
|
||||||
expandCity(divisionName: string, cityName: string): void;
|
expandCity(divisionName: string, cityName: string): void;
|
||||||
/**
|
/**
|
||||||
* Unlock an upgrade.
|
* Unlock an upgrade.npm run doc
|
||||||
* @param upgradeName - Name of the upgrade
|
* @param upgradeName - Name of the upgrade
|
||||||
*/
|
*/
|
||||||
unlockUpgrade(upgradeName: string): void;
|
unlockUpgrade(upgradeName: string): void;
|
||||||
|
Loading…
Reference in New Issue
Block a user