Core/Vehicles: Correct usage of npc_spellclick_spells instead of blatant hacks for vehicle entry.
Note: This may break a few vehicles, but only due to the absence of proper, non-hackish data.
This commit is contained in:
@@ -16456,6 +16456,51 @@ bool Unit::CheckPlayerCondition(Player* pPlayer)
|
||||
}
|
||||
}
|
||||
|
||||
bool Unit::HandleSpellClick(Unit* clicker, int8 seatId)
|
||||
{
|
||||
bool success = false;
|
||||
uint32 spellClickEntry = GetTypeId() == TYPEID_UNIT ? GetEntry() : GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID);
|
||||
SpellClickInfoMapBounds clickPair = sObjectMgr->GetSpellClickInfoMapBounds(spellClickEntry);
|
||||
for (SpellClickInfoMap::const_iterator itr = clickPair.first; itr != clickPair.second; ++itr)
|
||||
{
|
||||
if (itr->second.IsFitToRequirements(clicker, this))
|
||||
{
|
||||
Unit *caster = (itr->second.castFlags & NPC_CLICK_CAST_CASTER_CLICKER) ? clicker : this;
|
||||
Unit *target = (itr->second.castFlags & NPC_CLICK_CAST_TARGET_CLICKER) ? clicker : this;
|
||||
uint64 origCasterGUID = (itr->second.castFlags & NPC_CLICK_CAST_ORIG_CASTER_OWNER) ? GetOwnerGUID() : clicker->GetGUID();
|
||||
|
||||
SpellEntry const* spellEntry = sSpellStore.LookupEntry(itr->second.spellId);
|
||||
// if(!spellEntry) should be checked at npc_spellclick load
|
||||
|
||||
if (seatId > -1)
|
||||
{
|
||||
uint8 i = 0;
|
||||
bool valid = false;
|
||||
while (i < MAX_SPELL_EFFECTS && !valid)
|
||||
if (spellEntry->EffectApplyAuraName[i] == SPELL_AURA_CONTROL_VEHICLE)
|
||||
valid = true;
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
sLog->outErrorDb("Spell %u specified in npc_spellclick_spells is not a valid vehicle enter aura!", itr->second.spellId);
|
||||
return false;
|
||||
}
|
||||
|
||||
caster->CastCustomSpell(itr->second.spellId, SpellValueMod(SPELLVALUE_BASE_POINT0+i), seatId+1, target, true, NULL, NULL, origCasterGUID);
|
||||
}
|
||||
else
|
||||
caster->CastSpell(target, spellEntry, true, NULL, NULL, origCasterGUID);
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->ToCreature())
|
||||
this->ToCreature()->AI()->DoAction(EVENT_SPELLCLICK);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void Unit::EnterVehicle(Vehicle *vehicle, int8 seatId, AuraApplication const * aurApp)
|
||||
{
|
||||
if (!isAlive() || GetVehicleKit() == vehicle || vehicle->GetBase()->IsOnVehicle(this))
|
||||
|
||||
@@ -2057,6 +2057,7 @@ class Unit : public WorldObject
|
||||
bool m_ControlledByPlayer;
|
||||
|
||||
bool CheckPlayerCondition(Player* pPlayer);
|
||||
bool HandleSpellClick(Unit* clicker, int8 seatId = -1);
|
||||
void EnterVehicle(Unit *base, int8 seatId = -1, AuraApplication const * aurApp = NULL) { EnterVehicle(base->GetVehicleKit(), seatId, aurApp); }
|
||||
void EnterVehicle(Vehicle *vehicle, int8 seatId = -1, AuraApplication const * aurApp = NULL);
|
||||
void ExitVehicle(Position const* exitPosition = NULL);
|
||||
|
||||
@@ -282,7 +282,14 @@ void Vehicle::InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 typ
|
||||
if (minion)
|
||||
accessory->AddUnitTypeMask(UNIT_MASK_ACCESSORY);
|
||||
|
||||
accessory->EnterVehicle(this, seatId);
|
||||
|
||||
if (!me->HandleSpellClick(accessory, seatId))
|
||||
{
|
||||
sLog->outErrorDb("Vehicle entry %u in vehicle_accessory does not have a valid record in npc_spellclick_spells! Calling default EnterVehicle()",
|
||||
me->GetTypeId() == TYPEID_UNIT ? me->GetEntry() : me->GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID));
|
||||
accessory->EnterVehicle(this, seatId);
|
||||
}
|
||||
|
||||
// This is not good, we have to send update twice
|
||||
accessory->SendMovementFlagUpdate();
|
||||
|
||||
@@ -358,6 +365,7 @@ bool Vehicle::AddPassenger(Unit *unit, int8 seatId)
|
||||
if (!me->SetCharmedBy(unit, CHARM_TYPE_VEHICLE))
|
||||
ASSERT(false);
|
||||
|
||||
// hack: should be done by aura system
|
||||
if (VehicleScalingInfo const *scalingInfo = sObjectMgr->GetVehicleScalingInfo(m_vehicleInfo->m_ID))
|
||||
{
|
||||
Player *plr = unit->ToPlayer();
|
||||
|
||||
Reference in New Issue
Block a user