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-06-16 15:26:42 -04:00
|
|
|
import { render } from './ui/UI.js';
|
|
|
|
|
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
|
|
|
|
|
|
|
|
export class Pawn extends Serializable implements Tickable {
|
2021-06-19 12:40:01 -04:00
|
|
|
name: {
|
|
|
|
|
first: string,
|
|
|
|
|
last: string
|
|
|
|
|
};
|
|
|
|
|
sex: number;
|
|
|
|
|
age: number;
|
|
|
|
|
memories: Memory[];
|
|
|
|
|
|
2021-07-16 20:49:29 -04:00
|
|
|
job: TaskState<unknown>;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-06-22 22:38:49 -04:00
|
|
|
static serializationDependencies() {
|
2021-06-25 20:28:29 -04:00
|
|
|
return [TaskState]
|
2021-06-19 12:40:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toString() {
|
|
|
|
|
if(this.name) {
|
|
|
|
|
return this.name.first + ' ' + this.name.last;
|
|
|
|
|
} else {
|
|
|
|
|
return '[Object Pawn]';
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-14 22:03:55 -04:00
|
|
|
}
|
2021-07-16 20:49:29 -04:00
|
|
|
|
|
|
|
|
// const task =
|