mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 10:03:48 +01:00
Unify code paths for buying coffee and throwing parties
This commit is contained in:
parent
1ba5902e1e
commit
ffaa38d086
@ -333,14 +333,21 @@ export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size:
|
||||
corp.funds = corp.funds - cost;
|
||||
}
|
||||
|
||||
export function BuyCoffee(corp: ICorporation, office: OfficeSpace): void {
|
||||
const cost = 500e3 * office.employees.length;
|
||||
if (corp.funds < cost) { return; }
|
||||
|
||||
if (!office.setCoffee()) { return; }
|
||||
corp.funds -= cost;
|
||||
}
|
||||
|
||||
export function ThrowParty(corp: ICorporation, office: OfficeSpace, costPerEmployee: number): number {
|
||||
const totalCost = costPerEmployee * office.employees.length;
|
||||
if (corp.funds < totalCost) return 0;
|
||||
corp.funds = corp.funds - totalCost;
|
||||
let mult = 0;
|
||||
for (let i = 0; i < office.employees.length; ++i) {
|
||||
mult = office.employees[i].throwParty(costPerEmployee);
|
||||
}
|
||||
const mult = 1 + costPerEmployee / 10e6;
|
||||
const cost = costPerEmployee * office.employees.length;
|
||||
if (corp.funds < cost) { return 0; }
|
||||
|
||||
if (!office.setParty(mult)) { return 0; }
|
||||
corp.funds -= cost;
|
||||
|
||||
return mult;
|
||||
}
|
||||
@ -372,17 +379,6 @@ export function UpgradeWarehouse(corp: ICorporation, division: IIndustry, wareho
|
||||
corp.funds = corp.funds - sizeUpgradeCost;
|
||||
}
|
||||
|
||||
export function BuyCoffee(corp: ICorporation, division: IIndustry, office: OfficeSpace): void {
|
||||
const upgrade = IndustryUpgrades[0];
|
||||
const cost = office.employees.length * upgrade[1];
|
||||
if (corp.funds < cost) return;
|
||||
corp.funds = corp.funds - cost;
|
||||
division.upgrade(upgrade, {
|
||||
corporation: corp,
|
||||
office: office,
|
||||
});
|
||||
}
|
||||
|
||||
export function HireAdVert(corp: ICorporation, division: IIndustry, office: OfficeSpace): void {
|
||||
const upgrade = IndustryUpgrades[1];
|
||||
const cost = upgrade[1] * Math.pow(upgrade[2], division.upgrades[1]);
|
||||
|
@ -58,8 +58,8 @@ export class Employee {
|
||||
|
||||
//Returns the amount the employee needs to be paid
|
||||
process(marketCycles = 1, office: OfficeSpace): number {
|
||||
const gain = 0.003 * marketCycles,
|
||||
det = gain * Math.random();
|
||||
const gain = 0.003 * marketCycles;
|
||||
const det = gain * Math.random();
|
||||
this.exp += gain;
|
||||
|
||||
//Training
|
||||
@ -74,12 +74,6 @@ export class Employee {
|
||||
this.ene -= det;
|
||||
this.hap -= det;
|
||||
|
||||
if (this.ene < office.minEne) {
|
||||
this.ene = office.minEne;
|
||||
}
|
||||
if (this.hap < office.minHap) {
|
||||
this.hap = office.minHap;
|
||||
}
|
||||
const salary = this.sal * marketCycles * CorporationConstants.SecsPerMarketCycle;
|
||||
return salary;
|
||||
}
|
||||
@ -120,16 +114,6 @@ export class Employee {
|
||||
return prodBase * prodMult;
|
||||
}
|
||||
|
||||
//Process benefits from having an office party thrown
|
||||
throwParty(money: number): number {
|
||||
const mult = 1 + money / 10e6;
|
||||
this.mor *= mult;
|
||||
this.mor = Math.min(100, this.mor);
|
||||
this.hap *= mult;
|
||||
this.hap = Math.min(100, this.hap);
|
||||
return mult;
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("Employee", this);
|
||||
}
|
||||
|
@ -15,11 +15,20 @@ interface IParams {
|
||||
export class OfficeSpace {
|
||||
loc: string;
|
||||
size: number;
|
||||
|
||||
minEne = 0;
|
||||
maxEne = 100;
|
||||
minHap = 0;
|
||||
minMor = 0;
|
||||
|
||||
maxEne = 100;
|
||||
maxHap = 100;
|
||||
maxMor = 100;
|
||||
|
||||
autoCoffee = false;
|
||||
autoParty = false;
|
||||
coffeeMult = 0;
|
||||
partyMult = 0;
|
||||
|
||||
employees: Employee[] = [];
|
||||
employeeProd: { [key: string]: number } = {
|
||||
[EmployeePositions.Operations]: 0,
|
||||
@ -66,11 +75,8 @@ export class OfficeSpace {
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.employees.length; ++i) {
|
||||
const emp = this.employees[i];
|
||||
emp.pos = emp.nextPos;
|
||||
}
|
||||
|
||||
// Update employee jobs and job counts
|
||||
for (const employee of this.employees) { employee.pos = employee.nextPos; }
|
||||
this.calculateTotalEmployees();
|
||||
this.calculateNextEmployees();
|
||||
|
||||
@ -78,6 +84,7 @@ export class OfficeSpace {
|
||||
this.maxEne = 100;
|
||||
this.maxHap = 100;
|
||||
this.maxMor = 100;
|
||||
|
||||
if (industry.hasResearch("Go-Juice")) {
|
||||
this.maxEne += 10;
|
||||
}
|
||||
@ -87,6 +94,12 @@ export class OfficeSpace {
|
||||
if (industry.hasResearch("Sti.mu")) {
|
||||
this.maxMor += 10;
|
||||
}
|
||||
if (industry.hasResearch("AutoBrew")) {
|
||||
this.autoCoffee = true;
|
||||
}
|
||||
if (industry.hasResearch("AutoPartyManager")) {
|
||||
this.autoParty = true;
|
||||
}
|
||||
|
||||
// Calculate changes in Morale/Happiness/Energy for Employees
|
||||
let perfMult = 1; //Multiplier for employee morale/happiness/energy based on company performance
|
||||
@ -96,35 +109,40 @@ export class OfficeSpace {
|
||||
perfMult = Math.pow(1.01, marketCycles);
|
||||
}
|
||||
|
||||
const hasAutobrew = industry.hasResearch("AutoBrew");
|
||||
const hasAutoparty = industry.hasResearch("AutoPartyManager");
|
||||
let totalSalary = 0;
|
||||
for (const employee of this.employees) {
|
||||
const salary = employee.process(marketCycles, this);
|
||||
totalSalary += salary;
|
||||
|
||||
let salaryPaid = 0;
|
||||
for (let i = 0; i < this.employees.length; ++i) {
|
||||
const emp = this.employees[i];
|
||||
if (hasAutoparty) {
|
||||
emp.mor = this.maxMor;
|
||||
emp.hap = this.maxHap;
|
||||
if (this.autoCoffee) {
|
||||
employee.ene = this.maxEne;
|
||||
} else if (this.coffeeMult > 1) {
|
||||
employee.ene *= this.coffeeMult;
|
||||
} else {
|
||||
emp.mor *= perfMult;
|
||||
emp.hap *= perfMult;
|
||||
emp.mor = Math.min(emp.mor, this.maxMor);
|
||||
emp.hap = Math.min(emp.hap, this.maxHap);
|
||||
employee.ene *= perfMult;
|
||||
}
|
||||
|
||||
if (hasAutobrew) {
|
||||
emp.ene = this.maxEne;
|
||||
if (this.autoParty) {
|
||||
employee.mor = this.maxMor;
|
||||
employee.hap = this.maxHap;
|
||||
} else if (this.partyMult > 1) {
|
||||
employee.mor *= this.partyMult;
|
||||
employee.hap *= this.partyMult;
|
||||
} else {
|
||||
emp.ene *= perfMult;
|
||||
emp.ene = Math.min(emp.ene, this.maxEne);
|
||||
employee.mor *= perfMult;
|
||||
employee.hap *= perfMult;
|
||||
}
|
||||
|
||||
const salary = emp.process(marketCycles, this);
|
||||
salaryPaid += salary;
|
||||
employee.ene = Math.max(Math.min(employee.ene, this.maxEne), this.minEne);
|
||||
employee.mor = Math.max(Math.min(employee.mor, this.maxMor), this.minMor);
|
||||
employee.hap = Math.max(Math.min(employee.hap, this.maxHap), this.minHap);
|
||||
}
|
||||
|
||||
this.coffeeMult = 0;
|
||||
this.partyMult = 0;
|
||||
|
||||
this.calculateEmployeeProductivity(corporation, industry);
|
||||
return salaryPaid;
|
||||
return totalSalary;
|
||||
}
|
||||
|
||||
calculateNextEmployees(): void {
|
||||
@ -227,6 +245,24 @@ export class OfficeSpace {
|
||||
return count === target;
|
||||
}
|
||||
|
||||
setCoffee(mult = 1.05): boolean {
|
||||
if (mult > 1 && this.coffeeMult === 0 && !this.autoCoffee) {
|
||||
this.coffeeMult = mult;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
setParty(mult: number): boolean {
|
||||
if (mult > 1 && this.partyMult === 0 && !this.autoParty) {
|
||||
this.partyMult = mult;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
toJSON(): any {
|
||||
return Generic_toJSON("OfficeSpace", this);
|
||||
}
|
||||
|
@ -36,10 +36,10 @@ import {
|
||||
AssignJob,
|
||||
AutoAssignJob,
|
||||
UpgradeOfficeSize,
|
||||
ThrowParty,
|
||||
PurchaseWarehouse,
|
||||
UpgradeWarehouse,
|
||||
BuyCoffee,
|
||||
ThrowParty,
|
||||
HireAdVert,
|
||||
MakeProduct,
|
||||
Research,
|
||||
@ -774,16 +774,18 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
|
||||
const divisionName = ctx.helper.string("divisionName", _divisionName);
|
||||
const cityName = ctx.helper.city("cityName", _cityName);
|
||||
const costPerEmployee = ctx.helper.number("costPerEmployee", _costPerEmployee);
|
||||
if (costPerEmployee < 0)
|
||||
|
||||
if (costPerEmployee < 0) {
|
||||
throw new Error("Invalid value for Cost Per Employee field! Must be numeric and greater than 0");
|
||||
const office = getOffice(divisionName, cityName);
|
||||
}
|
||||
|
||||
const corporation = getCorporation();
|
||||
return netscriptDelay(
|
||||
(60 * 1000) / (player.hacking_speed_mult * calculateIntelligenceBonus(player.intelligence, 1)),
|
||||
workerScript,
|
||||
).then(function () {
|
||||
const office = getOffice(divisionName, cityName);
|
||||
|
||||
return netscriptDelay(0, workerScript).then(function () {
|
||||
return Promise.resolve(ThrowParty(corporation, office, costPerEmployee));
|
||||
});
|
||||
//return ThrowParty(corporation, office, costPerEmployee)
|
||||
},
|
||||
buyCoffee:
|
||||
(ctx: NetscriptContext) =>
|
||||
@ -791,13 +793,14 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
|
||||
checkAccess(ctx, 8);
|
||||
const divisionName = ctx.helper.string("divisionName", _divisionName);
|
||||
const cityName = ctx.helper.city("cityName", _cityName);
|
||||
|
||||
const corporation = getCorporation();
|
||||
return netscriptDelay(
|
||||
(60 * 1000) / (player.hacking_speed_mult * calculateIntelligenceBonus(player.intelligence, 1)),
|
||||
workerScript,
|
||||
).then(function () {
|
||||
return Promise.resolve(BuyCoffee(corporation, getDivision(divisionName), getOffice(divisionName, cityName)));
|
||||
const office = getOffice(divisionName, cityName);
|
||||
|
||||
return netscriptDelay(0, workerScript).then(function () {
|
||||
return Promise.resolve(BuyCoffee(corporation, office));
|
||||
});
|
||||
//BuyCoffee(corporation, getOffice(divisionName, cityName);
|
||||
},
|
||||
hireAdVert:
|
||||
(ctx: NetscriptContext) =>
|
||||
@ -829,6 +832,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript
|
||||
maxEne: office.maxEne,
|
||||
minHap: office.minHap,
|
||||
maxHap: office.maxHap,
|
||||
minMor: office.minMor,
|
||||
maxMor: office.maxMor,
|
||||
employees: office.employees.map((e) => e.name),
|
||||
employeeProd: {
|
||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -7222,6 +7222,8 @@ interface Office {
|
||||
minHap: number;
|
||||
/** Maximum happiness of the employees */
|
||||
maxHap: number;
|
||||
/** Minimum morale of the employees */
|
||||
minMor: number;
|
||||
/** Maximum morale of the employees */
|
||||
maxMor: number;
|
||||
/** Name of all the employees */
|
||||
|
Loading…
Reference in New Issue
Block a user