Eris  1.4.0
Avatar.h
1 #ifndef ERIS_AVATAR_H
2 #define ERIS_AVATAR_H
3 
4 #include "Types.h"
5 #include "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 <boost/optional.hpp>
19 
20 #include <vector>
21 
22 namespace Eris
23 {
24 
25 // Forward Declerations
26 class Account;
27 class IGRouter;
28 class View;
29 class Connection;
30 class TransferInfo;
31 class TimedEvent;
32 
34 class Avatar : virtual public sigc::trackable
35 {
36 public:
37 
39  const std::string & getId() const;
40 
41  // Get the Entity if of this Avatar. This can't be directly interacted with; all interaction must go through the Mind.
42  const std::string & getEntityId() const;
43 
44 
46  EntityPtr getEntity() const;
47 
48  View* getView() const;
49 
50  Connection* getConnection() const;
51 
53  double getWorldTime();
54 
62  void drop(Entity* entity, const WFMath::Point<3>& pos,
63  const WFMath::Quaternion& orientation, const std::string& loc);
64 
71  void drop(Entity* entity, const WFMath::Vector<3>& offset = WFMath::Vector<3>(0, 0, 0),
72  const WFMath::Quaternion& orientation = WFMath::Quaternion());
73 
75  void take(Entity*);
76 
78  void touch(Entity*, const WFMath::Point<3>& pos);
79 
81  void say(const std::string&);
82 
86  void sayTo(const std::string& message, const std::vector<std::string>& entities);
87 
89  void emote(const std::string&);
90 
92  void moveToPoint(const WFMath::Point<3>&, const WFMath::Quaternion& orient);
93 
95  void moveInDirection(const WFMath::Vector<3>&, const WFMath::Quaternion&);
96 
109  void place(Entity* entity, Entity* container, const WFMath::Point<3>& pos,
110  const WFMath::Quaternion& orientation = WFMath::Quaternion(),
111  boost::optional<float> offset = boost::none);
112 
113 // /**
114 // * @brief Use the currently wielded entity (tool) on another entity.
115 // * @param entity A pointer to the entity you wish to use your tool on.
116 // * @param position A position where you perform the operation.
117 // * @param op The operation of the tool to perform, or an empty string to use the default.
118 // *
119 // * If @a position is invalid the "pos" parameter will not be set on the USE operation.
120 // *
121 // * @sa WFMath::Point< 3 >::Point(), WFMath::Point< 3 >::setValid(), WFMath::Point< 3 >::isValid()
122 // **/
123 // void useOn(Entity * entity, const WFMath::Point< 3 > & position, const std::string& op);
124 
129  void attack(Entity* entity);
130 
135  void useStop();
136 
137  void deactivate();
138 
149  void setIsAdmin(bool isAdmin);
150 
161  bool getIsAdmin();
162 
169  void send(const Atlas::Objects::Operation::RootOperation& op);
170 
177  sigc::signal<void, Entity*> GotCharacterEntity;
178 
179  // These two signals just transmit the Entity's
180  // AddedMember and RemovedMember signals, but
181  // you're allowed to connect to them as soon as
182  // the Avatar has been created, instead of having to wait
183  // for the Entity to be created.
184 
186  sigc::signal<void,Entity*> InvAdded;
188  sigc::signal<void,Entity*> InvRemoved;
189 
192  sigc::signal<void, Entity*, const Atlas::Objects::Operation::RootOperation&> Hear;
193 
199  sigc::signal<void, const TransferInfo &> TransferRequested;
200 
201 protected:
202  friend class Account;
203 
207  Avatar(Account& pl, std::string mindId, std::string entityId);
208  virtual ~Avatar();
209 
210  friend class AccountRouter;
211  friend class IGRouter;
212 
215  void updateWorldTime(double t);
216 
217 protected:
218  void onEntityAppear(Entity* ent);
219  void onCharacterChildAdded(Entity* child);
220  void onCharacterChildRemoved(Entity* child);
224  void onAvatarEntityDeleted();
225 
226  virtual void onTransferRequested(const TransferInfo &transfer);
227 
228  void logoutResponse(const Atlas::Objects::Operation::RootOperation&);
229 
234  void logoutRequested();
235 
242  void logoutRequested(const TransferInfo& transferInfo);
243 
244  Account& m_account;
245 
246  std::string m_mindId;
247  std::string m_entityId;
248  EntityPtr m_entity;
249 
250  WFMath::TimeStamp m_stampAtLastOp;
251  double m_lastOpTime;
252 
253  IGRouter* m_router;
254  View* m_view;
255 
256  sigc::connection m_entityAppearanceCon;
257 
258  bool m_isAdmin;
259 
260  TimedEvent* m_logoutTimer;
261 };
262 
263 inline const std::string & Avatar::getId() const
264 {
265  return m_mindId;
266 }
267 
268 inline const std::string & Avatar::getEntityId() const
269 {
270  return m_entityId;
271 }
272 
273 
275 {
276  return m_entity;
277 }
278 
279 inline View* Avatar::getView() const
280 {
281  return m_view;
282 }
283 
284 } // of namespace Eris
285 
286 #endif
sigc::signal< void, Entity * > InvAdded
An object was added to the inventory.
Definition: Avatar.h:186
Class for things which occur after a period of time.
Definition: EventService.h:23
sigc::signal< void, Entity * > GotCharacterEntity
Emitted when the character entity of this Avatar is valid (and presumably, visible).
Definition: Avatar.h:177
void setIsAdmin(bool isAdmin)
Sets whether the current avatar is an admin character.
Definition: Avatar.cpp:434
void logoutRequested()
Called when a logout of the avatar has been requested by the server.
Definition: Avatar.cpp:423
void touch(Entity *, const WFMath::Point< 3 > &pos)
Touch an entity.
Definition: Avatar.cpp:134
void onAvatarEntityDeleted()
Called when the avatar entity is deleted.
Definition: Avatar.cpp:353
void sayTo(const std::string &message, const std::vector< std::string > &entities)
Say something (in-game), addressing one or many entities.
Definition: Avatar.cpp:161
View encapsulates the set of entities currently visible to an Avatar, as well as those that have rece...
Definition: View.h:37
void place(Entity *entity, Entity *container, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation=WFMath::Quaternion(), boost::optional< float > offset=boost::none)
Place an entity inside another one.
Definition: Avatar.cpp:232
void emote(const std::string &)
Emote something (in-game)
Definition: Avatar.cpp:179
Definition: IGRouter.h:13
void updateWorldTime(double t)
called by the IG router for each op it sees with a valid &#39;seconds&#39; attribute set. ...
Definition: Avatar.cpp:385
Definition: Account.cpp:36
sigc::signal< void, Entity *, const Atlas::Objects::Operation::RootOperation & > Hear
emitted when this Avatar hears something.
Definition: Avatar.h:192
void drop(Entity *entity, const WFMath::Point< 3 > &pos, const WFMath::Quaternion &orientation, const std::string &loc)
Drop an entity in the Avatar&#39;s inventory at the given location.
Definition: Avatar.cpp:87
void say(const std::string &)
Say something (in-game)
Definition: Avatar.cpp:149
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:36
void attack(Entity *entity)
Use the currently wielded entity (tool) on another entity.
Definition: Avatar.cpp:312
const std::string & getId() const
Get the Mind id of this Avatar. All interaction with the entity goes through the Mind.
Definition: Avatar.h:263
void send(const Atlas::Objects::Operation::RootOperation &op)
Sends an operation from this Avatar.
Definition: Avatar.cpp:444
void moveToPoint(const WFMath::Point< 3 > &, const WFMath::Quaternion &orient)
Have the character move towards a position. Any non-valid data will not be sent.
Definition: Avatar.cpp:194
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:58
bool getIsAdmin()
Gets whether the current avatar is an admin character.
Definition: Avatar.cpp:439
void moveInDirection(const WFMath::Vector< 3 > &, const WFMath::Quaternion &)
Set the character&#39;s velocity and orientation. Any non-valid data will not be sent.
Definition: Avatar.cpp:214
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:188
EntityPtr getEntity() const
Get the Entity this Avatar refers to.
Definition: Avatar.h:274
void useStop()
Stop the current task, if one is in progress.
Definition: Avatar.cpp:325
Avatar(Account &pl, std::string mindId, std::string entityId)
Create a new Avatar object.
Definition: Avatar.cpp:39
The player&#39;s avatar representation.
Definition: Avatar.h:34
void take(Entity *)
Move an entity into the Avatar&#39;s inventory.
Definition: Avatar.cpp:117
double getWorldTime()
get the current local approximation of world time.
Definition: Avatar.cpp:379
sigc::signal< void, const TransferInfo & > TransferRequested
Emitted when a character transfer authentication is requested.
Definition: Avatar.h:199