Skip to content

Instantly share code, notes, and snippets.

@Rochet2
Last active May 28, 2022 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rochet2/8bffd9d0847f4269c174 to your computer and use it in GitHub Desktop.
Save Rochet2/8bffd9d0847f4269c174 to your computer and use it in GitHub Desktop.
Phased duel
/*
Credits:
Rochet2
Tommy
There were few more, but couldnt find them
Release:
http://emudevs.com/showthread.php/3413-Phased-duel-(pets-work)?p=24109
Original source:
http://emudevs.com/showthread.php/2282-phase-out-dueling-error?p=15483&viewfull=1#post15483
*/
#include "ScriptPCH.h"
class PhasedDueling : public PlayerScript
{
public:
PhasedDueling(): PlayerScript("PhasedDueling") {}
void OnDuelStart(Player* firstplayer, Player* secondplayer) override
{
Map* map = firstplayer->GetMap();
if (map->IsDungeon())
return;
// Duel flag is used as duel center point
GameObject* go = map->GetGameObject(firstplayer->GetUInt64Value(PLAYER_DUEL_ARBITER));
if (!go)
return;
// Get players from 100 yard radius ( duel radius is 40-50 yd )
std::list<Player*> playerList;
Trinity::AnyPlayerInObjectRangeCheck checker(go, 100.0f);
Trinity::PlayerListSearcher<Trinity::AnyPlayerInObjectRangeCheck> searcher(go, playerList, checker);
go->VisitNearbyWorldObject(100.0f, searcher);
// insert players' phases to used phases, ignore GMs
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();
// loop all unique phases
for (uint32 phase = 2; phase <= ULONG_MAX / 2; phase *= 2)
{
// If phase in use, skip
if (usedPhases & phase)
continue;
// Phase players & pets, dont update visibility yet
firstplayer->SetPhaseMask(phase, false);
secondplayer->SetPhaseMask(phase, false);
// Phase duel flag
go->SetPhaseMask(phase, true);
// Update visibility here so pets will be phased and wont despawn
firstplayer->UpdateObjectVisibility();
secondplayer->UpdateObjectVisibility();
return;
}
// Couldnt find free unique phase
firstplayer->GetSession()->SendNotification("There are no free phases");
secondplayer->GetSession()->SendNotification("There are no free phases");
}
// Restore phases
void OnDuelEnd(Player* firstplayer, Player* secondplayer, DuelCompleteType type) override
{
// Phase players, dont update visibility yet
firstplayer->SetPhaseMask(GetNormalPhase(firstplayer), false);
secondplayer->SetPhaseMask(GetNormalPhase(secondplayer), false);
// Update visibility here so pets will be phased and wont despawn
firstplayer->UpdateObjectVisibility();
secondplayer->UpdateObjectVisibility();
}
// Attempt in storing the player phase with spell phases included.
uint32 GetNormalPhase(Player* player) const
{
if (player->IsGameMaster())
return uint32(PHASEMASK_ANYWHERE);
// GetPhaseMaskForSpawn copypaste
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_PhasedDueling()
{
new PhasedDueling();
}
@andreabreu
Copy link

[ 36%] Building CXX object src/server/scripts/CMakeFiles/scripts.dir/Custom/Phased_duel.cpp.o
/home/destrex/TrinityCore/src/server/scripts/Custom/Phased_duel.cpp: In member function 'virtual void PhasedDueling::OnDuelStart(Player_, Player_)':
/home/destrex/TrinityCore/src/server/scripts/Custom/Phased_duel.cpp:29:14: error: 'go' was not declared in this scope
if (!go)
^
compilation terminated due to -Wfatal-errors.
make[2]: *** [src/server/scripts/CMakeFiles/scripts.dir/Custom/Phased_duel.cpp.o] Error 1
make[1]: *** [src/server/scripts/CMakeFiles/scripts.dir/all] Error 2
make: *** [all] Error 2

Help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment