ManaPlus
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
Party Class Reference

#include <party.h>

Inheritance diagram for Party:
AvatarListModel ListModel

Public Types

typedef std::vector< PartyMember * > MemberList
 

Public Member Functions

void setName (const std::string &name)
 
PartyMemberaddMember (const BeingId id, const std::string &name)
 
PartyMembergetMember (const BeingId id) const
 
PartyMembergetMember (const std::string &name) const
 
const std::string & getName () const
 
int16_t getId () const
 
void removeMember (const PartyMember *const member)
 
void removeMember (const BeingId id)
 
void removeMember (const std::string &name)
 
void clearMembers ()
 
void removeFromMembers ()
 
int getNumberOfElements ()
 
AvatargetAvatarAt (const int index)
 
bool getInviteRights () const
 
void setRights (const int16_t rights)
 
bool isMember (const PartyMember *const member) const
 
bool isMember (const BeingId id) const
 
bool isMember (const std::string &name) const
 
void getNames (StringVect &names) const
 
void getNamesSet (std::set< std::string > &names) const
 
void sort ()
 
const MemberListgetMembers () const
 
- Public Member Functions inherited from AvatarListModel
 AvatarListModel ()
 
std::string getElementAt (int i)
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Static Public Member Functions

static PartygetParty (const int16_t id)
 
static void clearParties ()
 

Private Types

typedef std::map< int, Party * > PartyMap
 

Private Member Functions

 Party (const int16_t id)
 
 ~Party ()
 

Private Attributes

MemberList mMembers
 
std::string mName
 
int16_t mId
 
bool mCanInviteUsers
 

Static Private Attributes

static PartyMap parties
 

Detailed Description

Definition at line 62 of file party.h.

Member Typedef Documentation

◆ MemberList

typedef std::vector<PartyMember*> Party::MemberList

Definition at line 157 of file party.h.

◆ PartyMap

typedef std::map<int, Party*> Party::PartyMap
private

Definition at line 167 of file party.h.

Constructor & Destructor Documentation

◆ Party()

Party::Party ( const int16_t  id)
explicitprivate

Constructor with party id passed to it.

Definition at line 71 of file party.cpp.

71  :
72  mMembers(),
73  mName(),
74  mId(id),
75  mCanInviteUsers(false)
76 {
77  parties[id] = this;
78 }
static PartyMap parties
Definition: party.h:168
std::string mName
Definition: party.h:178
MemberList mMembers
Definition: party.h:177
int16_t mId
Definition: party.h:179
bool mCanInviteUsers
Definition: party.h:180

References parties.

Referenced by getParty().

◆ ~Party()

Party::~Party ( )
private

Definition at line 80 of file party.cpp.

81 {
82  clearMembers();
83 }
void clearMembers()
Definition: party.h:122

References clearMembers().

Member Function Documentation

◆ addMember()

PartyMember * Party::addMember ( const BeingId  id,
const std::string &  name 
)

Adds member to the list.

Definition at line 85 of file party.cpp.

87 {
88  PartyMember *m = getMember(id);
89  if (m != nullptr)
90  return m;
91 
92  m = new PartyMember(this, id, name);
93 
94  mMembers.push_back(m);
95 
96  return m;
97 }
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:99

References getMember(), and mMembers.

Referenced by EAthena::PartyRecv::processPartyInfo(), TmwAthena::PartyRecv::processPartyInfo(), and EAthena::PartyRecv::processPartyMemberInfo().

◆ clearMembers()

void Party::clearMembers ( )
inline

Definition at line 122 of file party.h.

123  { delete_all(mMembers); mMembers.clear(); }
void delete_all(Container &c)
Definition: dtor.h:56

References delete_all(), and mMembers.

Referenced by EAthena::PartyRecv::processPartyInfo(), TmwAthena::PartyRecv::processPartyInfo(), Ea::PartyRecv::processPartyLeave(), and ~Party().

◆ clearParties()

void Party::clearParties ( )
static

Definition at line 328 of file party.cpp.

329 {
330  PartyMap::iterator it = parties.begin();
331  while (it != parties.end())
332  {
333  delete (*it).second;
334  ++ it;
335  }
336  parties.clear();
337 }

