Core/Vehicles: add a way to delay the Vehicle despawn Time if its needed.

* New database table `vehicle_template` holds info for despawn delay with option to extend it in the future
This commit is contained in:
Sevi
2020-12-28 16:27:44 +01:00
committed by Shauren
parent d94f0d23b3
commit c7b10d3c5f
8 changed files with 72 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
--
-- Table structure for table `vehicle_template`
--
DROP TABLE IF EXISTS `vehicle_template`;
CREATE TABLE `vehicle_template` (
`creatureId` int(10) unsigned NOT NULL,
`despawnDelayMs` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`creatureId`)
) ENGINE=MyISAM;

View File

@@ -12956,7 +12956,7 @@ void Unit::_ExitVehicle(Position const* exitPosition)
if (vehicle->GetBase()->HasUnitTypeMask(UNIT_MASK_MINION) && vehicle->GetBase()->GetTypeId() == TYPEID_UNIT)
if (((Minion*)vehicle->GetBase())->GetOwner() == this)
vehicle->GetBase()->ToCreature()->DespawnOrUnsummon(1);
vehicle->GetBase()->ToCreature()->DespawnOrUnsummon(vehicle->GetDespawnDelay());
if (HasUnitTypeMask(UNIT_MASK_ACCESSORY))
{

View File

@@ -885,3 +885,11 @@ void VehicleJoinEvent::Abort(uint64)
if (Passenger->IsInWorld() && Passenger->HasUnitTypeMask(UNIT_MASK_ACCESSORY))
Passenger->ToCreature()->DespawnOrUnsummon();
}
Milliseconds Vehicle::GetDespawnDelay()
{
if (VehicleTemplate const* vehicleTemplate = sObjectMgr->GetVehicleTemplate(this))
return vehicleTemplate->DespawnDelay;
return 1ms;
}

View File

@@ -71,6 +71,8 @@ class TC_GAME_API Vehicle : public TransportBase
void RemovePendingEventsForPassenger(Unit* passenger);
Milliseconds GetDespawnDelay();
protected:
friend class VehicleJoinEvent;
uint32 UsableSeatNum; ///< Number of seats that match VehicleSeatEntry::UsableByPlayer, used for proper display flags

View File

@@ -19,6 +19,7 @@
#define __TRINITY_VEHICLEDEFINES_H
#include "Define.h"
#include "Duration.h"
#include <vector>
#include <map>
@@ -113,6 +114,11 @@ struct VehicleAccessory
uint8 SummonedType;
};
struct VehicleTemplate
{
Milliseconds DespawnDelay = Milliseconds::zero();
};
typedef std::vector<VehicleAccessory> VehicleAccessoryList;
typedef std::map<ObjectGuid::LowType, VehicleAccessoryList> VehicleAccessoryContainer;
typedef std::map<uint32, VehicleAccessoryList> VehicleAccessoryTemplateContainer;

View File

@@ -3252,6 +3252,41 @@ void ObjectMgr::LoadVehicleTemplateAccessories()
TC_LOG_INFO("server.loading", ">> Loaded %u Vehicle Template Accessories in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
void ObjectMgr::LoadVehicleTemplate()
{
uint32 oldMSTime = getMSTime();
_vehicleTemplateStore.clear();
// 0 1
QueryResult result = WorldDatabase.Query("SELECT creatureId, despawnDelayMs FROM vehicle_template");
if (!result)
{
TC_LOG_INFO("server.loading", ">> Loaded 0 vehicle template. DB table `vehicle_template` is empty.");
return;
}
do
{
Field* fields = result->Fetch();
uint32 creatureId = fields[0].GetUInt32();
if (!sObjectMgr->GetCreatureTemplate(creatureId))
{
TC_LOG_ERROR("sql.sql", "Table `vehicle_template`: Vehicle %u does not exist.", creatureId);
continue;
}
VehicleTemplate& vehicleTemplate = _vehicleTemplateStore[creatureId];
vehicleTemplate.DespawnDelay = Milliseconds(fields[1].GetInt32());
} while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " Vehicle Template entries in %u ms", _vehicleTemplateStore.size(), GetMSTimeDiffToNow(oldMSTime));
}
void ObjectMgr::LoadVehicleAccessories()
{
uint32 oldMSTime = getMSTime();
@@ -9991,6 +10026,11 @@ CreatureTemplate const* ObjectMgr::GetCreatureTemplate(uint32 entry) const
return nullptr;
}
VehicleTemplate const* ObjectMgr::GetVehicleTemplate(Vehicle* veh) const
{
return Trinity::Containers::MapGetValuePtr(_vehicleTemplateStore, veh->GetCreatureEntry());
}
VehicleAccessoryList const* ObjectMgr::GetVehicleAccessoryList(Vehicle* veh) const
{
if (Creature* cre = veh->GetBase()->ToCreature())

View File

@@ -1189,6 +1189,7 @@ class TC_GAME_API ObjectMgr
return nullptr;
}
VehicleTemplate const* GetVehicleTemplate(Vehicle* veh) const;
VehicleAccessoryList const* GetVehicleAccessoryList(Vehicle* veh) const;
DungeonEncounterList const* GetDungeonEncounterList(uint32 mapId, Difficulty difficulty) const;
@@ -1292,6 +1293,7 @@ class TC_GAME_API ObjectMgr
void LoadInstanceEncounters();
void LoadMailLevelRewards();
void LoadVehicleTemplateAccessories();
void LoadVehicleTemplate();
void LoadVehicleAccessories();
void LoadNPCText();
@@ -1749,6 +1751,7 @@ class TC_GAME_API ObjectMgr
SpellScriptsContainer _spellScriptsStore;
std::unordered_map<uint32, VehicleTemplate> _vehicleTemplateStore;
VehicleAccessoryTemplateContainer _vehicleTemplateAccessoryStore;
VehicleAccessoryContainer _vehicleAccessoryStore;

View File

@@ -1940,6 +1940,9 @@ void World::SetInitialWorldSettings()
TC_LOG_INFO("server.loading", "Loading UNIT_NPC_FLAG_SPELLCLICK Data..."); // must be after LoadQuests
sObjectMgr->LoadNPCSpellClickSpells();
TC_LOG_INFO("server.loading", "Loading Vehicle Templates...");
sObjectMgr->LoadVehicleTemplate(); // must be after LoadCreatureTemplates()
TC_LOG_INFO("server.loading", "Loading Vehicle Template Accessories...");
sObjectMgr->LoadVehicleTemplateAccessories(); // must be after LoadCreatureTemplates() and LoadNPCSpellClickSpells()