* `dir`: unit vector of direction of punch. Always defined. Points from the
puncher to the punched.
* `damage`: damage that will be done to entity.
+ * Can return `true` to prevent the default damage mechanism.
* `on_death(self, killer)`
* Called when the object dies.
* `killer`: an `ObjectRef` (can be `nil`)
if (!damage_handled) {
if (result.did_punch) {
setHP((s32)getHP() - result.damage,
- PlayerHPChangeReason(PlayerHPChangeReason::SET_HP));
+ PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher));
std::string str = gob_cmd_punched(getHP());
// create message and add to list
}
if (getHP() == 0 && !isGone()) {
- m_pending_removal = true;
clearParentAttachment();
clearChildAttachments();
m_env->getScriptIface()->luaentity_on_death(m_id, puncher);
+ m_pending_removal = true;
}
actionstream << puncher->getDescription() << " (id=" << puncher->getId() <<
"), damage=" << (old_hp - (s32)getHP()) <<
(damage_handled ? " (handled by Lua)" : "") << std::endl;
+ // TODO: give Lua control over wear
return result.wear;
}
u16 wear = pointed_object->punch(dir, &toolcap, playersao,
time_from_last_punch);
+ // Callback may have changed item, so get it again
+ playersao->getWieldedItem(&selected_item);
bool changed = selected_item.addWear(wear, m_itemdef);
if (changed)
playersao->setWieldedItem(selected_item);