For a real survival gameplay, we need to properly calculate damage caused by attacks and apply that damage through armor and to the players. Most damage-related calculations seem to be already documented on the minecraft wiki, so the calculation itself should be rather straight.
How I'd like to have the things work:
For each hit:
- server calculates raw damage (attacker mob type + weapons)
- server calculates received damage (dampened by receiver's armor)
- server packs those two values into TakeDamageInfo (extended) and lets plugins modify it, using HOOK_TAKE_DAMAGE
- server applies the "received damage" to the receiver
- special values for "received damage", recognized by the server: 0 = don't process at all
This way, without any plugins, the server will have realistic damage. If plugins want to do something about the damage, they can. They can modify the damage amount, or disable the damage altogether.
To have an effective API, the server also needs to export a few properties for cPawn:
- GetEquippedWeapon()
- GetEquippedHelmet()
- GetEquippedChestPlate()
- GetEquippedLeggings()
- GetEquippedBoots()
This will enable us to later add mobs with equipped items and plugins will have a unified way of checking for those. By default, these will return an empty item for everything else than a player, for whom they will return the correct inventory item.
EDIT: Edited the function names to be more descriptive.
EDIT: As suggested by FakeTruth, adding more info into TakeDamageInfo.
The TakeDamageInfo will describe not only the damage, but also the kind of processing to perform various other effects of a hit - knockback, poison, weakness etc.
TakeDamageInfo proposed contents:
- DamageType - enum - indicates whether damage is taken as a result of being hit by an entity, or from the enviroment / fire / drowning etc.
- Attacker - cPawn - instead of Instigator; may be NULL for environmental damage
- RawDamage - int - The amount of damage dealt, before subtracting armor
- FinalDamage - int - The amount of damage to be dealt (after armor); plugins may modify to change the outcome.
- Knockback - Vector3d - The amount of knockback that the receiver should get from this hit
- Effect - List of effects - Other effects (to be specified yet)
How I'd like to have the things work:
For each hit:
- server calculates raw damage (attacker mob type + weapons)
- server calculates received damage (dampened by receiver's armor)
- server packs those two values into TakeDamageInfo (extended) and lets plugins modify it, using HOOK_TAKE_DAMAGE
- server applies the "received damage" to the receiver
- special values for "received damage", recognized by the server: 0 = don't process at all
This way, without any plugins, the server will have realistic damage. If plugins want to do something about the damage, they can. They can modify the damage amount, or disable the damage altogether.
To have an effective API, the server also needs to export a few properties for cPawn:
- GetEquippedWeapon()
- GetEquippedHelmet()
- GetEquippedChestPlate()
- GetEquippedLeggings()
- GetEquippedBoots()
This will enable us to later add mobs with equipped items and plugins will have a unified way of checking for those. By default, these will return an empty item for everything else than a player, for whom they will return the correct inventory item.
EDIT: Edited the function names to be more descriptive.
EDIT: As suggested by FakeTruth, adding more info into TakeDamageInfo.
The TakeDamageInfo will describe not only the damage, but also the kind of processing to perform various other effects of a hit - knockback, poison, weakness etc.
TakeDamageInfo proposed contents:
- DamageType - enum - indicates whether damage is taken as a result of being hit by an entity, or from the enviroment / fire / drowning etc.
- Attacker - cPawn - instead of Instigator; may be NULL for environmental damage
- RawDamage - int - The amount of damage dealt, before subtracting armor
- FinalDamage - int - The amount of damage to be dealt (after armor); plugins may modify to change the outcome.
- Knockback - Vector3d - The amount of knockback that the receiver should get from this hit
- Effect - List of effects - Other effects (to be specified yet)