#include "gamedef.h"
#include "inventory.h"
#include "environment.h"
-#include "materials.h"
+#include "tool.h"
ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
Player(env->getGameDef()),
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)
writeV3F1000(os, getPosition());
// yaw
writeF1000(os, getYaw());
+ // dead
+ writeU8(os, getHP() == 0);
return os.str();
}
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 "<<getName()<<" punched by "
- <<puncher->getDescription()<<", damage "<<hitprop.hp
+ <<puncher->getDescription()<<", damage "<<hitparams.hp
<<" HP"<<std::endl;
- setHP(getHP() - hitprop.hp);
- punchitem.addWear(hitprop.wear, idef);
- puncher->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)
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()
{