Create teleporter device

This is for the curious payphone.
This commit is contained in:
Howard Abrams 2025-08-17 22:14:56 -07:00
parent 303c78f3be
commit ea68f8f3b9
2 changed files with 88 additions and 3 deletions

View file

@ -1,11 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
from re import sub
from string import punctuation
from evennia.commands.default.muxcommand import MuxCommand from evennia.commands.default.muxcommand import MuxCommand
from evennia import CmdSet from evennia import CmdSet
from evennia.utils import logger from evennia.utils import logger
from evennia.utils.eveditor import EvEditor from evennia.utils.eveditor import EvEditor
from .command import Command from commands.command import Command
class CmdKnock(Command): class CmdKnock(Command):
@ -271,6 +274,8 @@ class CmdOctopus(Command):
class CmdSetOctopus(CmdSet): class CmdSetOctopus(CmdSet):
def at_cmdset_creation(self): def at_cmdset_creation(self):
self.add(CmdOctopus) self.add(CmdOctopus)
class CmdRoll(MuxCommand): class CmdRoll(MuxCommand):
""" """
Roll the dice in your inventory. Roll the dice in your inventory.
@ -302,3 +307,29 @@ class CmdRoll(MuxCommand):
class CmdSetDice(CmdSet): class CmdSetDice(CmdSet):
def at_cmdset_creation(self): def at_cmdset_creation(self):
self.add(CmdRoll) 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)

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from random import choice, random, randint from random import choice, random, randint
from re import match, IGNORECASE from re import split, match, IGNORECASE
from enum import Enum from enum import Enum
from evennia import create_script from evennia import create_script
@ -16,7 +16,8 @@ from commands.misc import (CmdSetPuddle,
CmdSetKnock, CmdSetKnock,
CmdSetSmoke, CmdSetSmoke,
CmdSetRummage, CmdSetRummage,
CmdSetDice) CmdSetDice,
CmdSetPress)
from commands.consumables import CmdSetMakeConsumable from commands.consumables import CmdSetMakeConsumable
from commands.wizards import CmdSetWand from commands.wizards import CmdSetWand
from utils.word_list import routput, choices, paragraph from utils.word_list import routput, choices, paragraph
@ -1012,3 +1013,56 @@ class IceBreakerHat(Object):
paper.location = picker paper.location = picker
picker.announce_action(f"$You() $conj({self.db.make_verb or 'get'}) {self.db.make_name}.") 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)