aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorclick <none@none>2010-05-26 11:34:37 +0200
committerclick <none@none>2010-05-26 11:34:37 +0200
commit7a13839178847c682666e507651c49939681365a (patch)
tree73692e329ac38a71e29d2d6ef580f9bc796e6ce9 /src
parente4c03aa55ab1934c89786c271e31317f7bc75687 (diff)
Add support for random battlegrounds - port by n0n4me, original code by Vladimir and Griffonheart (Big thanks to all of you!)
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/AchievementMgr.cpp2
-rw-r--r--src/game/BattleGround.cpp26
-rw-r--r--src/game/BattleGround.h25
-rw-r--r--src/game/BattleGroundHandler.cpp29
-rw-r--r--src/game/BattleGroundMgr.cpp106
-rw-r--r--src/game/BattleGroundMgr.h2
-rw-r--r--src/game/BattleGroundRB.cpp81
-rw-r--r--src/game/BattleGroundRB.h54
-rw-r--r--src/game/CMakeLists.txt4
-rw-r--r--src/game/CharacterHandler.cpp1
-rw-r--r--src/game/DBCStructure.h2
-rw-r--r--src/game/DBCfmt.h2
-rw-r--r--src/game/GameEventMgr.cpp36
-rw-r--r--src/game/GameEventMgr.h5
-rw-r--r--src/game/GameObject.cpp8
-rw-r--r--src/game/Group.cpp9
-rw-r--r--src/game/Player.cpp62
-rw-r--r--src/game/Player.h10
-rw-r--r--src/game/SharedDefines.h4
-rw-r--r--src/game/SpellEffects.cpp6
-rw-r--r--src/game/World.cpp52
-rw-r--r--src/game/World.h13
22 files changed, 463 insertions, 76 deletions
diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp
index 3ba02514855..e0a79fc71ed 100644
--- a/src/game/AchievementMgr.cpp
+++ b/src/game/AchievementMgr.cpp
@@ -805,7 +805,7 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui
{
case 161: // AB, Overcome a 500 resource disadvantage
{
- if (bg->GetTypeID() != BATTLEGROUND_AB)
+ if (bg->GetTypeID(true) != BATTLEGROUND_AB)
continue;
if (!((BattleGroundAB*)bg)->IsTeamScores500Disadvantage(GetPlayer()->GetTeam()))
continue;
diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp
index 454c2a1de3d..df58b643294 100644
--- a/src/game/BattleGround.cpp
+++ b/src/game/BattleGround.cpp
@@ -130,6 +130,7 @@ void BattleGround::BroadcastWorker(Do& _do)
BattleGround::BattleGround()
{
m_TypeID = BattleGroundTypeId(0);
+ m_RandomTypeID = BattleGroundTypeId(0);
m_InstanceID = 0;
m_Status = STATUS_NONE;
m_ClientInstanceID = 0;
@@ -145,6 +146,7 @@ BattleGround::BattleGround()
m_Events = 0;
m_IsRated = false;
m_BuffChange = false;
+ m_IsRandom = false;
m_Name = "";
m_LevelMin = 0;
m_LevelMax = 0;
@@ -794,9 +796,29 @@ void BattleGround::EndBattleGround(uint32 winner)
}
}
+ uint32 win_kills = plr->GetRandomWinner() ? BG_REWARD_WINNER_HONOR_LAST : BG_REWARD_WINNER_HONOR_FIRST;
+ uint32 loos_kills = plr->GetRandomWinner() ? BG_REWARD_LOOSER_HONOR_LAST : BG_REWARD_LOOSER_HONOR_FIRST;
+ uint32 win_arena = plr->GetRandomWinner() ? BG_REWARD_WINNER_ARENA_LAST : BG_REWARD_WINNER_ARENA_FIRST;
+
// Reward winner team
if (team == winner)
+ {
+ if (IsRandom() || BattleGroundMgr::IsBGWeekend(GetTypeID()))
+ {
+ UpdatePlayerScore(plr, SCORE_BONUS_HONOR, GetBonusHonorFromKill(win_kills*2));
+ plr->ModifyArenaPoints(win_arena);
+ if (!plr->GetRandomWinner())
+ plr->SetRandomWinner(true);
+ }
+
plr->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_WIN_BG, 1);
+ }
+ else
+ {
+ if (IsRandom() || BattleGroundMgr::IsBGWeekend(GetTypeID()))
+ UpdatePlayerScore(plr, SCORE_BONUS_HONOR, GetBonusHonorFromKill(loos_kills*4));
+ }
+
plr->SetHealth(plr->GetMaxHealth());
plr->SetPower(POWER_MANA, plr->GetMaxPower(POWER_MANA));
@@ -839,7 +861,7 @@ uint32 BattleGround::GetBonusHonorFromKill(uint32 kills) const
uint32 BattleGround::GetBattlemasterEntry() const
{
- switch(GetTypeID())
+ switch(GetTypeID(true))
{
case BATTLEGROUND_AV: return 15972;
case BATTLEGROUND_WS: return 14623;
@@ -1647,7 +1669,7 @@ void BattleGround::HandleTriggerBuff(uint64 const& go_guid)
index--;
if (index < 0)
{
- sLog.outError("BattleGround (Type: %u) has buff gameobject (Guid: %u Entry: %u Type:%u) but it hasn't that object in its internal data",GetTypeID(),GUID_LOPART(go_guid),obj->GetEntry(),obj->GetGoType());
+ sLog.outError("BattleGround (Type: %u) has buff gameobject (Guid: %u Entry: %u Type:%u) but it hasn't that object in its internal data",GetTypeID(true),GUID_LOPART(go_guid),obj->GetEntry(),obj->GetGoType());
return;
}
diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h
index 6d9bdfc5ecd..38f4a0f443d 100644
--- a/src/game/BattleGround.h
+++ b/src/game/BattleGround.h
@@ -132,6 +132,16 @@ enum BattleGroundBuffObjects
BG_OBJECTID_BERSERKERBUFF_ENTRY = 179905
};
+enum BattleGroundRandomRewards
+{
+ BG_REWARD_WINNER_HONOR_FIRST = 30,
+ BG_REWARD_WINNER_ARENA_FIRST = 25,
+ BG_REWARD_WINNER_HONOR_LAST = 15,
+ BG_REWARD_WINNER_ARENA_LAST = 0,
+ BG_REWARD_LOOSER_HONOR_FIRST = 5,
+ BG_REWARD_LOOSER_HONOR_LAST = 5
+};
+
const uint32 Buff_Entries[3] = { BG_OBJECTID_SPEEDBUFF_ENTRY, BG_OBJECTID_REGENBUFF_ENTRY, BG_OBJECTID_BERSERKERBUFF_ENTRY };
enum BattleGroundStatus
@@ -168,9 +178,10 @@ enum BattleGroundQueueTypeId
BATTLEGROUND_QUEUE_EY = 4,
BATTLEGROUND_QUEUE_SA = 5,
BATTLEGROUND_QUEUE_IC = 6,
- BATTLEGROUND_QUEUE_2v2 = 7,
- BATTLEGROUND_QUEUE_3v3 = 8,
- BATTLEGROUND_QUEUE_5v5 = 9,
+ BATTLEGROUND_QUEUE_RB = 7,
+ BATTLEGROUND_QUEUE_2v2 = 8,
+ BATTLEGROUND_QUEUE_3v3 = 9,
+ BATTLEGROUND_QUEUE_5v5 = 10,
MAX_BATTLEGROUND_QUEUE_TYPES
};
@@ -326,7 +337,7 @@ class BattleGround
/* Battleground */
// Get methods:
char const* GetName() const { return m_Name; }
- BattleGroundTypeId GetTypeID() const { return m_TypeID; }
+ BattleGroundTypeId GetTypeID(bool GetRandom = false) const { return GetRandom ? m_RandomTypeID : m_TypeID; }
BattleGroundBracketId GetBracketId() const { return m_BracketId; }
uint32 GetInstanceID() const { return m_InstanceID; }
BattleGroundStatus GetStatus() const { return m_Status; }
@@ -348,10 +359,12 @@ class BattleGround
uint8 GetWinner() const { return m_Winner; }
uint32 GetBattlemasterEntry() const;
uint32 GetBonusHonorFromKill(uint32 kills) const;
+ bool IsRandom() { return m_IsRandom; }
// Set methods:
void SetName(char const* Name) { m_Name = Name; }
void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; }
+ void SetRandomTypeID(BattleGroundTypeId TypeID) { m_RandomTypeID = TypeID; }
//here we can count minlevel and maxlevel for players
void SetBracket(PvPDifficultyEntry const* bracketEntry);
void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; }
@@ -379,6 +392,8 @@ class BattleGround
void DecreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? --m_InvitedAlliance : --m_InvitedHorde; }
void IncreaseInvitedCount(uint32 team) { (team == ALLIANCE) ? ++m_InvitedAlliance : ++m_InvitedHorde; }
+
+ void SetRandom(bool isRandom) { m_IsRandom = isRandom; }
uint32 GetInvitedCount(uint32 team) const
{
if (team == ALLIANCE)
@@ -571,11 +586,13 @@ class BattleGround
uint32 m_StartMessageIds[BG_STARTING_EVENT_COUNT];
bool m_BuffChange;
+ bool m_IsRandom;
BGHonorMode m_HonorMode;
private:
/* Battleground */
BattleGroundTypeId m_TypeID;
+ BattleGroundTypeId m_RandomTypeID;
uint32 m_InstanceID; //BattleGround Instance's GUID!
BattleGroundStatus m_Status;
uint32 m_ClientInstanceID; //the instance-id which is sent to the client and without any other internal use
diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp
index 3e414399e5e..15e3c1e2018 100644
--- a/src/game/BattleGroundHandler.cpp
+++ b/src/game/BattleGroundHandler.cpp
@@ -96,6 +96,7 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
// can do this, since it's battleground, not arena
BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BGQueueTypeId(bgTypeId, 0);
+ BattleGroundQueueTypeId bgQueueTypeIdRandom = BattleGroundMgr::BGQueueTypeId(BATTLEGROUND_RB, 0);
// ignore if player is already in BG
if (_player->InBattleGround())
@@ -129,13 +130,39 @@ void WorldSession::HandleBattlemasterJoinOpcode(WorldPacket & recv_data)
_player->GetSession()->SendPacket(&data);
return;
}
+
+ if (_player->GetBattleGroundQueueIndex(bgQueueTypeIdRandom) < PLAYER_MAX_BATTLEGROUND_QUEUES)
+ {
+ //player is already in random queue
+ WorldPacket data;
+ sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, ERR_IN_RANDOM_BG);
+ _player->GetSession()->SendPacket(&data);
+ return;
+ }
+
+ if (_player->InBattleGroundQueue() && bgTypeId == BATTLEGROUND_RB)
+ {
+ //player is already in queue, can't start random queue
+ WorldPacket data;
+ sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, ERR_IN_NON_RANDOM_BG);
+ _player->GetSession()->SendPacket(&data);
+ return;
+ }
+
// check if already in queue
if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES)
//player is already in this queue
return;
+
// check if has free queue slots
if (!_player->HasFreeBattleGroundQueueId())
+ {
+ WorldPacket data;
+ sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, ERR_BATTLEGROUND_TOO_MANY_QUEUES);
+ _player->GetSession()->SendPacket(&data);
return;
+ }
+
BattleGroundQueue& bgQueue = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId];
GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, NULL, bgTypeId, bracketEntry, 0, false, isPremade, 0);
@@ -210,7 +237,7 @@ void WorldSession::HandleBattleGroundPlayerPositionsOpcode(WorldPacket & /*recv_
if (!bg) // can't be received if player not in battleground
return;
- switch(bg->GetTypeID())
+ switch(bg->GetTypeID(true))
{
case BATTLEGROUND_WS:
{
diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
index 1bb25606870..5b0c4da8596 100644
--- a/src/game/BattleGroundMgr.cpp
+++ b/src/game/BattleGroundMgr.cpp
@@ -38,7 +38,7 @@
#include "BattleGroundDS.h"
#include "BattleGroundRV.h"
#include "BattleGroundIC.h"
-#include "BattleGroundABG.h"
+#include "BattleGroundRB.h"
#include "Chat.h"
#include "Map.h"
#include "MapInstanced.h"
@@ -47,6 +47,7 @@
#include "GameEventMgr.h"
#include "ProgressBar.h"
#include "SharedDefines.h"
+#include "Formulas.h"
INSTANTIATE_SINGLETON_1(BattleGroundMgr);
@@ -1364,7 +1365,7 @@ void BattleGroundMgr::BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg)
}
*data << (int32)itr->second->DamageDone; // damage done
*data << (int32)itr->second->HealingDone; // healing done
- switch(bg->GetTypeID()) // battleground specific things
+ switch(bg->GetTypeID(true)) // battleground specific things
{
case BATTLEGROUND_AV:
*data << (uint32)0x00000005; // count of next fields
@@ -1400,7 +1401,7 @@ void BattleGroundMgr::BuildPvpLogDataPacket(WorldPacket *data, BattleGround *bg)
case BATTLEGROUND_DS: // wotlk
case BATTLEGROUND_RV: // wotlk
case BATTLEGROUND_IC: // wotlk
- case BATTLEGROUND_ABG: // wotlk
+ case BATTLEGROUND_RB: // wotlk
*data << (int32)0; // 0
break;
default:
@@ -1537,6 +1538,23 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
}
}
+ bool isRandom = false;
+
+ if (bgTypeId==BATTLEGROUND_RB)
+ {
+ // BATTLEGROUND_IC not works
+ BattleGroundTypeId random_bgs[] = {BATTLEGROUND_AV, BATTLEGROUND_WS, BATTLEGROUND_AB, BATTLEGROUND_EY, BATTLEGROUND_SA};
+ uint32 bg_num = urand(0,4);
+ bgTypeId = random_bgs[bg_num];
+ bg_template = GetBattleGroundTemplate(bgTypeId);
+ if (!bg_template)
+ {
+ sLog.outError("BattleGround: CreateNewBattleGround - bg template not found for %u", bgTypeId);
+ return NULL;
+ }
+ isRandom = true;
+ }
+
BattleGround *bg = NULL;
// create a copy of the BG template
switch(bgTypeId)
@@ -1577,8 +1595,8 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
case BATTLEGROUND_IC:
bg = new BattleGroundIC(*(BattleGroundIC*)bg_template);
break;
- case BATTLEGROUND_ABG:
- bg = new BattleGroundABG(*(BattleGroundABG*)bg_template);
+ case BATTLEGROUND_RB:
+ bg = new BattleGroundRB(*(BattleGroundRB*)bg_template);
break;
default:
//error, but it is handled few lines above
@@ -1587,7 +1605,7 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
// generate a new instance id
bg->SetInstanceID(MapManager::Instance().GenerateInstanceId()); // set instance id
- bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, bracketEntry->GetBracketId()));
+ bg->SetClientInstanceID(CreateClientVisibleInstanceId(isRandom ? BATTLEGROUND_RB : bgTypeId, bracketEntry->GetBracketId()));
// reset the new bg (set status to status_wait_queue from status_none)
bg->Reset();
@@ -1597,6 +1615,9 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
bg->SetBracket(bracketEntry);
bg->SetArenaType(arenaType);
bg->SetRated(isRated);
+ bg->SetRandom(isRandom);
+ bg->SetTypeID(isRandom ? BATTLEGROUND_RB : bgTypeId);
+ bg->SetRandomTypeID(bgTypeId);
return bg;
}
@@ -1620,7 +1641,7 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA
case BATTLEGROUND_DS: bg = new BattleGroundDS; break;
case BATTLEGROUND_RV: bg = new BattleGroundRV; break;
case BATTLEGROUND_IC: bg = new BattleGroundIC; break;
- case BATTLEGROUND_ABG: bg = new BattleGroundABG; break;
+ case BATTLEGROUND_RB: bg = new BattleGroundRB; break;
default:
bg = new BattleGround;
break;
@@ -1718,7 +1739,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
AStartLoc[2] = start->z;
AStartLoc[3] = fields[6].GetFloat();
}
- else if (bgTypeID == BATTLEGROUND_AA || bgTypeID == BATTLEGROUND_ABG)
+ else if (bgTypeID == BATTLEGROUND_AA || bgTypeID == BATTLEGROUND_RB)
{
AStartLoc[0] = 0;
AStartLoc[1] = 0;
@@ -1741,7 +1762,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
HStartLoc[2] = start->z;
HStartLoc[3] = fields[8].GetFloat();
}
- else if (bgTypeID == BATTLEGROUND_AA || bgTypeID == BATTLEGROUND_ABG)
+ else if (bgTypeID == BATTLEGROUND_AA || bgTypeID == BATTLEGROUND_RB)
{
HStartLoc[0] = 0;
HStartLoc[1] = 0;
@@ -1838,6 +1859,13 @@ void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket *data, const uint6
if (!plr)
return;
+ uint32 win_kills = plr->GetRandomWinner() ? BG_REWARD_WINNER_HONOR_LAST : BG_REWARD_WINNER_HONOR_FIRST;
+ uint32 win_arena = plr->GetRandomWinner() ? BG_REWARD_WINNER_ARENA_LAST : BG_REWARD_WINNER_ARENA_FIRST;
+ uint32 loos_kills = plr->GetRandomWinner() ? BG_REWARD_LOOSER_HONOR_LAST : BG_REWARD_LOOSER_HONOR_FIRST;
+
+ win_kills = (uint32)Trinity::Honor::hk_honor_at_level(plr->getLevel(), win_kills*2);
+ loos_kills = (uint32)Trinity::Honor::hk_honor_at_level(plr->getLevel(), loos_kills*2);
+
data->Initialize(SMSG_BATTLEFIELD_LIST);
*data << uint64(guid); // battlemaster guid
*data << uint8(fromWhere); // from where you joined
@@ -1846,20 +1874,21 @@ void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket *data, const uint6
*data << uint8(0); // unk
// Rewards
- *data << uint8(0); // 3.3.3 hasWin
- *data << uint32(0); // 3.3.3 winHonor
- *data << uint32(0); // 3.3.3 winArena
- *data << uint32(0); // 3.3.3 lossHonor
+ *data << uint8(plr->GetRandomWinner()); // 3.3.3 hasWin
+ *data << uint32(win_kills); // 3.3.3 winHonor
+ *data << uint32(win_arena); // 3.3.3 winArena
+ *data << uint32(loos_kills); // 3.3.3 lossHonor
+
+ uint8 isRandom = bgTypeId == BATTLEGROUND_RB;
- uint8 isRandom = 0;
*data << uint8(isRandom); // 3.3.3 isRandom
if (isRandom)
{
// Rewards (random)
- *data << uint8(0); // 3.3.3 hasWin_Random
- *data << uint32(0); // 3.3.3 winHonor_Random
- *data << uint32(0); // 3.3.3 winArena_Random
- *data << uint32(0); // 3.3.3 lossHonor_Random
+ *data << uint8(plr->GetRandomWinner()); // 3.3.3 hasWin_Random
+ *data << uint32(win_kills); // 3.3.3 winHonor_Random
+ *data << uint32(win_arena); // 3.3.3 winArena_Random
+ *data << uint32(loos_kills); // 3.3.3 lossHonor_Random
}
if (bgTypeId == BATTLEGROUND_AA) // arena
@@ -1947,8 +1976,8 @@ BattleGroundQueueTypeId BattleGroundMgr::BGQueueTypeId(BattleGroundTypeId bgType
return BATTLEGROUND_QUEUE_SA;
case BATTLEGROUND_IC:
return BATTLEGROUND_QUEUE_IC;
- case BATTLEGROUND_ABG:
- return BATTLEGROUND_QUEUE_NONE;
+ case BATTLEGROUND_RB:
+ return BATTLEGROUND_QUEUE_RB;
case BATTLEGROUND_AA:
case BATTLEGROUND_NA:
case BATTLEGROUND_RL:
@@ -1987,6 +2016,8 @@ BattleGroundTypeId BattleGroundMgr::BGTemplateId(BattleGroundQueueTypeId bgQueue
return BATTLEGROUND_SA;
case BATTLEGROUND_QUEUE_IC:
return BATTLEGROUND_IC;
+ case BATTLEGROUND_QUEUE_RB:
+ return BATTLEGROUND_RB;
case BATTLEGROUND_QUEUE_2v2:
case BATTLEGROUND_QUEUE_3v3:
case BATTLEGROUND_QUEUE_5v5:
@@ -2119,23 +2150,36 @@ void BattleGroundMgr::LoadBattleMastersEntry()
sLog.outString();
sLog.outString(">> Loaded %u battlemaster entries", count);
}
-bool BattleGroundMgr::IsBGWeekend(BattleGroundTypeId bgTypeId)
+
+HolidayIds BattleGroundMgr::BGTypeToWeekendHolidayId(BattleGroundTypeId bgTypeId)
{
switch (bgTypeId)
{
- case BATTLEGROUND_AV:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_AV);
- case BATTLEGROUND_EY:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_EY);
- case BATTLEGROUND_WS:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_WS);
- case BATTLEGROUND_SA:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_SA);
- default:
- return false;
+ case BATTLEGROUND_AV: return HOLIDAY_CALL_TO_ARMS_AV;
+ case BATTLEGROUND_EY: return HOLIDAY_CALL_TO_ARMS_EY;
+ case BATTLEGROUND_WS: return HOLIDAY_CALL_TO_ARMS_WS;
+ case BATTLEGROUND_SA: return HOLIDAY_CALL_TO_ARMS_SA;
+ default: return HOLIDAY_NONE;
}
}
+BattleGroundTypeId BattleGroundMgr::WeekendHolidayIdToBGType(HolidayIds holiday)
+{
+ switch (holiday)
+ {
+ case HOLIDAY_CALL_TO_ARMS_AV: return BATTLEGROUND_AV;
+ case HOLIDAY_CALL_TO_ARMS_EY: return BATTLEGROUND_EY;
+ case HOLIDAY_CALL_TO_ARMS_WS: return BATTLEGROUND_WS;
+ case HOLIDAY_CALL_TO_ARMS_SA: return BATTLEGROUND_SA;
+ default: return BATTLEGROUND_TYPE_NONE;
+ }
+}
+
+bool BattleGroundMgr::IsBGWeekend(BattleGroundTypeId bgTypeId)
+{
+ return IsHolidayActive(BGTypeToWeekendHolidayId(bgTypeId));
+}
+
void BattleGroundMgr::DoCompleteAchievement(uint32 achievement, Player * player)
{
AchievementEntry const* AE = GetAchievementStore()->LookupEntry(achievement);
diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h
index 892fcc153c5..dae25ac91cb 100644
--- a/src/game/BattleGroundMgr.h
+++ b/src/game/BattleGroundMgr.h
@@ -250,6 +250,8 @@ class BattleGroundMgr
static BattleGroundTypeId BGTemplateId(BattleGroundQueueTypeId bgQueueTypeId);
static uint8 BGArenaType(BattleGroundQueueTypeId bgQueueTypeId);
+ static HolidayIds BGTypeToWeekendHolidayId(BattleGroundTypeId bgTypeId);
+ static BattleGroundTypeId WeekendHolidayIdToBGType(HolidayIds holiday);
static bool IsBGWeekend(BattleGroundTypeId bgTypeId);
void DoCompleteAchievement(uint32 achievement, Player * player = NULL);
bool isAnyArenaEnabled() const { return m_EnabledArenas.size() != 0; }
diff --git a/src/game/BattleGroundRB.cpp b/src/game/BattleGroundRB.cpp
new file mode 100644
index 00000000000..cf22154ed11
--- /dev/null
+++ b/src/game/BattleGroundRB.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "Player.h"
+#include "BattleGround.h"
+#include "BattleGroundRB.h"
+#include "Language.h"
+
+BattleGroundRB::BattleGroundRB()
+{
+ //TODO FIX ME!
+ m_StartMessageIds[BG_STARTING_EVENT_FIRST] = 0;
+ m_StartMessageIds[BG_STARTING_EVENT_SECOND] = LANG_BG_WS_START_ONE_MINUTE;
+ m_StartMessageIds[BG_STARTING_EVENT_THIRD] = LANG_BG_WS_START_HALF_MINUTE;
+ m_StartMessageIds[BG_STARTING_EVENT_FOURTH] = LANG_BG_WS_HAS_BEGUN;
+}
+
+BattleGroundRB::~BattleGroundRB()
+{
+
+}
+
+void BattleGroundRB::Update(uint32 diff)
+{
+ BattleGround::Update(diff);
+}
+
+void BattleGroundRB::StartingEventCloseDoors()
+{
+}
+
+void BattleGroundRB::StartingEventOpenDoors()
+{
+}
+
+void BattleGroundRB::AddPlayer(Player *plr)
+{
+ BattleGround::AddPlayer(plr);
+ //create score and add it to map, default values are set in constructor
+ BattleGroundRBScore* sc = new BattleGroundRBScore;
+
+ m_PlayerScores[plr->GetGUID()] = sc;
+}
+
+void BattleGroundRB::RemovePlayer(Player* /*plr*/,uint64 /*guid*/)
+{
+}
+
+void BattleGroundRB::HandleAreaTrigger(Player * /*Source*/, uint32 /*Trigger*/)
+{
+ // this is wrong way to implement these things. On official it done by gameobject spell cast.
+ if (GetStatus() != STATUS_IN_PROGRESS)
+ return;
+}
+
+void BattleGroundRB::UpdatePlayerScore(Player* Source, uint32 type, uint32 value, bool doAddHonor)
+{
+ std::map<uint64, BattleGroundScore*>::iterator itr = m_PlayerScores.find(Source->GetGUID());
+
+ if (itr == m_PlayerScores.end()) // player not found...
+ return;
+
+ BattleGround::UpdatePlayerScore(Source,type,value, doAddHonor);
+}
diff --git a/src/game/BattleGroundRB.h b/src/game/BattleGroundRB.h
new file mode 100644
index 00000000000..a40ade5adfe
--- /dev/null
+++ b/src/game/BattleGroundRB.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __BATTLEGROUNDRB_H
+#define __BATTLEGROUNDRB_H
+
+class BattleGround;
+
+class BattleGroundRBScore : public BattleGroundScore
+{
+ public:
+ BattleGroundRBScore() {};
+ virtual ~BattleGroundRBScore() {};
+};
+
+class BattleGroundRB : public BattleGround
+{
+ friend class BattleGroundMgr;
+
+ public:
+ BattleGroundRB();
+ ~BattleGroundRB();
+ void Update(uint32 diff);
+
+ virtual void AddPlayer(Player *plr);
+ virtual void StartingEventCloseDoors();
+ virtual void StartingEventOpenDoors();
+
+ void RemovePlayer(Player *plr,uint64 guid);
+ void HandleAreaTrigger(Player *Source, uint32 Trigger);
+
+ /* Scorekeeping */
+ void UpdatePlayerScore(Player *Source, uint32 type, uint32 value, bool doAddHonor = true);
+
+ private:
+};
+#endif
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index 3197185240d..c425517f6cb 100644
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -27,7 +27,7 @@ SET(game_STAT_SRCS
BattleGround.cpp
BattleGroundAA.cpp
BattleGroundAB.cpp
- BattleGroundABG.cpp
+ BattleGroundRB.cpp
BattleGroundAV.cpp
BattleGroundBE.cpp
BattleGroundDS.cpp
@@ -41,7 +41,7 @@ SET(game_STAT_SRCS
BattleGround.h
BattleGroundAA.h
BattleGroundAB.h
- BattleGroundABG.h
+ BattleGroundRB.h
BattleGroundAV.h
BattleGroundBE.h
BattleGroundDS.h
diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
index f82b6edfc56..416827d73ea 100644
--- a/src/game/CharacterHandler.cpp
+++ b/src/game/CharacterHandler.cpp
@@ -98,6 +98,7 @@ bool LoginQueryHolder::Initialize()
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADTALENTS, "SELECT spell, spec FROM character_talent WHERE guid='%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADACCOUNTDATA, "SELECT type, time, data FROM character_account_data WHERE guid='%u'", GUID_LOPART(m_guid));
res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADSKILLS, "SELECT skill, value, max FROM character_skills WHERE guid = '%u'", GUID_LOPART(m_guid));
+ res &= SetPQuery(PLAYER_LOGIN_QUERY_LOADRANDOMBG, "SELECT guid FROM character_battleground_random WHERE guid = '%u'", GUID_LOPART(m_guid));
return res;
}
diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h
index f86eecc7644..584fc70984c 100644
--- a/src/game/DBCStructure.h
+++ b/src/game/DBCStructure.h
@@ -600,7 +600,7 @@ struct BattlemasterListEntry
char* name[16]; // 11-26
//uint32 nameFlags // 27 string flag, unused
uint32 maxGroupSize; // 28 maxGroupSize, used for checking if queue as group
- //uint32 HolidayWorldStateId; // 29 new 3.1
+ uint32 HolidayWorldStateId; // 29 new 3.1
//uint32 MinLevel; // 30
//uint32 SomeLevel; // 31, may be max level
};
diff --git a/src/game/DBCfmt.h b/src/game/DBCfmt.h
index a5c1bc92d65..bed688cc126 100644
--- a/src/game/DBCfmt.h
+++ b/src/game/DBCfmt.h
@@ -30,7 +30,7 @@ const char AreaTriggerEntryfmt[]="niffffffff";
const char AuctionHouseEntryfmt[]="niiixxxxxxxxxxxxxxxxx";
const char BankBagSlotPricesEntryfmt[]="ni";
const char BarberShopStyleEntryfmt[]="nixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiii";
-const char BattlemasterListEntryfmt[]="niiiiiiiiixssssssssssssssssxixxx";
+const char BattlemasterListEntryfmt[]="niiiiiiiiixssssssssssssssssxiixx";
const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiiiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const char CharTitlesEntryfmt[]="nxssssssssssssssssxxxxxxxxxxxxxxxxxxi";
const char ChatChannelsEntryfmt[]="iixssssssssssssssssxxxxxxxxxxxxxxxxxx";
diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp
index fca5dc83582..a2c6f2f2422 100644
--- a/src/game/GameEventMgr.cpp
+++ b/src/game/GameEventMgr.cpp
@@ -21,6 +21,7 @@
#include "GameEventMgr.h"
#include "World.h"
#include "ObjectMgr.h"
+#include "WorldPacket.h"
#include "PoolHandler.h"
#include "ProgressBar.h"
#include "Language.h"
@@ -243,7 +244,7 @@ void GameEventMgr::LoadFromDB()
pGameEvent.end = time_t(endtime);
pGameEvent.occurence = fields[3].GetUInt32();
pGameEvent.length = fields[4].GetUInt32();
- pGameEvent.holiday_id = fields[5].GetUInt32();
+ pGameEvent.holiday_id = HolidayIds(fields[5].GetUInt32());
pGameEvent.state = (GameEventState)(fields[7].GetUInt8());
pGameEvent.nextstart = 0;
@@ -254,12 +255,12 @@ void GameEventMgr::LoadFromDB()
continue;
}
- if (pGameEvent.holiday_id)
+ if (pGameEvent.holiday_id != HOLIDAY_NONE)
{
if (!sHolidaysStore.LookupEntry(pGameEvent.holiday_id))
{
sLog.outErrorDb("`game_event` game event id (%i) have not existed holiday id %u.",event_id,pGameEvent.holiday_id);
- pGameEvent.holiday_id = 0;
+ pGameEvent.holiday_id = HOLIDAY_NONE;
}
}
@@ -1168,6 +1169,7 @@ void GameEventMgr::UnApplyEvent(uint16 event_id)
ChangeEquipOrModel(event_id, false);
// Remove quests that are events only to non event npc
UpdateEventQuests(event_id, false);
+ UpdateWorldStates(event_id, false);
// update npcflags in this event
UpdateEventNPCFlags(event_id);
// remove vendor items
@@ -1198,6 +1200,7 @@ void GameEventMgr::ApplyNewEvent(uint16 event_id)
ChangeEquipOrModel(event_id, true);
// Add quests that are events only to non event npc
UpdateEventQuests(event_id, true);
+ UpdateWorldStates(event_id, true);
// update npcflags in this event
UpdateEventNPCFlags(event_id);
// add vendor items
@@ -1571,7 +1574,27 @@ void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate)
}
}
}
- }}
+ }
+}
+
+void GameEventMgr::UpdateWorldStates(uint16 event_id, bool Activate)
+{
+ GameEventData const& event = mGameEvent[event_id];
+ if (event.holiday_id != HOLIDAY_NONE)
+ {
+ BattleGroundTypeId bgTypeId = BattleGroundMgr::WeekendHolidayIdToBGType(event.holiday_id);
+ if (bgTypeId != BATTLEGROUND_TYPE_NONE)
+ {
+ BattlemasterListEntry const * bl = sBattlemasterListStore.LookupEntry(bgTypeId);
+ if (bl && bl->HolidayWorldStateId)
+ {
+ WorldPacket data;
+ sBattleGroundMgr.BuildUpdateWorldStatePacket(&data, bl->HolidayWorldStateId, Activate ? 1 : 0);
+ sWorld.SendGlobalMessage(&data);
+ }
+ }
+ }
+}
GameEventMgr::GameEventMgr()
{
@@ -1676,8 +1699,11 @@ void GameEventMgr::SendWorldStateUpdate(Player * plr, uint16 event_id)
}
}
- bool IsHolidayActive(HolidayIds id)
+bool IsHolidayActive(HolidayIds id)
{
+ if (id == HOLIDAY_NONE)
+ return false;
+
GameEventMgr::GameEventDataMap const& events = gameeventmgr.GetEventMap();
GameEventMgr::ActiveEvents const& ae = gameeventmgr.GetActiveEventList();
diff --git a/src/game/GameEventMgr.h b/src/game/GameEventMgr.h
index 7c673c92e66..2c3e41f5f20 100644
--- a/src/game/GameEventMgr.h
+++ b/src/game/GameEventMgr.h
@@ -55,13 +55,13 @@ struct GameEventQuestToEventConditionNum
struct GameEventData
{
- GameEventData() : start(1),end(0),nextstart(0),occurence(0),length(0),state(GAMEEVENT_NORMAL) {}
+ GameEventData() : start(1),end(0),nextstart(0),occurence(0),length(0),state(GAMEEVENT_NORMAL), holiday_id(HOLIDAY_NONE) {}
time_t start; // occurs after this time
time_t end; // occurs before this time
time_t nextstart; // after this time the follow-up events count this phase completed
uint32 occurence; // time between end and start
uint32 length; // length of the event (minutes) after finishing all conditions
- uint32 holiday_id;
+ HolidayIds holiday_id;
GameEventState state; // state of the game event, these are saved into the game_event table on change!
std::map<uint32 /*condition id*/, GameEventFinishCondition> conditions; // conditions to finish
std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event
@@ -123,6 +123,7 @@ class GameEventMgr
void GameEventUnspawn(int16 event_id);
void ChangeEquipOrModel(int16 event_id, bool activate);
void UpdateEventQuests(uint16 event_id, bool activate);
+ void UpdateWorldStates(uint16 event_id, bool Activate);
void UpdateEventNPCFlags(uint16 event_id);
void UpdateEventNPCVendor(uint16 event_id, bool activate);
void UpdateBattleGroundSettings();
diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp
index d8d376c0608..3aaac5afe31 100644
--- a/src/game/GameObject.cpp
+++ b/src/game/GameObject.cpp
@@ -865,7 +865,7 @@ bool GameObject::ActivateToQuest(Player *pTarget) const
//look for battlegroundAV for some objects which are only activated after mine gots captured by own team
if (GetEntry() == BG_AV_OBJECTID_MINE_N || GetEntry() == BG_AV_OBJECTID_MINE_S)
if (BattleGround *bg = pTarget->GetBattleGround())
- if (bg->GetTypeID() == BATTLEGROUND_AV && !(((BattleGroundAV*)bg)->PlayerCanDoMineQuest(GetEntry(),pTarget->GetTeam())))
+ if (bg->GetTypeID(true) == BATTLEGROUND_AV && !(((BattleGroundAV*)bg)->PlayerCanDoMineQuest(GetEntry(),pTarget->GetTeam())))
return false;
return true;
}
@@ -1441,15 +1441,15 @@ void GameObject::Use(Unit* user)
{
case 179785: // Silverwing Flag
// check if it's correct bg
- if (bg->GetTypeID() == BATTLEGROUND_WS)
+ if (bg->GetTypeID(true) == BATTLEGROUND_WS)
bg->EventPlayerClickedOnFlag(player, this);
break;
case 179786: // Warsong Flag
- if (bg->GetTypeID() == BATTLEGROUND_WS)
+ if (bg->GetTypeID(true) == BATTLEGROUND_WS)
bg->EventPlayerClickedOnFlag(player, this);
break;
case 184142: // Netherstorm Flag
- if (bg->GetTypeID() == BATTLEGROUND_EY)
+ if (bg->GetTypeID(true) == BATTLEGROUND_EY)
bg->EventPlayerClickedOnFlag(player, this);
break;
}
diff --git a/src/game/Group.cpp b/src/game/Group.cpp
index 87e02cb8148..1586d787dc3 100644
--- a/src/game/Group.cpp
+++ b/src/game/Group.cpp
@@ -29,6 +29,7 @@
#include "Formulas.h"
#include "ObjectAccessor.h"
#include "BattleGround.h"
+#include "BattleGroundMgr.h"
#include "MapManager.h"
#include "InstanceSaveMgr.h"
#include "MapInstanced.h"
@@ -1597,6 +1598,8 @@ GroupJoinBattlegroundResult Group::CanJoinBattleGroundQueue(BattleGround const*
uint32 arenaTeamId = reference->GetArenaTeamId(arenaSlot);
uint32 team = reference->GetTeam();
+ BattleGroundQueueTypeId bgQueueTypeIdRandom = BattleGroundMgr::BGQueueTypeId(BATTLEGROUND_RB, 0);
+
// check every member of the group to be able to join
for (GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
@@ -1617,6 +1620,12 @@ GroupJoinBattlegroundResult Group::CanJoinBattleGroundQueue(BattleGround const*
// don't let join if someone from the group is already in that bg queue
if (member->InBattleGroundQueueForBattleGroundQueueType(bgQueueTypeId))
return ERR_BATTLEGROUND_JOIN_FAILED; // not blizz-like
+ // don't let join if someone from the group is in bg queue random
+ if (member->InBattleGroundQueueForBattleGroundQueueType(bgQueueTypeIdRandom))
+ return ERR_IN_RANDOM_BG;
+ // don't let join to bg queue random if someone from the group is already in bg queue
+ if (bgOrTemplate->GetTypeID() == BATTLEGROUND_RB && member->InBattleGroundQueue())
+ return ERR_IN_NON_RANDOM_BG;
// check for deserter debuff in case not arena queue
if (bgOrTemplate->GetTypeID() != BATTLEGROUND_AA && !member->CanJoinToBattleground())
return ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS;
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index aae3890940f..9b83e023920 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -465,6 +465,8 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
// Honor System
m_lastHonorUpdateTime = time(NULL);
+ m_IsBGRandomWinner = false;
+
// Player summoning
m_summon_expire = 0;
m_summon_mapid = 0;
@@ -8060,7 +8062,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
//TODO: fix this big hack
if ((go->GetEntry() == BG_AV_OBJECTID_MINE_N || go->GetEntry() == BG_AV_OBJECTID_MINE_S))
if (BattleGround *bg = GetBattleGround())
- if (bg->GetTypeID() == BATTLEGROUND_AV)
+ if (bg->GetTypeID(true) == BATTLEGROUND_AV)
if (!(((BattleGroundAV*)bg)->PlayerCanDoMineQuest(go->GetEntry(),GetTeam())))
{
SendLootRelease(guid);
@@ -8188,7 +8190,7 @@ void Player::SendLoot(uint64 guid, LootType loot_type)
uint32 pLevel = bones->loot.gold;
bones->loot.clear();
if (BattleGround *bg = GetBattleGround())
- if (bg->GetTypeID() == BATTLEGROUND_AV)
+ if (bg->GetTypeID(true) == BATTLEGROUND_AV)
loot->FillLoot(1, LootTemplates_Creature, this, true);
// It may need a better formula
// Now it works like this: lvl10: ~6copper, lvl70: ~9silver
@@ -8531,7 +8533,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
data << uint32(2325) << uint32(0x0); // 13 sandworm E
break;
case 2597: // Alterac Valley
- if (bg && bg->GetTypeID() == BATTLEGROUND_AV)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_AV)
bg->FillInitialWorldStates(data);
else
{
@@ -8613,7 +8615,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3277: // Warsong Gulch
- if (bg && bg->GetTypeID() == BATTLEGROUND_WS)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_WS)
bg->FillInitialWorldStates(data);
else
{
@@ -8628,7 +8630,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3358: // Arathi Basin
- if (bg && bg->GetTypeID() == BATTLEGROUND_AB)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_AB)
bg->FillInitialWorldStates(data);
else
{
@@ -8667,7 +8669,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3820: // Eye of the Storm
- if (bg && bg->GetTypeID() == BATTLEGROUND_EY)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_EY)
bg->FillInitialWorldStates(data);
else
{
@@ -8840,7 +8842,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3698: // Nagrand Arena
- if (bg && bg->GetTypeID() == BATTLEGROUND_NA)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_NA)
bg->FillInitialWorldStates(data);
else
{
@@ -8850,7 +8852,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3702: // Blade's Edge Arena
- if (bg && bg->GetTypeID() == BATTLEGROUND_BE)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_BE)
bg->FillInitialWorldStates(data);
else
{
@@ -8860,7 +8862,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 3968: // Ruins of Lordaeron
- if (bg && bg->GetTypeID() == BATTLEGROUND_RL)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_RL)
bg->FillInitialWorldStates(data);
else
{
@@ -8870,7 +8872,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 4378: // Dalaran Sewers
- if (bg && bg->GetTypeID() == BATTLEGROUND_DS)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_DS)
bg->FillInitialWorldStates(data);
else
{
@@ -8881,7 +8883,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
break;
case 3703: // Shattrath City
case 4384: // Strand of the Ancients
- if (bg && bg->GetTypeID() == BATTLEGROUND_SA)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_SA)
bg->FillInitialWorldStates(data);
else
{
@@ -8916,7 +8918,7 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
}
break;
case 4406: // Ring of Valor
- if (bg && bg->GetTypeID() == BATTLEGROUND_RV)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_RV)
bg->FillInitialWorldStates(data);
else
{
@@ -8933,6 +8935,22 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
break;
}
GetSession()->SendPacket(&data);
+ SendBGWeekendWorldStates();
+}
+
+void Player::SendBGWeekendWorldStates()
+{
+ for (uint32 i = 1; i < sBattlemasterListStore.GetNumRows(); ++i)
+ {
+ BattlemasterListEntry const * bl = sBattlemasterListStore.LookupEntry(i);
+ if (bl && bl->HolidayWorldStateId)
+ {
+ if (BattleGroundMgr::IsBGWeekend((BattleGroundTypeId)bl->id))
+ SendUpdateWorldState(bl->HolidayWorldStateId, 1);
+ else
+ SendUpdateWorldState(bl->HolidayWorldStateId, 0);
+ }
+ }
}
uint32 Player::GetXPRestBonus(uint32 xp)
@@ -15886,10 +15904,10 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder)
if (player_at_bg && currentBg->GetStatus() != STATUS_WAIT_LEAVE)
{
- BattleGroundQueueTypeId bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(currentBg->GetTypeID(), currentBg->GetArenaType());
+ BattleGroundQueueTypeId bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(currentBg->GetTypeID(true), currentBg->GetArenaType());
AddBattleGroundQueueId(bgQueueTypeId);
- m_bgData.bgTypeID = currentBg->GetTypeID();
+ m_bgData.bgTypeID = currentBg->GetTypeID(true);
//join player to battleground group
currentBg->EventPlayerLoggedIn(this, GetGUID());
@@ -16214,6 +16232,7 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder)
_LoadQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADQUESTSTATUS));
_LoadDailyQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADDAILYQUESTSTATUS));
_LoadWeeklyQuestStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADWEKLYQUESTSTATUS));
+ _LoadRandomBGStatus(holder->GetResult(PLAYER_LOGIN_QUERY_LOADRANDOMBG));
// after spell and quest load
InitTalentForLevel();
@@ -23908,3 +23927,18 @@ void Player::RefundItem(Item *item)
ModifyArenaPoints(arenaRefund);
}
+
+void Player::SetRandomWinner(bool isWinner)
+{
+ m_IsBGRandomWinner = isWinner;
+ if (m_IsBGRandomWinner)
+ CharacterDatabase.PExecute("INSERT INTO character_battleground_random (guid) VALUES ('%u')", GetGUIDLow());
+}
+
+void Player::_LoadRandomBGStatus(QueryResult_AutoPtr result)
+{
+ //QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT guid FROM character_battleground_random WHERE guid = '%u'", GetGUIDLow());
+
+ if (result)
+ m_IsBGRandomWinner = true;
+}
diff --git a/src/game/Player.h b/src/game/Player.h
index d5dd504a3b1..0166eb2b23d 100644
--- a/src/game/Player.h
+++ b/src/game/Player.h
@@ -785,7 +785,8 @@ enum PlayerLoginQueryIndex
PLAYER_LOGIN_QUERY_LOADACCOUNTDATA = 24,
PLAYER_LOGIN_QUERY_LOADSKILLS = 25,
PLAYER_LOGIN_QUERY_LOADWEKLYQUESTSTATUS = 26,
- MAX_PLAYER_LOGIN_QUERY = 27
+ PLAYER_LOGIN_QUERY_LOADRANDOMBG = 27,
+ MAX_PLAYER_LOGIN_QUERY = 28
};
enum PlayerDelayedOperations
@@ -1940,6 +1941,7 @@ class Player : public Unit, public GridObject<Player>
void SendInitWorldStates(uint32 zone, uint32 area);
void SendUpdateWorldState(uint32 Field, uint32 Value);
void SendDirectMessage(WorldPacket *data);
+ void SendBGWeekendWorldStates();
void SendAurasForTarget(Unit *target);
@@ -2057,6 +2059,9 @@ class Player : public Unit, public GridObject<Player>
bool isTotalImmune();
bool CanCaptureTowerPoint();
+ bool GetRandomWinner() { return m_IsBGRandomWinner; }
+ void SetRandomWinner(bool isWinner);
+
/*********************************************************/
/*** OUTDOOR PVP SYSTEM ***/
/*********************************************************/
@@ -2302,6 +2307,8 @@ class Player : public Unit, public GridObject<Player>
BgBattleGroundQueueID_Rec m_bgBattleGroundQueueID[PLAYER_MAX_BATTLEGROUND_QUEUES];
BGData m_bgData;
+ bool m_IsBGRandomWinner;
+
/*********************************************************/
/*** QUEST SYSTEM ***/
/*********************************************************/
@@ -2329,6 +2336,7 @@ class Player : public Unit, public GridObject<Player>
void _LoadQuestStatus(QueryResult_AutoPtr result);
void _LoadDailyQuestStatus(QueryResult_AutoPtr result);
void _LoadWeeklyQuestStatus(QueryResult_AutoPtr result);
+ void _LoadRandomBGStatus(QueryResult_AutoPtr result);
void _LoadGroup(QueryResult_AutoPtr result);
void _LoadSkills(QueryResult_AutoPtr result);
void _LoadSpells(QueryResult_AutoPtr result);
diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h
index 22077649b6d..903dd4b09ca 100644
--- a/src/game/SharedDefines.h
+++ b/src/game/SharedDefines.h
@@ -2018,6 +2018,8 @@ enum CreatureEliteType
// values based at Holidays.dbc
enum HolidayIds
{
+ HOLIDAY_NONE = 0,
+
HOLIDAY_FIREWORKS_SPECTACULAR = 62,
HOLIDAY_FEAST_OF_WINTER_VEIL = 141,
HOLIDAY_NOBLEGARDEN = 181,
@@ -2712,7 +2714,7 @@ enum BattleGroundTypeId
BATTLEGROUND_DS = 10,
BATTLEGROUND_RV = 11,
BATTLEGROUND_IC = 30,
- BATTLEGROUND_ABG = 32
+ BATTLEGROUND_RB = 32
};
#define MAX_BATTLEGROUND_TYPE_ID 33
diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
index 350901b99dc..f38715a9359 100644
--- a/src/game/SpellEffects.cpp
+++ b/src/game/SpellEffects.cpp
@@ -3392,7 +3392,7 @@ void Spell::EffectOpenLock(uint32 effIndex)
// in battleground check
if (BattleGround *bg = player->GetBattleGround())
{
- if (bg->GetTypeID() == BATTLEGROUND_EY)
+ if (bg->GetTypeID(true) == BATTLEGROUND_EY)
bg->EventPlayerClickedOnFlag(player, gameObjTarget);
return;
}
@@ -4860,7 +4860,7 @@ void Spell::EffectSummonObjectWild(uint32 i)
{
case 489: //WS
{
- if (bg && bg->GetTypeID() == BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_WS && bg->GetStatus() == STATUS_IN_PROGRESS)
{
uint32 team = ALLIANCE;
@@ -4873,7 +4873,7 @@ void Spell::EffectSummonObjectWild(uint32 i)
}
case 566: //EY
{
- if (bg && bg->GetTypeID() == BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
+ if (bg && bg->GetTypeID(true) == BATTLEGROUND_EY && bg->GetStatus() == STATUS_IN_PROGRESS)
{
((BattleGroundEY*)bg)->SetDroppedFlagGUID(pGameObj->GetGUID());
}
diff --git a/src/game/World.cpp b/src/game/World.cpp
index c2b29141a62..0e90f89664d 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -1015,6 +1015,13 @@ void World::LoadConfigSettings(bool reload)
if (m_configs[CONFIG_QUEST_HIGH_LEVEL_HIDE_DIFF] > MAX_LEVEL)
m_configs[CONFIG_QUEST_HIGH_LEVEL_HIDE_DIFF] = MAX_LEVEL;
+ m_configs[CONFIG_RANDOM_BG_RESET_HOUR] = sConfig.GetIntDefault("BattleGround.Random.ResetHour", 6);
+ if (m_configs[CONFIG_RANDOM_BG_RESET_HOUR] < 0 || m_configs[CONFIG_RANDOM_BG_RESET_HOUR] > 23)
+ {
+ sLog.outError("BattleGround.Random.ResetHour (%i) can't be load. Set to 6.", m_configs[CONFIG_RANDOM_BG_RESET_HOUR]);
+ m_configs[CONFIG_RANDOM_BG_RESET_HOUR] = 6;
+ }
+
m_configs[CONFIG_DETECT_POS_COLLISION] = sConfig.GetBoolDefault("DetectPosCollision", true);
m_configs[CONFIG_RESTRICTED_LFG_CHANNEL] = sConfig.GetBoolDefault("Channel.RestrictedLfg", true);
@@ -1697,6 +1704,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Calculate next weekly quest reset time..." );
InitWeeklyQuestResetTime();
+ sLog.outString("Calculate random battleground reset time..." );
+ InitRandomBGResetTime();
+
sLog.outString("Starting objects Pooling system...");
poolhandler.Initialize();
@@ -1864,6 +1874,9 @@ void World::Update(uint32 diff)
if (m_gameTime > m_NextWeeklyQuestReset)
ResetWeeklyQuests();
+ if (m_gameTime > m_NextRandomBGReset)
+ ResetRandomBG();
+
/// <ul><li> Handle auctions when the timer has passed
if (m_timers[WUPDATE_AUCTIONS].Passed())
{
@@ -2551,6 +2564,33 @@ void World::InitDailyQuestResetTime()
}
}
+void World::InitRandomBGResetTime()
+{
+ time_t bgtime = uint64(sWorld.getWorldState(WS_BG_DAILY_RESET_TIME));
+ if (!bgtime)
+ m_NextRandomBGReset = time_t(time(NULL)); // game time not yet init
+
+ // generate time by config
+ time_t curTime = time(NULL);
+ tm localTm = *localtime(&curTime);
+ localTm.tm_hour = getConfig(CONFIG_RANDOM_BG_RESET_HOUR);
+ localTm.tm_min = 0;
+ localTm.tm_sec = 0;
+
+ // current day reset time
+ time_t nextDayResetTime = mktime(&localTm);
+
+ // next reset time before current moment
+ if (curTime >= nextDayResetTime)
+ nextDayResetTime += DAY;
+
+ // normalize reset time
+ m_NextRandomBGReset = m_NextRandomBGReset < curTime ? nextDayResetTime - DAY : nextDayResetTime;
+
+ if (!bgtime)
+ sWorld.setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
+}
+
void World::ResetDailyQuests()
{
sLog.outDetail("Daily quests reset for all characters.");
@@ -2581,6 +2621,18 @@ void World::ResetWeeklyQuests()
sWorld.setWorldState(WS_WEEKLY_QUEST_RESET_TIME, uint64(m_NextWeeklyQuestReset));
}
+void World::ResetRandomBG()
+{
+ sLog.outDetail("Random BG status reset for all characters.");
+ CharacterDatabase.Execute("DELETE FROM character_battleground_random");
+ for(SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr)
+ if (itr->second->GetPlayer())
+ itr->second->GetPlayer()->SetRandomWinner(false);
+
+ m_NextRandomBGReset = time_t(m_NextRandomBGReset + DAY);
+ sWorld.setWorldState(WS_BG_DAILY_RESET_TIME, uint64(m_NextRandomBGReset));
+}
+
void World::SetPlayerLimit(int32 limit, bool /*needUpdate*/)
{
m_playerLimit = limit;
diff --git a/src/game/World.h b/src/game/World.h
index ddc804f1968..9f48c13f1e3 100644
--- a/src/game/World.h
+++ b/src/game/World.h
@@ -278,6 +278,7 @@ enum WorldConfigs
CONFIG_MIN_LEVEL_STAT_SAVE,
CONFIG_STATS_SAVE_ONLY_ON_LOGOUT,
CONFIG_BG_XP_FOR_KILL,
+ CONFIG_RANDOM_BG_RESET_HOUR,
CONFIG_VALUE_COUNT
};
@@ -417,7 +418,8 @@ enum RealmZone
enum WorldStates
{
- WS_WEEKLY_QUEST_RESET_TIME = 20002 // Next weekly reset time
+ WS_WEEKLY_QUEST_RESET_TIME = 20002, // Next weekly reset time
+ WS_BG_DAILY_RESET_TIME = 20003 // Next daily BG reset time
};
// DB scripting commands
@@ -557,9 +559,11 @@ class World
/// Update time
uint32 GetUpdateTime() const { return m_updateTime; }
void SetRecordDiffInterval(int32 t) { if (t >= 0) m_configs[CONFIG_INTERVAL_LOG_UPDATE] = (uint32)t; }
- /// Next daily quests reset time
+
+ /// Next daily quests and random bg reset time
time_t GetNextDailyQuestsResetTime() const { return m_NextDailyQuestReset; }
time_t GetNextWeeklyQuestsResetTime() const { return m_NextWeeklyQuestReset; }
+ time_t GetNextRandomBGResetTime() const { return m_NextRandomBGReset; }
/// Get the maximum skill level a player can reach
uint16 GetConfigMaxSkillValue() const
@@ -681,8 +685,10 @@ class World
void InitDailyQuestResetTime();
void InitWeeklyQuestResetTime();
+ void InitRandomBGResetTime();
void ResetDailyQuests();
void ResetWeeklyQuests();
+ void ResetRandomBG();
private:
static volatile bool m_stopEvent;
static uint8 m_ExitCode;
@@ -748,9 +754,10 @@ class World
ACE_Based::LockedQueue<CliCommandHolder*,ACE_Thread_Mutex> cliCmdQueue;
SqlResultQueue *m_resultQueue;
- // next daily quests reset time
+ // next daily quests and random bg reset time
time_t m_NextDailyQuestReset;
time_t m_NextWeeklyQuestReset;
+ time_t m_NextRandomBGReset;
//Player Queue
Queue m_QueuedPlayer;