public static void AddAllParty(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { var cast = targets.Cast; if (cast.CasterChar != null) { // For Characters: Add the whole party if (targets.Cast.CasterChar.Group != null) { foreach (var member in cast.CasterChar.Group) { var chr = member.Character; if (chr != null) { targets.Add(chr); } } } else { failReason = SpellFailedReason.TargetNotInParty; } } else { var radius = targets.FirstHandler.GetRadius(); if (radius == 0) { // For NPCs: Add all friendly minions around (radius 30 if no radius is set?) radius = 30; } targets.AddAreaSource(cast.Spell.HasHarmfulEffects ? (TargetFilter)DefaultTargetFilters.IsFriendly : DefaultTargetFilters.IsHostile, ref failReason, radius); } }
/// <summary> /// Used for Lock picking and opening (with or without keys) /// </summary> public static void AddItemOrObject(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { if (targets.Cast.TargetItem == null && !(targets.Cast.SelectedTarget is GameObject)) { failReason = SpellFailedReason.BadTargets; } }
internal void Collect(SpellTargetCollection targets, ref SpellFailedReason failReason) { if (Adder != null) { Adder(targets, Filter, ref failReason); } }
internal void Collect(SpellTargetCollection targets, ref SpellFailedReason failReason) { if (this.Adder == null) { return; } this.Adder(targets, this.Filter, ref failReason); }
public static void AddObject(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { if (!(targets.Cast.SelectedTarget is GameObject)) { failReason = SpellFailedReason.BadTargets; } else { targets.Add(targets.Cast.SelectedTarget); } }
private void CreateHandler(SpellEffect effect, int h, SpellEffectHandler[] handlers, ref SpellTargetCollection targets, ref SpellFailedReason failReason) { var handler = effect.SpellEffectHandlerCreator(this, effect); handlers[h] = handler; // make sure, we have the right Caster-Type handler.CheckCasterType(ref failReason); if (failReason != SpellFailedReason.Ok) { return; } // find targets and amount SpellTargetCollection if effects have same ImplicitTargetTypes if (InitialTargets != null) { // do we have given targets? if (targets == null) { targets = CreateSpellTargetCollection(); } } else if (handler.HasOwnTargets) { // see if targets are shared between effects targets = null; for (var j = 0; j < h; j++) { var handler2 = handlers[j]; if (handler.Effect.SharesTargetsWith(handler2.Effect, IsAICast)) { // same targets -> share target collection targets = handler2.m_targets; break; } } if (targets == null) { targets = CreateSpellTargetCollection(); } } if (targets != null) { handler.m_targets = targets; targets.m_handlers.Add(handler); } }
public static void AddSelf(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { var self = targets.Cast.CasterObject; if (self == null) { // invalid trigger proc log.Warn("Invalid SpellCast tried to target self, but no Caster given: {0}", targets.Cast); failReason = SpellFailedReason.Error; return; } if ((failReason = targets.ValidateTargetForHandlers(self)) == SpellFailedReason.Ok) { targets.Add(self); } }
public static void AddChannelObject(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { var caster = targets.Cast.CasterUnit; if (caster != null) { if (caster.ChannelObject != null) { if ((failReason = targets.ValidateTarget(caster.ChannelObject, filter)) == SpellFailedReason.Ok) { targets.Add(caster.ChannelObject); } } else { failReason = SpellFailedReason.BadTargets; } } }
public static void AddSelf(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { WorldObject casterObject = targets.Cast.CasterObject; if (casterObject == null) { DefaultTargetAdders.log.Warn("Invalid SpellCast tried to target self, but no Caster given: {0}", (object)targets.Cast); failReason = SpellFailedReason.Error; } else { if ((sbyte)(failReason = targets.ValidateTargetForHandlers(casterObject)) != (sbyte)-1) { return; } targets.Add(casterObject); } }
public static void AddTargetsInArea(this SpellTargetCollection targets, Vector3 pos, TargetFilter targetFilter, float radius) { var handler = targets.FirstHandler; var spell = handler.Effect.Spell; var cast = handler.Cast; int limit; if (spell.MaxTargetEffect != null) { limit = spell.MaxTargetEffect.CalcEffectValue(cast.CasterReference); } else { //if IsAllied (used by group/raid spell targeting) it's save to asume the limit is the raid max size (40 players) since some spells have wrong dbc values if (targetFilter == DefaultTargetFilters.IsAllied) { limit = 40; } else { limit = (int)spell.MaxTargets; } } if (limit < 1) { limit = int.MaxValue; } cast.Map.IterateObjects(pos, radius > 0 ? radius : 5, cast.Phase, obj => { // AoE spells only make sense on Unit targets (at least there is no known spell that does anything else) if (obj is Unit && targets.ValidateTarget(obj, targetFilter) == SpellFailedReason.Ok) { return(targets.AddOrReplace(obj, limit)); } return(true); }); }
/// <summary> /// /// </summary> public static void AddSecondHighestThreatTarget(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { var caster = targets.Cast.CasterUnit as NPC; if (caster == null) { failReason = SpellFailedReason.NoValidTargets; return; } var nearest = caster.ThreatCollection.GetAggressorByThreatRank(2); if (nearest != null) { targets.Add(nearest); } else { failReason = SpellFailedReason.NoValidTargets; } }
/// <summary> /// /// </summary> public static void AddSecondHighestThreatTarget(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { NPC casterUnit = targets.Cast.CasterUnit as NPC; if (casterUnit == null) { failReason = SpellFailedReason.NoValidTargets; } else { Unit aggressorByThreatRank = casterUnit.ThreatCollection.GetAggressorByThreatRank(2); if (aggressorByThreatRank != null) { targets.Add((WorldObject)aggressorByThreatRank); } else { failReason = SpellFailedReason.NoValidTargets; } } }
public static void AddPet(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { var caster = targets.Cast.CasterObject; if (!(caster is Character)) { log.Warn("Non-Player {0} tried to cast Pet - spell {1}", caster, targets.Cast.Spell); failReason = SpellFailedReason.TargetNotPlayer; return; } var pet = ((Character)caster).ActivePet; if (pet == null) { failReason = SpellFailedReason.NoPet; return; } targets.Add(pet); }
public static void AddChannelObject(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { Unit casterUnit = targets.Cast.CasterUnit; if (casterUnit == null) { return; } if (casterUnit.ChannelObject != null) { if ((sbyte)(failReason = targets.ValidateTarget(casterUnit.ChannelObject, filter)) != (sbyte)-1) { return; } targets.Add(casterUnit.ChannelObject); } else { failReason = SpellFailedReason.BadTargets; } }
public static void AddAllParty(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { SpellCast cast = targets.Cast; if (cast.CasterChar != null) { if (targets.Cast.CasterChar.Group != null) { foreach (GroupMember groupMember in cast.CasterChar.Group) { Character character = groupMember.Character; if (character != null) { targets.Add((WorldObject)character); } } } else { failReason = SpellFailedReason.TargetNotInParty; } } else { float radius = targets.FirstHandler.GetRadius(); if ((double)radius == 0.0) { radius = 30f; } targets.AddAreaSource( cast.Spell.HasHarmfulEffects ? new TargetFilter(DefaultTargetFilters.IsFriendly) : new TargetFilter(DefaultTargetFilters.IsHostile), ref failReason, radius); } }
public static void AddTargetsInArea(this SpellTargetCollection targets, Vector3 pos, TargetFilter targetFilter, float radius) { SpellEffectHandler firstHandler = targets.FirstHandler; Spell spell = firstHandler.Effect.Spell; SpellCast cast = firstHandler.Cast; int limit = spell.MaxTargetEffect == null ? (!(targetFilter == new TargetFilter(DefaultTargetFilters.IsAllied)) ? (int)spell.MaxTargets : 40) : spell.MaxTargetEffect.CalcEffectValue(cast.CasterReference); if (limit < 1) { limit = int.MaxValue; } cast.Map.IterateObjects(pos, (double)radius > 0.0 ? radius : 5f, cast.Phase, (Func <WorldObject, bool>)(obj => { if (obj is Unit && targets.ValidateTarget(obj, targetFilter) == SpellFailedReason.Ok) { return(targets.AddOrReplace(obj, limit)); } return(true); })); }
public static void AddPet(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { WorldObject casterObject = targets.Cast.CasterObject; if (!(casterObject is Character)) { DefaultTargetAdders.log.Warn("Non-Player {0} tried to cast Pet - spell {1}", (object)casterObject, (object)targets.Cast.Spell); failReason = SpellFailedReason.TargetNotPlayer; } else { NPC activePet = ((Character)casterObject).ActivePet; if (activePet == null) { failReason = SpellFailedReason.NoPet; } else { targets.Add((WorldObject)activePet); } } }
private void CreateHandler(SpellEffect effect, int h, SpellEffectHandler[] handlers, ref SpellTargetCollection targets, ref SpellFailedReason failReason) { var handler = effect.SpellEffectHandlerCreator(this, effect); handlers[h] = handler; // make sure, we have the right Caster-Type handler.CheckCasterType(ref failReason); if (failReason != SpellFailedReason.Ok) { return; } // find targets and amount SpellTargetCollection if effects have same ImplicitTargetTypes if (m_initialTargets != null) { // do we have given targets? //targets = SpellTargetCollection.SpellTargetCollectionPool.Obtain(); if (targets == null) { targets = new SpellTargetCollection(); } } else if (handler.HasOwnTargets) { targets = null; // check if we have same target-types, else collect targets specifically for this Effect for (var j = 0; j < h; j++) { var handler2 = handlers[j]; if (handler.Effect.TargetsEqual(handler2.Effect)) { targets = handler2.m_targets; break; } } if (targets == null) { //targets = SpellTargetCollection.SpellTargetCollectionPool.Obtain(); targets = new SpellTargetCollection(); } } if (targets != null) { handler.m_targets = targets; targets.m_handlers.Add(handler); } }
/// <summary> /// Cleans up (if there is anything to clean) /// </summary> internal protected virtual void Cleanup() { m_cast = null; if (m_targets != null) { m_targets.Dispose(); m_targets = null; } }
/// <summary>Adds the selected targets and chain-targets (if any)</summary> public static void AddSelection(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason, bool harmful) { SpellCast cast = targets.Cast; if (cast == null) { return; } Unit casterObject = cast.CasterObject as Unit; WorldObject target = cast.SelectedTarget; if (target == null) { if (casterObject == null) { DefaultTargetAdders.log.Warn( "Invalid SpellCast, tried to add Selection but nothing selected and no Caster present: {0}", (object)targets.Cast); failReason = SpellFailedReason.Error; return; } target = (WorldObject)casterObject.Target; if (target == null) { failReason = SpellFailedReason.BadTargets; return; } } SpellEffect effect = targets.FirstHandler.Effect; Spell spell = effect.Spell; if (target != casterObject && casterObject != null) { if (!casterObject.IsInMaxRange(spell, target)) { failReason = SpellFailedReason.OutOfRange; } else if (casterObject.IsPlayer && !target.IsInFrontOf((WorldObject)casterObject)) { failReason = SpellFailedReason.UnitNotInfront; } } if (failReason != SpellFailedReason.Ok) { return; } failReason = targets.ValidateTarget(target, filter); if (failReason != SpellFailedReason.Ok) { return; } targets.Add(target); int limit = effect.ChainTargets; if (casterObject != null) { limit = casterObject.Auras.GetModifiedInt(SpellModifierType.ChainTargets, spell, limit); } if (limit <= 1 || !(target is Unit)) { return; } targets.FindChain((Unit)target, filter, true, limit); }
/// <summary> /// Your current summon or self /// </summary> public static void AddSummon(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { // if (Handler.SpellCast.Caster.Summon == null) targets.AddSelf(filter, ref failReason); }
/// <summary> /// Adds the selected targets and chain-targets (if any) /// </summary> public static void AddSelection(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason, bool harmful) { var cast = targets.Cast; if (cast == null) { return; } var caster = cast.CasterObject as Unit; var selected = cast.SelectedTarget; if (selected == null) { if (caster == null) { log.Warn("Invalid SpellCast, tried to add Selection but nothing selected and no Caster present: {0}", targets.Cast); failReason = SpellFailedReason.Error; return; } selected = caster.Target; if (selected == null) { failReason = SpellFailedReason.BadTargets; return; } } var effect = targets.FirstHandler.Effect; var spell = effect.Spell; if (selected != caster && caster != null) { if (!caster.IsInMaxRange(spell, selected)) { failReason = SpellFailedReason.OutOfRange; } else if (caster.IsPlayer && !selected.IsInFrontOf(caster)) { failReason = SpellFailedReason.UnitNotInfront; } } if (failReason == SpellFailedReason.Ok) { // standard checks failReason = targets.ValidateTarget(selected, filter); if (failReason == SpellFailedReason.Ok) { // add target and look for more if we have a chain effect targets.Add(selected); var chainCount = effect.ChainTargets; if (caster != null) { chainCount = caster.Auras.GetModifiedInt(SpellModifierType.ChainTargets, spell, chainCount); } if (chainCount > 1 && selected is Unit) { targets.FindChain((Unit)selected, filter, true, chainCount); } } } }
public static void AddAreaDest(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason, float radius) { targets.AddTargetsInArea(targets.Cast.TargetLoc, filter, radius); }
public static void AddChain(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { AddSelection(targets, filter, ref failReason, false); }
/// <summary> /// Adds targets around the target area /// </summary> public static void AddAreaDest(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { AddAreaDest(targets, filter, ref failReason, targets.FirstHandler.GetRadius()); }
/// <summary>Your current summon or self</summary> public static void AddSummon(this SpellTargetCollection targets, TargetFilter filter, ref SpellFailedReason failReason) { targets.AddSelf(filter, ref failReason); }