Core/Vehicle: Added RideSpellID field to override npc_spellclick_spells
Port From (https://github.com/TrinityCore/TrinityCore/commit/46251b56553b610588eea89b83b4b4e8b88e47da)
This commit is contained in:
@@ -1497,7 +1497,7 @@ namespace Game.Entities
|
||||
|
||||
// // We need to be immune to all types
|
||||
return (schoolImmunityMask & schoolMask) == schoolMask;
|
||||
};
|
||||
}
|
||||
|
||||
// If m_immuneToSchool type contain this school type, IMMUNE damage.
|
||||
if (hasImmunity(m_spellImmune[(int)SpellImmunity.School]))
|
||||
@@ -2745,48 +2745,75 @@ namespace Game.Entities
|
||||
if (!Global.ConditionMgr.IsObjectMeetingSpellClickConditions(spellClickEntry, clickInfo.spellId, clicker, this))
|
||||
continue;
|
||||
|
||||
Unit caster = Convert.ToBoolean(clickInfo.castFlags & (byte)SpellClickCastFlags.CasterClicker) ? clicker : this;
|
||||
Unit target = Convert.ToBoolean(clickInfo.castFlags & (byte)SpellClickCastFlags.TargetClicker) ? clicker : this;
|
||||
ObjectGuid origCasterGUID = Convert.ToBoolean(clickInfo.castFlags & (byte)SpellClickCastFlags.OrigCasterOwner) ? GetOwnerGUID() : clicker.GetGUID();
|
||||
|
||||
SpellInfo spellEntry = Global.SpellMgr.GetSpellInfo(clickInfo.spellId, caster.GetMap().GetDifficultyID());
|
||||
spellClickHandled = HandleSpellClick(clicker, seatId, clickInfo.spellId, flags, clickInfo);
|
||||
// if (!spellEntry) should be checked at npc_spellclick load
|
||||
}
|
||||
|
||||
SpellCastResult castResult = SpellCastResult.Success;
|
||||
if (seatId > -1)
|
||||
Creature creature = ToCreature();
|
||||
if (creature != null && creature.IsAIEnabled())
|
||||
creature.GetAI().OnSpellClick(clicker, ref spellClickHandled);
|
||||
}
|
||||
|
||||
public bool HandleSpellClick(Unit clicker, sbyte seatId, uint spellId, TriggerCastFlags flags = TriggerCastFlags.None, SpellClickInfo spellClickInfo = null)
|
||||
{
|
||||
byte i = 0;
|
||||
bool valid = false;
|
||||
foreach (var spellEffectInfo in spellEntry.GetEffects())
|
||||
Unit caster = clicker;
|
||||
Unit target = this;
|
||||
ObjectGuid origCasterGUID = caster.GetGUID();
|
||||
SpellCastResult castResult = SpellCastResult.Success;
|
||||
|
||||
if (spellClickInfo != null)
|
||||
{
|
||||
caster = (spellClickInfo.castFlags & (byte)SpellClickCastFlags.CasterClicker) != 0 ? clicker : this;
|
||||
target = (spellClickInfo.castFlags & (byte)SpellClickCastFlags.TargetClicker) != 0 ? clicker : this;
|
||||
origCasterGUID = (spellClickInfo.castFlags & (byte)SpellClickCastFlags.OrigCasterOwner) != 0 ? GetOwnerGUID() : clicker.GetGUID();
|
||||
}
|
||||
|
||||
if (spellId == 0)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"No valid spell specified for clickee {target.GetGUID()} and clicker {caster.GetGUID()}!");
|
||||
return false;
|
||||
}
|
||||
|
||||
SpellInfo spellEntry = Global.SpellMgr.GetSpellInfo(spellId, caster.GetMap().GetDifficultyID());
|
||||
|
||||
byte effectIndex = 0;
|
||||
bool hasControlVehicleAura = false;
|
||||
foreach (SpellEffectInfo spellEffectInfo in spellEntry.GetEffects())
|
||||
{
|
||||
if (spellEffectInfo.ApplyAuraName == AuraType.ControlVehicle)
|
||||
{
|
||||
valid = true;
|
||||
hasControlVehicleAura = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
|
||||
++effectIndex;
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
if (seatId > -1)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Spell {0} specified in npc_spellclick_spells is not a valid vehicle enter aura!", clickInfo.spellId);
|
||||
continue;
|
||||
if (!hasControlVehicleAura)
|
||||
{
|
||||
if (spellClickInfo == null)
|
||||
Log.outError(LogFilter.Sql, $"RideSpell {spellId} specified in vehicle_accessory or vehicle_template_accessory is not a valid vehicle enter aura!");
|
||||
else
|
||||
Log.outError(LogFilter.Sql, $"Spell {spellId} specified in npc_spellclick_spells is not a valid vehicle enter aura!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsInMap(caster))
|
||||
{
|
||||
CastSpellExtraArgs args = new(flags);
|
||||
args.OriginalCaster = origCasterGUID;
|
||||
args.AddSpellMod(SpellValueMod.BasePoint0 + i, seatId + 1);
|
||||
castResult = caster.CastSpell(target, clickInfo.spellId, args);
|
||||
args.AddSpellMod(SpellValueMod.BasePoint0 + effectIndex, seatId + 1);
|
||||
castResult = caster.CastSpell(target, spellId, args);
|
||||
}
|
||||
else // This can happen during Player._LoadAuras
|
||||
else // This can happen during Player::_LoadAuras
|
||||
{
|
||||
int[] bp = new int[SpellConst.MaxEffects];
|
||||
foreach (var spellEffectInfo in spellEntry.GetEffects())
|
||||
foreach (SpellEffectInfo spellEffectInfo in spellEntry.GetEffects())
|
||||
bp[spellEffectInfo.EffectIndex] = (int)spellEffectInfo.BasePoints;
|
||||
|
||||
bp[i] = seatId;
|
||||
bp[effectIndex] = seatId;
|
||||
|
||||
AuraCreateInfo createInfo = new(ObjectGuid.Create(HighGuid.Cast, SpellCastSource.Normal, GetMapId(), spellEntry.Id, GetMap().GenerateLowGuid(HighGuid.Cast)), spellEntry, GetMap().GetDifficultyID(), SpellConst.MaxEffectMask, this);
|
||||
createInfo.SetCaster(clicker);
|
||||
@@ -2806,16 +2833,11 @@ namespace Game.Entities
|
||||
createInfo.SetCaster(clicker);
|
||||
createInfo.SetCasterGUID(origCasterGUID);
|
||||
|
||||
|
||||
Aura.TryRefreshStackOrCreate(createInfo);
|
||||
}
|
||||
}
|
||||
|
||||
spellClickHandled = castResult == SpellCastResult.Success;
|
||||
}
|
||||
|
||||
Creature creature = ToCreature();
|
||||
if (creature != null && creature.IsAIEnabled())
|
||||
creature.GetAI().OnSpellClick(clicker, ref spellClickHandled);
|
||||
return castResult == SpellCastResult.Success;
|
||||
}
|
||||
|
||||
public bool HasAura(uint spellId, ObjectGuid casterGUID = default, ObjectGuid itemCasterGUID = default, uint reqEffMask = 0)
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Game.Entities
|
||||
|
||||
foreach (var acc in accessories)
|
||||
if (!evading || acc.IsMinion) // only install minions on evade mode
|
||||
InstallAccessory(acc.AccessoryEntry, acc.SeatId, acc.IsMinion, acc.SummonedType, acc.SummonTime);
|
||||
InstallAccessory(acc.AccessoryEntry, acc.SeatId, acc.IsMinion, acc.SummonedType, acc.SummonTime, acc.RideSpellID);
|
||||
}
|
||||
|
||||
public void Uninstall()
|
||||
@@ -261,7 +261,7 @@ namespace Game.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
void InstallAccessory(uint entry, sbyte seatId, bool minion, byte type, uint summonTime)
|
||||
void InstallAccessory(uint entry, sbyte seatId, bool minion, byte type, uint summonTime, uint? rideSpellId = null)
|
||||
{
|
||||
// @Prevent adding accessories when vehicle is uninstalling. (Bad script in OnUninstall/OnRemovePassenger/PassengerBoarded hook.)
|
||||
|
||||
@@ -280,6 +280,9 @@ namespace Game.Entities
|
||||
if (minion)
|
||||
accessory.AddUnitTypeMask(UnitTypeMask.Accessory);
|
||||
|
||||
if (rideSpellId.HasValue)
|
||||
_me.HandleSpellClick(accessory, seatId, rideSpellId.Value);
|
||||
else
|
||||
_me.HandleSpellClick(accessory, seatId);
|
||||
|
||||
// If for some reason adding accessory to vehicle fails it will unsummon in
|
||||
@@ -797,19 +800,21 @@ namespace Game.Entities
|
||||
|
||||
public struct VehicleAccessory
|
||||
{
|
||||
public VehicleAccessory(uint entry, sbyte seatId, bool isMinion, byte summonType, uint summonTime)
|
||||
public VehicleAccessory(uint entry, sbyte seatId, bool isMinion, byte summonType, uint summonTime, uint? rideSpellID)
|
||||
{
|
||||
AccessoryEntry = entry;
|
||||
IsMinion = isMinion;
|
||||
SummonTime = summonTime;
|
||||
SeatId = seatId;
|
||||
SummonedType = summonType;
|
||||
RideSpellID = rideSpellID;
|
||||
}
|
||||
public uint AccessoryEntry;
|
||||
public bool IsMinion;
|
||||
public uint SummonTime;
|
||||
public sbyte SeatId;
|
||||
public byte SummonedType;
|
||||
public uint? RideSpellID;
|
||||
}
|
||||
|
||||
public class VehicleTemplate
|
||||
|
||||
@@ -11404,8 +11404,8 @@ namespace Game
|
||||
|
||||
uint count = 0;
|
||||
|
||||
// 0 1 2 3 4 5
|
||||
SQLResult result = DB.World.Query("SELECT `entry`, `accessory_entry`, `seat_id`, `minion`, `summontype`, `summontimer` FROM `vehicle_template_accessory`");
|
||||
// 0 1 2 3 4 5 6
|
||||
SQLResult result = DB.World.Query("SELECT `entry`, `accessory_entry`, `seat_id`, `minion`, `summontype`, `summontimer`, `RideSpellID` FROM `vehicle_template_accessory`");
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 vehicle template accessories. DB table `vehicle_template_accessory` is empty.");
|
||||
@@ -11421,6 +11421,18 @@ namespace Game
|
||||
byte summonType = result.Read<byte>(4);
|
||||
uint summonTimer = result.Read<uint>(5);
|
||||
|
||||
uint? rideSpellId = null;
|
||||
if (!result.IsNull(6))
|
||||
{
|
||||
rideSpellId = result.Read<uint>(6);
|
||||
|
||||
if (!Global.SpellMgr.HasSpellInfo(rideSpellId.Value, Difficulty.None))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `vehicle_template_accessory`: rideSpellId {rideSpellId} does not exist for entry {entry}.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetCreatureTemplate(entry) == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `vehicle_template_accessory`: creature template entry {0} does not exist.", entry);
|
||||
@@ -11439,7 +11451,7 @@ namespace Game
|
||||
continue;
|
||||
}
|
||||
|
||||
_vehicleTemplateAccessoryStore.Add(entry, new VehicleAccessory(accessory, seatId, isMinion, summonType, summonTimer));
|
||||
_vehicleTemplateAccessoryStore.Add(entry, new VehicleAccessory(accessory, seatId, isMinion, summonType, summonTimer, rideSpellId));
|
||||
|
||||
++count;
|
||||
}
|
||||
@@ -11455,8 +11467,8 @@ namespace Game
|
||||
|
||||
uint count = 0;
|
||||
|
||||
// 0 1 2 3 4 5
|
||||
SQLResult result = DB.World.Query("SELECT `guid`, `accessory_entry`, `seat_id`, `minion`, `summontype`, `summontimer` FROM `vehicle_accessory`");
|
||||
// 0 1 2 3 4 5 6
|
||||
SQLResult result = DB.World.Query("SELECT `guid`, `accessory_entry`, `seat_id`, `minion`, `summontype`, `summontimer`, `RideSpellID` FROM `vehicle_accessory`");
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
@@ -11473,13 +11485,25 @@ namespace Game
|
||||
byte uiSummonType = result.Read<byte>(4);
|
||||
uint uiSummonTimer = result.Read<uint>(5);
|
||||
|
||||
uint? rideSpellId = null;
|
||||
if (!result.IsNull(6))
|
||||
{
|
||||
rideSpellId = result.Read<uint>(6);
|
||||
|
||||
if (!Global.SpellMgr.HasSpellInfo(rideSpellId.Value, Difficulty.None))
|
||||
{
|
||||
Log.outError(LogFilter.Sql, $"Table `vehicle_accessory`: rideSpellId {rideSpellId} does not exist for guid {uiGUID}.");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (GetCreatureTemplate(uiAccessory) == null)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Table `vehicle_accessory`: Accessory {0} does not exist.", uiAccessory);
|
||||
continue;
|
||||
}
|
||||
|
||||
_vehicleAccessoryStore.Add(uiGUID, new VehicleAccessory(uiAccessory, uiSeat, bMinion, uiSummonType, uiSummonTimer));
|
||||
_vehicleAccessoryStore.Add(uiGUID, new VehicleAccessory(uiAccessory, uiSeat, bMinion, uiSummonType, uiSummonTimer, rideSpellId));
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user