Merge pull request #1695 from danielyxie/dev

wtf
This commit is contained in:
hydroflame 2021-11-11 20:46:07 -05:00 committed by GitHub
commit 2cdfa46aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -54,7 +54,7 @@ export function buyDarkwebItem(itemName: string): void {
} }
// return if the player doesn't have enough money // return if the player doesn't have enough money
if (Player.money.lt(item.price)) { if (Player.money < item.price) {
Terminal.error("Not enough money to purchase " + item.program); Terminal.error("Not enough money to purchase " + item.program);
return; return;
} }

@ -87,7 +87,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal
} else { } else {
dialogBoxCreate(txt); dialogBoxCreate(txt);
} }
} else if (aug.baseCost !== 0 && Player.money.lt(aug.baseCost * factionInfo.augmentationPriceMult)) { } else if (aug.baseCost !== 0 && Player.money < aug.baseCost * factionInfo.augmentationPriceMult) {
const txt = "You don't have enough money to purchase " + aug.name; const txt = "You don't have enough money to purchase " + aug.name;
if (sing) { if (sing) {
return txt; return txt;
@ -99,7 +99,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal
return txt; return txt;
} }
dialogBoxCreate(txt); dialogBoxCreate(txt);
} else if (aug.baseCost === 0 || Player.money.gte(aug.baseCost * factionInfo.augmentationPriceMult)) { } else if (aug.baseCost === 0 || Player.money >= aug.baseCost * factionInfo.augmentationPriceMult) {
const queuedAugmentation = new PlayerOwnedAugmentation(aug.name); const queuedAugmentation = new PlayerOwnedAugmentation(aug.name);
if (aug.name == AugmentationNames.NeuroFluxGovernor) { if (aug.name == AugmentationNames.NeuroFluxGovernor) {
queuedAugmentation.level = getNextNeurofluxLevel(); queuedAugmentation.level = getNextNeurofluxLevel();

@ -63,7 +63,7 @@ export class PlayerObject implements IPlayer {
numPeopleKilled: number; numPeopleKilled: number;
location: LocationName; location: LocationName;
max_hp: number; max_hp: number;
money: any; money: number;
moneySourceA: MoneySourceTracker; moneySourceA: MoneySourceTracker;
moneySourceB: MoneySourceTracker; moneySourceB: MoneySourceTracker;
playtimeSinceLastAug: number; playtimeSinceLastAug: number;

@ -333,7 +333,7 @@ export function gainMoney(this: PlayerObject, money: number, source: string): vo
console.error("NaN passed into Player.gainMoney()"); console.error("NaN passed into Player.gainMoney()");
return; return;
} }
this.money = this.money.plus(money); this.money = this.money + money;
this.recordMoneySource(money, source); this.recordMoneySource(money, source);
} }
@ -342,8 +342,8 @@ export function loseMoney(this: PlayerObject, money: number, source: string): vo
console.error("NaN passed into Player.loseMoney()"); console.error("NaN passed into Player.loseMoney()");
return; return;
} }
if (this.money.eq(Infinity) && money === Infinity) return; if (this.money === Infinity && money === Infinity) return;
this.money = this.money.minus(money); this.money = this.money - money;
this.recordMoneySource(-1 * money, source); this.recordMoneySource(-1 * money, source);
} }

