Merge pull request #2618 from pigalot/Corp-Api-Updates

Corp api updates
This commit is contained in:
hydroflame
2022-01-18 18:05:23 -05:00
committed by GitHub
60 changed files with 2749 additions and 89 deletions
+34
View File
@@ -173,6 +173,40 @@ export class OfficeSpace {
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 {
return Generic_toJSON("OfficeSpace", this);
}