The character shouldn’t care about the duration of the powerup. The character should only care/know that a powerup is being applied to it. The powerup class itself should be responsible for it’s timing and for telling the character to start and stop it’s effects. The logic is sort of like this:
- Character overlaps a powerup so Character->Pickup(Powerup) is called passing in the powerup that the character wants to pick up.
- Character adds the powerup to an array of powerups (or inventory or whatever).
- Character calls Powerup->PickedupBy(Holder) passing in a reference to the charater that holds it
- Powerup->PickedupBy() stores a refernece to the Holder
- Powerup does whatever initialization/reinitialzaiton needed
- Powerup calls Holder->EnableDoubleDamage()
- In Powerup->Tick() if there is a valid holder, the powerup decrements it’s Duration. If Duration <= 0.0 then it calls Powerup->Expired()
- Powerup->Expired() calls Holder->DropPickup(Powerup)
8 Character->DropPickup() removes the Powerup for the inventory and calls Powerup->Drop() - Powerup->Drop() calls Holder->DisableDoubleDamage()
- Powerup->Drop() resets the holder
- Powerup->Drop() enables physics, does any deactivation/etc.
- Powerup->Finished() calls Destory()
When the pawn dies, it iterates over it’s inventory and calls Powerup->Drop() on all of them. That will cause the powerups to turn off their function and drop in to the world.
Hope that helps.