References parties.

◆ getAvatarAt()

Avatar * Party::getAvatarAt ( const int  index)
virtual

Implements AvatarListModel.

Definition at line 218 of file party.cpp.

219 {
220  return mMembers[index];
221 }

References mMembers.

◆ getId()

int16_t Party::getId ( ) const
inline

Get the id of the party.

Returns
Returns the id of the party

Definition at line 104 of file party.h.

105  { return mId; }

References mId.

◆ getInviteRights()

bool Party::getInviteRights ( ) const
inline

Get whether user can invite users to this party.

Returns
Returns true if user can invite users

Definition at line 140 of file party.h.

141  { return mCanInviteUsers; }

References mCanInviteUsers.

◆ getMember() [1/2]

PartyMember * Party::getMember ( const BeingId  id) const

Find a member by ID.

Returns
the member with the given ID, or NULL if they don't exist.

Definition at line 99 of file party.cpp.

100 {
101  MemberList::const_iterator itr = mMembers.begin();
102  const MemberList::const_iterator itr_end = mMembers.end();
103  while (itr != itr_end)
104  {
105  if ((*itr)->mId == id)
106  return (*itr);
107  ++itr;
108  }
109 
110  return nullptr;
111 }

References mMembers.

Referenced by addMember(), EAthena::PartyHandler::kick(), TmwAthena::PartyHandler::kick(), EAthena::PartyRecv::processPartyLeader(), EAthena::PartyRecv::processPartyMemberDead(), EAthena::PartyRecv::processPartyMemberJobLevel(), EAthena::PartyRecv::processPartyMessage(), TmwAthena::PartyRecv::processPartyMessage(), TmwAthena::PartyRecv::processPartyMove(), Ea::PartyRecv::processPartyUpdateCoords(), TmwAthena::PartyRecv::processPartyUpdateHp(), EAthena::PlayerRecv::processPlayerHeal(), EAthena::PlayerHandler::setStat(), TmwAthena::PlayerHandler::setStat(), and SocialPlayersTab::updateAvatar().

◆ getMember() [2/2]

PartyMember * Party::getMember ( const std::string &  name) const

Find a member by name.

Returns
the member with the given name, or NULL if they don't exist.

Definition at line 113 of file party.cpp.

114 {
115  MemberList::const_iterator itr = mMembers.begin();
116  const MemberList::const_iterator itr_end = mMembers.end();
117  while (itr != itr_end)
118  {
119  if (((*itr) != nullptr) && (*itr)->getName() == name)
120  return (*itr);
121 
122  ++itr;
123  }
124 
125  return nullptr;
126 }

References mMembers.

◆ getMembers()

const MemberList* Party::getMembers ( ) const
inline

Definition at line 159 of file party.h.

160  { return &mMembers; }

References mMembers.

Referenced by EAthena::PartyRecv::processPartyInfo(), and TmwAthena::PartyRecv::processPartyInfo().

◆ getName()

const std::string& Party::getName ( ) const
inline

Get the name of the party.

Returns
returns name of the party

Definition at line 97 of file party.h.

98  { return mName; }

References mName.

Referenced by SocialPartyTab::action(), PopupMenu::addPartyName(), SocialPartyTab::invite(), and SocialPartyTab::leave().

◆ getNames()

void Party::getNames ( StringVect names) const

Definition at line 285 of file party.cpp.

286 {
287  names.clear();
288  MemberList::const_iterator it = mMembers.begin();
289  const MemberList::const_iterator it_end = mMembers.end();
290  while (it != it_end)
291  {
292  const PartyMember *const m = *it;
293  if (m != nullptr)
294  names.push_back(m->getName());
295  ++it;
296  }
297 }
std::string getName() const
Definition: avatar.h:53

References Avatar::getName(), and mMembers.

Referenced by PartyTab::getAutoCompleteList().

◆ getNamesSet()

void Party::getNamesSet ( std::set< std::string > &  names) const

Definition at line 299 of file party.cpp.

