Make hitting players make a visual damage flash to the player texture and the screen...
authorPerttu Ahola <celeron55@gmail.com>
Fri, 2 Dec 2011 08:57:40 +0000 (10:57 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Fri, 2 Dec 2011 08:57:40 +0000 (10:57 +0200)
src/content_cao.cpp
src/serverremoteplayer.cpp

index eed5a8337ed1855a72f83cfc849ed6fe4f289d40..b9dc91e63c6a4e2e652d92764872ba6933e9681a 100644 (file)
@@ -2274,6 +2274,13 @@ public:
        {
                pos_translator.translate(dtime);
                updateNodePos();
+
+               if(m_damage_visual_timer > 0){
+                       m_damage_visual_timer -= dtime;
+                       if(m_damage_visual_timer <= 0){
+                               updateTextures("");
+                       }
+               }
        }
 
        void processMessage(const std::string &data)
@@ -2293,6 +2300,17 @@ public:
 
                        updateNodePos();
                }
+               else if(cmd == 1) // punched
+               {
+                       // damage
+                       s16 damage = readS16(is);
+                       
+                       if(m_is_local_player)
+                               m_env->damageLocalPlayer(damage, false);
+                       
+                       m_damage_visual_timer = 0.5;
+                       updateTextures("^[brighten");
+               }
        }
 
        void updateTextures(const std::string &mod)
@@ -2318,12 +2336,6 @@ public:
                        }
                }
        }
-       
-       bool directReportPunch(const std::string &toolname, v3f dir)
-       {
-               updateTextures("^[brighten");
-               return false;
-       }
 };
 
 // Prototype
index f2bb85c9274e5fd02c99c385f3ffbfed8e68ba51..ceb46c4ee62d4eec006a2438709b281d9ae218e5 100644 (file)
@@ -151,10 +151,19 @@ void ServerRemotePlayer::punch(ServerActiveObject *puncher,
        HittingProperties hitprop = getHittingProperties(&mp, &tp,
                        time_from_last_punch);
        
-       infostream<<"1. getHP()="<<getHP()<<std::endl;
        setHP(getHP() - hitprop.hp);
-       infostream<<"2. getHP()="<<getHP()<<std::endl;
        puncher->damageWieldedItem(hitprop.wear);
+
+       {
+               std::ostringstream os(std::ios::binary);
+               // command (1 = punched)
+               writeU8(os, 1);
+               // damage
+               writeS16(os, hitprop.hp);
+               // create message and add to list
+               ActiveObjectMessage aom(getId(), false, os.str());
+               m_messages_out.push_back(aom);
+       }
 }
 
 void ServerRemotePlayer::rightClick(ServerActiveObject *clicker)