eris 1.4.0
A WorldForge client library.
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#include <Atlas/Message/Element.h>
9
10#include <wfmath/point.h>
11#include <wfmath/vector.h>
12#include <wfmath/quaternion.h>
13#include <wfmath/timestamp.h>
14
15#include <sigc++/trackable.h>
16#include <sigc++/signal.h>
17#include <sigc++/connection.h>
18
19#include <boost/optional.hpp>
20
21#include <vector>
22
23namespace Eris {
24
25// Forward Declerations
26class Account;
27
28class IGRouter;
29
30class View;
31
32class Connection;
33
34class TransferInfo;
35
36class TimedEvent;
37
39class Avatar : virtual public sigc::trackable {
40public:
41
45 Avatar(Account& pl, std::string mindId, std::string entityId);
46
47 virtual ~Avatar();
48
49
51 const std::string& getId() const;
52
53 // Get the Entity if of this Avatar. This can't be directly interacted with; all interaction must go through the Mind.
54 const std::string& getEntityId() const;
55
56
58 Entity* getEntity() const;
59
60 View& getView() const;
61
62 Connection& getConnection() const;
63
64 Account& getAccount() const;
65
67 double getWorldTime();
68
70 void touch(Entity*, const WFMath::Point<3>& pos);
71
72 /*
73 * Wields an entity at an attach point, or removes the currently attached entity from
74 * the attach point.
75 *
76 * @param entity An entity, or null.
77 * @param attachPoint A named attach point.
78 */
79 void wield(Eris::Entity* entity, std::string attachPoint) const;
80
82 void say(const std::string&);
83
87 void sayTo(const std::string& message, const std::vector<std::string>& entities);
88
90 void emote(const std::string&);
91
93 void moveToPoint(const WFMath::Point<3>&, const WFMath::Quaternion& orient);
94
96 void moveInDirection(const WFMath::Vector<3>&, const WFMath::Quaternion&);
97
110 void place(const Entity* entity,
111 const Entity* container,
112 const WFMath::Point<3>& pos = WFMath::Point<3>(),
113 const WFMath::Quaternion& orientation = WFMath::Quaternion(),
114 boost::optional<float> offset = boost::none,
115 int amount = 1);
116
117
121 void useStop();
122
123 void deactivate();
124
135 void setIsAdmin(bool isAdmin);
136
147 bool getIsAdmin() const;
148
155 void send(const Atlas::Objects::Operation::RootOperation& op);
156
162 const std::map<std::string, std::unique_ptr<EntityRef>>& getActiveContainers() const;
163
170 sigc::signal<void, Entity*> GotCharacterEntity;
171
175 sigc::signal<void> CharacterEntityDeleted;
176
177 sigc::signal<void, Entity&> ContainerOpened;
178 sigc::signal<void, Entity&> ContainerClosed;
179
185 sigc::signal<void, const TransferInfo&> TransferRequested;
186
187protected:
188 friend class Account;
189
190 friend class AccountRouter;
191
192 friend class IGRouter;
193
196 void updateWorldTime(double t);
197
198protected:
199 void onEntityAppear(Entity* ent);
200
205
206 virtual void onTransferRequested(const TransferInfo& transfer);
207
208 void logoutResponse(const Atlas::Objects::Operation::RootOperation&);
209
214 void logoutRequested();
215
222 void logoutRequested(const TransferInfo& transferInfo);
223
224 void containerActiveChanged(const Atlas::Message::Element& element);
225
226 Account& m_account;
227
228 std::string m_mindId;
229 std::string m_entityId;
230 Entity* m_entity;
231
232 WFMath::TimeStamp m_stampAtLastOp;
233 double m_lastOpTime;
234
235 std::unique_ptr<View> m_view;
236 std::unique_ptr<IGRouter> m_router;
237
238 sigc::connection m_entityAppearanceCon;
239 sigc::connection m_avatarEntityDeletedConnection;
240
241 bool m_isAdmin;
242
243 std::unique_ptr<TimedEvent> m_logoutTimer;
244
245 std::map<std::string, std::unique_ptr<EntityRef>> m_activeContainers;
246
247 sigc::connection m_entityParentDeletedConnection;
248};
249
250inline const std::string& Avatar::getId() const {
251 return m_mindId;
252}
253
254inline const std::string& Avatar::getEntityId() const {
255 return m_entityId;
256}
257
258
259inline Entity* Avatar::getEntity() const {
260 return m_entity;
261}
262
263inline View& Avatar::getView() const {
264 return *m_view;
265}
266
267inline Account& Avatar::getAccount() const {
268 return m_account;
269}
270
271inline const std::map<std::string, std::unique_ptr<EntityRef>>& Avatar::getActiveContainers() const {
272 return m_activeContainers;
273}
274
275
276
277} // of namespace Eris
278
279#endif
Encapsulates all the state of an Atlas Account, and methods that operation on that state.
Definition: Account.h:42
void logoutRequested()
Called when a logout of the avatar has been requested by the server.
Definition: Avatar.cpp:409
bool getIsAdmin() const
Gets whether the current avatar is an admin character.
Definition: Avatar.cpp:422
void updateWorldTime(double t)
Definition: Avatar.cpp:321
double getWorldTime()
Definition: Avatar.cpp:316
Avatar(Account &pl, std::string mindId, std::string entityId)
Definition: Avatar.cpp:37
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:162
void setIsAdmin(bool isAdmin)
Sets whether the current avatar is an admin character.
Definition: Avatar.cpp:418
void onAvatarEntityDeleted()
Called when the avatar entity is deleted.
Definition: Avatar.cpp:301
void sayTo(const std::string &message, const std::vector< std::string > &entities)
Definition: Avatar.cpp:131
sigc::signal< void > CharacterEntityDeleted
Definition: Avatar.h:175
Entity * getEntity() const
Get the Entity this Avatar refers to.
Definition: Avatar.h:259
sigc::signal< void, const TransferInfo & > TransferRequested
Definition: Avatar.h:185
void place(const Entity *entity, const Entity *container, const WFMath::Point< 3 > &pos=WFMath::Point< 3 >(), const WFMath::Quaternion &orientation=WFMath::Quaternion(), boost::optional< float > offset=boost::none, int amount=1)
Place an entity inside another one.
Definition: Avatar.cpp:198
void moveInDirection(const WFMath::Vector< 3 > &, const WFMath::Quaternion &)
Set the character's velocity and orientation. Any non-valid data will not be sent.
Definition: Avatar.cpp:181
void useStop()
Stop the current task, if one is in progress.
Definition: Avatar.cpp:236
const std::map< std::string, std::unique_ptr< EntityRef > > & getActiveContainers() const
Definition: Avatar.h:271
void send(const Atlas::Objects::Operation::RootOperation &op)
Sends an operation from this Avatar.
Definition: Avatar.cpp:426
void touch(Entity *, const WFMath::Point< 3 > &pos)
Touch an entity.
Definition: Avatar.cpp:90
void say(const std::string &)
Say something (in-game)
Definition: Avatar.cpp:120
sigc::signal< void, Entity * > GotCharacterEntity
Definition: Avatar.h:170
const std::string & getId() const
Get the Mind id of this Avatar. All interaction with the entity goes through the Mind.
Definition: Avatar.h:250
void emote(const std::string &)
Emote something (in-game)
Definition: Avatar.cpp:148
Entity is a concrete (instantiable) class representing one game entity.
Definition: Entity.h:56
Definition: Account.cpp:33