aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--sql/updates/world/master/2023_07_30_01_world.sql16
-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
8 files changed, 56 insertions, 69 deletions
diff --git a/sql/updates/world/master/2023_07_30_01_world.sql b/sql/updates/world/master/2023_07_30_01_world.sql
new file mode 100644
index 00000000000..d6261b792ba
--- /dev/null
+++ b/sql/updates/world/master/2023_07_30_01_world.sql
@@ -0,0 +1,16 @@
+UPDATE `gameobject_template` SET `StringId`='bg_buff_object' WHERE `entry` IN (180380,184966,180376,179905,184972,179907,180378,184975,184978,180382,180148,179904,179906,180144,180145,180362,180377,180383,184965,184971,184974,184977,179899,180146,180147,180379,184964,180381,184970,184973,180384,184976,179871);
+
+SET @TRIGGER_ID := 29;
+SET @TRIGGER_SPAWN_ID := 30;
+
+DELETE FROM `areatrigger_template` WHERE `Id` = @TRIGGER_ID AND `IsServerSide` = 1;
+INSERT INTO `areatrigger_template` (`Id`, `IsServerSide`, `Type`, `Data0`, `Data1`) VALUES
+(@TRIGGER_ID, 1, 0, 3.0, 3.0);
+
+DELETE FROM `areatrigger` WHERE `SpawnId` BETWEEN @TRIGGER_SPAWN_ID+0 AND @TRIGGER_SPAWN_ID+4 AND `IsServerSide` = 1;
+INSERT INTO `areatrigger` (`SpawnId`, `AreaTriggerId`, `IsServerSide`, `MapId`, `PosX`, `PosY`, `PosZ`, `Orientation`, `ScriptName`, `Comment`) VALUES
+(@TRIGGER_SPAWN_ID+0, @TRIGGER_ID, 1, 2107, 815.29339599609375, 842.58331298828125, -56.0177841186523437, 3.176533222198486328, 'areatrigger_battleground_buffs', 'Arathi Basin - Battleground Buff - Farm'),
+(@TRIGGER_SPAWN_ID+1, @TRIGGER_ID, 1, 2107, 1147.0242919921875, 816.83160400390625, -99.2923507690429687, 0.4253254234790802, 'areatrigger_battleground_buffs', 'Arathi Basin - Battleground Buff - Gold Mine'),
+(@TRIGGER_SPAWN_ID+2, @TRIGGER_ID, 1, 2107, 808.84625244140625, 1185.41748046875, 11.92160511016845703, 5.619962215423583984, 'areatrigger_battleground_buffs', 'Arathi Basin - Battleground Buff - Lumber Mill'),
+(@TRIGGER_SPAWN_ID+3, @TRIGGER_ID, 1, 2107, 990.046875, 1008.62152099609375, -42.2709541320800781, 0.820303261280059814, 'areatrigger_battleground_buffs', 'Arathi Basin - Battleground Buff - Blacksmith'),
+(@TRIGGER_SPAWN_ID+4, @TRIGGER_ID, 1, 2107, 1184.251708984375, 1186.52783203125, -56.126007080078125, 2.367344856262207031, 'areatrigger_battleground_buffs', 'Arathi Basin - Battleground Buff - Stables');
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();
}