Skip to content

Commit ffdff84

Browse files
committed
added demo story 'the prancing llama'
1 parent 7638f6e commit ffdff84

File tree

10 files changed

+180
-2
lines changed

10 files changed

+180
-2
lines changed

stories/prancingllama/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Package containing a demo room and some stuff, to easily check out
3+
a running Tale framework (python -m tale.demo.story)
4+
5+
'Tale' mud driver, mudlib and interactive fiction framework
6+
Copyright by Irmen de Jong ([email protected])
7+
"""

stories/prancingllama/messages/banner.txt

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This is some additional licensing text.
2+
It has been written down in the messages/license.txt file.
3+
Games can optionally supply this to add more licensing info.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is the Message-of-the-day.
2+
This game is still under heavy development.
3+
Please report any problems you may find.
4+
(the MOTD will only be shown when running in MUD mode,
5+
Interactive Fiction stories don't have any use for a MOTD message).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
After a grizzling journey through the snow
2+
storm you have finally arrived at
3+
The Prancing Llama, the only refuge for miles
4+
and miles in this craggy, snow-covered
5+
landscape. You have heard many tales about
6+
this place, but now the time has come to
7+
make your own.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
from tale.llm_ext import LivingNpc
3+
4+
class Patron(LivingNpc):
5+
6+
def __init__(self, name: str, gender: str, *,
7+
title: str="", descr: str="", short_descr: str="", age: int, appearance: str, personality: str):
8+
super(Patron, self).__init__(name=name, gender=gender,
9+
title=title, descr=descr, short_descr=short_descr, age=age, appearance=appearance, personality=personality, occupation='Student')
10+
11+
def init(self) -> None:
12+
self.aliases = {"Patron"}
13+
14+
norhardt = Patron("Norhardt", "m", age=56, appearance="A grizzled old man, with parchment-like skin and sunken eyes. He\'s wearing ragged clothing and big leather boots. He\'s a formidable presence, commanding yet somber, clutching what looks like an old map", personality="An experienced explorer who is obsessed with finding the mythological Yeti which supposedly haunts these mountains. He won\'t stop talking about it.", descr="", short_descr="An old grizzled man sitting by the bar.")
15+
norhardt.aliases = {"norhardt", "old man", "grizzled man"}
16+
17+
elid_gold = Patron("Elid Gold", "m", age=51, appearance="A gentleman who's aged with grace. He has a slender appearance with regal facial features, and dark hair, but his (one) eye has a dangerous squint. The other is covered by a patch.", personality="Old Gold is a smooth-talking pick-pocket and charlatan. Although claiming to be retired, he never passes on an opportunity to relieve strangers of their valuables.", short_descr="A slender gentleman with a patch over one of his eyes, leaning against the wall.")
18+
elid_gold.aliases = {"elid", "one eyed man", "gentleman"}
19+
20+
shanda = Patron("Shanda Heard", "f", age=31, appearance="A fierce looking woman, with a face like chiseled from granite and a red bandana around her wild hair. She keeps an unblinking gaze on her surroundings.", personality="She's a heavy drinker and boaster, and for a free drink she will spill tales of her conquests and battles and long lost love. She's feared by many but respected by all for her prowess in battle.", short_descr="A fierce looking woman sitting by a table, whose eyes seem to follow you.")
21+
shanda.aliases = {"shanda", "fierce woman", "woman by table"}
22+
23+
count_karta = Patron("Count of Karta", "m", age=43, appearance="A hood shadows his facial features, but a prominent jaw juts out. His mouth seems to be working constantly, as if muttering about something.", personality="Having fled from an attempt on his life, and being discredited, he has come here to plan his revenge. He seems to have gold and is looking for able bodies to help him.", short_descr="A mysterious man by the fire.")
24+
count_karta.aliases = {"count", "karta", "mysterious man"}
25+
26+
urta = Patron("Urta", "f", age=44, appearance="A gruff, curvy woman with a long brown coat and bushy hair that reaches her waist. When not serving, she keeps polishing jugs with a dirty rag.", personality="She's the owner of the tavern, and of few words. But the words she speak are kind. She knows a little about all the patrons in her establishment.", short_descr="A curvy woman with long brown coat standing behind the bar.")
27+
urta.aliases = {"bartender", "inn keeper", "curvy woman"}

stories/prancingllama/story.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import pathlib
2+
import sys
3+
from typing import Optional, Generator
4+
5+
import tale
6+
from tale.driver import Driver
7+
from tale.main import run_from_cmdline
8+
from tale.player import Player, PlayerConnection
9+
from tale.charbuilder import PlayerNaming
10+
from tale.story import *
11+
12+
class Story(StoryBase):
13+
14+
config = StoryConfig()
15+
config.name = "The Prancing Llama"
16+
config.author = "Rickard Edén, [email protected]"
17+
config.author_address = "[email protected]"
18+
config.version = tale.__version__
19+
config.supported_modes = {GameMode.IF, GameMode.MUD}
20+
config.player_money = 10.5
21+
config.playable_races = {"human", "elf", "dwarf", "hobbit"}
22+
config.money_type = MoneyType.FANTASY
23+
config.server_tick_method = TickMethod.TIMER
24+
config.server_tick_time = 0.5
25+
config.gametime_to_realtime = 5
26+
config.display_gametime = True
27+
config.startlocation_player = "prancingllama.entrance"
28+
config.startlocation_wizard = "prancingllama.entrance"
29+
config.zones = ["prancingllama"]
30+
31+
def init(self, driver: Driver) -> None:
32+
"""Called by the game driver when it is done with its initial initialization."""
33+
self.driver = driver
34+
35+
def init_player(self, player: Player) -> None:
36+
"""
37+
Called by the game driver when it has created the player object (after successful login).
38+
You can set the hint texts on the player object, or change the state object, etc.
39+
"""
40+
pass
41+
42+
def create_account_dialog(self, playerconnection: PlayerConnection, playernaming: PlayerNaming) -> Generator:
43+
"""
44+
Override to add extra dialog options to the character creation process.
45+
Because there's no actual player yet, you receive PlayerConnection and PlayerNaming arguments.
46+
Write stuff to the user via playerconnection.output(...)
47+
Ask questions using the yield "input", "question?" mechanism.
48+
Return True to declare all is well, and False to abort the player creation process.
49+
"""
50+
age = yield "input", "Custom creation question: What is your age?"
51+
playernaming.story_data["age"] = int(age) # will be stored in the database (mud)
52+
occupation = yield "input", "Custom creation question: What is your trade?"
53+
playernaming.story_data["occupation"] = str(occupation) # will be stored in the database (mud)
54+
return True
55+
56+
def welcome(self, player: Player) -> str:
57+
"""welcome text when player enters a new game"""
58+
player.tell("<bright>Hello, %s! Welcome to %s.</>" % (player.title, self.config.name), end=True)
59+
player.tell("\n")
60+
player.tell(self.driver.resources["messages/welcome.txt"].text)
61+
player.tell("\n")
62+
return ""
63+
64+
def welcome_savegame(self, player: Player) -> str:
65+
"""welcome text when player enters the game after loading a saved game"""
66+
player.tell("<bright>Hello %s, welcome back to %s.</>" % (player.title, self.config.name), end=True)
67+
player.tell("\n")
68+
player.tell(self.driver.resources["messages/welcome.txt"].text)
69+
player.tell("\n")
70+
return ""
71+
72+
def goodbye(self, player: Player) -> None:
73+
"""goodbye text when player quits the game"""
74+
player.tell("Goodbye, %s. Please come back again soon." % player.title)
75+
player.tell("\n")
76+
77+
78+
if __name__ == "__main__":
79+
# story is invoked as a script, start it in the Tale Driver.
80+
gamedir = pathlib.Path(__file__).parent
81+
if gamedir.is_dir() or gamedir.is_file():
82+
cmdline_args = sys.argv[1:]
83+
cmdline_args.insert(0, "--game")
84+
cmdline_args.insert(1, str(gamedir))
85+
run_from_cmdline(cmdline_args)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
Package containing the zones of the demo game.
3+
4+
'Tale' mud driver, mudlib and interactive fiction framework
5+
Copyright by Irmen de Jong ([email protected])
6+
"""
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import random
2+
3+
from tale.base import Location, Exit, Door, Key, Living, ParseResult
4+
from tale.errors import StoryCompleted
5+
from tale.lang import capital
6+
from tale.player import Player
7+
from tale.util import Context, call_periodically
8+
from tale.verbdefs import AGGRESSIVE_VERBS
9+
from npcs.llama import *
10+
11+
12+
13+
main_hall = Location("Main Hall", "An area full of tables with people eating, drinking and talking")
14+
bar = Location("Bar", "A bar carved from a single, massive tree trunk stretches across the room")
15+
kitchen = Location("Kitchen", "The walls are lined with barrels and smoke is surrounding the steaming pots on the fires.")
16+
hearth = Location("Hearth", "A place for newly arrived visitors to unthaw their frozen limbs.")
17+
entrance = Location("Entrance", "A room full of furry and snow-covered coats. Loud voices and roars of laughter can be heard from the main hall.")
18+
outside = Location("Outside", "A snow-storm is raging across the craggy landscape outside, it's dark, and noone to be seen. It's better to stay indoors")
19+
20+
#library_door = Door(["school_grounds", "door"], school_grounds, "A door leading to the school grounds", "", locked=False, opened=True, key_code="1")
21+
22+
Exit.connect(main_hall, ["bar", "north"], "", "To the north you are you see some people sitting over by a massive bar.", bar, ["main_hall", "south"], "To the south you see an area full of tables with people eating, drinking and talking", "")
23+
24+
Exit.connect(main_hall, ["hearth", "west"], "To the west you see a giant hearth with a comforting fire", "", hearth, ["main_hall", "east"], "To the east you see an area full of tables with people eating, drinking and talking", "")
25+
26+
Exit.connect(bar, ["kitchen", "north"], "", "To the north, there's a door leading to the kitchen.", kitchen, ["bar", "south"], "Through a door to the south you see the bar, and beyond that, the main hall", "")
27+
28+
Exit.connect(main_hall, ["entrance", "south"], "", "The entrance to the building is to the south.", entrance, ["main_hall", "north"], "There's a warm glow and loud, noisy conversations coming through a doorway to the north", "")
29+
30+
Exit.connect(entrance, ["outside", "south"], "", "A biting wind reaches you through the door to the south.", outside, ["entrance", "north"], "There's shelter from the cold wind through a door to the north.", "")
31+
32+
main_hall.init_inventory([shanda, elid_gold])
33+
34+
bar.init_inventory([urta, norhardt])
35+
36+
hearth.init_inventory([count_karta])
37+
38+

tale/llm_ext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
3333
greet = True
3434
targeted = True
3535
if greet and targeted:
36-
self.tell_others("{self.title} says: \"Hi.\"", evoke=True)
37-
self.update_conversation("{self.title} says: \"Hi.\"")
36+
self.tell_others("{Actor} says: \"Hi.\"", evoke=True)
37+
self.update_conversation(f"{self.title} says: \"Hi.\"")
3838
elif parsed.verb == "say" and targeted:
3939
self.update_conversation(f'{actor.title}:{parsed.unparsed}\n')
4040
response = self.llm_util.generate_dialogue(conversation=self.conversation, character_card = self.character_card, character_name = self.title, target = actor.title )

0 commit comments

Comments
 (0)