mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-10 09:43:54 +01:00
applyForJob streamline and fix logic
This commit is contained in:
parent
69781359d5
commit
759c57b29a
@ -569,7 +569,7 @@ export function processWorkEarnings(this: IPlayer, numCycles = 1): void {
|
|||||||
|
|
||||||
/* Working for Company */
|
/* Working for Company */
|
||||||
export function startWork(this: IPlayer, companyName: string): void {
|
export function startWork(this: IPlayer, companyName: string): void {
|
||||||
this.resetWorkStatus(CONSTANTS.WorkTypeCompany, companyName);
|
if (this.isWorking) this.resetWorkStatus(CONSTANTS.WorkTypeCompany, companyName);
|
||||||
this.isWorking = true;
|
this.isWorking = true;
|
||||||
this.companyName = companyName;
|
this.companyName = companyName;
|
||||||
this.workType = CONSTANTS.WorkTypeCompany;
|
this.workType = CONSTANTS.WorkTypeCompany;
|
||||||
@ -1747,14 +1747,6 @@ export function hospitalize(this: IPlayer): number {
|
|||||||
//The 'sing' argument designates whether or not this is being called from
|
//The 'sing' argument designates whether or not this is being called from
|
||||||
//the applyToCompany() Netscript Singularity function
|
//the applyToCompany() Netscript Singularity function
|
||||||
export function applyForJob(this: IPlayer, entryPosType: CompanyPosition, sing = false): boolean {
|
export function applyForJob(this: IPlayer, entryPosType: CompanyPosition, sing = false): boolean {
|
||||||
// Get current company and job
|
|
||||||
let currCompany = null;
|
|
||||||
if (this.companyName !== "") {
|
|
||||||
currCompany = Companies[this.companyName];
|
|
||||||
}
|
|
||||||
const currPositionName = this.jobs[this.companyName];
|
|
||||||
|
|
||||||
// Get company that's being applied to
|
|
||||||
const company = Companies[this.location]; //Company being applied to
|
const company = Companies[this.location]; //Company being applied to
|
||||||
if (!(company instanceof Company)) {
|
if (!(company instanceof Company)) {
|
||||||
console.error(`Could not find company that matches the location: ${this.location}. Player.applyToCompany() failed`);
|
console.error(`Could not find company that matches the location: ${this.location}. Player.applyToCompany() failed`);
|
||||||
@ -1764,66 +1756,44 @@ export function applyForJob(this: IPlayer, entryPosType: CompanyPosition, sing =
|
|||||||
let pos = entryPosType;
|
let pos = entryPosType;
|
||||||
|
|
||||||
if (!this.isQualified(company, pos)) {
|
if (!this.isQualified(company, pos)) {
|
||||||
const reqText = getJobRequirementText(company, pos);
|
|
||||||
if (!sing) {
|
if (!sing) {
|
||||||
dialogBoxCreate("Unfortunately, you do not qualify for this position<br>" + reqText);
|
dialogBoxCreate("Unfortunately, you do not qualify for this position<br>" + getJobRequirementText(company, pos));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this company has the position
|
|
||||||
if (!company.hasPosition(pos)) {
|
if (!company.hasPosition(pos)) {
|
||||||
|
console.error(`Company ${company.name} does not have position ${pos}. Player.applyToCompany() failed`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const newPos = getNextCompanyPositionHelper(pos);
|
const nextPos = getNextCompanyPositionHelper(pos);
|
||||||
if (newPos == null) {
|
if (nextPos == null) break;
|
||||||
break;
|
if (company.hasPosition(nextPos) && this.isQualified(company, nextPos)) {
|
||||||
}
|
pos = nextPos;
|
||||||
|
} else break;
|
||||||
//Check if this company has this position
|
|
||||||
if (company.hasPosition(newPos)) {
|
|
||||||
if (!this.isQualified(company, newPos)) {
|
|
||||||
//If player not qualified for next job, break loop so player will be given current job
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pos = newPos;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if the determined job is the same as the player's current job
|
if (this.jobs[company.name] === pos.name) {
|
||||||
if (currCompany != null) {
|
//if the player already has this job with this employer
|
||||||
if (currCompany.name == company.name && pos.name == currPositionName) {
|
if (!sing) {
|
||||||
const nextPos = getNextCompanyPositionHelper(pos);
|
const nextPos = getNextCompanyPositionHelper(pos);
|
||||||
if (nextPos == null) {
|
if (nextPos == null || !company.hasPosition(nextPos)) {
|
||||||
if (!sing) {
|
dialogBoxCreate("You are already at the highest position for your field! No promotion available");
|
||||||
dialogBoxCreate("You are already at the highest position for your field! No promotion available");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else if (company.hasPosition(nextPos)) {
|
|
||||||
if (!sing) {
|
|
||||||
const reqText = getJobRequirementText(company, nextPos);
|
|
||||||
dialogBoxCreate("Unfortunately, you do not qualify for a promotion<br>" + reqText);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
if (!sing) {
|
const reqText = getJobRequirementText(company, nextPos);
|
||||||
dialogBoxCreate("You are already at the highest position for your field! No promotion available");
|
dialogBoxCreate("Unfortunately, you do not qualify for a promotion<br>" + reqText);
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.jobs[company.name] = pos.name;
|
this.jobs[company.name] = pos.name;
|
||||||
if (!this.focus && this.isWorking && this.companyName !== this.location) this.resetWorkStatus();
|
if (!this.isWorking) this.companyName = company.name;
|
||||||
this.companyName = this.location;
|
|
||||||
|
|
||||||
if (!sing) {
|
if (!sing) {
|
||||||
dialogBoxCreate("Congratulations! You were offered a new job at " + this.companyName + " as a " + pos.name + "!");
|
dialogBoxCreate("Congratulations! You were offered a new job at " + company.name + " as a " + pos.name + "!");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user