mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-26 15:16:24 +00:00
Merge branch 'azerothcore:master' into Playerbot
This commit is contained in:
@@ -640,7 +640,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
|
||||
Unit* caster = me;
|
||||
// Areatrigger Cast!
|
||||
if (e.GetScriptType() == SMART_SCRIPT_TYPE_AREATRIGGER)
|
||||
if (e.IsAreatriggerScript())
|
||||
caster = unit->SummonTrigger(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetOrientation(), 5000);
|
||||
|
||||
if (e.action.cast.targetsLimit)
|
||||
@@ -3990,27 +3990,29 @@ void SmartScript::GetTargets(ObjectVector& targets, SmartScriptHolder const& e,
|
||||
}
|
||||
case SMART_TARGET_INSTANCE_STORAGE:
|
||||
{
|
||||
if (InstanceScript* instance = GetBaseObject()->GetInstanceScript())
|
||||
{
|
||||
if (e.target.instanceStorage.type == 1)
|
||||
{
|
||||
if (Creature* creature = instance->GetCreature(e.target.instanceStorage.index))
|
||||
{
|
||||
targets.push_back(creature);
|
||||
}
|
||||
}
|
||||
else if (e.target.instanceStorage.type == 2)
|
||||
{
|
||||
if (GameObject* go = instance->GetGameObject(e.target.instanceStorage.index))
|
||||
{
|
||||
targets.push_back(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
InstanceScript* instance = nullptr;
|
||||
|
||||
if (e.IsAreatriggerScript() && scriptTrigger)
|
||||
instance = scriptTrigger->GetInstanceScript();
|
||||
else
|
||||
instance = GetBaseObject()->GetInstanceScript();
|
||||
|
||||
if (!instance)
|
||||
{
|
||||
LOG_ERROR("scripts.ai.sai", "SMART_TARGET_INSTANCE_STORAGE: Entry {} SourceType {} Event {} Action {} Target {} called outside an instance map.",
|
||||
e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.GetTargetType());
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.target.instanceStorage.type == 1)
|
||||
{
|
||||
if (Creature* creature = instance->GetCreature(e.target.instanceStorage.index))
|
||||
targets.push_back(creature);
|
||||
}
|
||||
else if (e.target.instanceStorage.type == 2)
|
||||
{
|
||||
if (GameObject* go = instance->GetGameObject(e.target.instanceStorage.index))
|
||||
targets.push_back(go);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -1993,6 +1993,8 @@ public:
|
||||
uint32 GetActionType() const { return (uint32)action.type; }
|
||||
uint32 GetTargetType() const { return (uint32)target.type; }
|
||||
|
||||
[[nodiscard]] bool IsAreatriggerScript() const { return source_type == SMART_SCRIPT_TYPE_AREATRIGGER; }
|
||||
|
||||
uint32 timer;
|
||||
uint32 priority;
|
||||
bool active;
|
||||
|
||||
@@ -2243,7 +2243,7 @@ void Player::SetGameMaster(bool on)
|
||||
CombatStopWithPets();
|
||||
|
||||
SetPhaseMask(uint32(PHASEMASK_ANYWHERE), false); // see and visible in all phases
|
||||
m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GM, GetSession()->GetSecurity());
|
||||
SetServerSideVisibilityDetect(SERVERSIDE_VISIBILITY_GM, GetSession()->GetSecurity());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2279,7 +2279,7 @@ void Player::SetGameMaster(bool on)
|
||||
UpdateArea(m_areaUpdateId);
|
||||
|
||||
getHostileRefMgr().setOnlineOfflineState(true);
|
||||
m_serverSideVisibilityDetect.SetValue(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER);
|
||||
SetServerSideVisibilityDetect(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER);
|
||||
}
|
||||
|
||||
UpdateObjectVisibility();
|
||||
@@ -2293,7 +2293,7 @@ void Player::SetGMVisible(bool on)
|
||||
{
|
||||
RemoveAurasDueToSpell(VISUAL_AURA);
|
||||
m_ExtraFlags &= ~PLAYER_EXTRA_GM_INVISIBLE;
|
||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER);
|
||||
SetServerSideVisibility(SERVERSIDE_VISIBILITY_GM, SEC_PLAYER);
|
||||
|
||||
getHostileRefMgr().setOnlineOfflineState(false);
|
||||
CombatStopWithPets();
|
||||
@@ -2302,7 +2302,7 @@ void Player::SetGMVisible(bool on)
|
||||
{
|
||||
AddAura(VISUAL_AURA, this);
|
||||
m_ExtraFlags |= PLAYER_EXTRA_GM_INVISIBLE;
|
||||
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GM, GetSession()->GetSecurity());
|
||||
SetServerSideVisibility(SERVERSIDE_VISIBILITY_GM, GetSession()->GetSecurity());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
void AddScripts() {}
|
||||
inline void AddScripts() {}
|
||||
|
||||
class WorldMock: public IWorld
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "ArenaSeasonRewardsDistributor.h"
|
||||
#include "WorldMock.h"
|
||||
#include <memory>
|
||||
|
||||
class MockArenaSeasonTeamRewarder : public ArenaSeasonTeamRewarder
|
||||
{
|
||||
@@ -31,12 +33,26 @@ class ArenaSeasonRewardDistributorTest : public ::testing::Test
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
_previousWorld = std::move(sWorld);
|
||||
_worldMock = new ::testing::NiceMock<WorldMock>();
|
||||
ON_CALL(*_worldMock, getIntConfig(::testing::_)).WillByDefault(::testing::Return(0));
|
||||
ON_CALL(*_worldMock, getIntConfig(CONFIG_LEGACY_ARENA_START_RATING)).WillByDefault(::testing::Return(1500));
|
||||
ON_CALL(*_worldMock, getIntConfig(CONFIG_ARENA_START_RATING)).WillByDefault(::testing::Return(0));
|
||||
sWorld.reset(_worldMock);
|
||||
|
||||
_mockRewarder = std::make_unique<MockArenaSeasonTeamRewarder>();
|
||||
_distributor = std::make_unique<ArenaSeasonRewardDistributor>(_mockRewarder.get());
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
sWorld = std::move(_previousWorld);
|
||||
}
|
||||
|
||||
std::unique_ptr<MockArenaSeasonTeamRewarder> _mockRewarder;
|
||||
std::unique_ptr<ArenaSeasonRewardDistributor> _distributor;
|
||||
std::unique_ptr<IWorld> _previousWorld;
|
||||
::testing::NiceMock<WorldMock>* _worldMock = nullptr;
|
||||
};
|
||||
|
||||
ArenaTeam ArenaTeamWithRating(int rating, int gamesPlayed)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "ArenaTeamMgr.h"
|
||||
#include "ArenaTeam.h"
|
||||
#include <memory>
|
||||
#include "WorldMock.h"
|
||||
|
||||
// Used to expose Type property.
|
||||
class ArenaTeamTest : public ArenaTeam
|
||||
@@ -46,6 +47,13 @@ class ArenaTeamFilterTest : public ::testing::Test
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
_previousWorld = std::move(sWorld);
|
||||
_worldMock = new ::testing::NiceMock<WorldMock>();
|
||||
ON_CALL(*_worldMock, getIntConfig(::testing::_)).WillByDefault(::testing::Return(0));
|
||||
ON_CALL(*_worldMock, getIntConfig(CONFIG_LEGACY_ARENA_START_RATING)).WillByDefault(::testing::Return(1500));
|
||||
ON_CALL(*_worldMock, getIntConfig(CONFIG_ARENA_START_RATING)).WillByDefault(::testing::Return(0));
|
||||
sWorld.reset(_worldMock);
|
||||
|
||||
team1 = ArenaTeamWithType(2); // 2v2
|
||||
team2 = ArenaTeamWithType(3); // 3v3
|
||||
team3 = ArenaTeamWithType(5); // 5v5
|
||||
@@ -60,12 +68,16 @@ protected:
|
||||
delete team1;
|
||||
delete team2;
|
||||
delete team3;
|
||||
|
||||
sWorld = std::move(_previousWorld);
|
||||
}
|
||||
|
||||
ArenaTeamMgr::ArenaTeamContainer arenaTeams;
|
||||
ArenaTeam* team1;
|
||||
ArenaTeam* team2;
|
||||
ArenaTeam* team3;
|
||||
std::unique_ptr<IWorld> _previousWorld;
|
||||
::testing::NiceMock<WorldMock>* _worldMock = nullptr;
|
||||
};
|
||||
|
||||
// Test for ArenaTeamFilterAllTeams: it should return all teams without filtering
|
||||
|
||||
218
src/test/server/game/Commands/GmVisibleCommandTest.cpp
Normal file
218
src/test/server/game/Commands/GmVisibleCommandTest.cpp
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by the
|
||||
* Free Software Foundation; either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "WorldSession.h"
|
||||
#include "WorldMock.h"
|
||||
#include "ObjectGuid.h"
|
||||
#include "ScriptDefines/MiscScript.h"
|
||||
#include "ScriptDefines/PlayerScript.h"
|
||||
#include "ScriptDefines/WorldObjectScript.h"
|
||||
#include "ScriptDefines/UnitScript.h"
|
||||
#include "ScriptDefines/CommandScript.h"
|
||||
#include "SharedDefines.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#ifndef TEST_F
|
||||
#define TEST_F(fixture, name) void fixture##_##name()
|
||||
#endif
|
||||
|
||||
using namespace testing;
|
||||
|
||||
namespace
|
||||
{
|
||||
class TestVisibilityScript : public PlayerScript
|
||||
{
|
||||
public:
|
||||
TestVisibilityScript() : PlayerScript("TestVisibilityScript", { PLAYERHOOK_ON_SET_SERVER_SIDE_VISIBILITY }) { }
|
||||
|
||||
void OnPlayerSetServerSideVisibility(Player* player, ServerSideVisibilityType& type, AccountTypes& sec) override
|
||||
{
|
||||
++CallCount;
|
||||
LastPlayer = player;
|
||||
LastType = type;
|
||||
LastSecurity = sec;
|
||||
}
|
||||
|
||||
static void EnsureRegistered()
|
||||
{
|
||||
if (!Instance)
|
||||
Instance = new TestVisibilityScript();
|
||||
}
|
||||
|
||||
static void Reset()
|
||||
{
|
||||
CallCount = 0;
|
||||
LastPlayer = nullptr;
|
||||
LastType = SERVERSIDE_VISIBILITY_GM;
|
||||
LastSecurity = SEC_PLAYER;
|
||||
}
|
||||
|
||||
inline static TestVisibilityScript* Instance = nullptr;
|
||||
inline static uint32 CallCount = 0;
|
||||
inline static Player* LastPlayer = nullptr;
|
||||
inline static ServerSideVisibilityType LastType = SERVERSIDE_VISIBILITY_GM;
|
||||
inline static AccountTypes LastSecurity = SEC_PLAYER;
|
||||
};
|
||||
|
||||
class TestPlayer : public Player
|
||||
{
|
||||
public:
|
||||
using Player::Player;
|
||||
|
||||
void UpdateObjectVisibility(bool /*forced*/ = true, bool /*fromUpdate*/ = false) override { }
|
||||
|
||||
void ForceInitValues(ObjectGuid::LowType guidLow = 1)
|
||||
{
|
||||
Object::_Create(guidLow, uint32(0), HighGuid::Player);
|
||||
}
|
||||
};
|
||||
|
||||
class GmVisibleCommandTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
EnsureScriptRegistriesInitialized();
|
||||
|
||||
TestVisibilityScript::EnsureRegistered();
|
||||
|
||||
originalWorld = sWorld.release();
|
||||
worldMock = new NiceMock<WorldMock>();
|
||||
sWorld.reset(worldMock);
|
||||
|
||||
static std::string emptyString;
|
||||
ON_CALL(*worldMock, GetDataPath()).WillByDefault(ReturnRef(emptyString));
|
||||
ON_CALL(*worldMock, GetRealmName()).WillByDefault(ReturnRef(emptyString));
|
||||
ON_CALL(*worldMock, GetDefaultDbcLocale()).WillByDefault(Return(LOCALE_enUS));
|
||||
ON_CALL(*worldMock, getRate(_)).WillByDefault(Return(1.0f));
|
||||
ON_CALL(*worldMock, getBoolConfig(_)).WillByDefault(Return(false));
|
||||
ON_CALL(*worldMock, getIntConfig(_)).WillByDefault(Return(0));
|
||||
ON_CALL(*worldMock, getFloatConfig(_)).WillByDefault(Return(0.0f));
|
||||
ON_CALL(*worldMock, GetPlayerSecurityLimit()).WillByDefault(Return(SEC_PLAYER));
|
||||
|
||||
session = new WorldSession(1, "gm", 0, nullptr, SEC_GAMEMASTER, EXPANSION_WRATH_OF_THE_LICH_KING,
|
||||
0, LOCALE_enUS, 0, false, false, 0);
|
||||
|
||||
player = new TestPlayer(session);
|
||||
player->ForceInitValues();
|
||||
session->SetPlayer(player);
|
||||
player->SetSession(session);
|
||||
|
||||
TestVisibilityScript::Reset();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
// Intentional leaks of session/player to avoid database access in destructors.
|
||||
IWorld* currentWorld = sWorld.release();
|
||||
delete currentWorld;
|
||||
worldMock = nullptr;
|
||||
|
||||
sWorld.reset(originalWorld);
|
||||
originalWorld = nullptr;
|
||||
session = nullptr;
|
||||
player = nullptr;
|
||||
}
|
||||
|
||||
void ExecuteCommand(std::string_view text)
|
||||
{
|
||||
if (text == ".gm visible off")
|
||||
{
|
||||
ApplyGmVisibleState(false);
|
||||
}
|
||||
else if (text == ".gm visible on")
|
||||
{
|
||||
ApplyGmVisibleState(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL() << "Unsupported test command: " << text;
|
||||
}
|
||||
}
|
||||
|
||||
static void EnsureScriptRegistriesInitialized()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (!initialized)
|
||||
{
|
||||
ScriptRegistry<MiscScript>::InitEnabledHooksIfNeeded(MISCHOOK_END);
|
||||
ScriptRegistry<WorldObjectScript>::InitEnabledHooksIfNeeded(WORLDOBJECTHOOK_END);
|
||||
ScriptRegistry<UnitScript>::InitEnabledHooksIfNeeded(UNITHOOK_END);
|
||||
ScriptRegistry<PlayerScript>::InitEnabledHooksIfNeeded(PLAYERHOOK_END);
|
||||
ScriptRegistry<CommandSC>::InitEnabledHooksIfNeeded(ALLCOMMANDHOOK_END);
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
IWorld* originalWorld = nullptr;
|
||||
NiceMock<WorldMock>* worldMock = nullptr;
|
||||
WorldSession* session = nullptr;
|
||||
TestPlayer* player = nullptr;
|
||||
|
||||
private:
|
||||
void ApplyGmVisibleState(bool makeVisible)
|
||||
{
|
||||
constexpr uint32 VISUAL_AURA = 37800;
|
||||
|
||||
if (makeVisible)
|
||||
{
|
||||
player->RemoveAurasDueToSpell(VISUAL_AURA);
|
||||
player->SetGMVisible(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
player->AddAura(VISUAL_AURA, player);
|
||||
player->SetGMVisible(false);
|
||||
}
|
||||
|
||||
player->UpdateObjectVisibility();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(GmVisibleCommandTest, SetsPlayerInvisibleAndInvokesHook)
|
||||
{
|
||||
ExecuteCommand(".gm visible off");
|
||||
|
||||
EXPECT_EQ(TestVisibilityScript::CallCount, 1u);
|
||||
EXPECT_EQ(TestVisibilityScript::LastPlayer, player);
|
||||
EXPECT_EQ(TestVisibilityScript::LastType, SERVERSIDE_VISIBILITY_GM);
|
||||
EXPECT_EQ(TestVisibilityScript::LastSecurity, session->GetSecurity());
|
||||
EXPECT_EQ(player->m_serverSideVisibility.GetValue(SERVERSIDE_VISIBILITY_GM), uint32(session->GetSecurity()));
|
||||
EXPECT_FALSE(player->isGMVisible());
|
||||
}
|
||||
|
||||
TEST_F(GmVisibleCommandTest, SetsPlayerVisibleAndInvokesHook)
|
||||
{
|
||||
// Ensure the player starts from invisible state to test the opposite transition as well.
|
||||
ExecuteCommand(".gm visible off");
|
||||
TestVisibilityScript::Reset();
|
||||
|
||||
ExecuteCommand(".gm visible on");
|
||||
|
||||
EXPECT_EQ(TestVisibilityScript::CallCount, 1u);
|
||||
EXPECT_EQ(TestVisibilityScript::LastPlayer, player);
|
||||
EXPECT_EQ(TestVisibilityScript::LastType, SERVERSIDE_VISIBILITY_GM);
|
||||
EXPECT_EQ(TestVisibilityScript::LastSecurity, SEC_PLAYER);
|
||||
EXPECT_EQ(player->m_serverSideVisibility.GetValue(SERVERSIDE_VISIBILITY_GM), uint32(SEC_PLAYER));
|
||||
EXPECT_TRUE(player->isGMVisible());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user