Dungeon Finder: Add vote kick support

--HG--
branch : trunk
This commit is contained in:
Spp
2010-08-13 15:38:10 +02:00
parent 55705e91d4
commit 3e29ae1ee8
7 changed files with 230 additions and 16 deletions
+149
View File
@@ -57,6 +57,10 @@ LFGMgr::~LFGMgr()
delete it->second;
m_Proposals.clear();
for (LfgPlayerBootMap::iterator it = m_Boots.begin(); it != m_Boots.end(); ++it)
delete it->second;
m_Boots.clear();
for (LfgRoleCheckMap::iterator it = m_RoleChecks.begin(); it != m_RoleChecks.end(); ++it)
delete it->second;
m_RoleChecks.clear();
@@ -1092,6 +1096,115 @@ void LFGMgr::RemoveProposal(LfgProposalMap::iterator itProposal, LfgUpdateType t
m_Proposals.erase(itProposal);
}
/// <summary>
/// Initialize a boot kick vote
/// </summary>
/// <param name="Group *">Group</param>
/// <param name="uint32">Player low guid who inits the vote kick</param>
/// <param name="uint32">Player low guid to be kicked </param>
/// <param name="std::string">kick reason</param>
void LFGMgr::InitBoot(Group *grp, uint32 iLowGuid, uint32 vLowguid, std::string reason)
{
if (!grp)
return;
LfgPlayerBoot *pBoot = new LfgPlayerBoot();
pBoot->inProgress = true;
pBoot->cancelTime = time_t(time(NULL)) + LFG_TIME_BOOT;
pBoot->reason = reason;
pBoot->victimLowGuid = vLowguid;
pBoot->votedNeeded = GROUP_LFG_KICK_VOTES_NEEDED;
PlayerSet players;
uint32 pLowGuid = 0;
for (GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{
if (Player *plrg = itr->getSource())
{
pLowGuid = plrg->GetGUIDLow();
if (pLowGuid == vLowguid)
pBoot->votes[pLowGuid] = 0; // Victim auto vote NO
else if (pLowGuid == iLowGuid)
pBoot->votes[pLowGuid] = 1; // Kicker auto vote YES
else
{
pBoot->votes[pLowGuid] = -1; // Other members need to vote
players.insert(plrg);
}
}
}
for (PlayerSet::const_iterator it = players.begin(); it != players.end(); ++it)
SendLfgBootPlayer(*it, pBoot);
grp->SetLfgKickActive(true);
m_Boots[grp->GetLowGUID()] = pBoot;
}
/// <summary>
/// Update Boot info with player answer
/// </summary>
/// <param name="Player *">Player guid</param>
/// <param name="uint8">Player answer</param>
void LFGMgr::UpdateBoot(Player *plr, uint8 accept)
{
Group *grp = plr ? plr->GetGroup() : NULL;
if (!grp)
return;
uint32 bootId = grp->GetLowGUID();
uint32 lowGuid = plr->GetGUIDLow();
LfgPlayerBootMap::iterator itBoot = m_Boots.find(bootId);
if (itBoot == m_Boots.end())
return;
LfgPlayerBoot *pBoot = itBoot->second;
if (!pBoot)
return;
if (pBoot->votes[lowGuid] != -1) // Cheat check: Player can't vote twice
return;
pBoot->votes[lowGuid] = accept;
uint8 votesNum = 0;
uint8 agreeNum = 0;
for (LfgAnswerMap::const_iterator itVotes = pBoot->votes.begin(); itVotes != pBoot->votes.end(); ++itVotes)
{
if (itVotes->second != -1)
{
++votesNum;
if (itVotes->second == 1)
++agreeNum;
}
}
if (agreeNum == pBoot->votedNeeded || // Vote passed
votesNum == pBoot->votes.size() || // All voted but not passed
(pBoot->votes.size() - votesNum + agreeNum) < pBoot->votedNeeded) // Vote didnt passed
{
// Send update info to all players
pBoot->inProgress = false;
for (LfgAnswerMap::const_iterator itVotes = pBoot->votes.begin(); itVotes != pBoot->votes.end(); ++itVotes)
if (Player *plrg = sObjectMgr.GetPlayer(itVotes->first))
if (plrg->GetGUIDLow() != pBoot->victimLowGuid)
SendLfgBootPlayer(plrg, pBoot);
if (agreeNum == pBoot->votedNeeded) // Vote passed - Kick player
{
Player::RemoveFromGroup(grp, MAKE_NEW_GUID(pBoot->victimLowGuid, 0, HIGHGUID_PLAYER));
if (Player *victim = sObjectMgr.GetPlayer(pBoot->victimLowGuid))
victim->TeleportToBGEntryPoint();
OfferContinue(grp);
grp->SetLfgKicks(grp->GetLfgKicks() + 1);
}
grp->SetLfgKickActive(false);
delete pBoot;
m_Boots.erase(itBoot);
}
}
/// <summary>
/// Teleports the player in or out the dungeon
/// </summary>
@@ -1305,6 +1418,42 @@ void LFGMgr::SendLfgPartyInfo(Player *plr)
}
}
/// <summary>
/// Build and Send LFG boot player info
/// </summary>
/// <param name="Player *">Player</param>
/// <param name="LfgPlayerBoot *">Boot info</param>
void LFGMgr::SendLfgBootPlayer(Player *plr, LfgPlayerBoot *pBoot)
{
sLog.outDebug("SMSG_LFG_BOOT_PLAYER");
int8 playerVote = pBoot->votes[plr->GetGUIDLow()];
uint8 votesNum = 0;
uint8 agreeNum = 0;
uint32 secsleft = uint8((pBoot->cancelTime - time(NULL)) / 1000);
for (LfgAnswerMap::const_iterator it = pBoot->votes.begin(); it != pBoot->votes.end(); ++it)
{
if (it->second != -1)
{
++votesNum;
if (it->second == 1)
++agreeNum;
}
}
WorldPacket data(SMSG_LFG_BOOT_PLAYER, 1 + 1 + 1 + 8 + 4 + 4 + 4 + 4 + pBoot->reason.length());
data << uint8(pBoot->inProgress); // Vote in progress
data << uint8(playerVote != -1); // Did Vote
data << uint8(playerVote == 1); // Agree
data << uint64(MAKE_NEW_GUID(pBoot->victimLowGuid, 0, HIGHGUID_PLAYER)); // Victim GUID
data << uint32(votesNum); // Total Votes
data << uint32(agreeNum); // Agree Count
data << uint32(secsleft); // Time Left
data << uint32(pBoot->votedNeeded); // Needed Votes
data << pBoot->reason.c_str(); // Kick reason
plr->GetSession()->SendPacket(&data);
}
/// <summary>
/// Build and Send LFG player reward
/// </summary>