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/Job.ts

69 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-08-22 11:07:49 -05:00
/// <reference path="./IResource.ts" />
abstract class Job implements IResource {
2021-09-05 14:45:37 -05:00
public readonly resourceType: ResourceType = ResourceType.job;
2021-08-22 11:07:49 -05:00
public readonly valueInWholeNumbers: boolean = true;
public readonly clickText: string = 'Hire';
2021-09-05 14:45:37 -05:00
public readonly clickDescription: string = 'Promote one of your followers.';
2021-09-04 22:21:14 -05:00
public value = 0;
public readonly cost: { [key: string]: number } = { };
2021-08-22 11:07:49 -05:00
2021-09-05 14:45:37 -05:00
public max: ((state: GameState) => number) | null = null;
public inc: ((state: GameState) => number) | null = null;
2021-08-22 11:07:49 -05:00
protected _costMultiplier: { [key: string]: number } = { };
2021-09-04 22:21:14 -05:00
protected _isUnlocked = false;
2021-08-22 11:07:49 -05:00
constructor (
public readonly name: string,
public readonly description: string
) { }
2021-08-22 11:07:49 -05:00
public clickAction (state: GameState): void {
if (this._availableJobs(state) <= 0) {
state.log('You have no unemployed followers to promote.');
return;
}
2021-09-05 14:45:37 -05:00
if (this.max !== null && this.value < this.max(state)
&& state.deductCost(this.cost)) {
2021-09-04 22:21:14 -05:00
this.addValue(1);
2021-08-22 11:07:49 -05:00
state.log(this._hireLog(1, state));
for (const rkey of Object.keys(this._costMultiplier)) {
this.cost[rkey] *= this._costMultiplier[rkey];
}
}
}
2021-09-04 22:21:14 -05:00
public addValue (amount: number): void {
this.value += amount;
2021-08-22 11:07:49 -05:00
}
2021-09-05 14:45:37 -05:00
public isUnlocked (_state: GameState): boolean {
return this._isUnlocked;
2021-08-22 11:07:49 -05:00
}
2021-09-05 14:45:37 -05:00
public advanceAction (_time: number, _state: GameState): void {
2021-08-22 11:07:49 -05:00
return;
}
protected _availableJobs (state: GameState): number {
// number of followers minus the number of filled jobs
const followers: number = state.getResource('plorg').value;
2021-09-05 14:45:37 -05:00
const hired: number = state.getResources().reduce(
(tot: number, rkey: string): number => {
2021-08-22 11:07:49 -05:00
const res: IResource = state.getResource(rkey);
2021-09-05 14:45:37 -05:00
return res.resourceType === ResourceType.job
2021-08-22 11:07:49 -05:00
? tot + res.value
: tot;
}, 0);
let max: number = followers - hired;
if (max < 0) max = 0;
return max;
}
2021-09-05 14:45:37 -05:00
protected _hireLog (amount: number, _state: GameState): string {
2021-08-22 11:07:49 -05:00
return `You hired ${amount} x ${this.name}.`;
}
}