crypto market hidden resource to drive faithcoin cost
This commit is contained in:
parent
199db37b01
commit
079ff29f97
|
@ -2,7 +2,7 @@
|
|||
/// <reference path="./render/DebugRenderer.ts" />
|
||||
|
||||
const versionMajor = 2;
|
||||
const versionMinor = 0;
|
||||
const versionMinor = 1;
|
||||
|
||||
let globalStartTime = 0;
|
||||
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);
|
||||
|
||||
// debug values to make the game play faster while testing
|
||||
config.cfgTitheAmount = 1000;
|
||||
config.cfgTimeBetweenTithes = 5000;
|
||||
config.cfgCryptoReturnAmount = 100;
|
||||
config.cfgCredibilityRestoreRate = 5;
|
||||
config.cfgPastorRecruitRate = 0.5;
|
||||
config.cfgTimeBetweenTithes = 5000;
|
||||
config.cfgTitheAmount = 1000;
|
||||
|
||||
const renderer = new DebugRenderer();
|
||||
renderer.onInitialRender = initialRender;
|
||||
const state = config.generateState();
|
||||
|
||||
// re-run main loop immediately on user clicks
|
||||
state.onResourceClick.push((): void => {
|
||||
state.onAction.push((): void => {
|
||||
if (globalTimeout !== null) {
|
||||
clearTimeout(globalTimeout);
|
||||
gameLoop(state, renderer);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
/// <reference path="./resource/Compound.ts" />
|
||||
/// <reference path="./resource/Credibility.ts" />
|
||||
/// <reference path="./resource/CryptoCurrency.ts" />
|
||||
/// <reference path="./resource/CryptoMarket.ts" />
|
||||
/// <reference path="./resource/Follower.ts" />
|
||||
/// <reference path="./resource/House.ts" />
|
||||
/// <reference path="./resource/Megachurch.ts" />
|
||||
|
@ -29,7 +30,8 @@ class GameConfig {
|
|||
|
||||
// general configs
|
||||
public cfgInitialMax: ResourceNumber = {
|
||||
cryptoCurrency: 1000,
|
||||
cryptoCurrency: 10000,
|
||||
cryptoMarket: 100000000,
|
||||
megaChurches: 2,
|
||||
money: 500000,
|
||||
followers: 5,
|
||||
|
@ -70,7 +72,10 @@ class GameConfig {
|
|||
public cfgCredibilityFollowerLossRatio = 0.04;
|
||||
public cfgCredibilityFollowerLossTime = 10000;
|
||||
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 cfgFollowerGainLossLogTimer = 10000;
|
||||
public cfgPassiveMax = 100;
|
||||
|
@ -194,6 +199,7 @@ class GameConfig {
|
|||
|
||||
// add passive resources
|
||||
state.addResource(ResourceKey.credibility, new Credibility(this));
|
||||
state.addResource(ResourceKey.cryptoMarket, new CryptoMarket(this));
|
||||
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class GameState {
|
||||
public readonly config: GameConfig;
|
||||
|
||||
public onResourceClick: Array<() => void> = [];
|
||||
public onAction: Array<() => void> = [];
|
||||
public logger: ILogger | null = null;
|
||||
|
||||
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 {
|
||||
const resource = this._resources[resourceKey];
|
||||
if (
|
||||
|
@ -83,7 +89,7 @@ class GameState {
|
|||
const action = resource.userActions[actionIndex];
|
||||
|
||||
action.performAction(this);
|
||||
for (const callback of this.onResourceClick) {
|
||||
for (const callback of this.onAction) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ class CryptoCurrency extends Purchasable {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -42,11 +42,6 @@ class Money implements IResource {
|
|||
public inc: (state: GameState) => number = (state) => {
|
||||
let inc = 0;
|
||||
|
||||
// crypto currency
|
||||
inc +=
|
||||
(state.resource.cryptoCurrency?.value ?? 0) *
|
||||
state.config.cfgCryptoReturnAmount;
|
||||
|
||||
// salaries
|
||||
inc -=
|
||||
(state.resource.pastors?.value ?? 0) *
|
||||
|
|
|
@ -5,8 +5,6 @@ abstract class Passive implements IResource {
|
|||
public readonly valueInWholeNumbers = false;
|
||||
public value = 0;
|
||||
|
||||
public advanceAction?: (time: number, state: GameState) => void = undefined;
|
||||
|
||||
constructor(
|
||||
public readonly label: string,
|
||||
public readonly singularName: string,
|
||||
|
|
|
@ -22,6 +22,7 @@ enum ResourceKey {
|
|||
pastors = 'pastors',
|
||||
money = 'money',
|
||||
cryptoCurrency = 'cryptoCurrency',
|
||||
cryptoMarket = 'cryptoMarket',
|
||||
tents = 'tents',
|
||||
houses = 'houses',
|
||||
churches = 'churches',
|
||||
|
|
|
@ -14,7 +14,7 @@ class DebugRenderer implements IRenderer {
|
|||
console.error('could not find game container');
|
||||
return;
|
||||
}
|
||||
state.onResourceClick.push((): void => {
|
||||
state.onAction.push((): void => {
|
||||
this._handleClick = true;
|
||||
});
|
||||
const style = document.createElement('link');
|
||||
|
|
Reference in New Issue