the pear goes back to sleep
This commit is contained in:
@@ -4,8 +4,9 @@ import { Food } from "../../types/food";
|
||||
|
||||
export interface IBrain {
|
||||
|
||||
init(chibi: Chibi): void;
|
||||
//function for time passegs + autonomous state changes
|
||||
exist(chibi: Chibi): void;
|
||||
exist(): void;
|
||||
|
||||
resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void
|
||||
resolveInteraction(interaction: EChibiInteraction, item?: Food): void
|
||||
}
|
||||
@@ -1,30 +1,44 @@
|
||||
import { Chibi } from "../../../types/chibi/chibi";
|
||||
import { EChibiInteraction } from "../../../types/chibi/chibi-interaction";
|
||||
import { ChibiState, isState, STATE_AWAKE, STATE_EATING, STATE_IDLE, STATE_SLEEPING, STATES } from "../../../types/chibi/chibi-state";
|
||||
import { EChibiStateName } from "../../../types/chibi/chibi-state-name";
|
||||
import { Food } from "../../../types/food";
|
||||
import { IBrain } from "../brain";
|
||||
|
||||
const MAX_TIME_AWAKE: number = 3;
|
||||
|
||||
export class Aperio implements IBrain {
|
||||
|
||||
private chibi!: Chibi;
|
||||
private hasBeenAwakeFor: number = 0;
|
||||
private state!: ChibiState;
|
||||
|
||||
exist(chibi: Chibi): void {
|
||||
console.log('Brain is braining');
|
||||
if (!EChibiStateName.Sleeping) {
|
||||
this.hasBeenAwakeFor++;
|
||||
if (this.hasBeenAwakeFor > 60) {
|
||||
chibi.state = EChibiStateName.Sleeping;
|
||||
}
|
||||
}
|
||||
init(chibi: Chibi): void {
|
||||
this.chibi = chibi;
|
||||
this.state = STATES[chibi.state];
|
||||
}
|
||||
|
||||
resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void {
|
||||
switch (chibi.state) {
|
||||
case EChibiStateName.Sleeping: chibi.state = this.resolveSleepingInteraction(interaction); break;
|
||||
case EChibiStateName.Awake: chibi.state = this.resolveAwakeInteraction(interaction, item); break;
|
||||
default:
|
||||
chibi.state = EChibiStateName.Sleeping; break;
|
||||
exist(): void {
|
||||
console.log('Brain is braining');
|
||||
if (isState(this.state, EChibiStateName.Awake)) {
|
||||
console.log('is awake');
|
||||
this.hasBeenAwakeFor++;
|
||||
if (this.hasBeenAwakeFor > MAX_TIME_AWAKE) {
|
||||
this.state = STATE_SLEEPING;
|
||||
this.chibi.state = EChibiStateName.Sleeping;
|
||||
this.hasBeenAwakeFor = 0;
|
||||
}
|
||||
}
|
||||
this.chibi.state = this.state.name;
|
||||
}
|
||||
|
||||
resolveInteraction(interaction: EChibiInteraction, item?: Food): void {
|
||||
if (isState(this.state, EChibiStateName.Sleeping)) {
|
||||
this.state = this.resolveSleepingInteraction(interaction);
|
||||
} else {
|
||||
this.state = this.resolveAwakeInteraction(interaction, item);
|
||||
}
|
||||
this.chibi.state = this.state.name;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -50,17 +64,17 @@ export class Aperio implements IBrain {
|
||||
after any interaction she has a 1/4 chance of going to sleep
|
||||
*/
|
||||
|
||||
private resolveSleepingInteraction(interaction: EChibiInteraction): EChibiStateName {
|
||||
private resolveSleepingInteraction(interaction: EChibiInteraction): ChibiState {
|
||||
if (EChibiInteraction.WakeUp) {
|
||||
return EChibiStateName.Awake;
|
||||
return STATE_AWAKE;
|
||||
}
|
||||
return EChibiStateName.Sleeping;
|
||||
return STATE_SLEEPING;
|
||||
}
|
||||
|
||||
private resolveAwakeInteraction(interaction: EChibiInteraction, item?: Food): EChibiStateName {
|
||||
private resolveAwakeInteraction(interaction: EChibiInteraction, item?: Food): ChibiState {
|
||||
if (EChibiInteraction.Feed) {
|
||||
return EChibiStateName.Eating;
|
||||
return STATE_EATING;
|
||||
}
|
||||
return EChibiStateName.Idle;
|
||||
return STATE_IDLE;
|
||||
}
|
||||
};
|
||||
@@ -13,6 +13,7 @@ import { BRAIN_MAP } from '../../logic/chibi-behaviour/brain-map';
|
||||
import { TranslateableComponent } from '../../components/translateable.component';
|
||||
import { Food } from '../../types/food';
|
||||
import { interval } from 'rxjs';
|
||||
import { ChibiState, STATES } from '../../types/chibi/chibi-state';
|
||||
|
||||
enum EInteractionMenuState {
|
||||
Neutral,
|
||||
@@ -20,6 +21,8 @@ enum EInteractionMenuState {
|
||||
Inventory
|
||||
}
|
||||
|
||||
const THINKING_INTERVAL: number = 10000;
|
||||
|
||||
@Component({
|
||||
selector: 'ff-interactions',
|
||||
imports: [HeaderComponent, InteractionCanvasComponent, FoodPantryComponent, InventoryComponent, ButtonComponent],
|
||||
@@ -46,16 +49,17 @@ export class InteractionsComponent extends TranslateableComponent {
|
||||
effect(() => {
|
||||
if (this.chibi()) {
|
||||
this.brain = BRAIN_MAP[this.chibi().name]!;
|
||||
this.brain.init(this.chibi());
|
||||
}
|
||||
})
|
||||
interval(1000).subscribe(() => {
|
||||
this.brain.exist(this.chibi());
|
||||
interval(THINKING_INTERVAL).subscribe(() => {
|
||||
this.brain.exist();
|
||||
})
|
||||
}
|
||||
|
||||
public interact(interaction: EChibiInteraction, item?: Food): void {
|
||||
console.log(`${interaction} ${this.chibi().name} and item ${item}`);
|
||||
this.brain.resolveInteraction(this.chibi(), interaction, item);
|
||||
this.brain.resolveInteraction(interaction, item);
|
||||
}
|
||||
|
||||
public openFoodPantry(): void {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
export enum EChibiStateName {
|
||||
Sleeping = 'Sleeping',
|
||||
Snoring = 'Snoring',
|
||||
Nightmare = 'Nightmare',
|
||||
Grumbling = 'Grumbling',
|
||||
Awake = 'Awake',
|
||||
Bored = 'Bored',
|
||||
Idle = 'Idle',
|
||||
Exited = 'Exited',
|
||||
Fighting = 'Fighting',
|
||||
Walking = 'Walking',
|
||||
Eating = 'Eating',
|
||||
Hungry = 'Hunry',
|
||||
Depressed = 'Depressed',
|
||||
|
||||
90
src/app/types/chibi/chibi-state.ts
Normal file
90
src/app/types/chibi/chibi-state.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { EChibiStateName } from "./chibi-state-name"
|
||||
|
||||
export type ChibiState = {
|
||||
name: EChibiStateName;
|
||||
parent?: ChibiState;
|
||||
}
|
||||
|
||||
export const isState = (state: ChibiState, stateName: EChibiStateName): boolean => {
|
||||
if (state.parent) {
|
||||
return state.name === stateName || isState(state.parent, stateName);
|
||||
}
|
||||
return state.name === stateName;
|
||||
}
|
||||
|
||||
export const STATE_SLEEPING: ChibiState = {
|
||||
name: EChibiStateName.Sleeping
|
||||
}
|
||||
|
||||
export const STATE_GRUMBLING: ChibiState = {
|
||||
name: EChibiStateName.Grumbling,
|
||||
parent: STATE_SLEEPING
|
||||
}
|
||||
|
||||
export const STATE_SNORING: ChibiState = {
|
||||
name: EChibiStateName.Snoring,
|
||||
parent: STATE_SLEEPING
|
||||
}
|
||||
|
||||
export const STATE_NIGHTMARE: ChibiState = {
|
||||
name: EChibiStateName.Nightmare,
|
||||
parent: STATE_SLEEPING
|
||||
}
|
||||
|
||||
export const STATE_AWAKE: ChibiState = {
|
||||
name: EChibiStateName.Awake
|
||||
}
|
||||
|
||||
export const STATE_EATING: ChibiState = {
|
||||
name: EChibiStateName.Eating,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
export const STATE_BORED: ChibiState = {
|
||||
name: EChibiStateName.Bored,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
export const STATE_IDLE: ChibiState = {
|
||||
name: EChibiStateName.Idle,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
export const STATE_EXITED: ChibiState = {
|
||||
name: EChibiStateName.Exited,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
|
||||
export const STATE_FIGHTING: ChibiState = {
|
||||
name: EChibiStateName.Fighting,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
|
||||
export const STATE_HUNGRY: ChibiState = {
|
||||
name: EChibiStateName.Hungry,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
|
||||
export const STATE_DEPRESSED: ChibiState = {
|
||||
name: EChibiStateName.Depressed,
|
||||
parent: STATE_AWAKE
|
||||
}
|
||||
|
||||
|
||||
export const STATES: Record<EChibiStateName, ChibiState> = {
|
||||
[EChibiStateName.Sleeping]: STATE_SLEEPING,
|
||||
[EChibiStateName.Snoring]: STATE_SNORING,
|
||||
[EChibiStateName.Nightmare]: STATE_NIGHTMARE,
|
||||
[EChibiStateName.Grumbling]: STATE_GRUMBLING,
|
||||
[EChibiStateName.Awake]: STATE_AWAKE,
|
||||
[EChibiStateName.Bored]: STATE_BORED,
|
||||
[EChibiStateName.Idle]: STATE_IDLE,
|
||||
[EChibiStateName.Exited]: STATE_EXITED,
|
||||
[EChibiStateName.Fighting]: STATE_FIGHTING,
|
||||
[EChibiStateName.Eating]: STATE_EATING,
|
||||
[EChibiStateName.Hungry]: STATE_HUNGRY,
|
||||
[EChibiStateName.Depressed]: STATE_DEPRESSED
|
||||
}
|
||||
Reference in New Issue
Block a user