// get_hit_params(groups, tool_capabilities[, time_from_last_punch]) static int l_get_hit_params(lua_State *L) { std::map<std::string, int> groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) push_hit_params(L, getHitParams(groups, &tp)); else push_hit_params(L, getHitParams(groups, &tp, luaL_checknumber(L, 3))); return 1; }
// get_hit_params(groups, tool_capabilities[, time_from_last_punch]) int ModApiUtil::l_get_hit_params(lua_State *L) { NO_MAP_LOCK_REQUIRED; std::map<std::string, int> groups; read_groups(L, 1, groups); ToolCapabilities tp = read_tool_capabilities(L, 2); if(lua_isnoneornil(L, 3)) push_hit_params(L, getHitParams(groups, &tp)); else push_hit_params(L, getHitParams(groups, &tp, luaL_checknumber(L, 3))); return 1; }
int PlayerSAO::punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, float time_from_last_punch) { // It's best that attachments cannot be punched if (isAttached()) return 0; if (!toolcap) return 0; // No effect if PvP disabled if (g_settings->getBool("enable_pvp") == false) { if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { std::string str = gob_cmd_punched(0, getHP()); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); return 0; } } HitParams hitparams = getHitParams(m_armor_groups, toolcap, time_from_last_punch); std::string punchername = "nil"; if (puncher != 0) punchername = puncher->getDescription(); PlayerSAO *playersao = m_player->getPlayerSAO(); bool damage_handled = m_env->getScriptIface()->on_punchplayer(playersao, puncher, time_from_last_punch, toolcap, dir, hitparams.hp); if (!damage_handled) { setHP(getHP() - hitparams.hp); } else { // override client prediction if (puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { std::string str = gob_cmd_punched(0, getHP()); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push(aom); } } actionstream << "Player " << m_player->getName() << " punched by " << punchername; if (!damage_handled) { actionstream << ", damage " << hitparams.hp << " HP"; } else { actionstream << ", damage handled by lua"; } actionstream << std::endl; return hitparams.wear; }
PunchDamageResult getPunchDamage( const ItemGroupList &armor_groups, const ToolCapabilities *toolcap, const ItemStack *punchitem, float time_from_last_punch ){ bool do_hit = true; { if(do_hit && punchitem){ if(itemgroup_get(armor_groups, "punch_operable") && (toolcap == NULL || punchitem->name == "")) do_hit = false; } if(do_hit){ if(itemgroup_get(armor_groups, "immortal")) do_hit = false; } } PunchDamageResult result; if(do_hit) { HitParams hitparams = getHitParams(armor_groups, toolcap, time_from_last_punch); result.did_punch = true; result.wear = hitparams.wear; result.damage = hitparams.hp; result.main_group = hitparams.main_group; } return result; }
int PlayerSAO::punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher, float time_from_last_punch) { // It's best that attachments cannot be punched if(isAttached()) return 0; if(!toolcap) return 0; // No effect if PvP disabled if(g_settings->getBool("enable_pvp") == false){ if(puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER){ std::string str = gob_cmd_punched(0, getHP()); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push_back(aom); return 0; } } HitParams hitparams = getHitParams(m_armor_groups, toolcap, time_from_last_punch); std::string punchername = "nil"; if ( puncher != 0 ) punchername = puncher->getDescription(); actionstream<<"Player "<<m_player->getName()<<" punched by " <<punchername<<", damage "<<hitparams.hp <<" HP"<<std::endl; setHP(getHP() - hitparams.hp); if(hitparams.hp != 0) { std::string str = gob_cmd_punched(hitparams.hp, getHP()); // create message and add to list ActiveObjectMessage aom(getId(), true, str); m_messages_out.push_back(aom); } return hitparams.wear; }
HitParams getHitParams(const ItemGroupList &groups, const ToolCapabilities *tp) { return getHitParams(groups, tp, 1000000); }