aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy <Golrag@users.noreply.github.com>2023-07-30 19:49:12 +0200
committerGitHub <noreply@github.com>2023-07-30 19:49:12 +0200
commitf5461a1161a5a9dfabe7a142ad84f8c900776c92 (patch)
tree4f327bbb5752acd5c8f75d5552ddd0489d76c0dc /src
parent845f61e0a969891b14e1f182fadd29af347a1a3f (diff)
Battlegrounds/Buffs: Rework using areatriggers (#29171)
* Rework GameObject trap handling for buffs (removed radius hack) * Add script for Old AreaTriggers * Add script for new AreaTriggers * Spawn AreaTriggers in Arathi Basin
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Battlegrounds/Battleground.cpp46
-rw-r--r--src/server/game/Battlegrounds/Battleground.h2
-rw-r--r--src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp2
-rw-r--r--src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp1
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp20
-rw-r--r--src/server/game/Entities/Object/Object.h2
-rw-r--r--src/server/scripts/World/areatrigger_scripts.cpp36
7 files changed, 40 insertions, 69 deletions
diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp
index 473e1124412..06d0b381b4d 100644
--- a/src/server/game/Battlegrounds/Battleground.cpp
+++ b/src/server/game/Battlegrounds/Battleground.cpp
@@ -75,7 +75,6 @@ Battleground::Battleground(BattlegroundTemplate const* battlegroundTemplate) : _
m_Events = 0;
m_StartDelayTime = 0;
m_IsRated = false;
- m_BuffChange = false;
m_IsRandom = false;
m_InBGFreeSlotQueue = false;
m_SetDeleteThis = false;
@@ -1647,51 +1646,6 @@ void Battleground::EndNow()
SetRemainingTime(0);
}
-// IMPORTANT NOTICE:
-// buffs aren't spawned/despawned when players captures anything
-// buffs are in their positions when battleground starts
-void Battleground::HandleTriggerBuff(ObjectGuid go_guid)
-{
- if (!FindBgMap())
- {
- TC_LOG_ERROR("bg.battleground", "Battleground::HandleTriggerBuff called with null bg map, {}", go_guid.ToString());
- return;
- }
-
- GameObject* obj = GetBgMap()->GetGameObject(go_guid);
- if (!obj || obj->GetGoType() != GAMEOBJECT_TYPE_TRAP || !obj->isSpawned())
- return;
-
- // Change buff type, when buff is used:
- int32 index = BgObjects.size() - 1;
- while (index >= 0 && BgObjects[index] != go_guid)
- index--;
- if (index < 0)
- {
- TC_LOG_ERROR("bg.battleground", "Battleground::HandleTriggerBuff: cannot find buff gameobject ({}, entry: {}, type: {}) in internal data for BG (map: {}, instance id: {})!",
- go_guid.ToString(), obj->GetEntry(), obj->GetGoType(), GetMapId(), m_InstanceID);
- return;
- }
-
- // Randomly select new buff
- uint8 buff = urand(0, 2);
- uint32 entry = obj->GetEntry();
- if (m_BuffChange && entry != Buff_Entries[buff])
- {
- // Despawn current buff
- SpawnBGObject(index, RESPAWN_ONE_DAY);
- // Set index for new one
- for (uint8 currBuffTypeIndex = 0; currBuffTypeIndex < 3; ++currBuffTypeIndex)
- if (entry == Buff_Entries[currBuffTypeIndex])
- {
- index -= currBuffTypeIndex;
- index += buff;
- }
- }
-
- SpawnBGObject(index, BUFF_RESPAWN_TIME);
-}
-
void Battleground::HandleKillPlayer(Player* victim, Player* killer)
{
// Keep in mind that for arena this will have to be changed a bit
diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h
index 1bca27efc86..d589c1e33d7 100644
--- a/src/server/game/Battlegrounds/Battleground.h
+++ b/src/server/game/Battlegrounds/Battleground.h
@@ -445,7 +445,6 @@ class TC_GAME_API Battleground : public ZoneScript
virtual void RemovePlayerAtLeave(ObjectGuid guid, bool Transport, bool SendPacket);
// can be extended in in BG subclass
- void HandleTriggerBuff(ObjectGuid go_guid);
void SetHoliday(bool is_holiday);
/// @todo make this protected:
@@ -556,7 +555,6 @@ class TC_GAME_API Battleground : public ZoneScript
// this must be filled in constructors!
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT];
- bool m_BuffChange;
bool m_IsRandom;
BGHonorMode m_HonorMode;
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp
index adec4dcdca8..07aeb6ef5d8 100644
--- a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp
@@ -23,13 +23,11 @@
#include "Map.h"
#include "ObjectMgr.h"
#include "Player.h"
-#include "Random.h"
#include "SpellInfo.h"
BattlegroundAB::BattlegroundAB(BattlegroundTemplate const* battlegroundTemplate) : Battleground(battlegroundTemplate)
{
m_IsInformedNearVictory = false;
- m_BuffChange = true;
BgObjects.resize(0);
BgCreatures.resize(0);
m_lastTick = 0;
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp
index 250857dacb0..f33ae2b444d 100644
--- a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp
@@ -38,7 +38,6 @@ uint32 BG_EY_HonorScoreTicks[BG_HONOR_MODE_NUM] =
BattlegroundEY::BattlegroundEY(BattlegroundTemplate const* battlegroundTemplate) : Battleground(battlegroundTemplate)
{
- m_BuffChange = true;
BgObjects.resize(BG_EY_OBJECT_MAX);
BgCreatures.resize(BG_EY_CREATURES_MAX);
m_Points_Trigger[FEL_REAVER] = TR_FEL_REAVER_BUFF;
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index df5c39ecffa..b7d77cad622 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -1150,17 +1150,9 @@ void GameObject::Update(uint32 diff)
// Type 0 despawns after being triggered, type 1 does not.
/// @todo This is activation radius. Casting radius must be selected from spell data.
- float radius;
- if (!goInfo->trap.radius)
- {
- // Battleground traps: data2 == 0 && data5 == 3
- if (goInfo->trap.cooldown != 3)
- break;
-
- radius = 3.f;
- }
- else
- radius = goInfo->trap.radius / 2.f;
+ float radius = goInfo->trap.radius / 2.f; // this division seems to date back to when the field was called diameter, don't think it is still relevant.
+ if (!radius)
+ break;
// Pointer to appropriate target if found any
Unit* target = nullptr;
@@ -1301,12 +1293,6 @@ void GameObject::Update(uint32 diff)
SetLootState(GO_JUST_DEACTIVATED);
else if (!goInfo->trap.charges)
SetLootState(GO_READY);
-
- // Battleground gameobjects have data2 == 0 && data5 == 3
- if (!goInfo->trap.radius && goInfo->trap.cooldown == 3)
- if (Player* player = target->ToPlayer())
- if (Battleground* bg = player->GetBattleground())
- bg->HandleTriggerBuff(GetGUID());
}
break;
}
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 4bc8fc28896..629367079a8 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -459,7 +459,7 @@ struct FindGameObjectOptions
Optional<std::string_view> StringId;
Optional<bool> IsSummon;
- Optional<bool> IsSpawned;
+ Optional<bool> IsSpawned = true; // most searches should be for spawned objects only, to search for "any" just clear this field at call site
bool IgnorePhases = false;
bool IgnoreNotOwnedPrivateObjects = true;
diff --git a/src/server/scripts/World/areatrigger_scripts.cpp b/src/server/scripts/World/areatrigger_scripts.cpp
index 71f1f89ae3e..8bf43d076ac 100644
--- a/src/server/scripts/World/areatrigger_scripts.cpp
+++ b/src/server/scripts/World/areatrigger_scripts.cpp
@@ -407,6 +407,40 @@ struct areatrigger_stormwind_teleport_unit : AreaTriggerAI
}
};
+void HandleBuffAreaTrigger(Player* player)
+{
+ if (GameObject* buffObject = player->FindNearestGameObjectWithOptions(4.0f, { .StringId = "bg_buff_object" }))
+ {
+ buffObject->ActivateObject(GameObjectActions::Disturb, 0, player);
+ buffObject->DespawnOrUnsummon();
+ }
+}
+
+struct areatrigger_battleground_buffs : AreaTriggerAI
+{
+ areatrigger_battleground_buffs(AreaTrigger* areatrigger) : AreaTriggerAI(areatrigger) { }
+
+ void OnUnitEnter(Unit* unit) override
+ {
+ if (!unit->IsPlayer())
+ return;
+
+ HandleBuffAreaTrigger(unit->ToPlayer());
+ }
+};
+
+class AreaTrigger_at_battleground_buffs : public AreaTriggerScript
+{
+public:
+ AreaTrigger_at_battleground_buffs() : AreaTriggerScript("at_battleground_buffs") { }
+
+ bool OnTrigger(Player* player, AreaTriggerEntry const* /*areaTrigger*/) override
+ {
+ HandleBuffAreaTrigger(player);
+ return true;
+ }
+};
+
void AddSC_areatrigger_scripts()
{
new AreaTrigger_at_coilfang_waterfall();
@@ -418,4 +452,6 @@ void AddSC_areatrigger_scripts()
new AreaTrigger_at_area_52_entrance();
new AreaTrigger_at_frostgrips_hollow();
RegisterAreaTriggerAI(areatrigger_stormwind_teleport_unit);
+ RegisterAreaTriggerAI(areatrigger_battleground_buffs);
+ new AreaTrigger_at_battleground_buffs();
}