implemented increments
This commit is contained in:
parent
80c74ed86b
commit
39f5830046
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ interface IResource {
|
|||
|
||||
resourceType: ResourceType;
|
||||
value: number;
|
||||
inc: number;
|
||||
max?: number;
|
||||
cost: { [key: string]: number };
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in New Issue