From ea68f8f3b9c9a3a694a65ec96250f072b49d6504 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Sun, 17 Aug 2025 22:14:56 -0700 Subject: [PATCH] Create teleporter device This is for the curious payphone. --- commands/misc.py | 33 +++++++++++++++++++++++- typeclasses/things.py | 58 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/commands/misc.py b/commands/misc.py index fb3c935..9097d16 100755 --- a/commands/misc.py +++ b/commands/misc.py @@ -1,11 +1,14 @@ #!/usr/bin/env python +from re import sub +from string import punctuation + from evennia.commands.default.muxcommand import MuxCommand from evennia import CmdSet from evennia.utils import logger from evennia.utils.eveditor import EvEditor -from .command import Command +from commands.command import Command class CmdKnock(Command): @@ -271,6 +274,8 @@ class CmdOctopus(Command): class CmdSetOctopus(CmdSet): def at_cmdset_creation(self): self.add(CmdOctopus) + + class CmdRoll(MuxCommand): """ Roll the dice in your inventory. @@ -302,3 +307,29 @@ class CmdRoll(MuxCommand): class CmdSetDice(CmdSet): def at_cmdset_creation(self): self.add(CmdRoll) + + +class CmdPress(Command): + """ + Press buttons or something similar. + + Usage: + + press + + Or: + + press [ details ] + + """ + key = "press" + alias = ["touch"] + + def func(self): + details = sub(rf"[{punctuation} \t]*", "", self.args) + self.obj.trigger(self.caller, details) + + +class CmdSetPress(CmdSet): + def at_cmdset_creation(self): + self.add(CmdPress) diff --git a/typeclasses/things.py b/typeclasses/things.py index d85ed5d..c8bd504 100755 --- a/typeclasses/things.py +++ b/typeclasses/things.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from random import choice, random, randint -from re import match, IGNORECASE +from re import split, match, IGNORECASE from enum import Enum from evennia import create_script @@ -16,7 +16,8 @@ from commands.misc import (CmdSetPuddle, CmdSetKnock, CmdSetSmoke, CmdSetRummage, - CmdSetDice) + CmdSetDice, + CmdSetPress) from commands.consumables import CmdSetMakeConsumable from commands.wizards import CmdSetWand from utils.word_list import routput, choices, paragraph @@ -1012,3 +1013,56 @@ class IceBreakerHat(Object): paper.location = picker picker.announce_action(f"$You() $conj({self.db.make_verb or 'get'}) {self.db.make_name}.") + + +class Teleporter(Object): + """ + Teleport a character to a new location. + Requires the following attributes: + + @set obj/pre_msg = "You press the lever." + @set obj/post_msg = "The catapult launches you into the air!" + @set obj/fail_msg = "Other than the click, nothing seems to happen." + + @set obj/destination = $search(Limbo) + @set obj/details = "01189998819991197253" + + Keep in mind that the details, if given, follows the `press` + command, but spaces and punctuation are ignored. + """ + + def at_object_creation(self): + """ + Add the `press` command to this object. + """ + self.cmdset.add_default(CmdSetPress) + + def trigger(self, victim, details=None): + """ + Called by the `press` command. + """ + + def announce(victim, msg): + if match(r"\$", msg): + victim.announce_action(msg) + else: + victim.msg(msg) + + def announce_seq(time_to_delay, victim, msgs): + lines = split(r" *;; *", msgs) + for line in lines: + logger.info(f"time_to_delay={time_to_delay}, announce, victim={victim}, line={line}") + delay(time_to_delay, announce, victim, line) + time_to_delay = time_to_delay + 2 + logger.info(f"returning {time_to_delay}") + return time_to_delay + + time_to_delay = announce_seq(0, victim, self.db.pre_msg) + + deets = self.db.details + if not deets or (deets and deets == details): + time_to_delay = announce_seq(time_to_delay, victim, self.db.post_msg) + delay(time_to_delay, victim.move_to, + self.db.destination, move_type="traverse") + else: + announce_seq(time_to_delay, victim, self.db.fail_msg)