PlayerGroups.cpp 22 KB

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