|
| 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) |
0 commit comments