Refactored Augmentation implementation to Typescript, and to have the multiplier information in the actrual Augmentation object

This commit is contained in:
danielyxie
2019-01-15 05:11:14 -08:00
parent bcb231a966
commit 6d8d25e0bb
30 changed files with 982 additions and 925 deletions
+10
View File
@@ -0,0 +1,10 @@
Implements the Re-sleeving feature, which allows players to purchase a new body
that comes with pre-existing Augmentations and experience. Note that purchasing
a new body causes you to lose all of your old Augmentations and experience
This feature is introduced in BitNode-10, and destroying BitNode-10 allows
the user to use it in other BitNodes (provided that they purchase the required
cortical stack Augmentation)
While they are based on the same concept, this feature is different than the
"Sleeve" mechanic.
+45
View File
@@ -0,0 +1,45 @@
/**
* Implements the Resleeve class, which defines a new body
* that the player can "re-sleeve" into.
*/
import { Person } from "../Person";
import { Augmentation } from "../../Augmentation/Augmentation";
import { Augmentations } from "../../Augmentation/Augmentations";
import { CONSTANTS } from "../../Constants";
export class Resleeve extends Person {
constructor() {
super();
}
getCost(): number {
// Each experience point adds this to the cost
const CostPerExp: number = 5;
// Final cost is multiplied by # Augs ^ this constant
const NumAugsExponent: number = 1.05;
// Get total exp in this re-sleeve
let totalExp: number = this.hacking_exp +
this.strength_exp +
this.defense_exp +
this.dexterity_exp +
this.agility_exp +
this.charisma_exp;
// Get total base Augmentation cost for this re-sleeve
let totalAugmentationCost: number = 0;
for (let i = 0; i < this.augmentations.length; ++i) {
const aug: Augmentation | null = Augmentations[this.augmentations[i]];
if (aug == null) {
console.error(`Could not find Augmentation ${this.augmentations[i]}`);
continue;
}
totalAugmentationCost += aug!.baseCost;
}
return (totalExp * CostPerExp) + (totalAugmentationCost * Math.pow(this.augmentations.length, NumAugsExponent));
}
}
@@ -0,0 +1,74 @@
/**
* Implements the Re-sleeving mechanic for BitNode-10.
* This allows the player to purchase and "use" new sleeves at VitaLife.
* These new sleeves come with different starting experience and Augmentations
* The cost of these new sleeves scales based on the exp and Augs.
*
* Note that this is different from the "Sleeve mechanic". The "Sleeve" mechanic
* provides new sleeves, essentially clones. This Re-sleeving mechanic lets
* the player purchase a new body with pre-existing Augmentations and experience
*
* As of right now, this feature is only available in BitNode 10
*/
import { Resleeve } from "./Resleeve";
import { IPlayer } from "../Person";
import { Augmentation } from "../../Augmentation/Augmentation";
import { Augmentations } from "../../Augmentation/Augmentations";
import { PlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { getRandomInt } from "../../../utils/helpers/getRandomInt";
// Executes the actual re-sleeve when one is purchased
export function resleeve(r: Resleeve, p: IPlayer) {
// Set the player's exp
p.hacking_exp = r.hacking_exp;
p.strength_exp = r.strength_exp;
p.defense_exp = r.defense_exp;
p.dexterity_exp = r.dexterity_exp;
p.agility_exp = r.agility_exp;
p.charisma_exp = r.charisma_exp;
// Clear all of the player's augmentations, including those that are
// purchased but not installed
p.queuedAugmentations.length = 0;
p.augmentations.length = 0;
for (let i = 0; i < r.augmentations.length; ++i) {
p.augmentations.push(new PlayerOwnedAugmentation(r.augmentations[i]));
}
p.reapplyAllAugmentations(true);
}
// Creates all of the Re-sleeves that will be available for purchase at VitaLife
export function generateResleeves(): Resleeve[] {
const NumResleeves: number = 40; // Total number of Resleeves to generate
let ret: Resleeve[] = [];
for (let i = 0; i < NumResleeves; ++i) {
// i will be a number indicating how "powerful" the Re-sleeve should be
let r: Resleeve = new Resleeve();
// Generate experience
const expMult: number = i + 1;
r.hacking_exp = expMult * getRandomInt(500, 1500);
r.strength_exp = expMult * getRandomInt(500, 1500);
r.defense_exp = expMult * getRandomInt(500, 1500);
r.dexterity_exp = expMult * getRandomInt(500, 1500);
r.agility_exp = expMult * getRandomInt(500, 1500);
r.charisma_exp = expMult * getRandomInt(500, 1500);
// Generate Augs
const baseNumAugs: number = Math.ceil((i + 1) / 2);
const numAugs: number = getRandomInt(baseNumAugs, baseNumAugs + 2);
for (let a = 0; a < numAugs; ++a) {
const augKeys: string[] = Object.keys(Augmentations);
r.augmentations.push(TODO);
}
}
return ret;
}