Classes:PowerReflection

From ZDoom Wiki
Jump to navigation Jump to search
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
  1. This actor is already defined in GZDoom, there's no reason to define it again.
  2. In fact, trying to define an actor with the same name will cause an error (because it already exists).
  3. If you want to make your own version of this actor, use inheritance.
  4. Definitions for existing actors are put on the wiki for reference purpose only.
Damage reflection power
Actor type Power Game MiniZDoomLogoIcon.png (ZDoom)
DoomEd Number None Class Name PowerReflection


Classes: InventoryPowerupPowerReflection
   (more)

PowerReflection is an internal class. An item of this class is placed in the player's inventory while the damage reflection powerup is in effect.

While in effect, if the player receives damage, the source of damage also receives damage. The reflect damage is calculated by multiplying it with the powerup's generic (type-less) damage factor. The result is then multiplied by the damage factor which matches the attack's damage type, if any. If multiple powerups of this type are in the inventory, the one with the maximum efficiency for the damage type received gets picked. If the damage type of the attack is Reflection or the source of damage is the player themselves, the powerup has no effect, and as a result, the source does not receive any reflect damage. In case of reflect damage, the type of damage the source receives is Reflection. Non-players do not benefit from this powerup.

The Powerup.Strength property, which acts as a multiplier, determines how much of the received damage to reflect regardless of damage factors. The rest of the damage, if any, is then subjected to the damage factor calculations detailed above. In addition, if the PowerReflection.ReflectType property is present, the type of the reflected damage is the same as the one the player received from the attack, otherwise it is Reflection. In the case of multiple powerups of this type, the one which reflects the most damage is also the one which determines the type of the reflected damage.


Like all other powerups, items of this class are never used directly. Instead you have to create a new item that inherits from PowerupGiver to give it to the player.

ZScript definition

class PowerReflection : Powerup
{
    bool ReflectType;
    property ReflectType : ReflectType;

    Default
    {
        Powerup.Duration -60;
        DamageFactor 0.5;
    }
}

Examples

Quarter of a fire-based attack's damage is reflected back on the source as damage.

class PowerReflectionA : PowerReflection
{
    Default
    {
        DamageFactor 1.0;
        DamageFactor "Fire", 0.25;
    }
}


Assume an ice-based attack with damage of 50. If both of these powerups are in the player's inventory, PowerReflectionB gets picked when reflecting the damage, as it is the one which yields the most damage.

class PowerReflectionA : PowerReflection
{
    Default
    {
        // 50 * 1.0 * 2.0 = 100
        DamageFactor 1.0;
        DamageFactor "Ice", 2.0;
    }
}

class PowerReflectionB : PowerReflection
{
    Default
    {
        // 50 * 5.0 * 0.5 = 125; this one reflects the most damage, so it gets picked.
        DamageFactor 5.0;
        DamageFactor "Ice", 0.5;
    }
}


This powerup reflects 80% of the damage off-hand, plus 30% of the rest of it.

class PowerReflectionA : PowerReflection
{
    Default
    {
        Powerup.Strength 0.8;
        PowerReflection.ReflectType;
        DamageFactor 0.3;
    }
}