From f57660c9940cca91c8de392b1f90b9e60f5c3ff2 Mon Sep 17 00:00:00 2001 From: Dustlint Date: Sun, 15 Mar 2026 19:42:28 +0100 Subject: [PATCH] pear refuses samey food --- .../chibi-behaviour/brains/aperio.brain.ts | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/app/logic/chibi-behaviour/brains/aperio.brain.ts b/src/app/logic/chibi-behaviour/brains/aperio.brain.ts index b35614c..3151c7e 100644 --- a/src/app/logic/chibi-behaviour/brains/aperio.brain.ts +++ b/src/app/logic/chibi-behaviour/brains/aperio.brain.ts @@ -42,7 +42,7 @@ export class Aperio implements IBrain { [EChibiInteraction.WakeUp]: (interaction: ChibiInteraction): ChibiState => this.wakeUp(interaction), }, [EChibiStateName.Awake]: { - [EChibiInteraction.Feed]: (interaction: ChibiInteraction): ChibiState => this.eat(interaction), + [EChibiInteraction.Feed]: (interaction: ChibiInteraction): ChibiState => this.feedTo(interaction), }, [EChibiStateName.Snoring]: undefined, [EChibiStateName.Nightmare]: undefined, @@ -120,6 +120,7 @@ export class Aperio implements IBrain { resolveSleeping(): void { if (isState(this.state, EChibiStateName.Sleeping)) { console.log(`${this.chibi.name} is sleeping.`); + this.hasBeenAwakeFor = 0; this.increaseHappyness(HAPPINESS_FROM_SLEEP); const awakeChance = this.randomService.obtainRandom(2048); if (awakeChance.matchesChance(1)) { @@ -156,8 +157,6 @@ export class Aperio implements IBrain { /* visiting caethya will wake her up and go into lovey-dovey mode - as long as the same food is not offered thrice in a row (except banana split) - pears energy never goes down pear will accept fights and enjoys them pear will accept walks and enjoys them @@ -179,19 +178,36 @@ export class Aperio implements IBrain { } else if (willGrumble) { return STATE_GRUMBLING; } - return STATE_SLEEPING; + return this.state; } - private eat(interaction: ChibiInteraction): ChibiState { + private feedTo(interaction: ChibiInteraction): ChibiState { console.log(`${this.chibi.name} should eat ${interaction.payload.name}`); const foodId = interaction.payload.id; if (this.preferredFoods.includes(foodId)) { - this.lastConsumedFoods.push(foodId); - this.increaseHappyness(100); + this.eat(interaction.payload); return STATE_EATING; - } else { + } else if (this.lastConsumedFoods[0] === foodId && this.lastConsumedFoods[1] === foodId && this.lastConsumedFoods[2] === foodId) { + console.log(`${this.chibi.name} refuses to eat another ${interaction.payload.name}!`); + return this.state; } + this.eat(interaction.payload); return STATE_EATING; } + + private eat(food: Food): void { + this.addToLastEatenFoods(food.id); + this.increaseHappyness(100); + } + + private addToLastEatenFoods(foodId: string): void { + if (this.lastConsumedFoods.length < 3) { + this.lastConsumedFoods.push(foodId); + } else { + this.lastConsumedFoods = this.lastConsumedFoods.slice(1, 3); + this.lastConsumedFoods.push(foodId); + } + console.log(this.lastConsumedFoods); + } }; \ No newline at end of file