@ -18,7 +18,7 @@ export function hasTorRouter(this: IPlayer): boolean {
export function getCurrentServer(this: IPlayer): BaseServer { export function getCurrentServer(this: IPlayer): BaseServer {
const server = GetServer(this.currentServer); const server = GetServer(this.currentServer);
if (server === null) throw new Error("somehow connected to a server that does not exist."); if (server === null) throw new Error(`somehow connected to a server that does not exist. ${this.currentServer}`);
return server; return server;
} }

@ -64,7 +64,7 @@ export function buyStock(
if (totalPrice == null) { if (totalPrice == null) {
return false; return false;
} }
if (Player.money.lt(totalPrice)) { if (Player.money < totalPrice) {
if (workerScript) { if (workerScript) {
workerScript.log( workerScript.log(
"buyStock", "buyStock",
@ -241,7 +241,7 @@ export function shortStock(
if (totalPrice == null) { if (totalPrice == null) {
return false; return false;
} }
if (Player.money.lt(totalPrice)) { if (Player.money < totalPrice) {
if (workerScript) { if (workerScript) {
workerScript.log( workerScript.log(
"shortStock", "shortStock",

@ -1 +0,0 @@
declare module "decimal.js";

@ -251,6 +251,22 @@ const Engine: {
const timeOffline = Engine._lastUpdate - lastUpdate; const timeOffline = Engine._lastUpdate - lastUpdate;
const numCyclesOffline = Math.floor(timeOffline / CONSTANTS._idleSpeed); const numCyclesOffline = Math.floor(timeOffline / CONSTANTS._idleSpeed);
// Generate coding contracts
// let numContracts = 0;
// if (numCyclesOffline < 3000 * 100) {
// // if we have less than 100 rolls, just roll them exactly.
// for (let i = 0; i < numCyclesOffline / 3000; i++) {
// if (Math.random() < 0.25) numContracts++;
// }
// } else {
// // just average it.
// numContracts = (numCyclesOffline / 3000) * 0.25;
// }
// console.log(`${numCyclesOffline} ${numContracts}`);
// for (let i = 0; i < numContracts; i++) {
// generateRandomContract();
// }
let offlineReputation = 0; let offlineReputation = 0;
const offlineHackingIncome = (Player.moneySourceA.hacking / Player.playtimeSinceLastAug) * timeOffline * 0.75; const offlineHackingIncome = (Player.moneySourceA.hacking / Player.playtimeSinceLastAug) * timeOffline * 0.75;
Player.gainMoney(offlineHackingIncome, "hacking"); Player.gainMoney(offlineHackingIncome, "hacking");

@ -856,7 +856,7 @@ describe("Stock Market Tests", function () {
expect(buyStock(stock, shares, null, suppressDialogOpt)).equal(true); expect(buyStock(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShares).equal(shares); expect(stock.playerShares).equal(shares);
expect(stock.playerAvgPx).greaterThan(0); expect(stock.playerAvgPx).greaterThan(0);
expect(Player.money.toNumber()).equal(0); expect(Player.money).equal(0);
}); });
}); });
@ -888,7 +888,7 @@ describe("Stock Market Tests", function () {
expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true); expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShares).equal(0); expect(stock.playerShares).equal(0);
expect(stock.playerAvgPx).equal(0); expect(stock.playerAvgPx).equal(0);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
it("should cap the number of sharse sold to however many the player owns", function () { it("should cap the number of sharse sold to however many the player owns", function () {
@ -902,7 +902,7 @@ describe("Stock Market Tests", function () {
expect(sellStock(stock, attemptedShares, null, suppressDialogOpt)).equal(true); expect(sellStock(stock, attemptedShares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShares).equal(0); expect(stock.playerShares).equal(0);
expect(stock.playerAvgPx).equal(0); expect(stock.playerAvgPx).equal(0);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
it("should properly update stock properties for partial transactions", function () { it("should properly update stock properties for partial transactions", function () {
@ -916,7 +916,7 @@ describe("Stock Market Tests", function () {
expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true); expect(sellStock(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShares).equal(shares); expect(stock.playerShares).equal(shares);
expect(stock.playerAvgPx).equal(origPrice); expect(stock.playerAvgPx).equal(origPrice);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
}); });
@ -950,7 +950,7 @@ describe("Stock Market Tests", function () {
expect(shortStock(stock, shares, null, suppressDialogOpt)).equal(true); expect(shortStock(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShortShares).equal(shares); expect(stock.playerShortShares).equal(shares);
expect(stock.playerAvgShortPx).greaterThan(0); expect(stock.playerAvgShortPx).greaterThan(0);
expect(Player.money.toNumber()).equal(0); expect(Player.money).equal(0);
}); });
}); });
@ -982,7 +982,7 @@ describe("Stock Market Tests", function () {
expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true); expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShortShares).equal(0); expect(stock.playerShortShares).equal(0);
expect(stock.playerAvgShortPx).equal(0); expect(stock.playerAvgShortPx).equal(0);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
it("should cap the number of sharse sold to however many the player owns", function () { it("should cap the number of sharse sold to however many the player owns", function () {
@ -996,7 +996,7 @@ describe("Stock Market Tests", function () {
expect(sellShort(stock, attemptedShares, null, suppressDialogOpt)).equal(true); expect(sellShort(stock, attemptedShares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShortShares).equal(0); expect(stock.playerShortShares).equal(0);
expect(stock.playerAvgShortPx).equal(0); expect(stock.playerAvgShortPx).equal(0);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
it("should properly update stock properties for partial transactions", function () { it("should properly update stock properties for partial transactions", function () {
@ -1010,7 +1010,7 @@ describe("Stock Market Tests", function () {
expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true); expect(sellShort(stock, shares, null, suppressDialogOpt)).equal(true);
expect(stock.playerShortShares).equal(shares); expect(stock.playerShortShares).equal(shares);
expect(stock.playerAvgShortPx).equal(origPrice); expect(stock.playerAvgShortPx).equal(origPrice);
expect(Player.money.toNumber()).equal(gain); expect(Player.money).equal(gain);
}); });
}); });
}); });