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 },
};
public cfgBuySpeed: { [key in ResourceKey]?: ResourceNumber } = {
compoundManagers: {
churches: 0.01,
houses: 0.02,
tents: 0.05,
},
};
public cfgCredibilityFollowerLossRatio = 0.04;
public cfgCredibilityFollowerLossTime = 10000;
public cfgCredibilityRestoreRate = 0.25;

View File

@ -18,8 +18,18 @@ class Church extends Infrastructure {
}
public max: (state: GameState) => number = (state) =>
(state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.churches ?? 0);
Math.floor(
(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 {
if (this._isUnlocked) return true;

View File

@ -11,9 +11,9 @@ class CompoundManager extends Job {
}
public max: (state: GameState) => number = (state) => {
return (
return Math.floor(
(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) =>
(state.resource.compounds?.value ?? 0) *
(state.config.cfgCapacity.compounds?.houses ?? 0);
Math.floor(
(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 {
if (this._isUnlocked) return true;

View File

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

View File

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

View File

@ -64,6 +64,16 @@ abstract class Purchasable implements IResource {
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 {
let verb = 'purchased';
if (amount < 0) {

View File

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

View File

@ -21,6 +21,11 @@ class Tent extends Infrastructure {
max +=
(state.resource.compounds?.value ?? 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
? Math.floor(resource.value)
: resource.value;
const max =
resource.max !== undefined ? resource.max(state) : undefined;
elV.innerHTML = formatNumber(value);
elT.innerHTML =
resource.max !== undefined
? ` / ${formatNumber(resource.max(state))}`
max !== undefined
? ` / ${formatNumber(
resource.valueInWholeNumbers ? Math.floor(max) : max
)}`
: '';
if (resource.userActions !== undefined) {
for (let i = 0; i < resource.userActions.length; i++) {