Part Behavior
To do the wild haunt:
if the location of the ghost is the location of the player:
let the escape be a random ghost-viable door;
if the escape is nothing:
say "You feel a swirl of air around you as if something is trying to escape! After a very frightening minute it seems to settle down again. Watching and waiting for something.";
now the ghost is wary;
stop;
else:
say "You feel a sudden gust of air rush past you, out through [the escape].";
silently try the ghost entering the escape;
now the ghost is noticed;
otherwise:
let N be the number of ghost-viable doors;
if N is zero:
do nothing;
[Trapped!]
otherwise if N is one:
if a random chance of 3 in 4 succeeds:
let the passage be a random ghost-viable door;
silently try the ghost entering the passage;
else: [stay still]
stop;
otherwise if N is two:
let X be a random number between 1 and 6;
if X is 1 or X is 2:
if the last used door of the ghost is a ghost-viable door:
silently try the ghost entering the last used door of the ghost;
otherwise:
silently try the ghost entering a random ghost-viable door;
else if X is 3 or X is 4 or X is 5:
silently try the ghost entering a random ghost-viable not-last-used door;
else: [stay still]
stop;
describe the haunting of the location of the ghost.
To do the wary haunt:
if the location of the ghost is not the location, stop;
if the ghost is in a closed container:
say "There's a furious scrabbling and scratching at the inside of [the holder of the ghost] as it tries to tear itself free! For a moment it seems like it might actually escape and take its revenge[--]then it goes quieter.[p]From [the holder of the ghost] you hear a faint but definite 'mrow?'.";
now the ghost is tame;
otherwise if there is a ghost-viable door (called the escape):
say "Seeing [the escape], the swirl of air vanishes through it.";
try the ghost entering the escape;
now the ghost is wild;
otherwise if the ghost is in a container:
say "The air swirls back out of [the holder of the ghost].";
move the ghost to the location of the holder of the ghost;
otherwise if there is a ghost-usable container (called the item):
say "The air swirls around [the item], then into it, examining [the random thing in the item].";
move the ghost to the item;
otherwise:
say "You hear no sound from the ghost. It's silent now. Waiting. Watching."
To do the tame haunt:
if the location of the ghost is not the location, stop;
if the ghost is in a closed container:
say "There's a faint, plaintive meowing and scratching from inside [the holder of the ghost].";
otherwise if the ghost is in an open container:
say "A faint swirl of air slinks out of [the holder of the ghost] and stalks around the room.";
move the ghost to the location of the holder of the ghost;
otherwise:
say "A cat-like form slinks around your ankles, then vanishes again.".
To do the friendly haunt:
move the ghost to the location;
say "You can feel the ghost of the cat slinking around you playfully. It seems you've made a friend."
Every turn:
[say "Ghost start [holder of the ghost].";]
if the ghost is wild:
do the wild haunt;
else if the ghost is wary:
do the wary haunt;
else if the ghost is tame:
do the tame haunt;
else if the ghost is friendly:
do the friendly haunt;
[say "Ghost end [holder of the ghost].";
say "Condition: [ferocity of the ghost].";]