Special rooms allow doors to be opened and closed
This commit is contained in:
parent
e5e1b41be5
commit
b89ca629ee
5 changed files with 77 additions and 18 deletions
|
|
@ -22,7 +22,8 @@ from evennia.contrib.rpg.character_creator.character_creator import ContribCharg
|
||||||
from commands.sittables import CmdNoSitStand
|
from commands.sittables import CmdNoSitStand
|
||||||
from commands.everyone import (CmdTake, CmdThink, CmdSay,
|
from commands.everyone import (CmdTake, CmdThink, CmdSay,
|
||||||
CmdWhisper, CmdRead, CmdEat, CmdDrink,
|
CmdWhisper, CmdRead, CmdEat, CmdDrink,
|
||||||
CmdUse, CmdPush, CmdPull)
|
CmdUse, CmdPush, CmdPull,
|
||||||
|
CmdOpen, CmdClose)
|
||||||
from commands.misc import CmdLight
|
from commands.misc import CmdLight
|
||||||
from typeclasses.tutorial import CmdTutorial
|
from typeclasses.tutorial import CmdTutorial
|
||||||
from commands.wizards import (CmdGM, CmdSpell, CmdGMTrigger,
|
from commands.wizards import (CmdGM, CmdSpell, CmdGMTrigger,
|
||||||
|
|
@ -50,6 +51,8 @@ class CharacterCmdSet(default_cmds.CharacterCmdSet):
|
||||||
self.add(CmdUse)
|
self.add(CmdUse)
|
||||||
self.add(CmdPush)
|
self.add(CmdPush)
|
||||||
self.add(CmdPull)
|
self.add(CmdPull)
|
||||||
|
self.add(CmdOpen)
|
||||||
|
self.add(CmdClose)
|
||||||
self.add(CmdLight)
|
self.add(CmdLight)
|
||||||
self.add(CmdTake)
|
self.add(CmdTake)
|
||||||
self.add(CmdThink)
|
self.add(CmdThink)
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,10 @@ class CmdOpen(Command):
|
||||||
room = opener.location
|
room = opener.location
|
||||||
to_open = self.args.strip()
|
to_open = self.args.strip()
|
||||||
|
|
||||||
|
if to_open == "":
|
||||||
|
opener.msg("What would you like to open?")
|
||||||
|
return
|
||||||
|
|
||||||
if room.has_method('do_open'):
|
if room.has_method('do_open'):
|
||||||
if room.do_open(opener, to_open):
|
if room.do_open(opener, to_open):
|
||||||
return
|
return
|
||||||
|
|
@ -184,13 +188,17 @@ class CmdClose(Command):
|
||||||
"""
|
"""
|
||||||
closer = self.caller
|
closer = self.caller
|
||||||
room = closer.location
|
room = closer.location
|
||||||
to_open = self.args.strip()
|
to_close = self.args.strip()
|
||||||
|
|
||||||
if room.has_method('do_close'):
|
if to_close == "":
|
||||||
if room.do_close(closer, to_open):
|
closer.msg("What would you like to close?")
|
||||||
return
|
return
|
||||||
|
|
||||||
item = closer.search(to_open)
|
if room.has_method('do_close'):
|
||||||
|
if room.do_close(closer, to_close):
|
||||||
|
return
|
||||||
|
|
||||||
|
item = closer.search(to_close)
|
||||||
if item:
|
if item:
|
||||||
if item.has_method('do_close'):
|
if item.has_method('do_close'):
|
||||||
item.do_close(closer)
|
item.do_close(closer)
|
||||||
|
|
|
||||||
|
|
@ -270,5 +270,5 @@ class Sconce(Producer, Opener):
|
||||||
if self.db.pull_msg:
|
if self.db.pull_msg:
|
||||||
self.location.msg_contents(self.db.pull_msg)
|
self.location.msg_contents(self.db.pull_msg)
|
||||||
self.do_open()
|
self.do_open()
|
||||||
delay(15, self.do_close)
|
delay(30, self.do_close)
|
||||||
delay(16, self.db.room.msg_contents, "The bookshelf slams shut.")
|
delay(31, self.db.room.msg_contents, "The bookcase slams shut.")
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ class ObjectParent:
|
||||||
def get_display_footer(self, _, **kwargs):
|
def get_display_footer(self, _, **kwargs):
|
||||||
return "\n"
|
return "\n"
|
||||||
|
|
||||||
|
def has_method(self, method_name):
|
||||||
|
"""True if this object has a method of a particular name."""
|
||||||
|
return hasattr(self, method_name) and callable(getattr(self, method_name))
|
||||||
|
|
||||||
|
|
||||||
class Object(ObjectParent, ContribRPObject):
|
class Object(ObjectParent, ContribRPObject):
|
||||||
"""
|
"""
|
||||||
|
|
@ -247,10 +251,6 @@ class Object(ObjectParent, ContribRPObject):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def has_method(self, method_name):
|
|
||||||
"""True if this object has a method of a particular name."""
|
|
||||||
return hasattr(self, method_name) and callable(getattr(self, method_name))
|
|
||||||
|
|
||||||
def characters_here(self, puppets=False):
|
def characters_here(self, puppets=False):
|
||||||
"""
|
"""
|
||||||
Return a list of characters in the current location.
|
Return a list of characters in the current location.
|
||||||
|
|
@ -389,10 +389,13 @@ class Listener:
|
||||||
def say_triggers(self, label, character, speech):
|
def say_triggers(self, label, character, speech):
|
||||||
trigs = self.get_attribute_trigger(label, character)
|
trigs = self.get_attribute_trigger(label, character)
|
||||||
if trigs:
|
if trigs:
|
||||||
|
try:
|
||||||
for _, trigger in enumerate(dict(trigs)):
|
for _, trigger in enumerate(dict(trigs)):
|
||||||
seq = trigs[trigger]
|
seq = trigs[trigger]
|
||||||
if match(trigger, speech, IGNORECASE):
|
if match(trigger, speech, IGNORECASE):
|
||||||
self.trigger_sequence(seq, character)
|
self.trigger_sequence(seq, character)
|
||||||
|
except:
|
||||||
|
self.trigger_sequence(trigs, character)
|
||||||
|
|
||||||
def other_say(self, speaker, speech):
|
def other_say(self, speaker, speech):
|
||||||
self.say_triggers('say', speaker, speech)
|
self.say_triggers('say', speaker, speech)
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,14 @@ from datetime import datetime
|
||||||
from re import match
|
from re import match
|
||||||
|
|
||||||
from evennia import utils
|
from evennia import utils
|
||||||
from evennia.utils import gametime, logger
|
from evennia.utils import gametime, logger, delay
|
||||||
from evennia.contrib.grid.extended_room import ExtendedRoom
|
from evennia.contrib.grid.extended_room import ExtendedRoom
|
||||||
from evennia.contrib.rpg.rpsystem import ContribRPRoom
|
from evennia.contrib.rpg.rpsystem import ContribRPRoom
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
# from .objects import LightSource
|
from typeclasses.pets import Hunger
|
||||||
from .pets import Hunger
|
from typeclasses.objects import ObjectParent
|
||||||
from .objects import ObjectParent
|
|
||||||
|
|
||||||
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
|
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
|
||||||
|
|
||||||
|
|
@ -144,3 +143,49 @@ class DabblersRoom(Room):
|
||||||
full_desc += " " + self.db.final_desc
|
full_desc += " " + self.db.final_desc
|
||||||
|
|
||||||
return full_desc
|
return full_desc
|
||||||
|
|
||||||
|
|
||||||
|
class OpenableRoom(Room):
|
||||||
|
"""
|
||||||
|
Rooms that accept the "open" and "close" command.
|
||||||
|
|
||||||
|
This will move an exit in and out of this location.
|
||||||
|
Set the follow properties:
|
||||||
|
|
||||||
|
@set here/open_exit = $search(red door)
|
||||||
|
@set here/open_exit_msg = "$You() $conj(open) the door!"
|
||||||
|
@set here/close_exit_msg = "$You() $conj(close) the door!"
|
||||||
|
@set here/close_automatic = 240
|
||||||
|
"""
|
||||||
|
def do_open(self, opener, item):
|
||||||
|
"""
|
||||||
|
Move the 'open_exit' to this location.
|
||||||
|
"""
|
||||||
|
the_exit = self.db.open_exit
|
||||||
|
if the_exit and the_exit.key.endswith(item):
|
||||||
|
if the_exit.location == self:
|
||||||
|
opener.msg(f"The {item} is already open.")
|
||||||
|
return True
|
||||||
|
the_exit.location = self
|
||||||
|
opener.announce_action(self.db.open_exit_msg or
|
||||||
|
f"$You() $conj(open) the {the_exit.name}")
|
||||||
|
if self.db.close_automatic:
|
||||||
|
delay(self.db.close_automatic, self.do_close)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def do_close(self, closer=None, item=None):
|
||||||
|
"""
|
||||||
|
Move the 'open_exit' exit to Limbo.
|
||||||
|
"""
|
||||||
|
the_exit = self.db.open_exit
|
||||||
|
if the_exit and (not item or the_exit.key.endswith(item)):
|
||||||
|
if the_exit.location == self: # It is opened and can be closed:
|
||||||
|
the_exit.location = None
|
||||||
|
if closer:
|
||||||
|
closer.announce_action(self.db.close_exit_msg or
|
||||||
|
f"$You() $conj(close) the {the_exit.name}")
|
||||||
|
else:
|
||||||
|
self.msg_contents(self.db.close_exit_msg)
|
||||||
|
elif closer:
|
||||||
|
closer.msg(f"The {item} is already closed.")
|
||||||
|
return True
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue