Properly use time_from_last_punch for limiting PvP punch damage

master
Perttu Ahola 2011-12-04 14:43:01 +02:00
parent ceaf8edade
commit 4cc117ddf6
5 changed files with 21 additions and 7 deletions

View File

@ -104,9 +104,9 @@ HittingProperties getHittingProperties(const MaterialProperties *mp,
time_from_last_punch);
// If digging time would be 1 second, 2 hearts go in 1 second.
s16 hp = 2.0 * 2.0 / digprop.time + 0.5;
s16 hp = 2.0 * 2.0 / digprop.time;
// Wear is the same as for digging a single node
s16 wear = (float)digprop.wear + 0.5;
s16 wear = (float)digprop.wear;
return HittingProperties(hp, wear);
}

View File

@ -2964,7 +2964,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
<<pointed.object_id<<std::endl;
// Do stuff
pointed_object->punch(srp);
pointed_object->punch(srp, srp->m_time_from_last_punch);
srp->m_time_from_last_punch = 0;
}
} // action == 0

View File

@ -31,11 +31,11 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env):
ServerActiveObject(env, v3f(0,0,0)),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_additional_items(),
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)
{
}
@ -43,9 +43,12 @@ ServerRemotePlayer::ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 pee
const char *name_):
Player(env->getGameDef()),
ServerActiveObject(env, pos_),
m_last_good_position(0,0,0),
m_last_good_position_age(0),
m_inventory_not_sent(false),
m_hp_not_sent(false),
m_is_in_environment(false),
m_time_from_last_punch(0),
m_position_not_sent(false)
{
setPosition(pos_);
@ -93,6 +96,8 @@ bool ServerRemotePlayer::unlimitedTransferDistance() const
void ServerRemotePlayer::step(float dtime, bool send_recommended)
{
m_time_from_last_punch += dtime;
if(send_recommended == false)
return;
@ -157,9 +162,14 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
HittingProperties hitprop = getHittingProperties(&mp, &tp,
time_from_last_punch);
actionstream<<"Player "<<getName()<<" punched by "
<<puncher->getDescription()<<", damage "<<hitprop.hp
<<" HP"<<std::endl;
setHP(getHP() - hitprop.hp);
puncher->damageWieldedItem(hitprop.wear);
if(hitprop.hp != 0)
{
std::ostringstream os(std::ios::binary);
// command (1 = punched)

View File

@ -74,7 +74,8 @@ public:
void rightClick(ServerActiveObject *clicker);
void setPos(v3f pos);
void moveTo(v3f pos, bool continuous);
virtual std::string getDescription(){return getName();}
virtual std::string getDescription()
{return std::string("player ")+getName();}
virtual void getWieldDiggingProperties(ToolDiggingProperties *dst);
virtual void damageWieldedItem(u16 amount);
@ -93,6 +94,8 @@ public:
bool m_hp_not_sent;
bool m_respawn_active;
bool m_is_in_environment;
// Incremented by step(), read and reset by Server
float m_time_from_last_punch;
private:
bool m_position_not_sent;

View File

@ -38,7 +38,7 @@ struct ToolDiggingProperties
float dd_crumbliness;
float dd_cuttability;
ToolDiggingProperties(float full_punch_interval_=1.0,
ToolDiggingProperties(float full_punch_interval_=2.0,
float a=0.75, float b=0, float c=0, float d=0, float e=0,
float f=50, float g=0, float h=0, float i=0, float j=0);
};