CORP: Validate city with office for product development (#579)

This commit is contained in:
Snarling 2023-06-07 00:30:10 -04:00 committed by GitHub
parent cbff2a420b
commit c67f32cdc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

@ -386,11 +386,12 @@ export function MakeProduct(
designInvest: number, designInvest: number,
marketingInvest: number, marketingInvest: number,
): void { ): void {
if (designInvest < 0) { // For invalid investment inputs, just use 0
designInvest = 0; if (isNaN(designInvest) || designInvest < 0) designInvest = 0;
} if (isNaN(marketingInvest) || marketingInvest < 0) marketingInvest = 0;
if (marketingInvest < 0) {
marketingInvest = 0; if (!division.offices[city]) {
throw new Error(`Cannot develop a product in a city without an office!`);
} }
if (productName == null || productName === "") { if (productName == null || productName === "") {
throw new Error("You must specify a name for your product!"); throw new Error("You must specify a name for your product!");
@ -398,12 +399,6 @@ export function MakeProduct(
if (!division.makesProducts) { if (!division.makesProducts) {
throw new Error("You cannot create products for this industry!"); throw new Error("You cannot create products for this industry!");
} }
if (isNaN(designInvest)) {
throw new Error("Invalid value for design investment");
}
if (isNaN(marketingInvest)) {
throw new Error("Invalid value for marketing investment");
}
if (corp.funds < designInvest + marketingInvest) { if (corp.funds < designInvest + marketingInvest) {
throw new Error("You don't have enough company funds to make this large of an investment"); throw new Error("You don't have enough company funds to make this large of an investment");
} }
@ -412,7 +407,7 @@ export function MakeProduct(
} }
const product = new Product({ const product = new Product({
name: productName.replace(/[<>]/g, "").trim(), //Sanitize for HTMl elements name: productName.replace(/[<>]/g, "").trim(), //Sanitize for HTMl elements?
createCity: city, createCity: city,
designInvestment: designInvest, designInvestment: designInvest,
advertisingInvestment: marketingInvest, advertisingInvestment: marketingInvest,

@ -713,8 +713,10 @@ export class Division {
if (this.state !== "PRODUCTION") continue; if (this.state !== "PRODUCTION") continue;
const city = product.creationCity; const city = product.creationCity;
const office = this.offices[city]; const office = this.offices[city];
if (!office) throw new Error(`Product ${name} being created in a city without an office. This is a bug.`); if (!office) {
console.error(`Product ${name} being created in a city without an office. This is a bug.`);
continue;
}
product.createProduct(marketCycles, office.employeeProductionByJob); product.createProduct(marketCycles, office.employeeProductionByJob);
if (product.developmentProgress >= 100) { if (product.developmentProgress >= 100) {
product.finishProduct(this); product.finishProduct(this);