2021-09-06 22:44:00 -05:00
|
|
|
/// <reference path="./Hidden.ts" />
|
|
|
|
|
|
|
|
class CryptoMarket extends Hidden {
|
2021-09-12 13:58:57 -05:00
|
|
|
public readonly resourceKey = ResourceKey.cryptoMarket;
|
|
|
|
|
2021-09-06 22:44:00 -05:00
|
|
|
private _adjustmentTime = 0;
|
|
|
|
|
|
|
|
constructor(config: GameConfig) {
|
|
|
|
super(
|
|
|
|
'crypto market',
|
|
|
|
'crypto markets',
|
|
|
|
'How much money a single FaithCoin is worth'
|
|
|
|
);
|
2021-09-12 13:58:57 -05:00
|
|
|
this.rawValue = config.cfgInitialCost.cryptoCurrency ?? 0;
|
2021-09-06 22:44:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public max = (state: GameState): number =>
|
|
|
|
state.config.cfgInitialMax.cryptoMarket ?? 0;
|
|
|
|
|
|
|
|
public advanceAction = (time: number, state: GameState): void => {
|
|
|
|
const crypto = state.resource.cryptoCurrency;
|
|
|
|
if (crypto === undefined) return;
|
|
|
|
this._adjustmentTime += time;
|
|
|
|
if (this._adjustmentTime >= state.config.cfgCryptoMarketAdjustPeriod) {
|
|
|
|
this._adjustmentTime = 0;
|
|
|
|
let adjustment =
|
|
|
|
this.value *
|
|
|
|
state.config.cfgCryptoMarketAdjustAmount *
|
|
|
|
2 *
|
|
|
|
Math.random() -
|
|
|
|
this.value * state.config.cfgCryptoMarketAdjustAmount;
|
|
|
|
adjustment +=
|
|
|
|
this.value *
|
|
|
|
state.config.cfgCryptoMarketAdjustAmount *
|
|
|
|
Math.random() *
|
|
|
|
state.config.cfgCryptoMarketGrowthBias;
|
|
|
|
if (
|
|
|
|
this.value + adjustment <
|
|
|
|
state.config.cfgCryptoCurrencyMinimumValue
|
|
|
|
) {
|
|
|
|
adjustment = state.config.cfgCryptoCurrencyMinimumValue - this.value;
|
|
|
|
}
|
|
|
|
//if (Math.abs(adjustment) > 0) {
|
|
|
|
this.addValue(adjustment, state);
|
|
|
|
state.log(
|
|
|
|
`FaithCoin just ${
|
|
|
|
adjustment > 0 ? 'increased' : 'decreased'
|
|
|
|
} in value by $${formatNumber(Math.abs(adjustment))}.`
|
|
|
|
);
|
|
|
|
//}
|
|
|
|
if (crypto?.cost !== undefined) {
|
|
|
|
crypto.cost.money = this.value;
|
|
|
|
state.autoAction(); // cause redraw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|