inetraction stuff
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { Chibi } from "../../types/chibi/chibi";
|
||||
import { EChibiInteraction } from "../../types/chibi/chibi-interaction";
|
||||
import { EChibiStateName } from "../../types/chibi/chibi-state-name";
|
||||
import { Food } from "../../types/food";
|
||||
|
||||
export interface IBrain {
|
||||
|
||||
//function for time passegs + autonomous state changes
|
||||
exist(chibi: Chibi): void;
|
||||
|
||||
resolveInteraction(state: EChibiStateName, interaction: EChibiInteraction): EChibiStateName
|
||||
resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void
|
||||
}
|
||||
@@ -1,12 +1,29 @@
|
||||
import { Chibi } from "../../../types/chibi/chibi";
|
||||
import { EChibiInteraction } from "../../../types/chibi/chibi-interaction";
|
||||
import { EChibiStateName } from "../../../types/chibi/chibi-state-name";
|
||||
import { Food } from "../../../types/food";
|
||||
import { IBrain } from "../brain";
|
||||
|
||||
export class Aperio implements IBrain {
|
||||
resolveInteraction(state: EChibiStateName, interaction: EChibiInteraction): EChibiStateName {
|
||||
switch (state) {
|
||||
case EChibiStateName.Sleeping: return this.resolveSleepingInteraction(interaction);
|
||||
default: return EChibiStateName.Sleeping;
|
||||
|
||||
private hasBeenAwakeFor: number = 0;
|
||||
|
||||
exist(chibi: Chibi): void {
|
||||
console.log('Brain is braining');
|
||||
if (!EChibiStateName.Sleeping) {
|
||||
this.hasBeenAwakeFor++;
|
||||
if (this.hasBeenAwakeFor > 60) {
|
||||
chibi.state = EChibiStateName.Sleeping;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +56,11 @@ export class Aperio implements IBrain {
|
||||
}
|
||||
return EChibiStateName.Sleeping;
|
||||
}
|
||||
|
||||
private resolveAwakeInteraction(interaction: EChibiInteraction, item?: Food): EChibiStateName {
|
||||
if (EChibiInteraction.Feed) {
|
||||
return EChibiStateName.Eating;
|
||||
}
|
||||
return EChibiStateName.Idle;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user