9
3

PlayerGroups.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "PlayerGroups.h"
  17. #include "../common/Log.h"
  18. #include "World.h"
  19. #include "Spells.h"
  20. #include "LuaInterface.h"
  21. #include "Bots/Bot.h"
  22. extern ZoneList zone_list;
  23. /******************************************************** PlayerGroup ********************************************************/
  24. PlayerGroup::PlayerGroup(int32 id) {
  25. m_id = id;
  26. }
  27. PlayerGroup::~PlayerGroup() {
  28. Disband();
  29. }
  30. bool PlayerGroup::AddMember(Entity* member) {
  31. // Check to make sure the entity we are adding is valid
  32. if (!member) {
  33. LogWrite(GROUP__ERROR, 0, "Group", "New member is null");
  34. return false;
  35. }
  36. // Make sure entity we are adding isn't already in a group by checking if it has a GroupMemberInfo pointer
  37. if (member->GetGroupMemberInfo()) {
  38. LogWrite(GROUP__ERROR, 0, "Group", "New member (%s) already has a group", member->GetName());
  39. return false;
  40. }
  41. // Create a new GroupMemberInfo and assign it to the new member
  42. GroupMemberInfo* gmi = new GroupMemberInfo;
  43. gmi->group_id = m_id;
  44. gmi->member = member;
  45. gmi->leader = false;
  46. if (member->IsPlayer())
  47. gmi->client = member->GetZone()->GetClientBySpawn(member);
  48. else
  49. gmi->client = 0;
  50. member->SetGroupMemberInfo(gmi);
  51. member->UpdateGroupMemberInfo();
  52. m_members.push_back(gmi);
  53. SendGroupUpdate();
  54. return true;
  55. }
  56. bool PlayerGroup::RemoveMember(Entity* member) {
  57. GroupMemberInfo* gmi = member->GetGroupMemberInfo();
  58. if (!gmi) {
  59. return false;
  60. }
  61. bool ret = false;
  62. member->SetGroupMemberInfo(0);
  63. deque<GroupMemberInfo*>::iterator erase_itr = m_members.end();
  64. deque<GroupMemberInfo*>::iterator itr;
  65. for (itr = m_members.begin(); itr != m_members.end(); itr++) {
  66. if (gmi == *itr)
  67. erase_itr = itr;
  68. if ((*itr)->client)
  69. (*itr)->client->GetPlayer()->SetCharSheetChanged(true);
  70. }
  71. if (erase_itr != m_members.end()) {
  72. ret = true;
  73. m_members.erase(erase_itr);
  74. }
  75. safe_delete(gmi);
  76. if (member->IsBot())
  77. ((Bot*)member)->Camp();
  78. return ret;
  79. }
  80. void PlayerGroup::Disband() {
  81. deque<GroupMemberInfo*>::iterator itr;
  82. for (itr = m_members.begin(); itr != m_members.end(); itr++) {
  83. if ((*itr)->member) {
  84. (*itr)->member->SetGroupMemberInfo(0);
  85. if ((*itr)->member->IsBot())
  86. ((Bot*)(*itr)->member)->Camp();
  87. }
  88. if ((*itr)->client)
  89. (*itr)->client->GetPlayer()->SetCharSheetChanged(true);
  90. safe_delete(*itr);
  91. }
  92. m_members.clear();
  93. }
  94. void PlayerGroup::SendGroupUpdate(Client* exclude) {
  95. deque<GroupMemberInfo*>::iterator itr;
  96. for (itr = m_members.begin(); itr != m_members.end(); itr++) {
  97. GroupMemberInfo* gmi = *itr;
  98. if (gmi->client && gmi->client != exclude && !gmi->client->IsZoning())
  99. gmi->client->GetPlayer()->SetCharSheetChanged(true);
  100. }
  101. }
  102. void PlayerGroup::SimpleGroupMessage(const char* message) {
  103. deque<GroupMemberInfo*>::iterator itr;
  104. for(itr = m_members.begin(); itr != m_members.end(); itr++) {
  105. GroupMemberInfo* info = *itr;
  106. if(info->client)
  107. info->client->SimpleMessage(CHANNEL_GROUP, message);
  108. }
  109. }
  110. void PlayerGroup::GroupChatMessage(Spawn* from, const char* message) {
  111. deque<GroupMemberInfo*>::iterator itr;
  112. for(itr = m_members.begin(); itr != m_members.end(); itr++) {
  113. GroupMemberInfo* info = *itr;
  114. if(info && info->client && info->client->GetCurrentZone())
  115. info->client->GetCurrentZone()->HandleChatMessage(info->client, from, 0, CHANNEL_GROUP_SAY, message, 0);
  116. }
  117. }
  118. void PlayerGroup::MakeLeader(Entity* new_leader) {
  119. deque<GroupMemberInfo*>::iterator itr;
  120. for (itr = m_members.begin(); itr != m_members.end(); itr++) {
  121. GroupMemberInfo* info = *itr;
  122. if (info->leader) {
  123. info->leader = false;
  124. break;
  125. }
  126. }
  127. new_leader->GetGroupMemberInfo()->leader = true;
  128. SendGroupUpdate();
  129. }
  130. /******************************************************** PlayerGroupManager ********************************************************/
  131. PlayerGroupManager::PlayerGroupManager() {
  132. m_nextGroupID = 1;
  133. MGroups.SetName("PlayerGroupManager::m_groups");
  134. MPendingInvites.SetName("PlayerGroupManager::m_pendingInvites");
  135. }
  136. PlayerGroupManager::~PlayerGroupManager() {
  137. MPendingInvites.writelock(__FUNCTION__, __LINE__);
  138. m_pendingInvites.clear();
  139. MPendingInvites.releasewritelock(__FUNCTION__, __LINE__);
  140. MGroups.writelock(__FUNCTION__, __LINE__);
  141. map<int32, PlayerGroup*>::iterator itr;
  142. for (itr = m_groups.begin(); itr != m_groups.end(); itr++)
  143. safe_delete(itr->second);
  144. m_groups.clear();
  145. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  146. }
  147. bool PlayerGroupManager::AddGroupMember(int32 group_id, Entity* member) {
  148. bool ret = false;
  149. MGroups.writelock(__FUNCTION__, __LINE__);
  150. if (m_groups.count(group_id) > 0) {
  151. PlayerGroup* group = m_groups[group_id];
  152. ret = group->AddMember(member);
  153. }
  154. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  155. return ret;
  156. }
  157. bool PlayerGroupManager::RemoveGroupMember(int32 group_id, Entity* member) {
  158. bool ret = false;
  159. bool remove = false;
  160. Client* client = 0;
  161. MGroups.writelock(__FUNCTION__, __LINE__);
  162. if (m_groups.count(group_id) > 0) {
  163. PlayerGroup* group = m_groups[group_id];
  164. LogWrite(MISC__TODO, 0, "TODO", "Update PlayerGroupManager::RemoveGroupMember() to support removing buffs from NPC group members");
  165. if (member->IsPlayer())
  166. client = member->GetGroupMemberInfo()->client;
  167. ret = group->RemoveMember(member);
  168. // If only 1 person left in the group set a flag to remove the group
  169. if (group->Size() == 1)
  170. remove = true;
  171. }
  172. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  173. if (client)
  174. RemoveGroupBuffs(group_id, client);
  175. // Call RemoveGroup outside the locks as it uses the same locks
  176. if (remove)
  177. RemoveGroup(group_id);
  178. return ret;
  179. }
  180. void PlayerGroupManager::NewGroup(Entity* leader) {
  181. MGroups.writelock(__FUNCTION__, __LINE__);
  182. // Highly doubt this will ever be needed but putting it in any way, basically bump the id and ensure
  183. // no active group is currently using this id, if we hit the max for an int32 then reset the id to 1
  184. while (m_groups.count(m_nextGroupID) > 0) {
  185. // If m_nextGroupID is at its max then reset it to 1, else increment it
  186. if (m_nextGroupID == 4294967295)
  187. m_nextGroupID = 1;
  188. else
  189. m_nextGroupID++;
  190. }
  191. // Create a new group with the valid ID we got from above
  192. PlayerGroup* new_group = new PlayerGroup(m_nextGroupID);
  193. // Add the leader to the group
  194. new_group->AddMember(leader);
  195. leader->GetGroupMemberInfo()->leader = true;
  196. // Add the new group to the list
  197. m_groups[m_nextGroupID] = new_group;
  198. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  199. }
  200. void PlayerGroupManager::RemoveGroup(int32 group_id) {
  201. MGroups.writelock(__FUNCTION__, __LINE__);
  202. // Check to see if the id is in the list
  203. if (m_groups.count(group_id) > 0) {
  204. // Get a pointer to the group
  205. PlayerGroup* group = m_groups[group_id];
  206. // Erase the group from the list
  207. m_groups.erase(group_id);
  208. // Delete the group
  209. safe_delete(group);
  210. }
  211. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  212. }
  213. int8 PlayerGroupManager::Invite(Player* leader, Entity* member) {
  214. int8 ret = 255; // Should be changed, if it is not then we have an unknown error
  215. // Lock the pending invite list so we can work with it
  216. MPendingInvites.writelock(__FUNCTION__, __LINE__);
  217. if (!member)
  218. ret = 6; // failure, not a valid target
  219. else if (member->IsNPC() && (!member->IsBot() /*|| !member->IsMec()*/))
  220. ret = 6;
  221. else if (leader == member)
  222. ret = 5; // failure, can't invite yourself
  223. else if (member->GetGroupMemberInfo())
  224. ret = 1; // failure, member already in a group
  225. // Check to see if the target of the invite already has a pending invite
  226. else if (m_pendingInvites.count(member->GetName()) > 0)
  227. ret = 2; // Target already has an invite
  228. // Check to see if the player that invited is already in a group
  229. else if (leader->GetGroupMemberInfo()) {
  230. // Read lock the group list so we can get the size of the inviters group
  231. MGroups.readlock(__FUNCTION__, __LINE__);
  232. int32 group_size = m_groups[leader->GetGroupMemberInfo()->group_id]->Size();
  233. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  234. // Check to see if the group is full
  235. if (m_groups[leader->GetGroupMemberInfo()->group_id]->Size() >= 6)
  236. ret = 3; // Group full
  237. // Group isn't full so add the member to the pending invite list
  238. else {
  239. m_pendingInvites[member->GetName()] = leader->GetName();
  240. ret = 0; // Success
  241. }
  242. }
  243. // Inviter is not in a group
  244. else {
  245. // Check to see if the inviter has a pending invite himself
  246. if (m_pendingInvites.count(leader->GetName()) > 0)
  247. ret = 4; // inviter already has a pending group invite
  248. // No pending invites for the inviter add both the inviter and the target of the invite to the list
  249. else {
  250. m_pendingInvites[leader->GetName()] = leader->GetName();
  251. m_pendingInvites[member->GetName()] = leader->GetName();
  252. ret = 0; // success
  253. }
  254. }
  255. // Release the lock on pending invites
  256. MPendingInvites.releasewritelock(__FUNCTION__, __LINE__);
  257. /* testing purposes only */
  258. if (ret == 0 && member->IsNPC())
  259. AcceptInvite(member);
  260. return ret;
  261. }
  262. int8 PlayerGroupManager::AcceptInvite(Entity* member) {
  263. int8 ret = 3; // default to unknown error
  264. MPendingInvites.writelock(__FUNCTION__, __LINE__);
  265. if (m_pendingInvites.count(member->GetName()) > 0) {
  266. string leader = m_pendingInvites[member->GetName()];
  267. Client* client_leader = zone_list.GetClientByCharName(leader);
  268. if (client_leader) {
  269. if (m_pendingInvites.count(leader) > 0) {
  270. NewGroup(client_leader->GetPlayer());
  271. m_pendingInvites.erase(leader);
  272. }
  273. // Remove from invite list and add to the group
  274. m_pendingInvites.erase(member->GetName());
  275. AddGroupMember(client_leader->GetPlayer()->GetGroupMemberInfo()->group_id, member);
  276. ret = 0; // success
  277. }
  278. else {
  279. // Was unable to find the leader, remove from the invite list
  280. m_pendingInvites.erase(member->GetName());
  281. ret = 2; // failure, can't find leader
  282. }
  283. }
  284. else
  285. ret = 1; // failure, no pending invite
  286. MPendingInvites.releasewritelock(__FUNCTION__, __LINE__);
  287. return ret;
  288. }
  289. void PlayerGroupManager::DeclineInvite(Entity* member) {
  290. MPendingInvites.writelock(__FUNCTION__, __LINE__);
  291. if (m_pendingInvites.count(member->GetName()) > 0) {
  292. string leader = m_pendingInvites[member->GetName()];
  293. m_pendingInvites.erase(member->GetName());
  294. if (m_pendingInvites.count(leader) > 0)
  295. m_pendingInvites.erase(leader);
  296. }
  297. MPendingInvites.releasewritelock(__FUNCTION__, __LINE__);
  298. }
  299. bool PlayerGroupManager::IsGroupIDValid(int32 group_id) {
  300. bool ret = false;
  301. MGroups.readlock(__FUNCTION__, __LINE__);
  302. ret = m_groups.count(group_id) > 0;
  303. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  304. return ret;
  305. }
  306. void PlayerGroupManager::SendGroupUpdate(int32 group_id, Client* exclude) {
  307. MGroups.writelock(__FUNCTION__, __LINE__);
  308. if (m_groups.count(group_id) > 0) {
  309. m_groups[group_id]->SendGroupUpdate(exclude);
  310. }
  311. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  312. }
  313. deque<GroupMemberInfo*>* PlayerGroupManager::GetGroupMembers(int32 group_id) {
  314. if (m_groups.count(group_id) > 0)
  315. return m_groups[group_id]->GetMembers();
  316. return 0;
  317. }
  318. void PlayerGroupManager::ClearPendingInvite(Entity* member) {
  319. MPendingInvites.writelock(__FUNCTION__, __LINE__);
  320. if (m_pendingInvites.count(member->GetName()) > 0)
  321. m_pendingInvites.erase(member->GetName());
  322. MPendingInvites.releasewritelock(__FUNCTION__, __LINE__);
  323. }
  324. void PlayerGroupManager::RemoveGroupBuffs(int32 group_id, Client* client) {
  325. SpellEffects* se = 0;
  326. Spell* spell = 0;
  327. LuaSpell* luaspell = 0;
  328. EQ2Packet* packet = 0;
  329. Entity* pet = 0;
  330. Player* player = 0;
  331. Entity* charmed_pet = 0;
  332. PlayerGroup* group = 0;
  333. MGroups.readlock(__FUNCTION__, __LINE__);
  334. if (m_groups.count(group_id) > 0)
  335. group = m_groups[group_id];
  336. if (group && client) {
  337. /* first remove all spell effects this group member has on them from other group members */
  338. player = client->GetPlayer();
  339. se = player->GetSpellEffects();
  340. for (int i = 0; i < NUM_SPELL_EFFECTS; i++) {
  341. if (se[i].spell_id != 0xFFFFFFFF) {
  342. //If the client is the caster, don't remove the spell
  343. if (se[i].caster == player)
  344. continue;
  345. luaspell = se[i].spell;
  346. spell = luaspell->spell;
  347. /* is this a friendly group spell? */
  348. if (spell && spell->GetSpellData()->group_spell && spell->GetSpellData()->friendly_spell) {
  349. //Remove all group buffs not cast by this player
  350. player->RemoveSpellEffect(luaspell);
  351. player->RemoveSpellBonus(luaspell);
  352. player->RemoveSkillBonus(spell->GetSpellID());
  353. //Also remove group buffs from pets
  354. pet = 0;
  355. charmed_pet = 0;
  356. if (player->HasPet()){
  357. pet = player->GetPet();
  358. pet = player->GetCharmedPet();
  359. }
  360. if (pet){
  361. pet->RemoveSpellEffect(luaspell);
  362. pet->RemoveSpellBonus(luaspell);
  363. }
  364. if (charmed_pet){
  365. charmed_pet->RemoveSpellEffect(luaspell);
  366. charmed_pet->RemoveSpellBonus(luaspell);
  367. }
  368. }
  369. }
  370. }
  371. packet = client->GetPlayer()->GetSkills()->GetSkillPacket(client->GetVersion());
  372. if (packet)
  373. client->QueuePacket(packet);
  374. }
  375. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  376. }
  377. int32 PlayerGroupManager::GetGroupSize(int32 group_id) {
  378. int32 ret = 0;
  379. MGroups.readlock(__FUNCTION__, __LINE__);
  380. if (m_groups.count(group_id) > 0)
  381. ret = m_groups[group_id]->Size();
  382. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  383. return ret;
  384. }
  385. void PlayerGroupManager::SendGroupQuests(int32 group_id, Client* client) {
  386. GroupMemberInfo* info = 0;
  387. MGroups.readlock(__FUNCTION__, __LINE__);
  388. if (m_groups.count(group_id) > 0) {
  389. deque<GroupMemberInfo*>* members = m_groups[group_id]->GetMembers();
  390. deque<GroupMemberInfo*>::iterator itr;
  391. for (itr = members->begin(); itr != members->end(); itr++) {
  392. info = *itr;
  393. if (info->client) {
  394. LogWrite(PLAYER__DEBUG, 0, "Player", "Send Quest Journal...");
  395. info->client->SendQuestJournal(false, client);
  396. client->SendQuestJournal(false, info->client);
  397. }
  398. }
  399. }
  400. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  401. }
  402. void PlayerGroupManager::SimpleGroupMessage(int32 group_id, const char* message) {
  403. MGroups.readlock(__FUNCTION__, __LINE__);
  404. if (m_groups.count(group_id) > 0)
  405. m_groups[group_id]->SimpleGroupMessage(message);
  406. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  407. }
  408. void PlayerGroupManager::GroupMessage(int32 group_id, const char* message, ...) {
  409. va_list argptr;
  410. char buffer[4096];
  411. buffer[0] = 0;
  412. va_start(argptr, message);
  413. vsnprintf(buffer, sizeof(buffer), message, argptr);
  414. va_end(argptr);
  415. SimpleGroupMessage(group_id, buffer);
  416. }
  417. void PlayerGroupManager::GroupChatMessage(int32 group_id, Spawn* from, const char* message) {
  418. MGroups.readlock(__FUNCTION__, __LINE__);
  419. if (m_groups.count(group_id) > 0)
  420. m_groups[group_id]->GroupChatMessage(from, message);
  421. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  422. }
  423. void PlayerGroupManager::MakeLeader(int32 group_id, Entity* new_leader) {
  424. MGroups.writelock(__FUNCTION__, __LINE__);
  425. if (m_groups.count(group_id) > 0)
  426. m_groups[group_id]->MakeLeader(new_leader);
  427. MGroups.releasewritelock(__FUNCTION__, __LINE__);
  428. }
  429. void PlayerGroupManager::UpdateGroupBuffs() {
  430. map<int32, PlayerGroup*>::iterator itr;
  431. deque<GroupMemberInfo*>::iterator member_itr;
  432. deque<GroupMemberInfo*>::iterator target_itr;
  433. map<int32, SkillBonusValue*>::iterator itr_skills;
  434. MaintainedEffects* me = nullptr;
  435. LuaSpell* luaspell = nullptr;
  436. Spell* spell = nullptr;
  437. Entity* group_member = nullptr;
  438. SkillBonus* sb = nullptr;
  439. EQ2Packet* packet = nullptr;
  440. int32 i = 0;
  441. PlayerGroup* group = nullptr;
  442. Player* caster = nullptr;
  443. vector<int32> new_target_list;
  444. Client* client = nullptr;
  445. bool has_effect = false;
  446. vector<BonusValues*>* sb_list = nullptr;
  447. BonusValues* bv = nullptr;
  448. Entity* pet = nullptr;
  449. Entity* charmed_pet = nullptr;
  450. for (itr = m_groups.begin(); itr != m_groups.end(); itr++) {
  451. group = itr->second;
  452. /* loop through the group members and see if any of them have any maintained spells that are group buffs and friendly.
  453. if so, update the list of targets and apply/remove effects as needed */
  454. for (member_itr = group->GetMembers()->begin(); member_itr != group->GetMembers()->end(); member_itr++) {
  455. if ((*member_itr)->client)
  456. caster = (*member_itr)->client->GetPlayer();
  457. else caster = 0;
  458. if (!caster)
  459. continue;
  460. if (!caster->GetMaintainedSpellBySlot(0))
  461. continue;
  462. // go through the player's maintained spells
  463. me = caster->GetMaintainedSpells();
  464. caster->GetMaintainedMutex()->readlock(__FUNCTION__, __LINE__);
  465. for (i = 0; i < NUM_MAINTAINED_EFFECTS; i++){
  466. if (me[i].spell_id == 0xFFFFFFFF)
  467. continue;
  468. luaspell = me[i].spell;
  469. spell = luaspell->spell;
  470. if (spell && spell->GetSpellData()->group_spell && spell->GetSpellData()->friendly_spell &&
  471. (spell->GetSpellData()->target_type == SPELL_TARGET_GROUP_AE || spell->GetSpellData()->target_type == SPELL_TARGET_RAID_AE)) {
  472. luaspell->MSpellTargets.writelock(__FUNCTION__, __LINE__);
  473. for (target_itr = group->GetMembers()->begin(); target_itr != group->GetMembers()->end(); target_itr++) {
  474. group_member = (*target_itr)->member;
  475. if (!group_member)
  476. continue;
  477. if (group_member == caster)
  478. continue;
  479. client = (*target_itr)->client;
  480. has_effect = false;
  481. if (group_member->GetSpellEffect(spell->GetSpellID(), caster))
  482. has_effect = true;
  483. // Check if player is within range of the caster
  484. if (group_member->GetZone() != caster->GetZone() || caster->GetDistance(group_member) > spell->GetSpellData()->radius){
  485. if (has_effect){
  486. group_member->RemoveSpellEffect(luaspell);
  487. group_member->RemoveSpellBonus(luaspell);
  488. group_member->RemoveSkillBonus(spell->GetSpellID());
  489. if (client) {
  490. packet = ((Player*)group_member)->GetSkills()->GetSkillPacket(client->GetVersion());
  491. if (packet)
  492. client->QueuePacket(packet);
  493. }
  494. //Also remove group buffs from pet
  495. if (group_member->HasPet()){
  496. pet = group_member->GetPet();
  497. charmed_pet = group_member->GetCharmedPet();
  498. if (pet){
  499. pet->RemoveSpellEffect(luaspell);
  500. pet->RemoveSpellBonus(luaspell);
  501. }
  502. if (charmed_pet){
  503. charmed_pet->RemoveSpellEffect(luaspell);
  504. charmed_pet->RemoveSpellBonus(luaspell);
  505. }
  506. }
  507. }
  508. continue;
  509. }
  510. //this group member is a target of the spell
  511. new_target_list.push_back(group_member->GetID());
  512. if (has_effect)
  513. continue;
  514. pet = 0;
  515. charmed_pet = 0;
  516. if (group_member->HasPet()){
  517. pet = group_member->GetPet();
  518. charmed_pet = group_member->GetCharmedPet();
  519. }
  520. group_member->AddSpellEffect(luaspell);
  521. if (pet)
  522. pet->AddSpellEffect(luaspell);
  523. if (charmed_pet)
  524. charmed_pet->AddSpellEffect(luaspell);
  525. //add group member to list of targets for caster's spell if true
  526. new_target_list.push_back(group_member->GetID());
  527. if (pet)
  528. new_target_list.push_back(pet->GetID());
  529. if (charmed_pet)
  530. new_target_list.push_back(charmed_pet->GetID());
  531. // look for a spell bonus on caster's spell
  532. sb_list = caster->GetAllSpellBonuses(luaspell);
  533. for (int32 x = 0; x < sb_list->size(); x++){
  534. bv = sb_list->at(x);
  535. group_member->AddSpellBonus(luaspell, bv->type, bv->value, bv->class_req, bv->race_req, bv->faction_req);
  536. if (pet)
  537. pet->AddSpellBonus(luaspell, bv->type, bv->value, bv->class_req, bv->race_req, bv->faction_req);
  538. if (charmed_pet)
  539. charmed_pet->AddSpellBonus(luaspell, bv->type, bv->value, bv->class_req, bv->race_req, bv->faction_req);
  540. }
  541. sb_list->clear();
  542. safe_delete(sb_list);
  543. // look for a skill bonus on the caster's spell
  544. sb = caster->GetSkillBonus(me[i].spell_id);
  545. if (sb) {
  546. for (itr_skills = sb->skills.begin(); itr_skills != sb->skills.end(); itr_skills++)
  547. group_member->AddSkillBonus(sb->spell_id, (*itr_skills).second->skill_id, (*itr_skills).second->value);
  548. }
  549. if (client) {
  550. packet = ((Player*)group_member)->GetSkills()->GetSkillPacket(client->GetVersion());
  551. if (packet)
  552. client->QueuePacket(packet);
  553. }
  554. }
  555. new_target_list.push_back(caster->GetID());
  556. luaspell->targets.swap(new_target_list);
  557. luaspell->MSpellTargets.releasewritelock(__FUNCTION__, __LINE__);
  558. new_target_list.clear();
  559. }
  560. }
  561. caster->GetMaintainedMutex()->releasereadlock(__FUNCTION__, __LINE__);
  562. }
  563. }
  564. }
  565. bool PlayerGroupManager::IsInGroup(int32 group_id, Entity* member) {
  566. bool ret = false;
  567. MGroups.readlock(__FUNCTION__, __LINE__);
  568. if (m_groups.count(group_id) > 0) {
  569. deque<GroupMemberInfo*>* members = m_groups[group_id]->GetMembers();
  570. for (int8 i = 0; i < members->size(); i++) {
  571. if (member == members->at(i)->member) {
  572. ret = true;
  573. break;
  574. }
  575. }
  576. }
  577. MGroups.releasereadlock(__FUNCTION__, __LINE__);
  578. return ret;
  579. }