Eris  1.3.21
Avatar.h
1 #ifndef ERIS_AVATAR_H
2 #define ERIS_AVATAR_H
3 
4 #include <Eris/Types.h>
5 #include <Eris/EntityRef.h>
6 
7 #include <Atlas/Objects/ObjectsFwd.h>
8 
9 #include <wfmath/point.h>
10 #include <wfmath/vector.h>
11 #include <wfmath/quaternion.h>
12 #include <wfmath/timestamp.h>
13 
14 #include <sigc++/trackable.h>
15 #include <sigc++/signal.h>
16 #include <sigc++/connection.h>
17 
18 #include <vector>
19 
20 namespace Eris
21 {
22 
23 // Forward Declerations
24 class Account;
25 class IGRouter;
26 class View;
27 class Connection;
28 class TransferInfo;
29 
31 class Avatar : virtual public sigc::trackable
32 {
33 public:
34  virtual ~Avatar();
35 
37  const std::string & getId() const;
38 
40  EntityPtr getEntity() const;
41 
42  View* getView() const;
43 
44  Connection* getConnection() const;
45 
47  double getWorldTime();
48 
49  const EntityRef& getWielded() const;
50 
58  void drop(Entity* entity, const WFMath::Point<3>& pos,
59  const WFMath::Quaternion& orientation, const std::string& loc);
60 
67  void drop(Entity* entity, const WFMath::Vector<3>& offset = WFMath::Vector<3>(0, 0, 0),
68  const WFMath::Quaternion& orientation = WFMath::Quaternion());
69 
71  void take(Entity*);
72 
74  void touch(Entity*);
75 
77  void say(const std::string&);
78 
82  void sayTo(const std::string& message, const std::vector<const Entity*>& entities);
83 
85  void emote(const std::string&);
86 
88  void moveToPoint(const WFMath::Point<3>&);
89 
91  void moveInDirection(const WFMath::Vector<3>&);
92 
94  void moveInDirection(const WFMath::Vector<3>&, const WFMath::Quaternion&);
95 
108  void place(Entity* entity, Entity* container, const WFMath::Point<3>& pos,
109  const WFMath::Quaternion& orientation = WFMath::Quaternion());
110 
112  void wield(Entity * entity);
113 
124  void useOn(Entity * entity, const WFMath::Point< 3 > & position, const std::string& op);
125 
130  void attack(Entity* entity);
131 
136  void useStop();
137 
138  void deactivate();
139 
150  void setIsAdmin(bool isAdmin);
151 
162  bool getIsAdmin();
163 
170  sigc::signal<void, Entity*> GotCharacterEntity;
171 
172  // These two signals just transmit the Entity's
173  // AddedMember and RemovedMember signals, but
174  // you're allowed to connect to them as soon as
175  // the Avatar has been created, instead of having to wait
176  // for the Entity to be created.
177 
179  sigc::signal<void,Entity*> InvAdded;
181  sigc::signal<void,Entity*> InvRemoved;
182 
185  sigc::signal<void, Entity*, const Atlas::Objects::Operation::RootOperation&> Hear;
186 
192  sigc::signal<void, const TransferInfo &> TransferRequested;
193 
194 protected:
195  friend class Account;
196 
200  Avatar(Account& pl, const std::string& entId);
201 
202  friend class AccountRouter;
203  friend class IGRouter;
204 
207  void updateWorldTime(double t);
208 
209 protected:
210  void onEntityAppear(Entity* ent);
211  void onCharacterChildAdded(Entity* child);
212  void onCharacterChildRemoved(Entity* child);
213 
214  void onCharacterWield(const Atlas::Message::Element&);
215  void onWieldedChanged();
216 
217  virtual void onTransferRequested(const TransferInfo &transfer);
218 
219  void logoutResponse(const Atlas::Objects::Operation::RootOperation&);
220 
225  void logoutRequested();
226 
233  void logoutRequested(const TransferInfo& transferInfo);
234 
235  Account& m_account;
236 
237  std::string m_entityId;
238  EntityPtr m_entity;
239 
240  WFMath::TimeStamp m_stampAtLastOp;
241  double m_lastOpTime;
242 
243  IGRouter* m_router;
244  View* m_view;
245 
246  EntityRef m_wielded;
247 
248  sigc::connection m_entityAppearanceCon;
249 
250  bool m_isAdmin;
251 };
252 
253 inline const std::string & Avatar::getId() const
254 {
255  return m_entityId;
256 }
257 
259 {
260  return m_entity;
261 }
262 
263 inline View* Avatar::getView() const
264 {
265  return m_view;
266 }
267 
268 inline const EntityRef& Avatar::getWielded() const
269 {
270  return m_wielded;
271 }
272 } // of namespace Eris
273 
274 #endif
sigc::signal< void, Entity * > InvAdded
An object was added to the inventory.
Definition: Avatar.h:179
void useOn(Entity *entity, const WFMath::Point< 3 > &position, const std::string &op)
Use the currently wielded entity (tool) on another entity.
Definition: Avatar.cpp:297
const std::string & getId() const
Get the Entity id of this Avatar.
Definition: Avatar.h:253
Definition: EntityRef.h:14
void moveInDirection(const WFMath::Vector< 3 > &)
Set the character's velocity.
Definition: Avatar.cpp:197
sigc::signal< void, Entity * > GotCharacterEntity
Emitted when the character entity of this Avatar is valid (and presumably, visible).
Definition: Avatar.h:170
void setIsAdmin(bool isAdmin)
Sets whether the current avatar is an admin character.
Definition: Avatar.cpp:450
void logoutRequested()
Called when a logout of the avatar has been requested by the server.
Definition: Avatar.cpp:439
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:33
void emote(const std::string &)
Emote something (in-game)
Definition: Avatar.cpp:168
Definition: IGRouter.h:13
void updateWorldTime(double t)
called by the IG router for each op it sees with a valid 'seconds' attribute set. ...
Definition: Avatar.cpp:400
Definition: Account.cpp:37
void place(Entity *entity, Entity *container, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation=WFMath::Quaternion())
Place an entity inside another one.
Definition: Avatar.cpp:247
sigc::signal< void, Entity *, const Atlas::Objects::Operation::RootOperation & > Hear
emitted when this Avatar hears something.
Definition: Avatar.h:185
void drop(Entity *entity, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, const std::string &loc)
Drop an entity in the Avatar's inventory at the given location.
Definition: Avatar.cpp:79
void say(const std::string &)
Say something (in-game)
Definition: Avatar.cpp:138
Definition: Account.cpp:35
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:37
Avatar(Account &pl, const std::string &entId)
Create a new Avatar object.
Definition: Avatar.cpp:40
void attack(Entity *entity)
Attach the specified entity.
Definition: Avatar.cpp:326
void wield(Entity *entity)
Wield an entity which is inside the Avatar's inventory.
Definition: Avatar.cpp:278
void touch(Entity *)
Touch an entity.
Definition: Avatar.cpp:126
Encapsulates all the state of an Atlas Account, and methods that operation on that state...
Definition: Account.h:44
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:57
bool getIsAdmin()
Gets whether the current avatar is an admin character.
Definition: Avatar.cpp:455
A TransferInfo object represents the encapsulation of various data required to successfully transfer ...
Definition: TransferInfo.h:16
sigc::signal< void, Entity * > InvRemoved
An object was removed from the inventory.
Definition: Avatar.h:181
void useStop()
Stop the current task, if one is in progress.
Definition: Avatar.cpp:339
void moveToPoint(const WFMath::Point< 3 > &)
Have the character move towards a position.
Definition: Avatar.cpp:183
The player's avatar representation.
Definition: Avatar.h:31
void take(Entity *)
Move an entity into the Avatar's inventory.
Definition: Avatar.cpp:109
void sayTo(const std::string &message, const std::vector< const Entity * > &entities)
Say something (in-game), addressing one or many entities.
Definition: Avatar.cpp:150
double getWorldTime()
get the current local approximation of world time.
Definition: Avatar.cpp:394
sigc::signal< void, const TransferInfo & > TransferRequested
Emitted when a character transfer authentication is requested.
Definition: Avatar.h:192
EntityPtr getEntity() const
Get the Entity this Avatar refers to.
Definition: Avatar.h:258