diff --git a/src/model/GameState.ts b/src/model/GameState.ts index daccdb6..79e4084 100644 --- a/src/model/GameState.ts +++ b/src/model/GameState.ts @@ -16,6 +16,9 @@ class GameState { if (this._resources[rkey].advanceAction !== null) { this._resources[rkey].advanceAction(time, this); } + if (this._resources[rkey].inc > 0) { + this._resources[rkey].value += this._resources[rkey].inc * time / 1000; + } } } diff --git a/src/model/resource/IResource.ts b/src/model/resource/IResource.ts index 7ded881..13db3bf 100644 --- a/src/model/resource/IResource.ts +++ b/src/model/resource/IResource.ts @@ -10,6 +10,7 @@ interface IResource { resourceType: ResourceType; value: number; + inc: number; max?: number; cost: { [key: string]: number }; diff --git a/src/model/resource/Purchasable.ts b/src/model/resource/Purchasable.ts index e4bd662..79aeb0b 100644 --- a/src/model/resource/Purchasable.ts +++ b/src/model/resource/Purchasable.ts @@ -4,6 +4,7 @@ abstract class Purchasable implements IResource { public readonly resourceType = ResourceType.Infrastructure; public readonly max?: number = null; public value: number = 0; + public inc: number = 0; public clickText: string = 'Purchase'; public clickDescription: string = 'Purchase'; @@ -20,6 +21,7 @@ abstract class Purchasable implements IResource { if (this.max !== null && this.value >= this.max) return; if (state.deductCost(this.cost)) { this.value += 1; + this.purchaseEffect(state); if (this._costMultiplier !== null && Object.keys(this._costMultiplier !== null)) { for (const rkey of Object.keys(this._costMultiplier)) { @@ -36,4 +38,8 @@ abstract class Purchasable implements IResource { public isUnlocked (state: GameState): boolean { return false; } + + protected purchaseEffect (state: GameState) { + return; + } } diff --git a/src/model/resource/Religion.ts b/src/model/resource/Religion.ts index 8e4af0e..68f3462 100644 --- a/src/model/resource/Religion.ts +++ b/src/model/resource/Religion.ts @@ -8,6 +8,7 @@ class Religion implements IResource { public readonly clickAction: () => void = null; public readonly advanceAction: (time: number) => void = null; public readonly cost: { [key: string]: number } = null; + public readonly inc: number = 0; constructor ( public readonly name: string, diff --git a/src/model/resource/SavingsBonds.ts b/src/model/resource/SavingsBonds.ts index bff43fd..dc8116b 100644 --- a/src/model/resource/SavingsBonds.ts +++ b/src/model/resource/SavingsBonds.ts @@ -14,10 +14,14 @@ class SavingsBonds extends Purchasable { public isUnlocked (state: GameState): boolean { if (this._isUnlocked) return true; - if (state.getResource('money').value >= 25) { + if (state.getResource('money').value >= this.cost.money) { this._isUnlocked = true; return true; } return false; } + + protected purchaseEffect (state: GameState) { + state.getResource('money').inc += 0.25; + } } diff --git a/src/render/DebugRenderer.ts b/src/render/DebugRenderer.ts index f74fec8..f88e336 100644 --- a/src/render/DebugRenderer.ts +++ b/src/render/DebugRenderer.ts @@ -48,8 +48,13 @@ class DebugRenderer implements IRenderer { const elV = el.getElementsByClassName('value')[0]; const elT = el.getElementsByClassName('max')[0]; elV.innerHTML = this.formatNumber(resource.value, 1); - elT.innerHTML = resource.max !== null ? ` / ${this.formatNumber(resource.max, 2)}` : ''; + elT.innerHTML = resource.max !== null ? ` / ${this.formatNumber(resource.max, 1)}` : ''; if (this._handleClick) { + if (resource.inc > 0) { + console.log(`${resource.name} inc ${resource.inc} to ${this.formatNumber(resource.inc, 1)}`); // tslint:disable-line + const elI = el.getElementsByClassName('inc')[0]; + elI.innerHTML = ` +${this.formatNumber(resource.inc, 1)}/s`; + } const elC = el.getElementsByClassName('cost'); if (elC.length > 0) { elC[0].innerHTML = this.getCostStr(resource, state);