Fixed a bunch of small issues. The RedButton example hasn't been working for a while, should be ok again now - also cleaned it up a bit.
This commit is contained in:
parent
1d93d8295f
commit
334c0b1d08
10 changed files with 87 additions and 94 deletions
|
|
@ -10,8 +10,6 @@ cmdset - this way you can often re-use the commands too.
|
|||
import random
|
||||
from src.commands.cmdset import CmdSet
|
||||
from game.gamesrc.commands.basecommand import Command
|
||||
from game.gamesrc.scripts.examples import red_button_scripts as scriptexamples
|
||||
|
||||
|
||||
# Some simple commands for the red button
|
||||
|
||||
|
|
@ -70,24 +68,20 @@ class CmdPush(Command):
|
|||
"""
|
||||
|
||||
if self.obj.db.lid_open:
|
||||
|
||||
# assign the blind state script to the caller.
|
||||
# this will assign the restricted BlindCmdset to
|
||||
# the caller at startup, and remove it again
|
||||
# once the time has run out
|
||||
self.caller.scripts.add(scriptexamples.BlindedState)
|
||||
|
||||
string = "You reach out to press the big red button ..."
|
||||
string += "\n\nA BOOM! A bright light blinds you!"
|
||||
string += "\nThe world goes dark ..."
|
||||
self.caller.msg(string)
|
||||
self.caller.location.msg_contents("%s presses the button. BOOM! %s is blinded by a flash!" %
|
||||
(self.caller.name, self.caller.name), exclude=self.caller)
|
||||
# the button's method will handle all setup of scripts etc.
|
||||
self.obj.press_button(self.caller)
|
||||
else:
|
||||
string = "You cannot push the button - there is a glass lid covering it."
|
||||
self.caller.msg(string)
|
||||
|
||||
|
||||
|
||||
class CmdSmashGlass(Command):
|
||||
"""
|
||||
smash glass
|
||||
|
|
@ -142,22 +136,15 @@ class CmdOpenLid(Command):
|
|||
if self.obj.db.lid_locked:
|
||||
self.caller.msg("This lid seems locked in place for the moment.")
|
||||
return
|
||||
string += "\nA ticking sound is heard, like a winding mechanism. Seems "
|
||||
|
||||
string = "\nA ticking sound is heard, like a winding mechanism. Seems "
|
||||
string += "the lid will soon close again."
|
||||
self.db.lid_open = False
|
||||
# add the relevant cmdsets to button
|
||||
self.obj.cmdset.add(LidClosedCmdsSet)
|
||||
# add the lid-close ticker script
|
||||
self.obj.scripts.add(scriptexamples.LidCloseTimer)
|
||||
|
||||
# add more info to the button description
|
||||
desc = self.obj.db.closed_desc
|
||||
self.obj.db.temp_desc = desc
|
||||
self.obj.db.desc = "%s\n%s" % (desc, "Its glass cover is open and the button exposed.")
|
||||
self.caller.msg(string)
|
||||
|
||||
self.caller.location.msg_contents("%s opens the lid of the button." %
|
||||
(self.caller.name), exclude=self.caller)
|
||||
# add the relevant cmdsets to button
|
||||
self.obj.cmdset.add(LidClosedCmdSet)
|
||||
# call object method
|
||||
self.obj.open_lid()
|
||||
|
||||
class CmdCloseLid(Command):
|
||||
|
|
@ -176,12 +163,9 @@ class CmdCloseLid(Command):
|
|||
def func(self):
|
||||
"Close the lid"
|
||||
|
||||
if self.db.closed_desc:
|
||||
self.obj.desc = self.db.closed_desc
|
||||
self.obj.db.lid_open = False
|
||||
self.obj.close_lid()
|
||||
|
||||
# this will clean out scripts dependent on lid being open.
|
||||
self.obj.scripts.validate()
|
||||
self.caller.msg("You close the button's lid. It clicks back into place.")
|
||||
self.caller.location.msg_contents("%s closes the button's lid." %
|
||||
(self.caller.name), exclude=self.caller)
|
||||
|
|
@ -313,8 +297,8 @@ class BlindCmdSet(CmdSet):
|
|||
|
||||
def at_cmdset_creation(self):
|
||||
"Setup the blind cmdset"
|
||||
from game.gamesrc.commands.default.general import CmdSay
|
||||
from game.gamesrc.commands.default.general import CmdPose
|
||||
from src.commands.default.general import CmdSay
|
||||
from src.commands.default.general import CmdPose
|
||||
self.add(CmdSay())
|
||||
self.add(CmdPose())
|
||||
self.add(CmdBlindLook())
|
||||
|
|
|
|||
|
|
@ -25,6 +25,12 @@ class RedButton(Object):
|
|||
definition in game/gamesrc/events/example.py to blink at regular
|
||||
intervals. It also uses a series of script and commands to handle
|
||||
pushing the button and causing effects when doing so.
|
||||
|
||||
The following attributes can be set on the button:
|
||||
desc_lid_open - description when lid is open
|
||||
desc_lid_closed - description when lid is closed
|
||||
desc_lamp_broken - description when lamp is broken
|
||||
|
||||
"""
|
||||
def at_object_creation(self):
|
||||
"""
|
||||
|
|
@ -43,11 +49,9 @@ class RedButton(Object):
|
|||
self.db.lamp_works = True
|
||||
self.db.lid_locked = False
|
||||
|
||||
# set the default cmdset to the object. This will by default surivive
|
||||
# a server reboot (otherwise we could have used permanent=False).
|
||||
self.cmdset.add_default(cmdsetexamples.DefaultCmdSet)
|
||||
self.cmdset.add_default(cmdsetexamples.DefaultCmdSet, permanent=True)
|
||||
|
||||
# since the other cmdsets relevant to the button are added 'on the fly',
|
||||
# since the cmdsets relevant to the button are added 'on the fly',
|
||||
# we need to setup custom scripts to do this for us (also, these scripts
|
||||
# check so they are valid (i.e. the lid is actually still closed)).
|
||||
# The AddClosedCmdSet script makes sure to add the Closed-cmdset.
|
||||
|
|
@ -57,7 +61,7 @@ class RedButton(Object):
|
|||
|
||||
# state-changing methods
|
||||
|
||||
def open_lid(self, feedback=True):
|
||||
def open_lid(self):
|
||||
"""
|
||||
Opens the glass lid and start the timer so it will soon close
|
||||
again.
|
||||
|
|
@ -65,18 +69,13 @@ class RedButton(Object):
|
|||
|
||||
if self.db.lid_open:
|
||||
return
|
||||
|
||||
desc = "This is a large red button, inviting yet evil-looking. "
|
||||
desc += "Its glass cover is open and the button exposed."
|
||||
desc = self.db.desc_lid_open
|
||||
if not desc:
|
||||
desc = "This is a large red button, inviting yet evil-looking. "
|
||||
desc += "Its glass cover is open and the button exposed."
|
||||
self.db.desc = desc
|
||||
self.db.lid_open = True
|
||||
|
||||
if feedback and self.location:
|
||||
string = "The lid slides clear of the button with a click."
|
||||
string += "\nA ticking sound is heard, suggesting the lid might have"
|
||||
string += " some sort of timed locking mechanism."
|
||||
self.location.msg_contents(string)
|
||||
|
||||
|
||||
# with the lid open, we validate scripts; this will clean out
|
||||
# scripts that depend on the lid to be closed.
|
||||
self.scripts.validate()
|
||||
|
|
@ -86,7 +85,7 @@ class RedButton(Object):
|
|||
# (this one cleans itself after being called once)
|
||||
self.scripts.add(scriptexamples.CloseLidEvent)
|
||||
|
||||
def close_lid(self, feedback=True):
|
||||
def close_lid(self):
|
||||
"""
|
||||
Close the glass lid. This validates all scripts on the button,
|
||||
which means that scripts only being valid when the lid is open
|
||||
|
|
@ -95,16 +94,13 @@ class RedButton(Object):
|
|||
|
||||
if not self.db.lid_open:
|
||||
return
|
||||
|
||||
desc = "This is a large red button, inviting yet evil-looking. "
|
||||
desc += "Its glass cover is closed, protecting it."
|
||||
desc = self.db.desc_lid_closed
|
||||
if not desc:
|
||||
desc = "This is a large red button, inviting yet evil-looking. "
|
||||
desc += "Its glass cover is closed, protecting it."
|
||||
self.db.desc = desc
|
||||
self.db.lid_open = False
|
||||
|
||||
if feedback and self.location:
|
||||
string = "With a click the lid slides back, securing the button once again."
|
||||
self.location.msg_contents(string)
|
||||
|
||||
# clean out scripts depending on lid to be open
|
||||
self.scripts.validate()
|
||||
# add scripts related to the closed state
|
||||
|
|
@ -116,11 +112,14 @@ class RedButton(Object):
|
|||
|
||||
"""
|
||||
self.db.lamp_works = False
|
||||
self.db.desc = "The big red button has stopped blinking for the time being."
|
||||
desc = self.db.desc_lamp_broken
|
||||
if not desc:
|
||||
self.db.desc += "\nThe big red button has stopped blinking for the time being."
|
||||
else:
|
||||
self.db.desc = desc
|
||||
|
||||
if feedback and self.location:
|
||||
string = "The lamp flickers, the button going dark."
|
||||
self.location.msg_contents(string)
|
||||
self.location.msg_contents("The lamp flickers, the button going dark.")
|
||||
self.scripts.validate()
|
||||
|
||||
def press_button(self, pobject):
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ class DeactivateButtonEvent(Script):
|
|||
(that just controls when at_repeat() is called)
|
||||
"""
|
||||
# closing the lid will also add the ClosedState script
|
||||
self.obj.close_lid(feedback=False)
|
||||
self.obj.close_lid()
|
||||
# lock the lid so other players can't access it until the
|
||||
# first one's effect has worn off.
|
||||
self.obj.db.lid_locked = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue