This repository has been archived on 2022-01-16. You can view files and clone it, but cannot push or open issues or pull requests.
irreligious/src/model/resource/Pastor.ts

64 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-08-22 11:07:49 -05:00
/// <reference path="./Job.ts" />
class Pastor extends Job {
2021-09-04 22:21:14 -05:00
private _timeSinceLastTithe = 0;
2021-08-22 11:07:49 -05:00
constructor() {
super(
2021-09-06 08:51:41 -05:00
'Pastors',
'pastor',
'pastors',
'Collect tithings for you and recruit new members from other faiths automatically.'
);
2021-08-22 11:07:49 -05:00
}
2021-09-05 14:45:37 -05:00
public max: (state: GameState) => number = (state) => {
let max =
(state.resource.churches?.value ?? 0) *
(state.config.cfgCapacity.churches?.pastors ?? 0);
max +=
(state.resource.megaChurches?.value ?? 0) *
(state.config.cfgCapacity.megaChurches?.pastors ?? 0);
2021-09-04 23:16:32 -05:00
return max;
2021-09-05 14:45:37 -05:00
};
2021-08-22 11:07:49 -05:00
public isUnlocked(state: GameState): boolean {
2021-08-22 11:07:49 -05:00
if (this._isUnlocked) return true;
this._isUnlocked = state.resource.churches?.isUnlocked(state) === true;
2021-09-04 23:11:13 -05:00
return this._isUnlocked;
2021-08-22 11:07:49 -05:00
}
public advanceAction(time: number, state: GameState): void {
2021-09-05 20:43:11 -05:00
super.advanceAction(time, state);
2021-08-22 11:07:49 -05:00
this._timeSinceLastTithe += time;
if (this._timeSinceLastTithe >= state.config.cfgTimeBetweenTithes) {
const money = state.resource.money;
const followers = state.resource.followers;
let tithed = Math.floor(
this.value * state.config.cfgPastorTitheCollectionFollowerMax
);
if (Math.floor(followers?.value ?? 0) < tithed)
tithed = Math.floor(followers?.value ?? 0);
let collected = tithed * state.config.cfgTitheAmount;
if (
money?.max !== undefined &&
collected > money.max(state) - money.value
)
2021-09-05 19:20:24 -05:00
collected = money.max(state) - money.value;
2021-08-22 11:07:49 -05:00
if (collected > 0) {
money?.addValue(collected, state);
if (followers !== undefined) {
state.log(
`Your pastors collected $${formatNumber(
collected
)} in tithings from ${formatNumber(tithed)} ${
tithed > 1 ? followers.pluralName : followers.singularName
}.`
);
}
2021-08-22 11:07:49 -05:00
}
this._timeSinceLastTithe = 0;
}
}
}