300 {
301  names.clear();
302  MemberList::const_iterator it = mMembers.begin();
303  const MemberList::const_iterator it_end = mMembers.end();
304  while (it != it_end)
305  {
306  const PartyMember *const m = *it;
307  if (m != nullptr)
308  names.insert(m->getName());
309  ++it;
310  }
311 }

References Avatar::getName(), and mMembers.

Referenced by EAthena::PartyRecv::processPartyInfo(), and TmwAthena::PartyRecv::processPartyInfo().

◆ getNumberOfElements()

int Party::getNumberOfElements ( )
inlinevirtual

Get size of members list.

Returns
Returns the number of members in the party.

Implements ListModel.

Definition at line 131 of file party.h.

132  { return CAST_S32(mMembers.size()); }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, and mMembers.

◆ getParty()

Party * Party::getParty ( const int16_t  id)
static

Definition at line 313 of file party.cpp.

314 {
315  const PartyMap::const_iterator it = parties.find(id);
316  if (it != parties.end())
317  return it->second;
318  Party *const party = new Party(id);
319  parties[id] = party;
320  return party;
321 }
Definition: party.h:63
Party(const int16_t id)
Definition: party.cpp:71
uint32_t party

References parties, party, and Party().

Referenced by LocalPlayer::nextTile(), Ea::PartyHandler::PartyHandler(), EAthena::PartyRecv::processPartyInfo(), TmwAthena::PartyRecv::processPartyInfo(), EAthena::PlayerRecv::processPlayerHeal(), Ea::PartyHandler::reload(), EAthena::PlayerHandler::setStat(), TmwAthena::PlayerHandler::setStat(), and SocialPlayersTab::updateAvatar().

◆ isMember() [1/3]

bool Party::isMember ( const BeingId  id) const

Definition at line 255 of file party.cpp.

256 {
257  MemberList::const_iterator itr = mMembers.begin();
258  const MemberList::const_iterator itr_end = mMembers.end();
259  while (itr != itr_end)
260  {
261  const PartyMember *const m = *itr;
262  if ((m != nullptr) && m->mId == id)
263  return true;
264  ++itr;
265  }
266 
267  return false;
268 }
BeingId mId
Definition: avatar.h:187

References Avatar::mId, and mMembers.

◆ isMember() [2/3]

bool Party::isMember ( const PartyMember *const  member) const

Definition at line 230 of file party.cpp.

231 {
232  if (member == nullptr)
233  return false;
234 
235  if ((member->mParty != nullptr) && member->mParty != this)
236  return false;
237 
238  MemberList::const_iterator itr = mMembers.begin();
239  const MemberList::const_iterator itr_end = mMembers.end();
240  while (itr != itr_end)
241  {
242  const PartyMember *const m = *itr;
243  if (m != nullptr &&
244  m->mId == member->mId &&
245  m->getName() == member->getName())
246  {
247  return true;
248  }
249  ++itr;
250  }
251 
252  return false;
253 }
Party * mParty
Definition: party.h:58

References Avatar::getName(), Avatar::mId, mMembers, and PartyMember::mParty.

◆ isMember() [3/3]

bool Party::isMember ( const std::string &  name) const

Definition at line 270 of file party.cpp.

271 {
272  MemberList::const_iterator itr = mMembers.begin();
273  const MemberList::const_iterator itr_end = mMembers.end();
274  while (itr != itr_end)
275  {
276  const PartyMember *const m = *itr;
277  if ((m != nullptr) && m->getName() == name)
278  return true;
279  ++itr;
280  }
281 
282  return false;
283 }

References Avatar::getName(), and mMembers.

◆ removeFromMembers()

void Party::removeFromMembers ( )

Definition at line 201 of file party.cpp.

202 {
203  if (actorManager == nullptr)
204  return;
205 
206  MemberList::const_iterator itr = mMembers.begin();
207  const MemberList::const_iterator itr_end = mMembers.end();
208 
209  while (itr != itr_end)
210  {
211  Being *const b = actorManager->findBeing((*itr)->getID());
212  if (b != nullptr)
213  b->setParty(nullptr);
214  ++itr;
215  }
216 }
ActorManager * actorManager
Being * findBeing(const BeingId id) const
Definition: being.h:96
void setParty(Party *const party)
Definition: being.cpp:1307

