crypto market hidden resource to drive faithcoin cost

This commit is contained in:
Rudis Muiznieks 2021-09-06 22:44:00 -05:00
parent 199db37b01
commit 079ff29f97
10 changed files with 101 additions and 18 deletions

View File

@ -2,7 +2,7 @@
/// <reference path="./render/DebugRenderer.ts" /> /// <reference path="./render/DebugRenderer.ts" />
const versionMajor = 2; const versionMajor = 2;
const versionMinor = 0; const versionMinor = 1;
let globalStartTime = 0; let globalStartTime = 0;
let globalTimeout: number | null = null; let globalTimeout: number | null = null;
@ -45,18 +45,17 @@ The game's source code on <a href='https://github.com/rudism/irreligious'>Github
const config = new GameConfig(versionMajor, versionMinor); const config = new GameConfig(versionMajor, versionMinor);
// debug values to make the game play faster while testing // debug values to make the game play faster while testing
config.cfgTitheAmount = 1000;
config.cfgTimeBetweenTithes = 5000;
config.cfgCryptoReturnAmount = 100;
config.cfgCredibilityRestoreRate = 5; config.cfgCredibilityRestoreRate = 5;
config.cfgPastorRecruitRate = 0.5; config.cfgPastorRecruitRate = 0.5;
config.cfgTimeBetweenTithes = 5000;
config.cfgTitheAmount = 1000;
const renderer = new DebugRenderer(); const renderer = new DebugRenderer();
renderer.onInitialRender = initialRender; renderer.onInitialRender = initialRender;
const state = config.generateState(); const state = config.generateState();
// re-run main loop immediately on user clicks // re-run main loop immediately on user clicks
state.onResourceClick.push((): void => { state.onAction.push((): void => {
if (globalTimeout !== null) { if (globalTimeout !== null) {
clearTimeout(globalTimeout); clearTimeout(globalTimeout);
gameLoop(state, renderer); gameLoop(state, renderer);

View File

@ -4,6 +4,7 @@
/// <reference path="./resource/Compound.ts" /> /// <reference path="./resource/Compound.ts" />
/// <reference path="./resource/Credibility.ts" /> /// <reference path="./resource/Credibility.ts" />
/// <reference path="./resource/CryptoCurrency.ts" /> /// <reference path="./resource/CryptoCurrency.ts" />
/// <reference path="./resource/CryptoMarket.ts" />
/// <reference path="./resource/Follower.ts" /> /// <reference path="./resource/Follower.ts" />
/// <reference path="./resource/House.ts" /> /// <reference path="./resource/House.ts" />
/// <reference path="./resource/Megachurch.ts" /> /// <reference path="./resource/Megachurch.ts" />
@ -29,7 +30,8 @@ class GameConfig {
// general configs // general configs
public cfgInitialMax: ResourceNumber = { public cfgInitialMax: ResourceNumber = {
cryptoCurrency: 1000, cryptoCurrency: 10000,
cryptoMarket: 100000000,
megaChurches: 2, megaChurches: 2,
money: 500000, money: 500000,
followers: 5, followers: 5,
@ -70,7 +72,10 @@ class GameConfig {
public cfgCredibilityFollowerLossRatio = 0.04; public cfgCredibilityFollowerLossRatio = 0.04;
public cfgCredibilityFollowerLossTime = 10000; public cfgCredibilityFollowerLossTime = 10000;
public cfgCredibilityRestoreRate = 0.25; public cfgCredibilityRestoreRate = 0.25;
public cfgCryptoReturnAmount = 1; public cfgCryptoCurrencyMinimumValue = 1;
public cfgCryptoMarketAdjustAmount = 0.1;
public cfgCryptoMarketAdjustPeriod = 30000;
public cfgCryptoMarketGrowthBias = 0.1;
public cfgDefaultSellMultiplier = 0.5; public cfgDefaultSellMultiplier = 0.5;
public cfgFollowerGainLossLogTimer = 10000; public cfgFollowerGainLossLogTimer = 10000;
public cfgPassiveMax = 100; public cfgPassiveMax = 100;
@ -194,6 +199,7 @@ class GameConfig {
// add passive resources // add passive resources
state.addResource(ResourceKey.credibility, new Credibility(this)); state.addResource(ResourceKey.credibility, new Credibility(this));
state.addResource(ResourceKey.cryptoMarket, new CryptoMarket(this));
return state; return state;
} }

View File

@ -3,7 +3,7 @@
class GameState { class GameState {
public readonly config: GameConfig; public readonly config: GameConfig;
public onResourceClick: Array<() => void> = []; public onAction: Array<() => void> = [];
public logger: ILogger | null = null; public logger: ILogger | null = null;
public now = 0; public now = 0;
@ -70,6 +70,12 @@ class GameState {
} }
} }
public autoAction(): void {
for (const callback of this.onAction) {
callback();
}
}
public performAction(resourceKey: ResourceKey, actionIndex: number): void { public performAction(resourceKey: ResourceKey, actionIndex: number): void {
const resource = this._resources[resourceKey]; const resource = this._resources[resourceKey];
if ( if (
@ -83,7 +89,7 @@ class GameState {
const action = resource.userActions[actionIndex]; const action = resource.userActions[actionIndex];
action.performAction(this); action.performAction(this);
for (const callback of this.onResourceClick) { for (const callback of this.onAction) {
callback(); callback();
} }
} }

View File

@ -14,6 +14,8 @@ class CryptoCurrency extends Purchasable {
this.valueInWholeNumbers = false; this.valueInWholeNumbers = false;
} }
public max: (state: GameState) => number = (state) => public isUnlocked = (_state: GameState): boolean => true;
public max = (state: GameState): number =>
state.config.cfgInitialMax.cryptoCurrency ?? 0; state.config.cfgInitialMax.cryptoCurrency ?? 0;
} }

View File

@ -0,0 +1,55 @@
/// <reference path="./Hidden.ts" />
class CryptoMarket extends Hidden {
private _adjustmentTime = 0;
constructor(config: GameConfig) {
super(
'crypto market',
'crypto markets',
'How much money a single FaithCoin is worth'
);
this.value = config.cfgInitialCost.cryptoCurrency ?? 0;
}
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
}
}
};
}

View File

@ -0,0 +1,21 @@
/// <reference path="./IResource.ts" />
abstract class Hidden implements IResource {
public readonly resourceType = ResourceType.passive;
public readonly valueInWholeNumbers = false;
public value = 0;
constructor(
public readonly singularName: string,
public readonly pluralName: string,
public readonly description: string
) {}
public addValue(amount: number, _state: GameState): void {
this.value += amount;
}
public isUnlocked(_state: GameState): boolean {
return true;
}
}

View File

@ -42,11 +42,6 @@ class Money implements IResource {
public inc: (state: GameState) => number = (state) => { public inc: (state: GameState) => number = (state) => {
let inc = 0; let inc = 0;
// crypto currency
inc +=
(state.resource.cryptoCurrency?.value ?? 0) *
state.config.cfgCryptoReturnAmount;
// salaries // salaries
inc -= inc -=
(state.resource.pastors?.value ?? 0) * (state.resource.pastors?.value ?? 0) *

View File

@ -5,8 +5,6 @@ abstract class Passive implements IResource {
public readonly valueInWholeNumbers = false; public readonly valueInWholeNumbers = false;
public value = 0; public value = 0;
public advanceAction?: (time: number, state: GameState) => void = undefined;
constructor( constructor(
public readonly label: string, public readonly label: string,
public readonly singularName: string, public readonly singularName: string,

View File

@ -22,6 +22,7 @@ enum ResourceKey {
pastors = 'pastors', pastors = 'pastors',
money = 'money', money = 'money',
cryptoCurrency = 'cryptoCurrency', cryptoCurrency = 'cryptoCurrency',
cryptoMarket = 'cryptoMarket',
tents = 'tents', tents = 'tents',
houses = 'houses', houses = 'houses',
churches = 'churches', churches = 'churches',

View File

@ -14,7 +14,7 @@ class DebugRenderer implements IRenderer {
console.error('could not find game container'); console.error('could not find game container');
return; return;
} }
state.onResourceClick.push((): void => { state.onAction.push((): void => {
this._handleClick = true; this._handleClick = true;
}); });
const style = document.createElement('link'); const style = document.createElement('link');