From 2d35c71cd14b4cb6ccaf6641cd7b614f9b1c705e Mon Sep 17 00:00:00 2001 From: Griatch Date: Fri, 19 Aug 2016 22:48:44 +0200 Subject: [PATCH] Make @typeclass/reset also purge cmdsets. Resolves #1000. --- evennia/commands/default/building.py | 2 +- evennia/typeclasses/models.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/evennia/commands/default/building.py b/evennia/commands/default/building.py index 8d01af9bc0..fb4cba7818 100644 --- a/evennia/commands/default/building.py +++ b/evennia/commands/default/building.py @@ -1641,7 +1641,7 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS): old_typeclass_path = obj.typeclass_path # we let this raise exception if needed - obj.swap_typeclass(new_typeclass, clean_attributes=reset) + obj.swap_typeclass(new_typeclass, clean_attributes=reset, clean_cmdsets=reset) if is_same: string = "%s updated its existing typeclass (%s).\n" % (obj.name, obj.path) diff --git a/evennia/typeclasses/models.py b/evennia/typeclasses/models.py index 0f4f2c40ec..3aa6cfc0f2 100644 --- a/evennia/typeclasses/models.py +++ b/evennia/typeclasses/models.py @@ -407,7 +407,7 @@ class TypedObject(SharedMemoryModel): return any(hasattr(cls, "path") and cls.path in typeclass for cls in self.__class__.mro()) def swap_typeclass(self, new_typeclass, clean_attributes=False, - run_start_hooks=True, no_default=True): + run_start_hooks=True, no_default=True, clean_cmdsets=False): """ This performs an in-situ swap of the typeclass. This means that in-game, this object will suddenly be something else. @@ -437,6 +437,7 @@ class TypedObject(SharedMemoryModel): allow for swapping to a default typeclass in case the given one fails for some reason. Instead the old one will be preserved. + clean_cmdsets (bool, optional): Delete all cmdsets on the object. Returns: result (bool): True/False depending on if the swap worked or not. @@ -470,6 +471,10 @@ class TypedObject(SharedMemoryModel): else: self.attributes.clear() self.nattributes.clear() + if clean_cmdsets: + # purge all cmdsets + self.cmdset.clear() + self.cmdset.remove_default() if run_start_hooks: # fake this call to mimic the first save