pear refuses samey food
This commit is contained in:
@@ -42,7 +42,7 @@ export class Aperio implements IBrain {
|
||||
[EChibiInteraction.WakeUp]: (interaction: ChibiInteraction): ChibiState => this.wakeUp(interaction),
|
||||
},
|
||||
[EChibiStateName.Awake]: {
|
||||
[EChibiInteraction.Feed]: (interaction: ChibiInteraction<Food>): ChibiState => this.eat(interaction),
|
||||
[EChibiInteraction.Feed]: (interaction: ChibiInteraction<Food>): 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<Food>): ChibiState {
|
||||
private feedTo(interaction: ChibiInteraction<Food>): 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user