Damage calculation / API
#1
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)
Reply
Thanks given by: Taugeshtu
#2
How about also adding the knockback and effects to the TDI, that way plugins can change the knockback amount and we dont need a magic -1 value for damage. I would like players to be able to get healed instead of damaged through TakeDamage by providing negative damage values.
Reply
Thanks given by:
#3
A magical sword of healing? Or an enchantment of life-stealing? Sounds reasonable.
(for some reason, I was reminded of this:
[Image: 3442927_9285ace80b_m.jpeg] )
Reply
Thanks given by:
#4
Yes ^^
Reply
Thanks given by:
#5
Editted to include the TDI changes
Reply
Thanks given by:
#6
I think I'm in the right mood to do this Smile
Reply
Thanks given by:
#7
(12-18-2012, 09:54 PM)xoft Wrote: I think I'm in the right mood to do this Smile

Yay! PvP servers incoming! Smile
Reply
Thanks given by:
#8
(12-18-2012, 09:54 PM)xoft Wrote: I think I'm in the right mood to do this Smile

Let me know if you need any help with this.
Reply
Thanks given by:
#9
Rev 1087 has the first version of the refactoring. I think it should work, but I'm unable to test neither armor nor PvP. I need people to test this. Best would be if someone added an OnTakeDamage hook to the Debuggers plugin that would log the amount of damages that the server sends in TakeDamageInfo, so that people can verify correct values are being given.
Also, armor is currently not depleted by absorbing hits. And of course, we don't have enchantments yet (but the code is ready for them Wink

Debuggers plugin logs the dealt damage, as of rev 1089. So now I need testers. Here's the referential mc-wiki page: http://www.minecraftwiki.net/wiki/Damage#Dealing_damage
Reply
Thanks given by:
#10
it works fine for me Smile i tested it and it worked Smile i also get the good amount of damage. (3.5 damage with diamond sword etc).
EDIT:
btw i if someone is wearing armor, other players don't see that.
Reply
Thanks given by:




Users browsing this thread: 8 Guest(s)