Entity damage mechanism¶
damage = 0 foreach group in cap.damage_groups: damage += cap.damage_groups[group] * limit(actual_interval / cap.full_punch_interval, 0.0, 1.0) * (object.armor_groups[group] / 100.0) -- Where object.armor_groups[group] is 0 for inexistent values return damage
Client predicts damage based on damage groups. Because of this, it is able to give an immediate response when an entity is damaged or dies; the response is pre-defined somehow (e.g. by defining a sprite animation) (not implemented; TODO). Currently a smoke puff will appear when an entity dies.
immortal completely disables normal damage.
Entities can define a special armor group, which is
group disables the regular damage mechanism for players punching it by hand or
a non-tool item, so that it can do something else than take damage.
On the Lua side, every punch calls:
entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction, damage)
This should never be called directly, because damage is usually not handled by the entity itself.
puncheris the object performing the punch. Can be
nil. Should never be accessed unless absolutely required, to encourage interoperability.
time_from_last_punchis time from last punch (by
directionis a unit vector, pointing from the source of the punch to the punched object.
damagedamage that will be done to entity Return value of this function will determine if damage is done by this function (retval true) or shall be done by engine (retval false)
To punch an entity/object in Lua, call:
object:punch(puncher, time_from_last_punch, tool_capabilities, direction)
- Return value is tool wear.
- Parameters are equal to the above callback.
puncherdoes not equal
directionwill be automatically filled in based on the location of