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

References parties.

71  :
72  mMembers(),
73  mName(),
74  mId(id),
75  mCanInviteUsers(false)
76 {
77  parties[id] = this;
78 }
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 80 of file party.cpp.

References clearMembers().

81 {
82  clearMembers();
83 }
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 85 of file party.cpp.

References getMember(), and mMembers.

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

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 }
MemberList mMembers
Definition: party.h:176
PartyMember * getMember(const BeingId id) const
Definition: party.cpp:99

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

References parties.

Referenced by Client::stateSwitchLogin1().

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

◆ getAvatarAt()

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

Implements AvatarListModel.

Definition at line 218 of file party.cpp.

References mMembers.

219 {
220  return mMembers[index];
221 }
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 113 of file party.cpp.

References mMembers.

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 }
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 285 of file party.cpp.

References Avatar::getName(), and mMembers.

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

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:52
MemberList mMembers
Definition: party.h:176

◆ getNamesSet()

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

Definition at line 299 of file party.cpp.

References Avatar::getName(), and mMembers.

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

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 }
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 313 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().

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: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 230 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().

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 }
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 255 of file party.cpp.

References Avatar::mId, and mMembers.

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 }
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 270 of file party.cpp.

References Avatar::getName(), and mMembers.

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 }
std::string getName() const
Definition: avatar.h:52
MemberList mMembers
Definition: party.h:176

◆ removeFromMembers()

void Party::removeFromMembers ( )

Definition at line 201 of file party.cpp.

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

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

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 }
MemberList mMembers
Definition: party.h:176
Being * findBeing(const BeingId id) const
void setParty(Party *const party)
Definition: being.cpp:1268
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 128 of file party.cpp.

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

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

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 }
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 155 of file party.cpp.

References Avatar::mId, and mMembers.

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 }
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 178 of file party.cpp.

References Avatar::getName(), and mMembers.

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 }
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 223 of file party.cpp.

References mCanInviteUsers.

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

◆ sort()

void Party::sort ( )

Definition at line 323 of file party.cpp.

References mMembers, and partySorter.

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

324 {
325  std::sort(mMembers.begin(), mMembers.end(), partySorter);
326 }
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: