X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fserverremoteplayer.cpp;h=667ece7f22c8b0ab85717115ed6ea8ac5bbcd631;hb=54917e306256d4d39b95335986fce93b8c56a6e3;hp=b4dbbdb1b0663f7d9abd45b972079c247e8252ce;hpb=f22c73f50169b978f13c0b6511805b9d4a1a6871;p=minetest.git diff --git a/src/serverremoteplayer.cpp b/src/serverremoteplayer.cpp index b4dbbdb1b..667ece7f2 100644 --- a/src/serverremoteplayer.cpp +++ b/src/serverremoteplayer.cpp @@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gamedef.h" #include "inventory.h" #include "environment.h" -#include "materials.h" +#include "tool.h" ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env): Player(env->getGameDef()), @@ -34,7 +34,6 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env): m_wield_index(0), m_inventory_not_sent(false), m_hp_not_sent(false), - m_respawn_active(false), m_is_in_environment(false), m_time_from_last_punch(0), m_position_not_sent(false) @@ -159,6 +158,8 @@ std::string ServerRemotePlayer::getClientInitializationData() writeV3F1000(os, getPosition()); // yaw writeF1000(os, getYaw()); + // dead + writeU8(os, getHP() == 0); return os.str(); } @@ -168,51 +169,46 @@ std::string ServerRemotePlayer::getStaticData() return ""; } -void ServerRemotePlayer::punch(ServerActiveObject *puncher, +int ServerRemotePlayer::punch(v3f dir, + const ToolCapabilities *toolcap, + ServerActiveObject *puncher, float time_from_last_punch) { - if(!puncher) - return; + if(!toolcap) + return 0; // No effect if PvP disabled if(g_settings->getBool("enable_pvp") == false){ if(puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) - return; + return 0; } - // "Material" properties of a player - MaterialProperties mp; - mp.diggability = DIGGABLE_NORMAL; - mp.crackiness = -0.5; - mp.cuttability = 0.5; - - IItemDefManager *idef = m_env->getGameDef()->idef(); - ItemStack punchitem = puncher->getWieldedItem(); - ToolDiggingProperties tp = - punchitem.getToolDiggingProperties(idef); - - HittingProperties hitprop = getHittingProperties(&mp, &tp, - time_from_last_punch); + // "Material" groups of the player + ItemGroupList groups; + groups["choppy"] = 2; + groups["fleshy"] = 3; + + HitParams hitparams = getHitParams(groups, toolcap, time_from_last_punch); actionstream<<"Player "<getDescription()<<", damage "<getDescription()<<", damage "<setWieldedItem(punchitem); + setHP(getHP() - hitparams.hp); - if(hitprop.hp != 0) + if(hitparams.hp != 0) { std::ostringstream os(std::ios::binary); // command (1 = punched) writeU8(os, 1); // damage - writeS16(os, hitprop.hp); + writeS16(os, hitparams.hp); // create message and add to list ActiveObjectMessage aom(getId(), false, os.str()); m_messages_out.push_back(aom); } + + return hitparams.wear; } void ServerRemotePlayer::rightClick(ServerActiveObject *clicker) @@ -247,6 +243,19 @@ void ServerRemotePlayer::setHP(s16 hp_) if(hp != oldhp) m_hp_not_sent = true; + + // On death or reincarnation send an active object message + if((hp == 0) != (oldhp == 0)) + { + std::ostringstream os(std::ios::binary); + // command (2 = update death state) + writeU8(os, 2); + // dead? + writeU8(os, hp == 0); + // create message and add to list + ActiveObjectMessage aom(getId(), false, os.str()); + m_messages_out.push_back(aom); + } } s16 ServerRemotePlayer::getHP() {