Core/Dungeon Finder: Simplify Spell Luck of the draw code

Core/Dungeon Finder: Partial recode of "group list" using existing Lfg functions
This commit is contained in:
Spp
2013-02-04 04:08:51 +01:00
parent ffb4c63fe3
commit f753c989f2
5 changed files with 77 additions and 55 deletions

View File

@@ -2039,3 +2039,29 @@ void LFGMgr::SetupGroupMember(uint64 guid, uint64 gguid)
SetGroup(guid, gguid);
AddPlayerToGroup(gguid, guid);
}
bool LFGMgr::inRandomLfgDungeon(uint64 guid)
{
if (GetState(guid) != LFG_STATE_NONE)
{
LfgDungeonSet const& dungeons = GetSelectedDungeons(guid);
if (!dungeons.empty())
{
LFGDungeonData const* dungeon = GetLFGDungeon(*dungeons.begin());
if (dungeon && (dungeon->type == LFG_TYPE_RANDOM || dungeon->seasonal))
return true;
}
}
return false;
}
bool LFGMgr::inLfgDungeonMap(uint64 guid, uint32 map, Difficulty difficulty)
{
if (uint32 dungeonId = GetDungeon(guid, true))
if (LFGDungeonData const* dungeon = GetLFGDungeon(dungeonId))
if (uint32(dungeon->map) == map && dungeon->difficulty == difficulty)
return true;
return false;
}

View File

@@ -381,6 +381,9 @@ class LFGMgr
void SetupGroupMember(uint64 guid, uint64 gguid);
uint64 GetGroup(uint64 guid);
bool inRandomLfgDungeon(uint64 guid);
bool inLfgDungeonMap(uint64 guid, uint32 map, Difficulty difficulty);
private:
uint8 GetTeam(uint64 guid);
void RestoreState(uint64 guid, char const* debugMsg);

View File

@@ -2486,11 +2486,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
}
if (group && group->isLFGGroup())
if (uint32 dungeonId = sLFGMgr->GetDungeon(group->GetGUID(), true))
if (LFGDungeonData const* dungeon = sLFGMgr->GetLFGDungeon(dungeonId))
if (LFGDungeonData const* randomDungeon = sLFGMgr->GetLFGDungeon(*(sLFGMgr->GetSelectedDungeons(player->GetGUID()).begin())))
if (uint32(dungeon->map) == GetId() && dungeon->difficulty == GetDifficulty() && randomDungeon->type == LFG_TYPE_RANDOM)
player->CastSpell(player, LFG_SPELL_LUCK_OF_THE_DRAW, true);
player->CastSpell(player, LFG_SPELL_LUCK_OF_THE_DRAW, true);
}
// for normal instances cancel the reset schedule when the

View File

@@ -33,7 +33,7 @@
#include "ace/INET_Addr.h"
#include "Player.h"
#include "Pet.h"
#include "LFG.h"
#include "LFGMgr.h"
#include "GroupMgr.h"
class misc_commandscript : public CommandScript
@@ -2834,41 +2834,40 @@ public:
{
handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"));
Group::MemberSlotList const& members = groupTarget->GetMemberSlots();
Group::MemberSlotList::const_iterator itr;
for (itr = members.begin(); itr != members.end(); ++itr)
for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
std::ostringstream flags, roles;
if ((*itr).flags & MEMBER_FLAG_ASSISTANT)
flags << "Assistant ";
if ((*itr).flags & MEMBER_FLAG_MAINTANK)
flags << "MainTank ";
if ((*itr).flags & MEMBER_FLAG_MAINASSIST)
flags << "MainAssist ";
Group::MemberSlot const& slot = *itr;
if ((*itr).roles & PLAYER_ROLE_LEADER)
roles << "Leader ";
if ((*itr).roles & PLAYER_ROLE_TANK)
roles << "Tank ";
if ((*itr).roles & PLAYER_ROLE_HEALER)
roles << "Healer ";
if ((*itr).roles & PLAYER_ROLE_DAMAGE)
roles << "Damage ";
std::string flags;
if (slot.flags & MEMBER_FLAG_ASSISTANT)
flags = "Assistant";
if (slot.flags & MEMBER_FLAG_MAINTANK)
{
if (!flags.empty())
flags.append(", ");
flags.append("MainTank");
}
if (slot.flags & MEMBER_FLAG_MAINASSIST)
{
if (!flags.empty())
flags.append(", ");
flags.append("MainAssist");
}
if (flags.empty())
flags = "None";
Player* p = ObjectAccessor::FindPlayer((*itr).guid);
const char* onlineState = (p && p->IsInWorld()) ? "online" : "offline";
std::string flagsStr = (flags.str().empty()) ? "None" : flags.str();
std::string rolesStr = (roles.str().empty()) ? "None" : roles.str();
handler->PSendSysMessage(LANG_GROUP_PLAYER_NAME_GUID, (*itr).name.c_str(), onlineState, GUID_LOPART((*itr).guid), flagsStr.c_str(), rolesStr.c_str());
handler->PSendSysMessage(LANG_GROUP_PLAYER_NAME_GUID, slot.name.c_str(), onlineState,
GUID_LOPART(slot.guid), flags.c_str(), LFGMgr::GetRolesString(slot.roles).c_str());
}
return true;
}
else
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, nameTarget.c_str());
return true;
}
return true;
}

View File

@@ -1715,10 +1715,29 @@ class spell_gen_luck_of_the_draw : public SpellScriptLoader
class spell_gen_luck_of_the_draw_AuraScript : public AuraScript
{
PrepareAuraScript(spell_gen_luck_of_the_draw_AuraScript);
Map const* map;
Difficulty difficulty;
bool Load()
{
return GetUnitOwner()->GetTypeId() == TYPEID_PLAYER;
Player* owner = GetUnitOwner()->ToPlayer();
if (!owner)
return false;
Group* group = owner->GetGroup();
if (!group || group->isLFGGroup())
return false;
if (!sLFGMgr->inRandomLfgDungeon(owner->GetGUID()))
return false;
map = owner->GetMap();
difficulty = owner->GetMap()->GetDifficulty();
if (!sLFGMgr->inLfgDungeonMap(owner->GetGUID(), map->GetId(), difficulty))
return false;
return true;
}
// cheap hax to make it have update calls
@@ -1730,30 +1749,9 @@ class spell_gen_luck_of_the_draw : public SpellScriptLoader
void Update(AuraEffect* /*effect*/)
{
if (Player* owner = GetUnitOwner()->ToPlayer())
{
const LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(owner->GetGUID());
LfgDungeonSet::const_iterator itr = dungeons.begin();
if (itr == dungeons.end())
{
Remove(AURA_REMOVE_BY_DEFAULT);
return;
}
LFGDungeonData const* randomDungeon = sLFGMgr->GetLFGDungeon(*itr);
if (Group* group = owner->GetGroup())
if (Map const* map = owner->GetMap())
if (group->isLFGGroup())
if (uint32 dungeonId = sLFGMgr->GetDungeon(group->GetGUID(), true))
if (LFGDungeonData const* dungeon = sLFGMgr->GetLFGDungeon(dungeonId))
if (uint32(dungeon->map) == map->GetId() && dungeon->difficulty == map->GetDifficulty())
if (randomDungeon && randomDungeon->type == LFG_TYPE_RANDOM)
return; // in correct dungeon
Map const* currentMap = GetUnitOwner()->ToPlayer()->GetMap();
if (currentMap != map || currentMap->GetDifficulty() != difficulty)
Remove(AURA_REMOVE_BY_DEFAULT);
}
}
void Register()