References actorManager, ActorManager::findBeing(), mMembers, and Being::setParty().

Referenced by Ea::PartyRecv::processPartyLeave().

◆ removeMember() [1/3]

void Party::removeMember ( const BeingId  id)

Removes a member from the party.

Definition at line 155 of file party.cpp.

156 {
157  bool deleted = true;
158  while (deleted)
159  {
160  deleted = false;
161  MemberList::iterator itr = mMembers.begin();
162  const MemberList::iterator itr_end = mMembers.end();
163  while (itr != itr_end)
164  {
165  PartyMember *const member = *itr;
166  if ((member != nullptr) && member->mId == id)
167  {
168  mMembers.erase(itr);
169  delete member;
170  deleted = true;
171  break;
172  }
173  ++itr;
174  }
175  }
176 }

References Avatar::mId, and mMembers.

◆ removeMember() [2/3]

void Party::removeMember ( const PartyMember *const  member)

Removes a member from the party.

Definition at line 128 of file party.cpp.

129 {
130  if (member == nullptr)
131  return;
132 
133  bool deleted = true;
134  while (deleted)
135  {
136  deleted = false;
137  MemberList::iterator itr = mMembers.begin();
138  const MemberList::iterator itr_end = mMembers.end();
139  while (itr != itr_end)
140  {
141  PartyMember *const m = *itr;
142  if ((m != nullptr) && m->mId == member->mId
143  && m->getName() == member->getName())
144  {
145  mMembers.erase(itr);
146  delete m;
147  deleted = true;
148  break;
149  }
150  ++itr;
151  }
152  }
153 }

References Avatar::getName(), Avatar::mId, and mMembers.

Referenced by Ea::PartyRecv::processPartyLeave(), and Being::setParty().

◆ removeMember() [3/3]

void Party::removeMember ( const std::string &  name)

Removes a member from the party.

Definition at line 178 of file party.cpp.

179 {
180  bool deleted = true;
181  while (deleted)
182  {
183  deleted = false;
184  MemberList::iterator itr = mMembers.begin();
185  const MemberList::iterator itr_end = mMembers.end();
186  while (itr != itr_end)
187  {
188  PartyMember *const member = *itr;
189  if ((member != nullptr) && member->getName() == name)
190  {
191  mMembers.erase(itr);
192  delete member;
193  deleted = true;
194  break;
195  }
196  ++itr;
197  }
198  }
199 }

References Avatar::getName(), and mMembers.

◆ setName()

void Party::setName ( const std::string &  name)
inline

Set the party's name.

Definition at line 70 of file party.h.

71  { mName = name; }

References mName.

Referenced by EAthena::PartyRecv::processPartyInfo(), and TmwAthena::PartyRecv::processPartyInfo().

◆ setRights()

void Party::setRights ( const int16_t  rights)

Definition at line 223 of file party.cpp.

224 {
225  // to invite, rights must be greater than 0
226  if (rights > 0)
227  mCanInviteUsers = true;
228 }

References mCanInviteUsers.

◆ sort()

void Party::sort ( )

Definition at line 323 of file party.cpp.

324 {
325  std::sort(mMembers.begin(), mMembers.end(), partySorter);
326 }
static class SortPartyFunctor partySorter

References mMembers, and partySorter.

Referenced by EAthena::PartyRecv::processPartyInfo(), and TmwAthena::PartyRecv::processPartyInfo().

Field Documentation

◆ mCanInviteUsers

bool Party::mCanInviteUsers
private

Definition at line 180 of file party.h.

Referenced by getInviteRights(), and setRights().

◆ mId

int16_t Party::mId
private

Definition at line 179 of file party.h.

Referenced by getId().

◆ mMembers

MemberList Party::mMembers
private

◆ mName

std::string Party::mName
private

Definition at line 178 of file party.h.

Referenced by getName(), and setName().

◆ parties

Party::PartyMap Party::parties
staticprivate

Definition at line 168 of file party.h.

Referenced by clearParties(), getParty(), and Party().


The documentation for this class was generated from the following files: