started on inc and cost refactors
This commit is contained in:
parent
14e1b646a9
commit
a0daffbddf
7
TODO.md
7
TODO.md
|
@ -1,3 +1,8 @@
|
||||||
|
## In Progress
|
||||||
|
|
||||||
|
- [ ] change `inc` to a `ResourceNumber` instead of a `number`
|
||||||
|
- [ ] change `cost` into a function that computes based on `value`
|
||||||
|
|
||||||
## Initial Game Progression Plan
|
## Initial Game Progression Plan
|
||||||
|
|
||||||
### Phase 1: 0-1K Followers
|
### Phase 1: 0-1K Followers
|
||||||
|
@ -82,7 +87,7 @@
|
||||||
- [x] add an action to sell purchasables and regain some portion of their cost
|
- [x] add an action to sell purchasables and regain some portion of their cost
|
||||||
- [ ] add a `policy` resource type that can be toggled on or off
|
- [ ] add a `policy` resource type that can be toggled on or off
|
||||||
- [x] remove recruitment effects of credibility (that will be for notoriety instead)
|
- [x] remove recruitment effects of credibility (that will be for notoriety instead)
|
||||||
- [ ] change `value` to a getter that does `Math.floor` if it's a whole number resource
|
- [x] change `value` to a getter that does `Math.floor` if it's a whole number resource
|
||||||
|
|
||||||
## Long-Term Ideas
|
## Long-Term Ideas
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ interface IResource {
|
||||||
readonly description: string;
|
readonly description: string;
|
||||||
readonly valueInWholeNumbers: boolean;
|
readonly valueInWholeNumbers: boolean;
|
||||||
|
|
||||||
readonly cost?: ResourceNumber;
|
cost?: (state: GameState) => ResourceNumber;
|
||||||
|
inc?: (state: GameState) => ResourceNumber;
|
||||||
|
|
||||||
max?: (state: GameState) => number;
|
max?: (state: GameState) => number;
|
||||||
inc?: (state: GameState) => number;
|
|
||||||
advanceAction?: (time: number, state: GameState) => void;
|
advanceAction?: (time: number, state: GameState) => void;
|
||||||
userActions?: ResourceAction[];
|
userActions?: ResourceAction[];
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ abstract class Purchasable extends Resource {
|
||||||
protected _sellMultiplier?: number | ResourceNumber;
|
protected _sellMultiplier?: number | ResourceNumber;
|
||||||
protected _isUnlocked = false;
|
protected _isUnlocked = false;
|
||||||
|
|
||||||
|
private _lastWholeNumberValue = 0;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly label: string,
|
public readonly label: string,
|
||||||
public readonly singularName: string,
|
public readonly singularName: string,
|
||||||
|
@ -63,7 +65,6 @@ abstract class Purchasable extends Resource {
|
||||||
|
|
||||||
public restoreConfig = (config: ResourceConfig): void => {
|
public restoreConfig = (config: ResourceConfig): void => {
|
||||||
this.rawValue = config.value;
|
this.rawValue = config.value;
|
||||||
if (config.cost !== undefined) this.cost = config.cost;
|
|
||||||
if (
|
if (
|
||||||
config.config !== undefined &&
|
config.config !== undefined &&
|
||||||
typeof config.config.isUnlocked === 'boolean'
|
typeof config.config.isUnlocked === 'boolean'
|
||||||
|
@ -72,6 +73,21 @@ abstract class Purchasable extends Resource {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public addValue = (amount: number, _: GameState): void => {
|
||||||
|
this.rawValue += amount;
|
||||||
|
const wholeNumberChange = this.value - this._lastWholeNumberValue;
|
||||||
|
if (wholeNumberChange > 0) {
|
||||||
|
for (const key in this._costMultiplier) {
|
||||||
|
const rkey = <ResourceKey>key;
|
||||||
|
this.cost[rkey] =
|
||||||
|
(this.cost[rkey] ?? 0) *
|
||||||
|
(this._costMultiplier[rkey] ?? 1) *
|
||||||
|
wholeNumberChange;
|
||||||
|
}
|
||||||
|
this._lastWholeNumberValue = this.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
protected _purchaseLog(amount: number, _state: GameState): string {
|
protected _purchaseLog(amount: number, _state: GameState): string {
|
||||||
let verb = 'purchased';
|
let verb = 'purchased';
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
|
@ -88,11 +104,6 @@ abstract class Purchasable extends Resource {
|
||||||
if (state.deductCost(this.cost)) {
|
if (state.deductCost(this.cost)) {
|
||||||
this.addValue(1, state);
|
this.addValue(1, state);
|
||||||
state.log(this._purchaseLog(1, state));
|
state.log(this._purchaseLog(1, state));
|
||||||
for (const key in this._costMultiplier) {
|
|
||||||
const rkey = <ResourceKey>key;
|
|
||||||
this.cost[rkey] =
|
|
||||||
(this.cost[rkey] ?? 0) * (this._costMultiplier[rkey] ?? 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +127,7 @@ abstract class Purchasable extends Resource {
|
||||||
costBack[rkey] = cost * -1 * multiplier;
|
costBack[rkey] = cost * -1 * multiplier;
|
||||||
state.deductCost(costBack);
|
state.deductCost(costBack);
|
||||||
}
|
}
|
||||||
this.addValue(1, state);
|
this.addValue(-1, state);
|
||||||
state.log(this._purchaseLog(-1, state));
|
state.log(this._purchaseLog(-1, state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
/// <reference path="./IResource.ts" />
|
/// <reference path="./IResource.ts" />
|
||||||
|
|
||||||
abstract class Resource implements IResource {
|
abstract class Resource implements IResource {
|
||||||
public cost?: ResourceNumber = undefined;
|
|
||||||
|
|
||||||
protected rawValue = 0;
|
protected rawValue = 0;
|
||||||
|
|
||||||
public abstract readonly resourceType: ResourceType;
|
public abstract readonly resourceType: ResourceType;
|
||||||
|
@ -26,6 +24,5 @@ abstract class Resource implements IResource {
|
||||||
|
|
||||||
public restoreConfig = (config: ResourceConfig): void => {
|
public restoreConfig = (config: ResourceConfig): void => {
|
||||||
this.rawValue = config.value;
|
this.rawValue = config.value;
|
||||||
this.cost = config.cost;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,6 @@ type ResourceConfigValues = { [key: string]: string | number | boolean };
|
||||||
|
|
||||||
type ResourceConfig = {
|
type ResourceConfig = {
|
||||||
value: number;
|
value: number;
|
||||||
cost?: ResourceNumber;
|
|
||||||
config?: ResourceConfigValues;
|
config?: ResourceConfigValues;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Reference in New Issue