Sinon tu as cette solution qui fonctionne très bien.
Ce code m'a été donné par PixelPirate.
class Duel: public PlayerScript
{
public:
Duel(): PlayerScript("Duel") {}
void OnDuelStart(Player* firstplayer, Player* secondplayer) override{
Map* map = firstplayer->GetMap();
if (map->IsDungeon())
return;
GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER));
if (!go)
return;
std::list<Player*> playerList;
Trinity::AnyPlayerInObjectRangeCheck checker(go, 100.0f);
Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(go, playerList, checker);
go->VisitNearbyWorldObject(100.0f, searcher);
uint32 usedPhases = 0;
if (!playerList.empty())
for (std::list<Player*>::const_iterator it = playerList.begin(); it != playerList.end(); ++it)
if (!(*it)->IsGameMaster())
usedPhases |= (*it)->GetPhaseMask();
for (uint32 phase = 2; phase <= ULONG_MAX / 2; phase *= 2){
if (usedPhases & phase)
continue;
firstplayer->SetPhaseMask(phase, false);
secondplayer->SetPhaseMask(phase, false);
go->SetPhaseMask(phase, true);
firstplayer->UpdateObjectVisibility();
secondplayer->UpdateObjectVisibility();
return;
}
firstplayer->GetSession()->SendNotification("Il n'y a aucunes phases de disponibles");
secondplayer->GetSession()->SendNotification("Il n'y a aucunes phases de disponibles");
}
void OnDuelEnd(Player* firstplayer, Player* secondplayer, DuelCompleteType type) override{
firstplayer->SetPhaseMask(GetNormalPhase(firstplayer), false);
secondplayer->SetPhaseMask(GetNormalPhase(secondplayer), false);
firstplayer->UpdateObjectVisibility();
secondplayer->UpdateObjectVisibility();
}
uint32 GetNormalPhase(Player* player) const{
if (player->IsGameMaster())
return uint32(PHASEMASK_ANYWHERE);
uint32 phase = PHASEMASK_NORMAL;
Player::AuraEffectList const& phases = player->GetAuraEffectsByType(SPELL_AURA_PHASE);
if (!phases.empty())
phase = phases.front()->GetMiscValue();
if (uint32 n_phase = phase & ~PHASEMASK_NORMAL)
return n_phase;
return PHASEMASK_NORMAL;
}
};
void AddSC_Duel(){
new Duel();
}