New player method unbind all instances

This commit is contained in:
Asandru
2015-02-09 19:48:38 +02:00
committed by Rochet2
parent 166dacee83
commit 5f6417663e
2 changed files with 40 additions and 1 deletions

View File

@@ -706,6 +706,7 @@ ElunaRegister<Player> PlayerMethods[] =
{ "LeaveBattleground", &LuaPlayer::LeaveBattleground }, // :LeaveBattleground([teleToEntryPoint]) - The player leaves the battleground
// {"BindToInstance", &LuaPlayer::BindToInstance}, // :BindToInstance() - Binds the player to the current instance
{ "UnbindInstance", &LuaPlayer::UnbindInstance }, // :UnbindInstance(map, difficulty) - Unbinds the player from an instance
{ "UnbindAllInstances", &LuaPlayer::UnbindAllInstances }, // :UnbindAllInstances() - Unbinds the player from all instances
{ "RemoveFromBattlegroundRaid", &LuaPlayer::RemoveFromBattlegroundRaid }, // :RemoveFromBattlegroundRaid() - Removes the player from a battleground or battlefield raid
#if (!defined(TBC) && !defined(CLASSIC))
{ "ResetAchievements", &LuaPlayer::ResetAchievements }, // :ResetAchievements() - Resets player<65>s achievements

View File

@@ -2174,11 +2174,19 @@ namespace LuaPlayer
return 0;
}
/**
* Unbinds the [Player] from his instances except the one he currently is in.
*
* Difficulty is not used on classic.
*
* @param uint32 map = true
* @param uint32 difficulty = 0
*/
int UnbindInstance(Eluna* /*E*/, lua_State* L, Player* player)
{
uint32 map = Eluna::CHECKVAL<uint32>(L, 2);
#ifndef CLASSIC
uint32 difficulty = Eluna::CHECKVAL<uint32>(L, 3);
uint32 difficulty = Eluna::CHECKVAL<uint32>(L, 3, 0);
if (difficulty < MAX_DIFFICULTY)
player->UnbindInstance(map, (Difficulty)difficulty);
@@ -2188,6 +2196,36 @@ namespace LuaPlayer
return 0;
}
/**
* Unbinds the [Player] from his instances except the one he currently is in.
*/
int UnbindAllInstances(Eluna* /*E*/, lua_State* L, Player* player)
{
#ifdef CLASSIC
Player::BoundInstancesMap& binds = player->GetBoundInstances();
for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
{
if (itr->first != player->GetMapId())
player->UnbindInstance(itr);
else
++itr;
}
#else
for (uint8 i = 0; i < MAX_DIFFICULTY; ++i)
{
Player::BoundInstancesMap& binds = player->GetBoundInstances(Difficulty(i));
for (Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
{
if (itr->first != player->GetMapId())
player->UnbindInstance(itr, Difficulty(i));
else
++itr;
}
}
#endif
return 0;
}
/**
* Forces the [Player] to leave a [BattleGround]
*