Refactoring of map spawner mechanism. Still not working correctly

This commit is contained in:
Griatch 2021-07-03 18:05:49 +02:00
parent 90ad6c112c
commit 61ab313ee3
9 changed files with 647 additions and 313 deletions

View file

@ -816,6 +816,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
use_destination=True,
to_none=False,
move_hooks=True,
alternative_source=None,
**kwargs,
):
"""
@ -837,6 +838,10 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
move_hooks (bool): If False, turn off the calling of move-related hooks
(at_before/after_move etc) with quiet=True, this is as quiet a move
as can be done.
alternative_source (Object, optional): Normally, the current `self.location` is
assumed the 'source' of the move. This allows for replacing this
with a custom source (for example to create a teleporter room that
retains the original source when moving to another place).
Keyword Args:
Passed on to announce_move_to and announce_move_from hooks.
@ -861,7 +866,6 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
7. `self.at_after_move(source_location)`
"""
def logerr(string="", err=None):
"""Simple log helper method"""
logger.log_trace()
@ -872,6 +876,8 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
if not emit_to_obj:
emit_to_obj = self
source_location = alternative_source or self.location
if not destination:
if to_none:
# immediately move to None. There can be no hooks called since
@ -887,15 +893,12 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# Before the move, call eventual pre-commands.
if move_hooks:
try:
if not self.at_before_move(destination, **kwargs):
if not source_location.at_before_move(destination, **kwargs):
return False
except Exception as err:
logerr(errtxt.format(err="at_before_move()"), err)
return False
# Save the old location
source_location = self.location
# Call hook on source location
if move_hooks and source_location:
try:
@ -2446,7 +2449,7 @@ class DefaultRoom(DefaultObject):
if not locks and account:
locks = cls.lockstring.format(**{"id": account.id})
elif not locks and not account:
locks = cls.lockstring(**{"id": obj.id})
locks = cls.lockstring.format(**{"id": obj.id})
obj.locks.add(locks)
@ -2461,6 +2464,7 @@ class DefaultRoom(DefaultObject):
obj.db.desc = description if description else _("This is a room.")
except Exception as e:
raise
errors.append("An error occurred while creating this '%s' object." % key)
logger.log_err(e)
@ -2667,7 +2671,7 @@ class DefaultExit(DefaultObject):
obj.db.desc = description if description else _("This is an exit.")
except Exception as e:
errors.append("An error occurred while creating this '%s' object." % key)
errors.append("An error occurred while creating this '%s' object (%s)." % key)
logger.log_err(e)
return obj, errors