the pear goes back to sleep
This commit is contained in:
@@ -4,8 +4,9 @@ import { Food } from "../../types/food";
|
|||||||
|
|
||||||
export interface IBrain {
|
export interface IBrain {
|
||||||
|
|
||||||
|
init(chibi: Chibi): void;
|
||||||
//function for time passegs + autonomous state changes
|
//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 { Chibi } from "../../../types/chibi/chibi";
|
||||||
import { EChibiInteraction } from "../../../types/chibi/chibi-interaction";
|
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 { EChibiStateName } from "../../../types/chibi/chibi-state-name";
|
||||||
import { Food } from "../../../types/food";
|
import { Food } from "../../../types/food";
|
||||||
import { IBrain } from "../brain";
|
import { IBrain } from "../brain";
|
||||||
|
|
||||||
|
const MAX_TIME_AWAKE: number = 3;
|
||||||
|
|
||||||
export class Aperio implements IBrain {
|
export class Aperio implements IBrain {
|
||||||
|
|
||||||
|
private chibi!: Chibi;
|
||||||
private hasBeenAwakeFor: number = 0;
|
private hasBeenAwakeFor: number = 0;
|
||||||
|
private state!: ChibiState;
|
||||||
|
|
||||||
exist(chibi: Chibi): void {
|
init(chibi: Chibi): void {
|
||||||
console.log('Brain is braining');
|
this.chibi = chibi;
|
||||||
if (!EChibiStateName.Sleeping) {
|
this.state = STATES[chibi.state];
|
||||||
this.hasBeenAwakeFor++;
|
|
||||||
if (this.hasBeenAwakeFor > 60) {
|
|
||||||
chibi.state = EChibiStateName.Sleeping;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void {
|
exist(): void {
|
||||||
switch (chibi.state) {
|
console.log('Brain is braining');
|
||||||
case EChibiStateName.Sleeping: chibi.state = this.resolveSleepingInteraction(interaction); break;
|
if (isState(this.state, EChibiStateName.Awake)) {
|
||||||
case EChibiStateName.Awake: chibi.state = this.resolveAwakeInteraction(interaction, item); break;
|
console.log('is awake');
|
||||||
default:
|
this.hasBeenAwakeFor++;
|
||||||
chibi.state = EChibiStateName.Sleeping; break;
|
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
|
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) {
|
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) {
|
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 { TranslateableComponent } from '../../components/translateable.component';
|
||||||
import { Food } from '../../types/food';
|
import { Food } from '../../types/food';
|
||||||
import { interval } from 'rxjs';
|
import { interval } from 'rxjs';
|
||||||
|
import { ChibiState, STATES } from '../../types/chibi/chibi-state';
|
||||||
|
|
||||||
enum EInteractionMenuState {
|
enum EInteractionMenuState {
|
||||||
Neutral,
|
Neutral,
|
||||||
@@ -20,6 +21,8 @@ enum EInteractionMenuState {
|
|||||||
Inventory
|
Inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const THINKING_INTERVAL: number = 10000;
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ff-interactions',
|
selector: 'ff-interactions',
|
||||||
imports: [HeaderComponent, InteractionCanvasComponent, FoodPantryComponent, InventoryComponent, ButtonComponent],
|
imports: [HeaderComponent, InteractionCanvasComponent, FoodPantryComponent, InventoryComponent, ButtonComponent],
|
||||||
@@ -46,16 +49,17 @@ export class InteractionsComponent extends TranslateableComponent {
|
|||||||
effect(() => {
|
effect(() => {
|
||||||
if (this.chibi()) {
|
if (this.chibi()) {
|
||||||
this.brain = BRAIN_MAP[this.chibi().name]!;
|
this.brain = BRAIN_MAP[this.chibi().name]!;
|
||||||
|
this.brain.init(this.chibi());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
interval(1000).subscribe(() => {
|
interval(THINKING_INTERVAL).subscribe(() => {
|
||||||
this.brain.exist(this.chibi());
|
this.brain.exist();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public interact(interaction: EChibiInteraction, item?: Food): void {
|
public interact(interaction: EChibiInteraction, item?: Food): void {
|
||||||
console.log(`${interaction} ${this.chibi().name} and item ${item}`);
|
console.log(`${interaction} ${this.chibi().name} and item ${item}`);
|
||||||
this.brain.resolveInteraction(this.chibi(), interaction, item);
|
this.brain.resolveInteraction(interaction, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public openFoodPantry(): void {
|
public openFoodPantry(): void {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
export enum EChibiStateName {
|
export enum EChibiStateName {
|
||||||
Sleeping = 'Sleeping',
|
Sleeping = 'Sleeping',
|
||||||
|
Snoring = 'Snoring',
|
||||||
|
Nightmare = 'Nightmare',
|
||||||
|
Grumbling = 'Grumbling',
|
||||||
Awake = 'Awake',
|
Awake = 'Awake',
|
||||||
Bored = 'Bored',
|
Bored = 'Bored',
|
||||||
Idle = 'Idle',
|
Idle = 'Idle',
|
||||||
Exited = 'Exited',
|
Exited = 'Exited',
|
||||||
Fighting = 'Fighting',
|
Fighting = 'Fighting',
|
||||||
Walking = 'Walking',
|
|
||||||
Eating = 'Eating',
|
Eating = 'Eating',
|
||||||
Hungry = 'Hunry',
|
Hungry = 'Hunry',
|
||||||
Depressed = 'Depressed',
|
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