Properly use time_from_last_punch for limiting PvP punch damage
authorPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 12:43:01 +0000 (14:43 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 4 Dec 2011 12:43:01 +0000 (14:43 +0200)
src/materials.cpp
src/server.cpp
src/serverremoteplayer.cpp
src/serverremoteplayer.h
src/tooldef.h

index 3f88f9d455ab0f3b4b5c6d5a65b7e88fa83eaade..d2d37ebf46ceddb10e99bde1c8b8e7272871d45f 100644 (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);
 }
index 8fbc0f793dd761a047bfbd3506806dd0f2ecb1c6..11c11b259c729da64167eb29eb1cb275d146bab4 100644 (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
index 900cc54329466e6cb32048c3205a0cf636a896ca..1681900e009d66f2cc3e8846c19f2d2965e96c84 100644 (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)
index 15a9ebc38cd4dba467faafa5acddf557d1d0be11..bdc3bba208f5553edddb1112c6661962b3a899fe 100644 (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;
index c30579cb2358709daa4e69813de5f5a4e3d32fc3..68a894898e3a465a401354cb0e4cec4fc47eef7e 100644 (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);
 };