Validate city name coming from netscript

This commit is contained in:
Olivier Gagnon
2022-03-30 11:34:03 -04:00
parent ab93cfa887
commit 98ae97afea
5 changed files with 70 additions and 53 deletions
+24 -17
View File
@@ -1,5 +1,5 @@
import { IPlayer } from 'src/PersonObjects/IPlayer';
import { MaterialSizes } from './MaterialSizes';
import { IPlayer } from "src/PersonObjects/IPlayer";
import { MaterialSizes } from "./MaterialSizes";
import { ICorporation } from "./ICorporation";
import { IIndustry } from "./IIndustry";
import { IndustryStartingCosts, IndustryResearchTrees } from "./IndustryData";
@@ -17,6 +17,7 @@ import { Employee } from "./Employee";
import { IndustryUpgrades } from "./IndustryUpgrades";
import { ResearchMap } from "./ResearchMap";
import { isRelevantMaterial } from "./ui/Helpers";
import { CityName } from "src/Locations/data/CityNames";
export function NewIndustry(corporation: ICorporation, industry: string, name: string): void {
if (corporation.divisions.find(({ type }) => industry == type))
@@ -64,7 +65,7 @@ export function UnlockUpgrade(corporation: ICorporation, upgrade: CorporationUnl
if (corporation.funds < upgrade[1]) {
throw new Error("Insufficient funds");
}
if(corporation.unlockUpgrades[upgrade[0]] === 1){
if (corporation.unlockUpgrades[upgrade[0]] === 1) {
throw new Error(`You have already unlocked the ${upgrade[2]} upgrade!`);
}
corporation.unlock(upgrade);
@@ -222,15 +223,15 @@ export function SellProduct(product: Product, city: string, amt: string, price:
product.sllman[city][1] = "";
}
} else if (all) {
for (let i = 0; i < cities.length; ++i) {
const tempCity = cities[i];
product.sllman[tempCity][0] = true;
product.sllman[tempCity][1] = qty;
}
} else {
product.sllman[city][0] = true;
product.sllman[city][1] = qty;
for (let i = 0; i < cities.length; ++i) {
const tempCity = cities[i];
product.sllman[tempCity][0] = true;
product.sllman[tempCity][1] = qty;
}
} else {
product.sllman[city][0] = true;
product.sllman[city][1] = qty;
}
}
}
@@ -295,7 +296,7 @@ export function BuyBackShares(corporation: ICorporation, player: IPlayer, numSha
if (numShares > corporation.issuedShares) throw new Error("You don't have that many shares to buy!");
if (!corporation.public) throw new Error("You haven't gone public!");
const buybackPrice = corporation.sharePrice * 1.1;
if (player.money < (numShares * buybackPrice)) throw new Error("You cant afford that many shares!");
if (player.money < numShares * buybackPrice) throw new Error("You cant afford that many shares!");
corporation.numShares += numShares;
corporation.issuedShares -= numShares;
player.loseMoney(numShares * buybackPrice, "corporation");
@@ -404,13 +405,13 @@ export function MakeProduct(
if (corp.funds < designInvest + marketingInvest) {
throw new Error("You don't have enough company funds to make this large of an investment");
}
let maxProducts = 3
let maxProducts = 3;
if (division.hasResearch("uPgrade: Capacity.II")) {
maxProducts = 5
maxProducts = 5;
} else if (division.hasResearch("uPgrade: Capacity.I")) {
maxProducts = 4
maxProducts = 4;
}
const products = division.products
const products = division.products;
if (Object.keys(products).length >= maxProducts) {
throw new Error(`You are already at the max products (${maxProducts}) for division: ${division.name}!`);
}
@@ -445,7 +446,13 @@ export function Research(division: IIndustry, researchName: string): void {
division.researched[researchName] = true;
}
export function ExportMaterial(divisionName: string, cityName: string, material: Material, amt: string, division?: Industry): void {
export function ExportMaterial(
divisionName: string,
cityName: string,
material: Material,
amt: string,
division?: Industry,
): void {
// Sanitize amt
let sanitizedAmt = amt.replace(/\s+/g, "").toUpperCase();
sanitizedAmt = sanitizedAmt.replace(/[^-()\d/*+.MAX]/g, "");