mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-19 06:29:50 -04:00
Battlefields: Move BF scripts out of game
This commit introduces the usual script interface for battlefields.
This commit is contained in:
committed by
Peter Keresztes Schmidt
parent
7b3d691c0b
commit
f7faf20254
@@ -0,0 +1,8 @@
|
||||
DROP TABLE IF EXISTS `battlefield_template`;
|
||||
CREATE TABLE `battlefield_template` (
|
||||
`TypeId` tinyint unsigned not null,
|
||||
`ScriptName` varchar(64) default '' not null,
|
||||
`comment` text null
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
INSERT INTO `battlefield_template` (`TypeId`, `ScriptName`, `comment`) VALUES (1, 'battlefield_wg', null);
|
||||
@@ -25,7 +25,8 @@
|
||||
|
||||
enum BattlefieldTypes
|
||||
{
|
||||
BATTLEFIELD_WG // Wintergrasp
|
||||
BATTLEFIELD_WG = 1, // Wintergrasp
|
||||
BATTLEFIELD_MAX
|
||||
};
|
||||
|
||||
enum BattlefieldIDs
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
*/
|
||||
|
||||
#include "BattlefieldMgr.h"
|
||||
#include "BattlefieldWG.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Log.h"
|
||||
#include "Player.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
BattlefieldMgr::BattlefieldMgr()
|
||||
{
|
||||
@@ -41,34 +43,44 @@ BattlefieldMgr* BattlefieldMgr::instance()
|
||||
|
||||
void BattlefieldMgr::InitBattlefield()
|
||||
{
|
||||
Battlefield* wg = new BattlefieldWG();
|
||||
// respawn, init variables
|
||||
if (!wg->SetupBattlefield())
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
uint32 count = 0;
|
||||
|
||||
if (QueryResult result = WorldDatabase.Query("SELECT TypeId, ScriptName FROM battlefield_template"))
|
||||
{
|
||||
TC_LOG_INFO("bg.battlefield", "Battlefield: Wintergrasp init failed.");
|
||||
delete wg;
|
||||
}
|
||||
else
|
||||
{
|
||||
_battlefieldSet.push_back(wg);
|
||||
TC_LOG_INFO("bg.battlefield", "Battlefield: Wintergrasp successfully initiated.");
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 typeId = fields[0].GetUInt32();
|
||||
|
||||
if (typeId >= BATTLEFIELD_MAX)
|
||||
{
|
||||
TC_LOG_ERROR("sql.sql", "BattlefieldMgr::InitBattlefield: Invalid TypeId value %u in battlefield_template, skipped.", typeId);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32 scriptId = sObjectMgr->GetScriptId(fields[1].GetString());
|
||||
|
||||
Battlefield* bf = sScriptMgr->CreateBattlefield(scriptId);
|
||||
|
||||
if (!bf->SetupBattlefield())
|
||||
{
|
||||
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u failed.", typeId);
|
||||
delete bf;
|
||||
}
|
||||
else
|
||||
{
|
||||
_battlefieldSet.push_back(bf);
|
||||
TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u succeeded.", typeId);
|
||||
}
|
||||
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
}
|
||||
|
||||
/*
|
||||
For Cataclysm: Tol Barad
|
||||
Battlefield* tb = new BattlefieldTB;
|
||||
// respawn, init variables
|
||||
if (!tb->SetupBattlefield())
|
||||
{
|
||||
TC_LOG_DEBUG("bg.battlefield", "Battlefield: Tol Barad init failed.");
|
||||
delete tb;
|
||||
}
|
||||
else
|
||||
{
|
||||
_battlefieldSet.push_back(tb);
|
||||
TC_LOG_DEBUG("bg.battlefield", "Battlefield: Tol Barad successfully initiated.");
|
||||
}
|
||||
*/
|
||||
TC_LOG_INFO("server.loading", ">> Loaded %u battlefields in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void BattlefieldMgr::AddZone(uint32 zoneId, Battlefield* bf)
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "Bag.h"
|
||||
#include "Battlefield.h"
|
||||
#include "BattlefieldMgr.h"
|
||||
#include "BattlefieldWG.h"
|
||||
#include "Battleground.h"
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "BattlegroundScore.h"
|
||||
@@ -9414,11 +9413,11 @@ void Player::SendBattlefieldWorldStates() const
|
||||
/// Send misc stuff that needs to be sent on every login, like the battle timers.
|
||||
if (sWorld->getBoolConfig(CONFIG_WINTERGRASP_ENABLE))
|
||||
{
|
||||
if (BattlefieldWG* wg = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG)))
|
||||
if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG))
|
||||
{
|
||||
SendUpdateWorldState(WS_BATTLEFIELD_WG_ACTIVE, wg->IsWarTime() ? 0 : 1);
|
||||
uint32 timer = wg->IsWarTime() ? 0 : (wg->GetTimer() / 1000); // 0 - Time to next battle
|
||||
SendUpdateWorldState(ClockWorldState[1], uint32(GameTime::GetGameTime() + timer));
|
||||
SendUpdateWorldState(WS_BATTLEFIELD_WG_TIME_NEXT_BATTLE, uint32(GameTime::GetGameTime() + timer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9601,6 +9601,8 @@ void ObjectMgr::LoadScriptNames()
|
||||
QueryResult result = WorldDatabase.Query(
|
||||
"SELECT DISTINCT(ScriptName) FROM achievement_criteria_data WHERE ScriptName <> '' AND type = 11 "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM battlefield_template WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' "
|
||||
"UNION "
|
||||
"SELECT DISTINCT(ScriptName) FROM creature WHERE ScriptName <> '' "
|
||||
|
||||
@@ -77,6 +77,10 @@ template<>
|
||||
struct is_script_database_bound<AreaTriggerScript>
|
||||
: std::true_type { };
|
||||
|
||||
template<>
|
||||
struct is_script_database_bound<BattlefieldScript>
|
||||
: std::true_type { };
|
||||
|
||||
template<>
|
||||
struct is_script_database_bound<BattlegroundScript>
|
||||
: std::true_type { };
|
||||
@@ -595,6 +599,11 @@ class ScriptRegistrySwapHooks<GameObjectScript, Base>
|
||||
GameObject, GameObjectScript, Base
|
||||
> { };
|
||||
|
||||
/// This hook is responsible for swapping BattlefieldScripts
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<BattlefieldScript, Base>
|
||||
: public UnsupportedScriptRegistrySwapHooks<Base> { };
|
||||
|
||||
/// This hook is responsible for swapping BattlegroundScript's
|
||||
template<typename Base>
|
||||
class ScriptRegistrySwapHooks<BattlegroundScript, Base>
|
||||
@@ -1591,6 +1600,12 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger)
|
||||
return tmpscript->OnTrigger(player, trigger);
|
||||
}
|
||||
|
||||
Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId)
|
||||
{
|
||||
GET_SCRIPT_RET(BattlefieldScript, scriptId, tmpscript, nullptr);
|
||||
return tmpscript->GetBattlefield();
|
||||
}
|
||||
|
||||
Battleground* ScriptMgr::CreateBattleground(BattlegroundTypeId /*typeId*/)
|
||||
{
|
||||
/// @todo Implement script-side battlegrounds.
|
||||
@@ -2226,6 +2241,12 @@ bool OnlyOnceAreaTriggerScript::OnTrigger(Player* player, AreaTriggerEntry const
|
||||
void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(InstanceScript* script, uint32 triggerId) { script->ResetAreaTriggerDone(triggerId); }
|
||||
void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(Player const* player, AreaTriggerEntry const* trigger) { if (InstanceScript* instance = player->GetInstanceScript()) ResetAreaTriggerDone(instance, trigger->id); }
|
||||
|
||||
BattlefieldScript::BattlefieldScript(char const* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
ScriptRegistry<BattlefieldScript>::Instance()->AddScript(this);
|
||||
}
|
||||
|
||||
BattlegroundScript::BattlegroundScript(char const* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
@@ -2322,6 +2343,7 @@ template class TC_GAME_API ScriptRegistry<ItemScript>;
|
||||
template class TC_GAME_API ScriptRegistry<CreatureScript>;
|
||||
template class TC_GAME_API ScriptRegistry<GameObjectScript>;
|
||||
template class TC_GAME_API ScriptRegistry<AreaTriggerScript>;
|
||||
template class TC_GAME_API ScriptRegistry<BattlefieldScript>;
|
||||
template class TC_GAME_API ScriptRegistry<BattlegroundScript>;
|
||||
template class TC_GAME_API ScriptRegistry<OutdoorPvPScript>;
|
||||
template class TC_GAME_API ScriptRegistry<CommandScript>;
|
||||
|
||||
@@ -26,6 +26,7 @@ class AccountMgr;
|
||||
class AuctionHouseObject;
|
||||
class Aura;
|
||||
class AuraScript;
|
||||
class Battlefield;
|
||||
class Battleground;
|
||||
class BattlegroundMap;
|
||||
class Channel;
|
||||
@@ -463,6 +464,17 @@ class TC_GAME_API OnlyOnceAreaTriggerScript : public AreaTriggerScript
|
||||
void ResetAreaTriggerDone(Player const* /*player*/, AreaTriggerEntry const* /*trigger*/);
|
||||
};
|
||||
|
||||
class TC_GAME_API BattlefieldScript : public ScriptObject
|
||||
{
|
||||
protected:
|
||||
|
||||
BattlefieldScript(char const* name);
|
||||
|
||||
public:
|
||||
|
||||
virtual Battlefield* GetBattlefield() const = 0;
|
||||
};
|
||||
|
||||
class TC_GAME_API BattlegroundScript : public ScriptObject
|
||||
{
|
||||
protected:
|
||||
@@ -938,6 +950,10 @@ class TC_GAME_API ScriptMgr
|
||||
|
||||
bool OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger);
|
||||
|
||||
public: /* BattlefieldScript */
|
||||
|
||||
Battlefield* CreateBattlefield(uint32 scriptId);
|
||||
|
||||
public: /* BattlegroundScript */
|
||||
|
||||
Battleground* CreateBattleground(BattlegroundTypeId typeId);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
#include "SpellMgr.h"
|
||||
#include "BattlefieldMgr.h"
|
||||
#include "BattlefieldWG.h"
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "Chat.h"
|
||||
#include "Containers.h"
|
||||
|
||||
+16
@@ -32,6 +32,7 @@
|
||||
#include "Opcodes.h"
|
||||
#include "Player.h"
|
||||
#include "Random.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "SpellAuras.h"
|
||||
#include "TemporarySummon.h"
|
||||
#include "World.h"
|
||||
@@ -1851,3 +1852,18 @@ void WintergraspWorkshop::Save()
|
||||
{
|
||||
sWorld->setWorldState(_staticInfo->WorldStateId, _state);
|
||||
}
|
||||
|
||||
class Battlefield_wintergrasp : public BattlefieldScript
|
||||
{
|
||||
public:
|
||||
Battlefield_wintergrasp() : BattlefieldScript("battlefield_wg") { }
|
||||
|
||||
Battlefield* GetBattlefield() const override
|
||||
{
|
||||
return new BattlefieldWG();
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_BF_wintergrasp() {
|
||||
new Battlefield_wintergrasp();
|
||||
}
|
||||
+3
-9
@@ -41,12 +41,6 @@ struct WintergraspObjectPositionData;
|
||||
typedef std::vector<BfWGGameObjectBuilding*> GameObjectBuildingVect;
|
||||
typedef std::vector<WintergraspWorkshop*> WorkshopVect;
|
||||
|
||||
// used in Player.cpp
|
||||
extern uint32 const ClockWorldState[];
|
||||
|
||||
// used in zone_wintergrasp.cpp
|
||||
TC_GAME_API extern uint32 const WintergraspFaction[];
|
||||
|
||||
enum WintergraspSpells
|
||||
{
|
||||
// Wartime auras
|
||||
@@ -215,7 +209,7 @@ class WintergraspCapturePoint : public BfCapturePoint
|
||||
* WinterGrasp Battlefield *
|
||||
* ######################### */
|
||||
|
||||
class TC_GAME_API BattlefieldWG : public Battlefield
|
||||
class BattlefieldWG : public Battlefield
|
||||
{
|
||||
public:
|
||||
~BattlefieldWG();
|
||||
@@ -507,7 +501,7 @@ enum WintergraspGameObject
|
||||
// ********************************************************************
|
||||
|
||||
// Structure for different buildings that can be destroyed during battle
|
||||
struct TC_GAME_API BfWGGameObjectBuilding
|
||||
struct BfWGGameObjectBuilding
|
||||
{
|
||||
private:
|
||||
// WG object
|
||||
@@ -560,7 +554,7 @@ public:
|
||||
};
|
||||
|
||||
// Structure for the 6 workshop
|
||||
struct TC_GAME_API WintergraspWorkshop
|
||||
struct WintergraspWorkshop
|
||||
{
|
||||
private:
|
||||
BattlefieldWG* _wg; // Pointer to wintergrasp
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This file is part of the TrinityCore 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 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
void AddSC_BF_wintergrasp();
|
||||
|
||||
void AddBattlefieldScripts()
|
||||
{
|
||||
AddSC_BF_wintergrasp();
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "ScriptMgr.h"
|
||||
#include "Battlefield.h"
|
||||
#include "BattlefieldMgr.h"
|
||||
#include "BattlefieldWG.h"
|
||||
#include "Battlefield/BattlefieldWG.h"
|
||||
#include "DBCStores.h"
|
||||
#include "GameObject.h"
|
||||
#include "GameObjectAI.h"
|
||||
@@ -360,8 +360,8 @@ class go_wg_vehicle_teleporter : public GameObjectScript
|
||||
|
||||
bool IsFriendly(Unit* passenger)
|
||||
{
|
||||
return ((me->GetFaction() == WintergraspFaction[TEAM_HORDE] && passenger->GetFaction() == HORDE) ||
|
||||
(me->GetFaction() == WintergraspFaction[TEAM_ALLIANCE] && passenger->GetFaction() == ALLIANCE));
|
||||
return ((me->GetFaction() == FACTION_HORDE_GENERIC_WG && passenger->GetFaction() == HORDE) ||
|
||||
(me->GetFaction() == FACTION_ALLIANCE_GENERIC_WG && passenger->GetFaction() == ALLIANCE));
|
||||
}
|
||||
|
||||
Creature* GetValidVehicle(Creature* cVeh)
|
||||
|
||||
Reference in New Issue
Block a user