'This performs an in-situ swap of the typeclass. This means
that in-game, this object will suddenly be something else.
Player will not be affected. To \'move\' a player to a different
object entirely (while retaining this object\'s type), use
self.player.swap_object().
Note that this might be an error prone operation if the
old/new typeclass was heavily customized - your code
might expect one and not the other, so be careful to
bug test your code if using this feature! Often its easiest
to create a new object and just swap the player over to
that one instead.
Args:
new_typeclass (str or classobj): Type to switch to.
clean_attributes (bool or list, optional): Will delete all
attributes stored on this object (but not any of the
database fields such as name or location). You can\'t get
attributes back, but this is often the safest bet to make
sure nothing in the new typeclass clashes with the old
one. If you supply a list, only those named attributes
will be cleared.
run_start_hooks (str or None, optional): This is either None,
to not run any hooks, "all" to run all hooks defined by
at_first_start, or a string giving the name of the hook
to run (for example \'at_object_creation\'). This will
always be called without arguments.
no_default (bool, optiona): If set, the swapper will not
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.'

def swap_typeclass(self, new_typeclass, clean_attributes=False, run_start_hooks='all', no_default=True, clean_cmdsets=False):

    if (not callable(new_typeclass)):
        new_typeclass = class_from_module(new_typeclass, defaultpaths=settings.TYPECLASS_PATHS)
    if inherits_from(self, 'evennia.scripts.models.ScriptDB'):
        if (self.interval > 0):
            raise RuntimeError(("Cannot    use    swap_typeclass    on    time-dependent    Script    '%s'.\nStop    and    start    a    new    Script    of    the    right    type    instead." % self.key))
    self.typeclass_path = new_typeclass.path
    self.__class__ = new_typeclass
    if clean_attributes:
        if is_iter(clean_attributes):
            for attr in clean_attributes:
                self.attributes.remove(attr)
            for nattr in clean_attributes:
                if hasattr(self.ndb, nattr):
                    self.nattributes.remove(nattr)
        else:
            self.attributes.clear()
            self.nattributes.clear()
    if clean_cmdsets:
        self.cmdset.clear()
        self.cmdset.remove_default()
    if (run_start_hooks == 'all'):
        self.at_first_save()
    elif run_start_hooks:
        getattr(self, run_start_hooks)()
