tents remember unlock state, compound managers buy stuff

This commit is contained in:
Rudis Muiznieks 2021-09-11 21:26:54 -05:00
parent 2126ed483b
commit f03489b506
10 changed files with 62 additions and 15 deletions

View File

@ -77,6 +77,14 @@ class GameConfig {
tents: { followers: 2 }, tents: { followers: 2 },
}; };
public cfgBuySpeed: { [key in ResourceKey]?: ResourceNumber } = {
compoundManagers: {
churches: 0.01,
houses: 0.02,
tents: 0.05,
},
};
public cfgCredibilityFollowerLossRatio = 0.04; public cfgCredibilityFollowerLossRatio = 0.04;
public cfgCredibilityFollowerLossTime = 10000; public cfgCredibilityFollowerLossTime = 10000;
public cfgCredibilityRestoreRate = 0.25; public cfgCredibilityRestoreRate = 0.25;

View File

@ -18,8 +18,18 @@ class Church extends Infrastructure {
} }
public max: (state: GameState) => number = (state) => public max: (state: GameState) => number = (state) =>
(state.resource.compounds?.value ?? 0) * Math.floor(
(state.config.cfgCapacity.compounds?.churches ?? 0); (state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.churches ?? 0)
);
public inc: (state: GameState) => number = (state) => {
// compound managers
return (
(state.resource.compoundManagers?.value ?? 0) *
(state.config.cfgBuySpeed.compoundManagers?.churches ?? 0)
);
};
public isUnlocked(state: GameState): boolean { public isUnlocked(state: GameState): boolean {
if (this._isUnlocked) return true; if (this._isUnlocked) return true;

View File

@ -11,9 +11,9 @@ class CompoundManager extends Job {
} }
public max: (state: GameState) => number = (state) => { public max: (state: GameState) => number = (state) => {
return ( return Math.floor(
(state.resource.compounds?.value ?? 0) * (state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.compoundManagers ?? 0) (state.config.cfgCapacity.compounds?.compoundManagers ?? 0)
); );
}; };

View File

@ -16,8 +16,18 @@ class House extends Infrastructure {
} }
public max: (state: GameState) => number = (state) => public max: (state: GameState) => number = (state) =>
(state.resource.compounds?.value ?? 0) * Math.floor(
(state.config.cfgCapacity.compounds?.houses ?? 0); (state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.houses ?? 0)
);
public inc: (state: GameState) => number = (state) => {
// compound managers
return (
(state.resource.compoundManagers?.value ?? 0) *
(state.config.cfgBuySpeed.compoundManagers?.houses ?? 0)
);
};
public isUnlocked(state: GameState): boolean { public isUnlocked(state: GameState): boolean {
if (this._isUnlocked) return true; if (this._isUnlocked) return true;

View File

@ -19,8 +19,6 @@ interface IResource {
addValue: (amount: number, state: GameState) => void; addValue: (amount: number, state: GameState) => void;
isUnlocked: (state: GameState) => boolean; isUnlocked: (state: GameState) => boolean;
emitConfig?: () => { [key: string]: string | number | boolean }; emitConfig?: () => ResourceConfigValues;
restoreConfig?: (config: { restoreConfig?: (config: ResourceConfigValues) => void;
[key: string]: string | number | boolean;
}) => void;
} }

View File

@ -19,7 +19,7 @@ class Pastor extends Job {
max += max +=
(state.resource.megaChurches?.value ?? 0) * (state.resource.megaChurches?.value ?? 0) *
(state.config.cfgCapacity.megaChurches?.pastors ?? 0); (state.config.cfgCapacity.megaChurches?.pastors ?? 0);
return max; return Math.floor(max);
}; };
public isUnlocked(state: GameState): boolean { public isUnlocked(state: GameState): boolean {

View File

@ -64,6 +64,16 @@ abstract class Purchasable implements IResource {
return; return;
} }
public emitConfig: () => ResourceConfigValues = () => {
return { isUnlocked: this._isUnlocked };
};
public restoreConfig: (config: ResourceConfigValues) => void = (config) => {
if (typeof config.isUnlocked === 'boolean') {
this._isUnlocked = config.isUnlocked;
}
};
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) {

View File

@ -42,10 +42,12 @@ type ResourceAction = {
performAction: (state: GameState) => void; performAction: (state: GameState) => void;
}; };
type ResourceConfigValues = { [key: string]: string | number | boolean };
type ResourceConfig = { type ResourceConfig = {
value: number; value: number;
cost?: ResourceNumber; cost?: ResourceNumber;
config?: { [key: string]: string | number | boolean }; config?: ResourceConfigValues;
}; };
type SaveData = { type SaveData = {

View File

@ -21,6 +21,11 @@ class Tent extends Infrastructure {
max += max +=
(state.resource.compounds?.value ?? 0) * (state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.tents ?? 0); (state.config.cfgCapacity.compounds?.tents ?? 0);
return max; return Math.floor(max);
}; };
public inc: (state: GameState) => number = (state) =>
// compound managers
(state.resource.compoundManagers?.value ?? 0) *
(state.config.cfgBuySpeed.compoundManagers?.tents ?? 0);
} }

View File

@ -115,10 +115,14 @@ class DebugRenderer implements IRenderer {
const value = resource.valueInWholeNumbers const value = resource.valueInWholeNumbers
? Math.floor(resource.value) ? Math.floor(resource.value)
: resource.value; : resource.value;
const max =
resource.max !== undefined ? resource.max(state) : undefined;
elV.innerHTML = formatNumber(value); elV.innerHTML = formatNumber(value);
elT.innerHTML = elT.innerHTML =
resource.max !== undefined max !== undefined
? ` / ${formatNumber(resource.max(state))}` ? ` / ${formatNumber(
resource.valueInWholeNumbers ? Math.floor(max) : max
)}`
: ''; : '';
if (resource.userActions !== undefined) { if (resource.userActions !== undefined) {
for (let i = 0; i < resource.userActions.length; i++) { for (let i = 0; i < resource.userActions.length; i++) {