]> git.lizzy.rs Git - dragonfireclient.git/blob - src/serverremoteplayer.h
Properly use time_from_last_punch for limiting PvP punch damage
[dragonfireclient.git] / src / serverremoteplayer.h
1 /*
2 Minetest-c55
3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef SERVERREMOTEPLAYER_HEADER
21 #define SERVERREMOTEPLAYER_HEADER
22
23 #include "player.h"
24 #include "serverobject.h"
25 #include "content_object.h" // Object type IDs
26
27 /*
28         Player on the server
29 */
30
31 class ServerRemotePlayer : public Player, public ServerActiveObject
32 {
33 public:
34         ServerRemotePlayer(ServerEnvironment *env);
35         ServerRemotePlayer(ServerEnvironment *env, v3f pos_, u16 peer_id_,
36                         const char *name_);
37
38         virtual ~ServerRemotePlayer();
39
40         virtual bool isLocal() const
41         { return false; }
42
43         virtual void move(f32 dtime, Map &map, f32 pos_max_d)
44         {
45         }
46         
47         virtual void setPosition(const v3f &position);
48         
49         // Returns a reference
50         virtual InventoryItem* getWieldedItem();
51         
52         /* ServerActiveObject interface */
53
54         u8 getType() const
55         {return ACTIVEOBJECT_TYPE_PLAYER;}
56         
57         // Called after id has been set and has been inserted in environment
58         void addedToEnvironment();
59         // Called before removing from environment
60         void removingFromEnvironment();
61         
62         bool environmentDeletes() const
63         { return false; }
64
65         virtual bool unlimitedTransferDistance() const;
66         
67         bool isStaticAllowed() const
68         { return false; }
69
70         void step(float dtime, bool send_recommended);
71         std::string getClientInitializationData();
72         std::string getStaticData();
73         void punch(ServerActiveObject *puncher, float time_from_last_punch);
74         void rightClick(ServerActiveObject *clicker);
75         void setPos(v3f pos);
76         void moveTo(v3f pos, bool continuous);
77         virtual std::string getDescription()
78         {return std::string("player ")+getName();}
79
80         virtual void getWieldDiggingProperties(ToolDiggingProperties *dst);
81         virtual void damageWieldedItem(u16 amount);
82         // If all fits, eats item and returns true. Otherwise returns false.
83         virtual bool addToInventory(InventoryItem *item);
84         virtual void addToInventoryLater(InventoryItem *item);
85         void clearAddToInventoryLater();
86         void completeAddToInventoryLater(u16 preferred_index);
87         virtual void setHP(s16 hp_);
88         virtual s16 getHP();
89         
90         v3f m_last_good_position;
91         float m_last_good_position_age;
92         std::vector<InventoryItem*> m_additional_items;
93         bool m_inventory_not_sent;
94         bool m_hp_not_sent;
95         bool m_respawn_active;
96         bool m_is_in_environment;
97         // Incremented by step(), read and reset by Server
98         float m_time_from_last_punch;
99
100 private:
101         bool m_position_not_sent;
102 };
103
104 #endif
105