This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
irreligious/src/model/resource/Purchasable.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

/// <reference path="./IResource.ts" />
abstract class Purchasable implements IResource {
public readonly resourceType = ResourceType.Infrastructure;
public readonly max?: number = null;
public value: number = 0;
2021-08-20 23:30:32 -05:00
public inc: number = 0;
public clickText: string = 'Purchase';
public clickDescription: string = 'Purchase';
public cost: { [key: string]: number } = null;
protected _costMultiplier: { [key: string]: number } = null;
constructor (
public readonly name: string,
public readonly description: string
) { }
public clickAction (state: GameState) {
if (this.max !== null && this.value >= this.max) return;
if (state.deductCost(this.cost)) {
this.value += 1;
2021-08-20 23:30:32 -05:00
this.purchaseEffect(state);
if (this._costMultiplier !== null
&& Object.keys(this._costMultiplier !== null)) {
for (const rkey of Object.keys(this._costMultiplier)) {
this.cost[rkey] *= this._costMultiplier[rkey];
}
}
}
}
public advanceAction (time: number, state: GameState): void {
return;
}
public isUnlocked (state: GameState): boolean {
return false;
}
2021-08-20 23:30:32 -05:00
protected purchaseEffect (state: GameState) {
return;
}
}