-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcorp-truxican.js
129 lines (124 loc) · 4.74 KB
/
corp-truxican.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Reassigns your employees to the jobs they're best suited for, while maintaining the same number of employees in each position.
class Employee {
constructor(ns, division, city, name) {
this.ns = ns;
this.division = division;
this.city = city;
this.name = name;
}
get int() {
let c = eval("this.ns.corporation");
return c.getEmployee(this.division, this.city, this.name).int * (1 + .1 * c.getUpgradeLevel("Neural Accelerators")) * (c.hasResearched(this.division, "Overclock") ? 1.25 : 1) * (c.hasResearched(this.division, "CPH4 Injections") ? 1.1 : 1);
}
get eff() {
let c = eval("this.ns.corporation");
return c.getEmployee(this.division, this.city, this.name).eff * (1 + .1 * c.getUpgradeLevel("FocusWires")) * (c.hasResearched(this.division, "Overclock") ? 1.25 : 1) * (c.hasResearched(this.division, "CPH4 Injections") ? 1.1 : 1);
}
get cre() {
let c = eval("this.ns.corporation");
return c.getEmployee(this.division, this.city, this.name).cre * (1 + .1 * c.getUpgradeLevel("Nuoptimal Nootropic Injector Implants")) * (c.hasResearched(this.division, "CPH4 Injections") ? 1.1 : 1);
}
get cha() {
let c = eval("this.ns.corporation");
return c.getEmployee(this.division, this.city, this.name).cha * (1 + .1 * c.getUpgradeLevel("Speech Processor Implants")) * (c.hasResearched(this.division, "CPH4 Injections") ? 1.1 : 1);
}
get exp() {
let c = eval("this.ns.corporation");
return c.getEmployee(this.division, this.city, this.name).exp;
}
get operations() {
return this.int * .6 + this.cha * .1 + this.exp + this.cre * .5 + this.eff;
}
get engineer() {
return this.int + this.cha * .1 + this.exp * 1.5 + this.eff;
}
get business() {
return this.int * .4 + this.cha + this.exp * .5;
}
get management() {
return this.cha * 2 + this.exp + this.cre * .2 + this.eff * .7;
}
get researchanddevelopment() {
return this.int * 1.5 + this.exp * .8 + this.cre + this.eff * .5;
}
get training() {
return 0;
}
get unassigned() {
return 0;
}
get jobs() {
return {
"Operations": this.operations,
"Business": this.business,
"Engineer": this.engineer,
"Management": this.management,
"Research & Development": this.researchanddevelopment,
"Unassigned": this.unassigned,
"Training": this.training
}
}
}
export class Office {
constructor(ns, division, city) {
this.ns = ns;
this.division = division;
this.city = city;
}
async truxican() {
let c = eval("this.ns.corporation");
let answer = {};
let currentjobs = {
"Operations": 0,
"Business": 0,
"Engineer": 0,
"Management": 0,
"Research & Development": 0,
"Unassigned": 0,
"Training": 0
}
while (c.getCorporation().state === "START")
await this.ns.sleep(0);
while (c.getCorporation().state != "START")
await this.ns.sleep(0);
for (let employee of c.getOffice(this.division, this.city).employees) {
answer[employee] = new Employee(this.ns, this.division, this.city, employee).jobs;
currentjobs[c.getEmployee(this.division, this.city, employee).pos] += 1;
await this.ns.sleep(0);
}
let ranges = {}
let final = [];
for (let role of ["Operations", "Business", "Engineer", "Management", "Research & Development", "Unassigned", "Training"]) {
if (currentjobs[role] > 0) {
ranges[role] = [Object.keys(answer).map(x => answer[x][role]).reduce((a, b) => { return a <= b ? a : b }), Object.keys(answer).map(x => answer[x][role]).reduce((a, b) => { return a >= b ? a : b })]
for (let employee of c.getOffice(this.division, this.city).employees) {
if (ranges[role][0] == ranges[role][1]) {
final.push([0, 0, employee, role]);
} else {
final.push([(answer[employee][role] - ranges[role][0]) / (ranges[role][1] - ranges[role][0]), answer[employee][role], employee, role]);
}
}
}
}
final = final.sort((a, b) => { if (a[0] == b[0]) return a[1] - b[1]; return a[0] - b[0]; });
while (final.length > 0) {
if (currentjobs[final[final.length - 1][3]] > 0) {
if (c.getEmployee(this.division, this.city, final[final.length - 1][2]).pos != final[final.length - 1][3]) {
//this.ns.tprint(this.division, " ", this.city, " ", final[final.length-1][2], ": ", c.getEmployee(this.division, this.city, final[final.length-1][2]).pos, " -> ", final[final.length-1][3]);
}
c.assignJob(this.division, this.city, final[final.length - 1][2], final[final.length - 1][3]);
currentjobs[final[final.length - 1][3]] -= 1;
final = final.filter(x => x[2] != final[final.length - 1][2]);
} else {
final = final.filter(x => x[3] != final[final.length - 1][3]);
}
await this.ns.sleep(0);
}
}
}
/*
export async function main(ns) {
const CorpApi = eval("ns.corporation")
while (CorpApi.getCorporation().state != "START") { await ns.sleep(10) }
await (new Office(ns, ns.args[0], ns.args[1]).truxican());
}*/