hadean-old/src/Pawn.ts

104 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-06-14 22:03:55 -04:00
import { Serializable } from 'frigid';
import faker from 'faker';
2021-07-16 20:49:29 -04:00
import { Task, TaskState } from './registries/Tasks.js';
2021-06-16 16:22:33 -04:00
import Time, { Tickable } from './Time.js';
2021-06-14 22:03:55 -04:00
import { Game } from './Game.js';
2021-07-20 16:37:38 -04:00
import { render, Renderable, RenderMode } from '@ui';
2021-06-16 15:26:42 -04:00
import { Memory } from './Memory.js';
2021-06-26 03:11:18 -04:00
import { getTheme } from '@themes';
2021-06-14 22:03:55 -04:00
2021-06-23 01:28:06 -04:00
// TODO add stats getter to return % of all stats
2021-06-14 22:03:55 -04:00
2021-07-19 01:53:30 -04:00
export class Pawn extends Serializable implements Tickable, Renderable {
2021-06-19 12:40:01 -04:00
name: {
first: string,
last: string
};
sex: number;
age: number;
memories: Memory[];
2021-07-19 01:53:30 -04:00
job: TaskState<unknown, unknown>;
2021-07-16 20:49:29 -04:00
2021-06-19 12:40:01 -04:00
async tick() {
this.age ++;
}
get idle() {
2021-07-16 20:49:29 -04:00
return !this.job;
2021-06-19 12:40:01 -04:00
}
ctor() {
this.name ??= {
first: faker.name.firstName(),
last: faker.name.lastName()
};
if(!this.sex) {
this.sex = Math.round(Math.random());
this.name.first = faker.name.firstName(this.sex);
}
this.memories ??= [];
if(!this.age) {
this.age = Math.floor(525600 * (16 + Math.random() * 9));
this.memories.push({
type: "birth",
location: Game.current.name,
time: {
age: 0,
locale: new Time(Game.current.clock.stamp - this.age).toString()
}
})
}
2021-07-16 20:49:29 -04:00
// if(this.job?.completed) {
// this.stopWorking();
// }
}
taskCompleted() {
this.job = null
2021-06-19 12:40:01 -04:00
}
stopWorking() {
if(this.job) {
2021-07-16 20:49:29 -04:00
// this.job.unclaim(this);
2021-06-19 12:40:01 -04:00
this.job = null;
}
}
get status() {
2021-07-16 20:49:29 -04:00
return 'SEMETHING';
// if(this.job) {
// return this.job.task.status;
// } else {
// return this.awake ? getTheme().status.idle('IDLE') : getTheme().status.self('RESTING')
// }
2021-06-19 12:40:01 -04:00
}
static serializationDependencies() {
return [TaskState]
2021-06-19 12:40:01 -04:00
}
toString() {
2021-07-19 01:53:30 -04:00
return this.render(RenderMode.ONELINE);
}
render(mode: RenderMode): string {
if(mode === RenderMode.ONELINE) {
if(this.name) {
return this.name.first + ' ' + this.name.last;
} else {
return '[Object Pawn]';
}
} else if (mode === RenderMode.DETAILS) {
return `${
this.toString()
}{|}${
this.status
}\nDETAILS\nDETAILS`
2021-06-19 12:40:01 -04:00
}
}
2021-06-14 22:03:55 -04:00
}
2021-07-16 20:49:29 -04:00
// const task =