aboutsummaryrefslogtreecommitdiff
path: root/src/content_sao.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r--src/content_sao.cpp56
1 files changed, 35 insertions, 21 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 5c03c9053..0c105bb0f 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -531,33 +531,47 @@ int LuaEntitySAO::punch(v3f dir,
m_removed = true;
return 0;
}
- lua_State *L = m_env->getLua();
- scriptapi_luaentity_punch(L, m_id, puncher,
- time_from_last_punch, toolcap, dir);
+
+ ItemStack *punchitem = NULL;
+ ItemStack punchitem_static;
+ if(puncher){
+ punchitem_static = puncher->getWieldedItem();
+ punchitem = &punchitem_static;
+ }
- HitParams hitparams = getHitParams(m_armor_groups, toolcap,
+ PunchDamageResult result = getPunchDamage(
+ m_armor_groups,
+ toolcap,
+ punchitem,
time_from_last_punch);
- actionstream<<getDescription()<<" punched by "
- <<puncher->getDescription()<<", damage "<<hitparams.hp
- <<" HP"<<std::endl;
-
- setHP(getHP() - hitparams.hp);
-
+ if(result.did_punch)
{
- std::ostringstream os(std::ios::binary);
- // command
- writeU8(os, LUAENTITY_CMD_PUNCHED);
- // damage
- writeS16(os, hitparams.hp);
- // result_hp
- writeS16(os, getHP());
- // create message and add to list
- ActiveObjectMessage aom(getId(), true, os.str());
- m_messages_out.push_back(aom);
+ actionstream<<getDescription()<<" punched by "
+ <<puncher->getDescription()<<", damage "<<result.damage
+ <<" HP"<<std::endl;
+
+ setHP(getHP() - result.damage);
+
+ {
+ std::ostringstream os(std::ios::binary);
+ // command
+ writeU8(os, LUAENTITY_CMD_PUNCHED);
+ // damage
+ writeS16(os, result.damage);
+ // result_hp
+ writeS16(os, getHP());
+ // create message and add to list
+ ActiveObjectMessage aom(getId(), true, os.str());
+ m_messages_out.push_back(aom);
+ }
}
- return hitparams.wear;
+ lua_State *L = m_env->getLua();
+ scriptapi_luaentity_punch(L, m_id, puncher,
+ time_from_last_punch, toolcap, dir);
+
+ return result.wear;
}
void LuaEntitySAO::rightClick(ServerActiveObject *clicker)