Fixed errors due to the removal of execute_cmd("look") calls in the

latest revisions - this turns out to bypass the normal use of cmdsets
to control things like the dark room in the tutorial. Resolves the
second mentioned error in #889.
This commit is contained in:
Griatch 2015-12-15 19:26:11 +01:00
parent 97f2cf1757
commit 03d415beb1
3 changed files with 27 additions and 12 deletions

View file

@ -15,7 +15,7 @@ from evennia import TICKER_HANDLER
from evennia import CmdSet, Command, DefaultRoom
from evennia import utils, create_object, search_object
from evennia import syscmdkeys, default_cmds
from evennia.contrib.tutorial_world.objects import LightSource, TutorialObject
from evennia.contrib.tutorial_world.objects import LightSource
# the system error-handling module is defined in the settings. We load the
# given setting here using utils.object_from_module. This way we can use
@ -831,7 +831,7 @@ class DarkRoom(TutorialRoom):
if there is a light-giving object in the room overall (like if
a splinter was dropped in the room)
"""
return obj.is_superuser or obj.db.is_giving_light or obj.is_superuser or any(o for o in obj.contents if o.db.is_giving_light)
return obj.is_superuser or obj.db.is_giving_light or any(o for o in obj.contents if o.db.is_giving_light)
def _heal(self, character):
"""
@ -840,14 +840,18 @@ class DarkRoom(TutorialRoom):
health = character.db.health_max or 20
character.db.health = health
def check_light_state(self):
def check_light_state(self, exclude=None):
"""
This method checks if there are any light sources in the room.
If there isn't it makes sure to add the dark cmdset to all
characters in the room. It is called whenever characters enter
the room and also by the Light sources when they turn on.
Args:
exclude (Object): An object to not include in the light check.
"""
if any(self._carries_light(obj) for obj in self.contents):
if any(self._carries_light(obj) for obj in self.contents if obj != exclude):
self.locks.add("view:all()")
self.cmdset.remove(DarkCmdSet)
self.db.is_lit = True
for char in (obj for obj in self.contents if obj.has_player):
@ -856,6 +860,7 @@ class DarkRoom(TutorialRoom):
else:
# noone is carrying light - darken the room
self.db.is_lit = False
self.locks.add("view:false()")
self.cmdset.add(DarkCmdSet, permanent=True)
for char in (obj for obj in self.contents if obj.has_player):
if char.is_superuser:
@ -872,7 +877,7 @@ class DarkRoom(TutorialRoom):
# a puppeted object, that is, a Character
self._heal(obj)
# in case the new guy carries light with them
self.check_light_state()
self.check_light_state()
def at_object_leave(self, obj, target_location):
"""
@ -880,7 +885,10 @@ class DarkRoom(TutorialRoom):
DarkCmdSet if necessary. This also works if they are
teleported away.
"""
self.check_light_state()
# since this hook is called while the object is still in the room,
# we exclude it from the light check, to ignore any light sources
# it may be carrying.
self.check_light_state(exclude=obj)
#------------------------------------------------------------