bitburner-src/src/Hacknet/HashUpgrade.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-03-25 04:03:24 +01:00
/**
* Object representing an upgrade that can be purchased with hashes
*/
export interface IConstructorParams {
cost?: number;
2019-03-25 04:03:24 +01:00
costPerLevel: number;
desc: string;
hasTargetServer?: boolean;
name: string;
value: number;
2021-08-19 07:45:26 +02:00
effectText?: (level: number) => JSX.Element | null;
2019-03-25 04:03:24 +01:00
}
export class HashUpgrade {
/**
* If the upgrade has a flat cost (never increases), it goes here
* Otherwise, this property should be undefined
*
* This property overrides the 'costPerLevel' property
*/
cost?: number;
2019-03-25 04:03:24 +01:00
/**
* Base cost for this upgrade. Every time the upgrade is purchased,
* its cost increases by this same amount (so its 1x, 2x, 3x, 4x, etc.)
*/
2021-04-30 05:52:56 +02:00
costPerLevel = 0;
2019-03-25 04:03:24 +01:00
/**
* Description of what the upgrade does
*/
2021-04-30 05:52:56 +02:00
desc = "";
2019-03-25 04:03:24 +01:00
/**
* Boolean indicating that this upgrade's effect affects a single server,
* the "target" server
*/
2021-04-30 05:52:56 +02:00
hasTargetServer = false;
2019-03-25 04:03:24 +01:00
// Name of upgrade
2021-04-30 05:52:56 +02:00
name = "";
2019-03-25 04:03:24 +01:00
// Generic value used to indicate the potency/amount of this upgrade's effect
// The meaning varies between different upgrades
2021-04-30 05:52:56 +02:00
value = 0;
2019-03-25 04:03:24 +01:00
constructor(p: IConstructorParams) {
if (p.cost != null) { this.cost = p.cost; }
2021-08-19 07:45:26 +02:00
if (p.effectText != null) { this.effectText = p.effectText; }
2019-03-25 04:03:24 +01:00
this.costPerLevel = p.costPerLevel;
this.desc = p.desc;
this.hasTargetServer = p.hasTargetServer ? p.hasTargetServer : false;
this.name = p.name;
this.value = p.value;
}
2021-08-19 22:37:59 +02:00
// Functions that returns the UI element to display the effect of this upgrade.
effectText: (level: number) => JSX.Element | null = () => null;
2019-03-25 04:03:24 +01:00
getCost(levels: number): number {
if (typeof this.cost === "number") { return this.cost; }
2019-03-25 04:03:24 +01:00
return Math.round((levels + 1) * this.costPerLevel);
}
}