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 61 of file party.h.

Member Typedef Documentation

◆ MemberList

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

Definition at line 156 of file party.h.

◆ PartyMap

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

Definition at line 166 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 70 of file party.cpp.

References parties.

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

◆ ~Party()

Party::~Party ( )
private

Definition at line 79 of file party.cpp.

References clearMembers().

80 {
81  clearMembers();
82 }
void clearMembers()
Definition: party.h:121

Member Function Documentation

◆ addMember()

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

Adds member to the list.

Definition at line 84 of file party.cpp.

References getMember(), and mMembers.

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

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

◆ clearMembers()

void Party::clearMembers ( )
inline

Definition at line 121 of file party.h.

References delete_all().

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

122  { delete_all(mMembers); mMembers.clear(); }
MemberList mMembers
Definition: party.h:176
void delete_all(Container &c)
Definition: dtor.h:55

◆ clearParties()

void Party::clearParties ( )
static

Definition at line 327 of file party.cpp.

References parties.

Referenced by Client::stateSwitchLogin1().

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

◆ getAvatarAt()

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

Implements AvatarListModel.

Definition at line 217 of file party.cpp.

References mMembers.

218 {
219  return mMembers[index];
220 }
MemberList mMembers
Definition: party.h:176

◆ getId()

int16_t Party::getId ( ) const
inline

Get the id of the party.

Returns
Returns the id of the party

Definition at line 103 of file party.h.

References Avatar::mId.

104  { return mId; }
int16_t mId
Definition: party.h:178

◆ 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 139 of file party.h.

References A_WARN_UNUSED.

140  { return mCanInviteUsers; }
bool mCanInviteUsers
Definition: party.h:179

◆ getMember() [1/2]

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

◆ 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 112 of file party.cpp.

References mMembers.

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

◆ getMembers()

const MemberList* Party::getMembers ( ) const
inline

◆ getName()

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

Get the name of the party.

Returns
returns name of the party

Definition at line 96 of file party.h.

References Avatar::mName.

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

97  { return mName; }
std::string mName
Definition: party.h:177

◆ getNames()

void Party::getNames ( StringVect names) const

Definition at line 284 of file party.cpp.

References Avatar::getName(), and mMembers.

Referenced by PartyTab::getAutoCompleteList(), and replaceVars().

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

◆ getNamesSet()

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

Definition at line 298 of file party.cpp.

References Avatar::getName(), and mMembers.

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

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

◆ getNumberOfElements()

int Party::getNumberOfElements ( )
inlinevirtual

Get size of members list.

Returns
Returns the number of members in the party.

Implements ListModel.

Definition at line 130 of file party.h.

References A_WARN_UNUSED, and CAST_S32.

131  { return CAST_S32(mMembers.size()); }
MemberList mMembers
Definition: party.h:176
#define CAST_S32
Definition: cast.h:29

◆ getParty()

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

Definition at line 312 of file party.cpp.

References parties, and party.

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

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

◆ isMember() [1/3]

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

Definition at line 229 of file party.cpp.

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

Referenced by PopupMenu::addParty(), Ea::BeingRecv::processNameResponse(), EAthena::BeingRecv::processNameResponse2(), and PopupMenu::showPlayerGMCommands().

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

◆ isMember() [2/3]

bool Party::isMember ( const BeingId  id) const

Definition at line 254 of file party.cpp.

References Avatar::mId, and mMembers.

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

◆ isMember() [3/3]

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

Definition at line 269 of file party.cpp.

References Avatar::getName(), and mMembers.

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

◆ removeFromMembers()

void Party::removeFromMembers ( )

Definition at line 200 of file party.cpp.

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

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

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

◆ removeMember() [1/3]

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

Removes a member from the party.

Definition at line 127 of file party.cpp.

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

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

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

◆ removeMember() [2/3]

void Party::removeMember ( const BeingId  id)

Removes a member from the party.

Definition at line 154 of file party.cpp.

References Avatar::mId, and mMembers.

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

◆ removeMember() [3/3]

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

Removes a member from the party.

Definition at line 177 of file party.cpp.

References Avatar::getName(), and mMembers.

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

◆ setName()

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

Set the party's name.

Definition at line 69 of file party.h.

References A_WARN_UNUSED, and Avatar::mName.

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

70  { mName = name; }
std::string mName
Definition: party.h:177

◆ setRights()

void Party::setRights ( const int16_t  rights)

Definition at line 222 of file party.cpp.

References mCanInviteUsers.

223 {
224  // to invite, rights must be greater than 0
225  if (rights > 0)
226  mCanInviteUsers = true;
227 }
bool mCanInviteUsers
Definition: party.h:179

◆ sort()

void Party::sort ( )

Definition at line 322 of file party.cpp.

References mMembers, and partySorter.

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

323 {
324  std::sort(mMembers.begin(), mMembers.end(), partySorter);
325 }
MemberList mMembers
Definition: party.h:176
static class SortPartyFunctor partySorter

Field Documentation

◆ mCanInviteUsers

bool Party::mCanInviteUsers
private

Definition at line 179 of file party.h.

Referenced by setRights().

◆ mId

int16_t Party::mId
private

Definition at line 178 of file party.h.

◆ mMembers

MemberList Party::mMembers
private

◆ mName

std::string Party::mName
private

Definition at line 177 of file party.h.

◆ parties

Party::PartyMap Party::parties
staticprivate

Definition at line 167 of file party.h.

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


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