CORPORATION: parse material Sell field once (#562)

This commit is contained in:
zerbosh 2023-06-04 16:28:35 +02:00 committed by GitHub
parent d8fee8e25a
commit bda1daf49f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -499,8 +499,8 @@ export class Division {
const adjustedQty = mat.stored / (corpConstants.secondsPerMarketCycle * marketCycles); const adjustedQty = mat.stored / (corpConstants.secondsPerMarketCycle * marketCycles);
if (isString(mat.desiredSellAmount)) { if (isString(mat.desiredSellAmount)) {
//Dynamically evaluated //Dynamically evaluated
let tmp = mat.desiredSellAmount.replace(/MAX/g, (adjustedQty + "").toUpperCase()); let tmp = mat.desiredSellAmount.replace(/MAX/g, adjustedQty.toString());
tmp = tmp.replace(/PROD/g, mat.productionAmount + ""); tmp = tmp.replace(/PROD/g, mat.productionAmount.toString());
try { try {
sellAmt = eval(tmp); sellAmt = eval(tmp);
} catch (e) { } catch (e) {
@ -550,7 +550,7 @@ export class Division {
} else if (mat.marketTa1) { } else if (mat.marketTa1) {
sCost = mat.marketPrice + markupLimit; sCost = mat.marketPrice + markupLimit;
} else if (isString(mat.desiredSellPrice)) { } else if (isString(mat.desiredSellPrice)) {
sCost = mat.desiredSellPrice.replace(/MP/g, mat.marketPrice + ""); sCost = mat.desiredSellPrice.replace(/MP/g, mat.marketPrice.toString());
sCost = eval(sCost); sCost = eval(sCost);
} else { } else {
sCost = mat.desiredSellPrice; sCost = mat.desiredSellPrice;
@ -581,25 +581,7 @@ export class Division {
corporation.getSalesMult() * corporation.getSalesMult() *
advertisingFactor * advertisingFactor *
this.getSalesMultiplier(); this.getSalesMultiplier();
if (isString(mat.desiredSellAmount)) {
//Dynamically evaluated
let tmp = mat.desiredSellAmount.replace(/MAX/g, (mat.maxSellPerCycle + "").toUpperCase());
tmp = tmp.replace(/PROD/g, mat.productionAmount + "");
try {
sellAmt = eval(tmp);
} catch (e) {
dialogBoxCreate(
`Error evaluating your sell amount for material ${mat.name} in ${this.name}'s ${city} office. The sell amount is being set to zero, sellAmt is set to ${sellAmt}`,
);
sellAmt = 0;
}
sellAmt = Math.min(mat.maxSellPerCycle, sellAmt);
sellAmt = Math.max(sellAmt, 0);
} else {
//Player's input value is just a number
sellAmt = Math.min(mat.maxSellPerCycle, mat.desiredSellAmount);
}
sellAmt = Math.min(mat.maxSellPerCycle, sellAmt); sellAmt = Math.min(mat.maxSellPerCycle, sellAmt);
sellAmt = sellAmt * corpConstants.secondsPerMarketCycle * marketCycles; sellAmt = sellAmt * corpConstants.secondsPerMarketCycle * marketCycles;
sellAmt = Math.min(mat.stored, sellAmt); sellAmt = Math.min(mat.stored, sellAmt);
@ -640,7 +622,7 @@ export class Division {
let amtStr = exp.amount.replace( let amtStr = exp.amount.replace(
/MAX/g, /MAX/g,
(mat.stored / (corpConstants.secondsPerMarketCycle * marketCycles) + "").toUpperCase(), (mat.stored / (corpConstants.secondsPerMarketCycle * marketCycles)).toString(),
); );
amtStr = amtStr.replace(/EPROD/g, "(" + mat.productionAmount + ")"); amtStr = amtStr.replace(/EPROD/g, "(" + mat.productionAmount + ")");
amtStr = amtStr.replace(/IPROD/g, "(" + tempMaterial.productionAmount + ")"); amtStr = amtStr.replace(/IPROD/g, "(" + tempMaterial.productionAmount + ")");
@ -839,7 +821,7 @@ export class Division {
const desiredSellAmount = product.cityData[city].desiredSellAmount; const desiredSellAmount = product.cityData[city].desiredSellAmount;
if (isString(desiredSellAmount)) { if (isString(desiredSellAmount)) {
//Sell amount is dynamically evaluated //Sell amount is dynamically evaluated
let tmp: number | string = desiredSellAmount.replace(/MAX/g, (adjustedQty + "").toUpperCase()); let tmp: number | string = desiredSellAmount.replace(/MAX/g, adjustedQty.toString());
tmp = tmp.replace(/PROD/g, product.cityData[city].productionAmount.toString()); tmp = tmp.replace(/PROD/g, product.cityData[city].productionAmount.toString());
try { try {
tmp = eval(tmp); tmp = eval(tmp);
@ -899,7 +881,7 @@ export class Division {
console.error(`mku is zero, reverting to 1 to avoid Infinity`); console.error(`mku is zero, reverting to 1 to avoid Infinity`);
product.markup = 1; product.markup = 1;
} }
sCostString = sCostString.replace(/MP/g, product.productionCost + ""); sCostString = sCostString.replace(/MP/g, product.productionCost.toString());
sCost = Math.max(product.productionCost, eval(sCostString)); sCost = Math.max(product.productionCost, eval(sCostString));
} else { } else {
sCost = sellPrice; sCost = sellPrice;