2021-08-20 20:47:02 -05:00
|
|
|
/// <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;
|
2021-08-20 20:47:02 -05:00
|
|
|
|
2021-08-20 23:00:24 -05:00
|
|
|
public clickText: string = 'Purchase';
|
|
|
|
public clickDescription: string = 'Purchase';
|
|
|
|
|
|
|
|
public cost: { [key: string]: number } = null;
|
|
|
|
protected _costMultiplier: { [key: string]: number } = null;
|
2021-08-20 20:47:02 -05:00
|
|
|
|
|
|
|
constructor (
|
|
|
|
public readonly name: string,
|
2021-08-20 23:00:24 -05:00
|
|
|
public readonly description: string
|
2021-08-20 20:47:02 -05:00
|
|
|
) { }
|
|
|
|
|
|
|
|
public clickAction (state: GameState) {
|
|
|
|
if (this.max !== null && this.value >= this.max) return;
|
2021-08-20 23:00:24 -05:00
|
|
|
if (state.deductCost(this.cost)) {
|
2021-08-20 20:47:02 -05:00
|
|
|
this.value += 1;
|
2021-08-20 23:30:32 -05:00
|
|
|
this.purchaseEffect(state);
|
2021-08-20 23:00:24 -05:00
|
|
|
if (this._costMultiplier !== null
|
|
|
|
&& Object.keys(this._costMultiplier !== null)) {
|
|
|
|
for (const rkey of Object.keys(this._costMultiplier)) {
|
|
|
|
this.cost[rkey] *= this._costMultiplier[rkey];
|
|
|
|
}
|
|
|
|
}
|
2021-08-20 20:47:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-20 23:00:24 -05:00
|
|
|
public advanceAction (time: number, state: GameState): void {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public isUnlocked (state: GameState): boolean {
|
|
|
|
return false;
|
2021-08-20 20:47:02 -05:00
|
|
|
}
|
2021-08-20 23:30:32 -05:00
|
|
|
|
|
|
|
protected purchaseEffect (state: GameState) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-20 20:47:02 -05:00
|
|
|
}
|