mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 10:03:48 +01:00
few more adjustments
* fixed the export material fix * changed teh dev menu fund adjuster for more granular control * added checks for smartSupply and setSmartSupply * few random autolints
This commit is contained in:
parent
51d10290d2
commit
3e36e6a80b
@ -14,6 +14,7 @@ import { EmployeePositions } from "./EmployeePositions";
|
|||||||
import { Employee } from "./Employee";
|
import { Employee } from "./Employee";
|
||||||
import { IndustryUpgrades } from "./IndustryUpgrades";
|
import { IndustryUpgrades } from "./IndustryUpgrades";
|
||||||
import { ResearchMap } from "./ResearchMap";
|
import { ResearchMap } from "./ResearchMap";
|
||||||
|
import { isRelevantMaterial } from "./ui/Helpers";
|
||||||
|
|
||||||
export function NewIndustry(corporation: ICorporation, industry: string, name: string): void {
|
export function NewIndustry(corporation: ICorporation, industry: string, name: string): void {
|
||||||
for (let i = 0; i < corporation.divisions.length; ++i) {
|
for (let i = 0; i < corporation.divisions.length; ++i) {
|
||||||
@ -384,7 +385,7 @@ export function Research(division: IIndustry, researchName: string): void {
|
|||||||
division.researched[researchName] = true;
|
division.researched[researchName] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExportMaterial(divisionName: string, cityName: string, material: Material, amt: string, warehouse?: Warehouse | 0): void {
|
export function ExportMaterial(divisionName: string, cityName: string, material: Material, amt: string, division?: Industry): void {
|
||||||
// Sanitize amt
|
// Sanitize amt
|
||||||
let sanitizedAmt = amt.replace(/\s+/g, "").toUpperCase();
|
let sanitizedAmt = amt.replace(/\s+/g, "").toUpperCase();
|
||||||
sanitizedAmt = sanitizedAmt.replace(/[^-()\d/*+.MAX]/g, "");
|
sanitizedAmt = sanitizedAmt.replace(/[^-()\d/*+.MAX]/g, "");
|
||||||
@ -401,7 +402,7 @@ export function ExportMaterial(divisionName: string, cityName: string, material:
|
|||||||
throw new Error("Invalid amount entered for export");
|
throw new Error("Invalid amount entered for export");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!warehouse || !warehouse.materials.hasOwnProperty(material.name)) {
|
if (!division || !isRelevantMaterial(material.name, division)) {
|
||||||
throw new Error(`You cannot export material: ${material.name} to division: ${divisionName}!`);
|
throw new Error(`You cannot export material: ${material.name} to division: ${divisionName}!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +50,7 @@ export function ExportModal(props: IProps): React.ReactElement {
|
|||||||
|
|
||||||
function exportMaterial(): void {
|
function exportMaterial(): void {
|
||||||
try {
|
try {
|
||||||
const warehouse = currentDivision && currentDivision.warehouses.first
|
ExportMaterial(industry, city, props.mat, amt, currentDivision);
|
||||||
ExportMaterial(industry, city, props.mat, amt, warehouse);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
dialogBoxCreate(err + "");
|
dialogBoxCreate(err + "");
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,18 @@ interface IProps {
|
|||||||
export function Corporation(props: IProps): React.ReactElement {
|
export function Corporation(props: IProps): React.ReactElement {
|
||||||
function addTonsCorporationFunds(): void {
|
function addTonsCorporationFunds(): void {
|
||||||
if (props.player.corporation) {
|
if (props.player.corporation) {
|
||||||
props.player.corporation.funds = props.player.corporation.funds + 1e99;
|
props.player.corporation.funds = props.player.corporation.funds + bigNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function modifyCorporationFunds(modify: number): (x: number) => void {
|
||||||
|
return function (funds: number): void {
|
||||||
|
if (props.player.corporation) {
|
||||||
|
props.player.corporation.funds += funds * modify;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function resetCorporationFunds(): void {
|
function resetCorporationFunds(): void {
|
||||||
if (props.player.corporation) {
|
if (props.player.corporation) {
|
||||||
props.player.corporation.funds = props.player.corporation.funds - props.player.corporation.funds;
|
props.player.corporation.funds = props.player.corporation.funds - props.player.corporation.funds;
|
||||||
@ -77,8 +85,17 @@ export function Corporation(props: IProps): React.ReactElement {
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<Button onClick={addTonsCorporationFunds}>Tons of funds</Button>
|
<Typography>Funds:</Typography>
|
||||||
<Button onClick={resetCorporationFunds}>Reset funds</Button>
|
</td>
|
||||||
|
<td>
|
||||||
|
<Adjuster
|
||||||
|
label="set funds"
|
||||||
|
placeholder="amt"
|
||||||
|
tons={addTonsCorporationFunds}
|
||||||
|
add={modifyCorporationFunds(1)}
|
||||||
|
subtract={modifyCorporationFunds(-1)}
|
||||||
|
reset={resetCorporationFunds}
|
||||||
|
/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -193,7 +193,7 @@ export function NetscriptCorporation(
|
|||||||
|
|
||||||
function bribe(factionName: string, amountCash: number, amountShares: number): boolean {
|
function bribe(factionName: string, amountCash: number, amountShares: number): boolean {
|
||||||
if (!player.factions.includes(factionName)) throw new Error("Invalid faction name");
|
if (!player.factions.includes(factionName)) throw new Error("Invalid faction name");
|
||||||
if (isNaN(amountCash) || amountCash < 0 || isNaN(amountShares) || amountShares < 0) throw new Error("Invalid value for amount field! Must be numeric, grater than 0.");
|
if (isNaN(amountCash) || amountCash < 0 || isNaN(amountShares) || amountShares < 0) throw new Error("Invalid value for amount field! Must be numeric, grater than 0.");
|
||||||
const corporation = getCorporation();
|
const corporation = getCorporation();
|
||||||
if (corporation.funds < amountCash) return false;
|
if (corporation.funds < amountCash) return false;
|
||||||
if (corporation.numShares < amountShares) return false;
|
if (corporation.numShares < amountShares) return false;
|
||||||
@ -271,25 +271,25 @@ export function NetscriptCorporation(
|
|||||||
|
|
||||||
function getSafeDivision(division: Industry): NSDivision {
|
function getSafeDivision(division: Industry): NSDivision {
|
||||||
const cities: string[] = [];
|
const cities: string[] = [];
|
||||||
for (const office of Object.values(division.offices)) {
|
for (const office of Object.values(division.offices)) {
|
||||||
if (office === 0) continue;
|
if (office === 0) continue;
|
||||||
cities.push(office.loc);
|
cities.push(office.loc);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
name: division.name,
|
name: division.name,
|
||||||
type: division.type,
|
type: division.type,
|
||||||
awareness: division.awareness,
|
awareness: division.awareness,
|
||||||
popularity: division.popularity,
|
popularity: division.popularity,
|
||||||
prodMult: division.prodMult,
|
prodMult: division.prodMult,
|
||||||
research: division.sciResearch.qty,
|
research: division.sciResearch.qty,
|
||||||
lastCycleRevenue: division.lastCycleRevenue,
|
lastCycleRevenue: division.lastCycleRevenue,
|
||||||
lastCycleExpenses: division.lastCycleExpenses,
|
lastCycleExpenses: division.lastCycleExpenses,
|
||||||
thisCycleRevenue: division.thisCycleRevenue,
|
thisCycleRevenue: division.thisCycleRevenue,
|
||||||
thisCycleExpenses: division.thisCycleExpenses,
|
thisCycleExpenses: division.thisCycleExpenses,
|
||||||
upgrades: division.upgrades,
|
upgrades: division.upgrades,
|
||||||
cities: cities,
|
cities: cities,
|
||||||
products: division.products === undefined ? [] : Object.keys(division.products),
|
products: division.products === undefined ? [] : Object.keys(division.products),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const warehouseAPI: WarehouseAPI = {
|
const warehouseAPI: WarehouseAPI = {
|
||||||
@ -409,6 +409,8 @@ export function NetscriptCorporation(
|
|||||||
const cityName = helper.string("sellProduct", "cityName", acityName);
|
const cityName = helper.string("sellProduct", "cityName", acityName);
|
||||||
const enabled = helper.boolean(aenabled);
|
const enabled = helper.boolean(aenabled);
|
||||||
const warehouse = getWarehouse(divisionName, cityName);
|
const warehouse = getWarehouse(divisionName, cityName);
|
||||||
|
if (!hasUnlockUpgrade("SmartSupply"))
|
||||||
|
throw helper.makeRuntimeErrorMsg(`corporation.setSmartSupply`, `You have not purchased the SmartSupply upgrade!`);
|
||||||
SetSmartSupply(warehouse, enabled);
|
SetSmartSupply(warehouse, enabled);
|
||||||
},
|
},
|
||||||
setSmartSupplyUseLeftovers: function (adivisionName: any, acityName: any, amaterialName: any, aenabled: any): void {
|
setSmartSupplyUseLeftovers: function (adivisionName: any, acityName: any, amaterialName: any, aenabled: any): void {
|
||||||
@ -419,6 +421,8 @@ export function NetscriptCorporation(
|
|||||||
const enabled = helper.boolean(aenabled);
|
const enabled = helper.boolean(aenabled);
|
||||||
const warehouse = getWarehouse(divisionName, cityName);
|
const warehouse = getWarehouse(divisionName, cityName);
|
||||||
const material = getMaterial(divisionName, cityName, materialName);
|
const material = getMaterial(divisionName, cityName, materialName);
|
||||||
|
if (!hasUnlockUpgrade("SmartSupply"))
|
||||||
|
throw helper.makeRuntimeErrorMsg(`corporation.setSmartSupply`, `You have not purchased the SmartSupply upgrade!`);
|
||||||
SetSmartSupplyUseLeftovers(warehouse, material, enabled);
|
SetSmartSupplyUseLeftovers(warehouse, material, enabled);
|
||||||
},
|
},
|
||||||
buyMaterial: function (adivisionName: any, acityName: any, amaterialName: any, aamt: any): void {
|
buyMaterial: function (adivisionName: any, acityName: any, amaterialName: any, aamt: any): void {
|
||||||
@ -462,7 +466,7 @@ export function NetscriptCorporation(
|
|||||||
const targetCity = helper.string("exportMaterial", "targetCity", atargetCity);
|
const targetCity = helper.string("exportMaterial", "targetCity", atargetCity);
|
||||||
const materialName = helper.string("exportMaterial", "materialName", amaterialName);
|
const materialName = helper.string("exportMaterial", "materialName", amaterialName);
|
||||||
const amt = helper.string("exportMaterial", "amt", aamt);
|
const amt = helper.string("exportMaterial", "amt", aamt);
|
||||||
ExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt + "", getWarehouse(targetDivision,targetCity));
|
ExportMaterial(targetDivision, targetCity, getMaterial(sourceDivision, sourceCity, materialName), amt + "", getDivision(targetDivision));
|
||||||
},
|
},
|
||||||
cancelExportMaterial: function (
|
cancelExportMaterial: function (
|
||||||
asourceDivision: any,
|
asourceDivision: any,
|
||||||
@ -489,7 +493,7 @@ export function NetscriptCorporation(
|
|||||||
const on = helper.boolean(aon);
|
const on = helper.boolean(aon);
|
||||||
if (!getDivision(divisionName).hasResearch("Market-TA.I"))
|
if (!getDivision(divisionName).hasResearch("Market-TA.I"))
|
||||||
throw helper.makeRuntimeErrorMsg(`corporation.setMaterialMarketTA1`, `You have not researched MarketTA.I for division: ${divisionName}`);
|
throw helper.makeRuntimeErrorMsg(`corporation.setMaterialMarketTA1`, `You have not researched MarketTA.I for division: ${divisionName}`);
|
||||||
SetMaterialMarketTA1( getMaterial(divisionName, cityName, materialName), on);
|
SetMaterialMarketTA1(getMaterial(divisionName, cityName, materialName), on);
|
||||||
},
|
},
|
||||||
setMaterialMarketTA2: function (adivisionName: any, acityName: any, amaterialName: any, aon: any): void {
|
setMaterialMarketTA2: function (adivisionName: any, acityName: any, amaterialName: any, aon: any): void {
|
||||||
checkAccess("setMaterialMarketTA2", 7);
|
checkAccess("setMaterialMarketTA2", 7);
|
||||||
@ -516,7 +520,7 @@ export function NetscriptCorporation(
|
|||||||
const productName = helper.string("setProductMarketTA2", "productName", aproductName);
|
const productName = helper.string("setProductMarketTA2", "productName", aproductName);
|
||||||
const on = helper.boolean(aon);
|
const on = helper.boolean(aon);
|
||||||
if (!getDivision(divisionName).hasResearch("Market-TA.II"))
|
if (!getDivision(divisionName).hasResearch("Market-TA.II"))
|
||||||
throw helper.makeRuntimeErrorMsg(`corporation.setMaterialMarketTA2`, `You have not researched MarketTA.II for division: ${divisionName}`);
|
throw helper.makeRuntimeErrorMsg(`corporation.setProductMarketTA2`, `You have not researched MarketTA.II for division: ${divisionName}`);
|
||||||
SetProductMarketTA2(getProduct(divisionName, productName), on);
|
SetProductMarketTA2(getProduct(divisionName, productName), on);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -731,6 +735,8 @@ export function NetscriptCorporation(
|
|||||||
const percent = helper.number("issueDividends", "percent", apercent);
|
const percent = helper.number("issueDividends", "percent", apercent);
|
||||||
if (percent < 0 || percent > 100) throw new Error("Invalid value for percent field! Must be numeric, grater than 0, and less than 100");
|
if (percent < 0 || percent > 100) throw new Error("Invalid value for percent field! Must be numeric, grater than 0, and less than 100");
|
||||||
const corporation = getCorporation();
|
const corporation = getCorporation();
|
||||||
|
if (!corporation.public)
|
||||||
|
throw helper.makeRuntimeErrorMsg(`corporation.issueDividends`, `Your company has not gone public!`);
|
||||||
IssueDividends(corporation, percent);
|
IssueDividends(corporation, percent);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -789,24 +795,24 @@ export function NetscriptCorporation(
|
|||||||
const industryName = helper.string("getExpandIndustryCost", "industryName", aindustryName);
|
const industryName = helper.string("getExpandIndustryCost", "industryName", aindustryName);
|
||||||
return getExpandIndustryCost(industryName);
|
return getExpandIndustryCost(industryName);
|
||||||
},
|
},
|
||||||
getExpandCityCost: function(): number {
|
getExpandCityCost: function (): number {
|
||||||
checkAccess("getExpandCityCost");
|
checkAccess("getExpandCityCost");
|
||||||
return getExpandCityCost();
|
return getExpandCityCost();
|
||||||
},
|
},
|
||||||
getInvestmentOffer: function(): InvestmentOffer {
|
getInvestmentOffer: function (): InvestmentOffer {
|
||||||
checkAccess("getInvestmentOffer");
|
checkAccess("getInvestmentOffer");
|
||||||
return getInvestmentOffer();
|
return getInvestmentOffer();
|
||||||
},
|
},
|
||||||
acceptInvestmentOffer: function(): boolean {
|
acceptInvestmentOffer: function (): boolean {
|
||||||
checkAccess("acceptInvestmentOffer");
|
checkAccess("acceptInvestmentOffer");
|
||||||
return acceptInvestmentOffer();
|
return acceptInvestmentOffer();
|
||||||
},
|
},
|
||||||
goPublic: function(anumShares: any): boolean {
|
goPublic: function (anumShares: any): boolean {
|
||||||
checkAccess("acceptInvestmentOffer");
|
checkAccess("acceptInvestmentOffer");
|
||||||
const numShares = helper.number("goPublic", "numShares", anumShares);
|
const numShares = helper.number("goPublic", "numShares", anumShares);
|
||||||
return goPublic(numShares);
|
return goPublic(numShares);
|
||||||
},
|
},
|
||||||
bribe: function(afactionName: string, aamountCash: any, aamountShares: any): boolean {
|
bribe: function (afactionName: string, aamountCash: any, aamountShares: any): boolean {
|
||||||
checkAccess("bribe");
|
checkAccess("bribe");
|
||||||
const factionName = helper.string("bribe", "factionName", afactionName);
|
const factionName = helper.string("bribe", "factionName", afactionName);
|
||||||
const amountCash = helper.number("bribe", "amountCash", aamountCash);
|
const amountCash = helper.number("bribe", "amountCash", aamountCash);
|
||||||
|
Loading…
Reference in New Issue
Block a user