Post event sequences from a GMTrigger command
This commit is contained in:
parent
322a22e630
commit
0a955fe2b6
3 changed files with 114 additions and 4 deletions
|
|
@ -21,7 +21,7 @@ from evennia.contrib.rpg.rpsystem import RPSystemCmdSet
|
|||
from evennia.contrib.rpg.character_creator.character_creator import ContribChargenCmdSet
|
||||
from commands.sittables import CmdNoSitStand
|
||||
from commands.everyone import CmdTake, CmdThink, CmdSay, CmdWhisper
|
||||
from commands.wizards import CmdGM
|
||||
from commands.wizards import CmdGM, CmdGMTrigger
|
||||
|
||||
class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||
"""
|
||||
|
|
@ -46,6 +46,7 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
|||
self.add(CmdSay)
|
||||
self.add(CmdWhisper)
|
||||
self.add(CmdGM)
|
||||
self.add(CmdGMTrigger)
|
||||
|
||||
|
||||
class AccountCmdSet(default_cmds.AccountCmdSet):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from re import match
|
||||
|
||||
from evennia import CmdSet
|
||||
from evennia.utils import logger
|
||||
from evennia.utils import delay, logger
|
||||
from evennia.commands.default.muxcommand import MuxCommand
|
||||
|
||||
from .command import Command
|
||||
|
||||
from utils.word_list import routput
|
||||
|
||||
class CmdFly(Command):
|
||||
"""Cast the 'fly' spell.
|
||||
|
|
@ -64,3 +66,110 @@ class CmdGM(MuxCommand):
|
|||
o.msg(self.args)
|
||||
|
||||
logger.info(f"switches = {self.switches} lhs={self.lhs} rhs={self.rhs} / args={self.args}")
|
||||
|
||||
|
||||
class CmdGMTrigger(Command):
|
||||
"""The trigger command kicks off a series of named events.
|
||||
|
||||
Usage:
|
||||
|
||||
trigger trigger-name
|
||||
trigger :game trigger-name
|
||||
trigger/character trigger-name
|
||||
trigger/character:game trigger-name
|
||||
|
||||
Where 'game' defaults to the value previously set:
|
||||
|
||||
@set npc/currentgame = "session1"
|
||||
|
||||
Triggers are typically set on the NPC (which would be in the room
|
||||
with the PCs) or the room. Using the command:
|
||||
|
||||
@set npc/triggers:session1 = {"darkness": {"desc": "Make the
|
||||
room go black", "timer": 1, "events": [ "The room gets dark",
|
||||
"And then pitch-black.", ("You can't help it, but scream!", "You
|
||||
hear a scream!")]}}
|
||||
|
||||
The 'set' command, as a complicated data structure, should be set
|
||||
in a batchcommand.
|
||||
|
||||
"""
|
||||
key = "trigger"
|
||||
aliases = ["trig"]
|
||||
locks = "cmd:perm(gm) or perm(Admin)"
|
||||
|
||||
def parse(self):
|
||||
m = match(r" *(/[^: ]+)?(:[^ ]+)? *(.*)", self.args)
|
||||
if m:
|
||||
self.name = m.group(3)
|
||||
if m.group(2):
|
||||
self.game = m.group(2)[1:]
|
||||
else:
|
||||
self.game = None
|
||||
if m.group(1):
|
||||
self.switches = m.group(1)[1:].split(',')
|
||||
else:
|
||||
self.switches = []
|
||||
else:
|
||||
self.caller.msg("Usage trigger/dest:game trigger")
|
||||
return False
|
||||
|
||||
def func(self):
|
||||
npc = self.caller
|
||||
self.send_to = []
|
||||
|
||||
for switch in self.switches:
|
||||
o = npc.search(switch)
|
||||
if o:
|
||||
self.send_to = self.send_to + [o]
|
||||
else:
|
||||
return
|
||||
|
||||
game = self.game or npc.db.currentgame
|
||||
if not game:
|
||||
npc.msg("Specify the game, or set a default with |g@set self/currentgame = <game>")
|
||||
return
|
||||
|
||||
triggers = dict(npc.attributes.get(key='triggers', category=game))
|
||||
|
||||
if not self.name:
|
||||
npc.msg("What event do you want to trigger?")
|
||||
for name,details in triggers.items():
|
||||
npc.msg(f" - {name} : {details['desc']}")
|
||||
return
|
||||
|
||||
trigger = triggers[self.name]
|
||||
if trigger:
|
||||
npc.msg(f"Triggering: |w{trigger['desc']}")
|
||||
self.trigger(trigger['events'],
|
||||
trigger.get('timer', 5),
|
||||
self.send_to)
|
||||
else:
|
||||
npc.msg(f"Didn't find '{self.name}' to trigger.")
|
||||
|
||||
def trigger(self, events, time_delay, dests=[]):
|
||||
"""
|
||||
Given a list of events, send each events at an interval.
|
||||
If an event is a tuple instead of a string, the first
|
||||
element goes to 'dests' and the second goes to the room
|
||||
(based on the caller's location).
|
||||
"""
|
||||
for idx, event in enumerate(events):
|
||||
if isinstance(event, str):
|
||||
delay(time_delay * idx,
|
||||
self.caller.location.msg_contents,
|
||||
"\n" + routput(event))
|
||||
else:
|
||||
char = event[0]
|
||||
room = event[1]
|
||||
|
||||
if room:
|
||||
delay(time_delay * idx,
|
||||
self.caller.location.msg_contents,
|
||||
"\n" + routput(room),
|
||||
exclude=dests)
|
||||
if char:
|
||||
for dest in dests:
|
||||
delay(time_delay * idx,
|
||||
dest.msg,
|
||||
"\n" + routput(char))
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ class Book(Readable):
|
|||
|
||||
def do_read(self, reader):
|
||||
super().do_read(reader)
|
||||
reader.announce_action(f"reads |p book. You notice the title, |w{self.db.title}|n.")
|
||||
reader.announce_action("reads |p book.")
|
||||
|
||||
def do_burn(self, reader, drop=False):
|
||||
if isinstance(reader.location, DabblersRoom):
|
||||
|
|
|
|||
Loading…
Reference in a new issue