/* EQ2Emulator: Everquest II Server Emulator Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net) This file is part of EQ2Emulator. EQ2Emulator is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. EQ2Emulator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with EQ2Emulator. If not, see . */ #ifndef __PLAYERGROUPS_H__ #define __PLAYERGROUPS_H__ #include #include #include "../common/types.h" #include "Entity.h" using namespace std; /// All the generic info for the group window, plus a client pointer for players struct GroupMemberInfo { int32 group_id; string name; string zone; sint32 hp_current; sint32 hp_max; sint32 power_current; sint32 power_max; int16 level_current; int16 level_max; int8 race_id; int8 class_id; bool leader; Client* client; Entity* member; }; /// Represents a players group in game class PlayerGroup { public: PlayerGroup(int32 id); ~PlayerGroup(); /// Adds a new member to the players group /// Entity to add to the group, can be a Player or NPC /// True if the member was added bool AddMember(Entity* member); /// Removes a member from the players group /// Entity to remove from the player group /// True if the member was removed bool RemoveMember(Entity* member); /// Removes all members from the group and destroys the group void Disband(); /// Sends updates to all the clients in the group /// Client to exclude from the update void SendGroupUpdate(Client* exclude = 0); /// Gets the total number of members in the group /// int32, number of members in the group int32 Size() { return m_members.size(); } /// Gets a pointer to the list of members /// deque pointer deque* GetMembers() { return &m_members; } void SimpleGroupMessage(const char* message); void GroupChatMessage(Spawn* from, const char* message); void MakeLeader(Entity* new_leader); void RemoveClientReference(Client* remove); void UpdateGroupMemberInfo(Entity* ent, bool groupMembersLocked=false); Mutex MGroupMembers; // Mutex for the group members private: int32 m_id; // ID of this group deque m_members; // List of members in this group }; /// Responsible for managing all the player groups in the world class PlayerGroupManager { public: PlayerGroupManager(); ~PlayerGroupManager(); /// Adds a member to a group /// ID of the group to add a member to /// Entity* to add to the group /// True if the member was added to the group bool AddGroupMember(int32 group_id, Entity* member); /// Removes a member from a group /// ID of the group to remove a member from /// Entity* to remove from the group /// True if the member was removed from the group bool RemoveGroupMember(int32 group_id, Entity* member); /// Creates a new group with the provided Entity* as the leader /// The Entity* that will be the leader of the group void NewGroup(Entity* leader); /// Removes the group from the group manager /// ID of the group to remove void RemoveGroup(int32 group_id); /// Handles a player inviting another player or NPC to a group /// Player that sent the invite /// Player or NPC that is the target of the invite /// Error code if invite was unsuccessful, 0 if successful int8 Invite(Player* leader, Entity* member); /// Handles accepting of a group invite /// Entity* that is accepting the invite /// Error code if accepting the invite failed, 0 if successful int8 AcceptInvite(Entity* member); /// Handles declining of a group invite /// Entity* that is declining the invite void DeclineInvite(Entity* member); /// Checks to see if there is a group with the given id in the group manager /// ID to check for /// True if a group with the given ID is found bool IsGroupIDValid(int32 group_id); /// Send updates to all the clients in the group /// ID of the group to send updates to /// Client* to exclude from the update, usually the one that triggers the update void SendGroupUpdate(int32 group_id, Client* exclude = 0); PlayerGroup* GetGroup(int32 group_id); /// Read locks the group list, no changes to the list should be made when using this /// Name of the function called from, used for better debugging in the event of a deadlock /// Line number that this was called from, used for better debugging in the event of a deadlock void GroupLock(const char* function = 0, int32 line = 0U) { MGroups.readlock(function, line); } /// Releases the readlock acquired from GroupLock() /// Name of the function called from, used for better debugging in the event of a deadlock /// Line number that this was called from, used for better debugging in the event of a deadlock void ReleaseGroupLock(const char* function = 0, int32 line = 0U) { MGroups.releasereadlock(function, line); } void ClearPendingInvite(Entity* member); void RemoveGroupBuffs(int32 group_id, Client* client); int32 GetGroupSize(int32 group_id); void SendGroupQuests(int32 group_id, Client* client); void SimpleGroupMessage(int32 group_id, const char* message); void GroupMessage(int32 group_id, const char* message, ...); void GroupChatMessage(int32 group_id, Spawn* from, const char* message); void MakeLeader(int32 group_id, Entity* new_leader); void UpdateGroupBuffs(); bool IsInGroup(int32 group_id, Entity* member); // TODO: Any function below this comment bool IsSpawnInGroup(int32 group_id, string name); // used in follow Player* GetGroupLeader(int32 group_id); private: int32 m_nextGroupID; // Used to generate a new unique id for new groups map m_groups; // int32 is the group id, PlayerGroup* is a pointer to the actual group map m_pendingInvites; // First string is the person invited to the group, second string is the leader of the group Mutex MGroups; // Mutex for the group map (m_groups) Mutex MPendingInvites; // Mutex for the pending invites map (m_pendingInvites) }; #endif