2021-08-20 20:47:02 -05:00
|
|
|
/// <reference path="./IResource.ts" />
|
|
|
|
|
|
|
|
abstract class Purchasable implements IResource {
|
2021-08-21 10:44:53 -05:00
|
|
|
public readonly resourceType: ResourceType = ResourceType.Infrastructure;
|
2021-08-20 20:47:02 -05:00
|
|
|
public value: number = 0;
|
|
|
|
|
2021-08-20 23:00:24 -05:00
|
|
|
public clickText: string = 'Purchase';
|
|
|
|
public clickDescription: string = 'Purchase';
|
|
|
|
|
2021-08-21 12:45:58 -05:00
|
|
|
public cost: { [key: string]: number } | null = null;
|
2021-08-21 10:44:53 -05:00
|
|
|
|
2021-08-21 12:45:58 -05:00
|
|
|
protected _costMultiplier: { [key: string]: number } | null = null;
|
2021-08-21 10:44:53 -05:00
|
|
|
protected _baseMax: number | null = 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
|
|
|
) { }
|
|
|
|
|
2021-08-21 10:44:53 -05:00
|
|
|
public clickAction (state: GameState): void {
|
|
|
|
if (this.max(state) !== null && this.value >= this.max(state)) return;
|
2021-08-20 23:00:24 -05:00
|
|
|
if (state.deductCost(this.cost)) {
|
2021-08-21 12:45:58 -05:00
|
|
|
this.value += this._incrementAmount(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-21 10:44:53 -05:00
|
|
|
public inc (state: GameState): number | null {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public max (state: GameState): number | null {
|
|
|
|
return this._baseMax;
|
|
|
|
}
|
|
|
|
|
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-21 12:45:58 -05:00
|
|
|
|
|
|
|
protected _incrementAmount (state: GameState): number {
|
|
|
|
return 1;
|
|
|
|
}
|
2021-08-20 20:47:02 -05:00
|
|
|
}
|