2025-11-13 17:46:30 -08:00
|
|
|
#include "ScriptMgr.h"
|
|
|
|
|
#include "Config.h"
|
|
|
|
|
#include "Player.h"
|
|
|
|
|
#include "Unit.h"
|
|
|
|
|
#include "Item.h"
|
2025-11-13 18:16:48 -08:00
|
|
|
#include "SharedDefines.h"
|
2025-11-13 17:46:30 -08:00
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
bool sEnabled = true;
|
|
|
|
|
uint32 sRequiredItemId = 0;
|
|
|
|
|
uint32 sRequiredEquipId = 0;
|
|
|
|
|
uint32 sRequiredSpellId = 0;
|
|
|
|
|
uint32 sMinLevel = 60;
|
|
|
|
|
|
|
|
|
|
bool HasEquippedItem(Player* player, uint32 entry)
|
|
|
|
|
{
|
|
|
|
|
if (!player)
|
|
|
|
|
return false;
|
|
|
|
|
if (!entry)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
|
|
|
|
|
{
|
|
|
|
|
if (Item* it = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot))
|
|
|
|
|
if (it->GetEntry() == entry)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RequirementsMet(Player* player)
|
|
|
|
|
{
|
|
|
|
|
if (!player)
|
|
|
|
|
return false;
|
|
|
|
|
if (!sEnabled)
|
|
|
|
|
return false;
|
2025-11-13 18:19:43 -08:00
|
|
|
if (player->GetLevel() < sMinLevel)
|
2025-11-13 17:46:30 -08:00
|
|
|
return false;
|
|
|
|
|
if (sRequiredItemId && !player->HasItemCount(sRequiredItemId, 1, false))
|
|
|
|
|
return false;
|
|
|
|
|
if (sRequiredEquipId && !HasEquippedItem(player, sRequiredEquipId))
|
|
|
|
|
return false;
|
|
|
|
|
if (sRequiredSpellId && !player->HasSpell(sRequiredSpellId))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SwiftTravelForm_WorldScript : public WorldScript
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SwiftTravelForm_WorldScript() : WorldScript("SwiftTravelForm_WorldScript") {}
|
|
|
|
|
|
|
|
|
|
void OnAfterConfigLoad(bool) override
|
|
|
|
|
{
|
|
|
|
|
sEnabled = sConfigMgr->GetOption<bool>("SwiftTravelForm.Enable", true);
|
|
|
|
|
sRequiredItemId = sConfigMgr->GetOption<uint32>("SwiftTravelForm.RequiredItem", 0u);
|
|
|
|
|
sRequiredEquipId = sConfigMgr->GetOption<uint32>("SwiftTravelForm.RequiredEquipment", 0u);
|
|
|
|
|
sRequiredSpellId = sConfigMgr->GetOption<uint32>("SwiftTravelForm.RequiredSpell", 0u);
|
|
|
|
|
sMinLevel = sConfigMgr->GetOption<uint32>("SwiftTravelForm.MinLevel", 60u);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SwiftTravelForm_UnitScript : public UnitScript
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SwiftTravelForm_UnitScript() : UnitScript("SwiftTravelForm_UnitScript") {}
|
|
|
|
|
|
2025-11-13 18:21:13 -08:00
|
|
|
void OnUnitSetShapeshiftForm(Unit* unit, uint8 form) override
|
2025-11-13 17:46:30 -08:00
|
|
|
{
|
|
|
|
|
if (!sEnabled)
|
|
|
|
|
return;
|
|
|
|
|
if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Player* player = unit->ToPlayer();
|
|
|
|
|
if (!RequirementsMet(player))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (form == FORM_TRAVEL)
|
|
|
|
|
player->SetSpeed(MOVE_RUN, 2.0f, true);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void AddSC_swift_travel_form()
|
|
|
|
|
{
|
|
|
|
|
new SwiftTravelForm_WorldScript();
|
|
|
|
|
new SwiftTravelForm_UnitScript();
|
|
|
|
|
}
|