Yeah, unfortunately it doesn't appear to be as simple as I thought. The problem is that the unmorphing code
removes all
PowerMorph items from the inventory.
We can attempt to circumvent this by giving the player an additional inventory item that indicates that they should be morphed upon level change:
Code: Select all
class MorphToken : Inventory
{
Default
{
+INVENTORY.UNDROPPABLE;
}
override void Travelled()
{
if (Owner != null)
{
Owner.GiveInventory('PowerCarPlayer', 1);
}
}
}
class PowerCarPlayer : PowerMorph
{
Default
{
...
}
override void InitEffect()
{
Owner.GiveInventory('MorphToken', 1);
Super.InitEffect();
}
override void DepleteOrDestroy()
{
Owner.TakeInventory('MorphToken', 1);
Super.DepleteOrDestroy();
}
}
Note that you do not need to explicitly take away the
MorphToken when you want to undo the effect because the above code already accounts for it (taking away
PowerCarPlayer will also remove the token). Also, the code assumes that the powerup will never expire on its own.