/// <summary>Duel target type</summary> /// <param name="targets"></param> /// <param name="target"></param> /// <param name="failedReason"></param> public static void IsHostileOrHealable(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { WorldObject casterObject = effectHandler.Cast.CasterObject; Spell spell = effectHandler.Cast.Spell; bool hasHarmfulEffects = spell.HasHarmfulEffects; if (spell.HasHarmfulEffects == spell.HasBeneficialEffects) { return; } if (hasHarmfulEffects != casterObject.MayAttack((IFactionMember)target)) { if (hasHarmfulEffects) { failedReason = SpellFailedReason.TargetFriendly; } else { failedReason = SpellFailedReason.TargetEnemy; } } else { if (!hasHarmfulEffects || target.CanBeHarmed) { return; } failedReason = SpellFailedReason.NotHere; } }
protected Buff(int id, FightActor target, FightActor caster, SpellEffectHandler effectHandler, Spell spell, bool critical, FightDispellableEnum dispelable, FightActor triggerer = null) { Id = id; Target = target; Caster = caster; EffectHandler = effectHandler; Spell = spell; Critical = critical; Duration = triggerer != null && EffectFix?.TriggerBuffDuration != null ? (short)EffectFix.TriggerBuffDuration : (short)(EffectHandler.Duration == -1 ? -1000 : Effect.Duration); Dispellable = EffectFix?.Dispellable != null ? (FightDispellableEnum)EffectFix.Dispellable : dispelable; Delay = (short)EffectHandler.Delay; CustomActionId = (short?)EffectFix?.ActionId; Efficiency = 1.0d; if (triggerer == null && effectHandler.CastHandler?.Informations.Triggerer != null) { triggerer = effectHandler.CastHandler.Informations.Triggerer; } BuffTriggered = triggerer != null; DecrementReference = triggerer ?? Caster; }
public static void IsFriendly(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (effectHandler.Cast.CasterObject.MayAttack(target)) { failedReason = SpellFailedReason.TargetEnemy; } }
/// <summary> /// /// </summary> public static void IsVisible(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { failedReason = effectHandler.Cast.CasterUnit.CanSee(target) ? SpellFailedReason.Ok : SpellFailedReason.BmOrInvisgod; }
/// <summary> /// Duel target type /// </summary> /// <param name="targets"></param> /// <param name="target"></param> /// <param name="failedReason"></param> public static void IsHostileOrHealable(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { var caster = effectHandler.Cast.CasterObject; var spell = effectHandler.Cast.Spell; var isHarmful = spell.HasHarmfulEffects; var isHarmfulAndBeneficial = spell.HasHarmfulEffects == spell.HasBeneficialEffects; if (!isHarmfulAndBeneficial) { if (isHarmful != caster.MayAttack(target)) { if (isHarmful) { failedReason = SpellFailedReason.TargetFriendly; } else { failedReason = SpellFailedReason.TargetEnemy; } } else if (isHarmful && !target.CanBeHarmed) { failedReason = SpellFailedReason.NotHere; } } }
public void AddSpellEffectHandler(SpellEffectHandler handler) { var type = handler.GetType(); if (type.GetCustomAttribute <DefaultEffectHandlerAttribute>() != null) { throw new Exception("Default handler cannot be added"); } var attributes = type.GetCustomAttributes <EffectHandlerAttribute>().ToArray(); if (attributes.Length == 0) { throw new Exception(string.Format("EffectHandler '{0}' has no EffectHandlerAttribute", type.Name)); } var ctor = type.GetConstructor(new[] { typeof(EffectDice), typeof(FightActor), typeof(SpellCastHandler), typeof(Cell), typeof(bool) }); if (ctor == null) { throw new Exception("No valid constructors found !"); } foreach (var effect in attributes.Select(entry => entry.Effect)) { m_spellsEffectHandler.Add(effect, ctor.CreateDelegate <SpellEffectConstructor>()); if (!m_effectsHandlers.ContainsKey(effect)) { m_effectsHandlers.Add(effect, new List <Type>()); } m_effectsHandlers[effect].Add(type); } }
public static void IsSameClass(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { var caster = effectHandler.Cast.CasterUnit; if (caster == null || !(target is Unit) || caster.Class != ((Unit)target).Class) { failedReason = SpellFailedReason.BadTargets; } }
public static void IsSamePartyAndClass(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { IsAllied(effectHandler, target, ref failedReason); if (failedReason == SpellFailedReason.Ok) { IsSameClass(effectHandler, target, ref failedReason); } }
public static void IsAllied(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (effectHandler.Cast.CasterObject.IsAlliedWith((IFactionMember)target)) { return; } failedReason = SpellFailedReason.TargetNotInParty; }
public static void IsFriendly(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (!effectHandler.Cast.CasterObject.MayAttack((IFactionMember)target)) { return; } failedReason = SpellFailedReason.TargetEnemy; }
public override bool IsTargetValid(FightActor actor, SpellEffectHandler handler) { if (Caster) { return(Required ? handler.Caster.HasState(State) : !handler.Caster.HasState(State)); } return(Required ? actor.HasState(State) : !actor.HasState(State)); }
/// <summary> /// AI heal spells. /// This evaluator demonstrates how to losen constraints - i.e. don't go for the best choice, but go for anyone that satisfies some condition. /// </summary> public static int AnyWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (!(target is Unit)) { return(int.MaxValue); } Unit unit = (Unit)target; return(unit.MaxHealth - unit.Health >= effectHandler.CalcDamageValue() / 2 ? -1 : 0); }
/// <summary>AI heal spells</summary> public static int MostWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (!(target is Unit)) { return(int.MaxValue); } Unit unit = (Unit)target; return(-Math.Min(unit.MaxHealth - unit.Health, effectHandler.CalcDamageValue())); }
public static void IsSamePartyAndClass(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { DefaultTargetFilters.IsAllied(effectHandler, target, ref failedReason); if (failedReason != SpellFailedReason.Ok) { return; } DefaultTargetFilters.IsSameClass(effectHandler, target, ref failedReason); }
public TriggerBuff(int id, FightActor target, FightActor caster, SpellEffectHandler effect, Spell spell, Spell parentSpell, bool critical, FightDispellableEnum dispelable, int priority, TriggerBuffApplyHandler applyTrigger, TriggerBuffRemoveHandler removeTrigger = null) : base(id, target, caster, effect, spell, critical, dispelable) { ParentSpell = parentSpell; ApplyTrigger = applyTrigger; RemoveTrigger = removeTrigger; Triggers = Effect.Triggers.Split('|').Select(GetTriggerFromString).ToList(); }
/// <summary> /// /// </summary> public static int NearestEvaluator(SpellEffectHandler effectHandler, WorldObject target) { WorldObject casterObject = effectHandler.Cast.CasterObject; if (casterObject == null) { return(0); } return((int)(casterObject.GetDistanceSq(target) * 10.0)); }
public static void IsSameClass(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { Unit casterUnit = effectHandler.Cast.CasterUnit; if (casterUnit != null && target is Unit && casterUnit.Class == ((Unit)target).Class) { return; } failedReason = SpellFailedReason.BadTargets; }
public static void IsHostile(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { var caster = effectHandler.Cast.CasterObject; if (!caster.MayAttack(target)) { failedReason = SpellFailedReason.TargetFriendly; } else if (!target.CanBeHarmed) { failedReason = SpellFailedReason.NotHere; } }
/// <summary> /// /// </summary> public static int NearestEvaluator(SpellEffectHandler effectHandler, WorldObject target) { var caster = effectHandler.Cast.CasterObject; if (caster == null) { // no one is near or close return 0; } // the less the squared distance, the closer the target // less means better in evaluators return (int)(caster.GetDistanceSq(target) * 10); // round the float to one digit after the dot }
public static void IsInFrontOfCaster(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason, TargetFilter filter) { var caster = effectHandler.Cast.CasterObject; if (caster.IsPlayer && !target.IsInFrontOf(caster)) { failedReason = SpellFailedReason.NotInfront; } else { filter(effectHandler, target, ref failedReason); } }
/// <summary> /// AI heal spells /// </summary> public static int MostWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (target is Unit) { // try to select the most wounded var unit = (Unit)target; var missingHealth = unit.MaxHealth - unit.Health; // cap at the max that the spell can heal // else weaker creatures might never get healed, simply because they can't lose as much health return(-Math.Min(missingHealth, effectHandler.CalcDamageValue())); } return(int.MaxValue); }
/// <summary> /// /// </summary> public static int NearestEvaluator(SpellEffectHandler effectHandler, WorldObject target) { var caster = effectHandler.Cast.CasterObject; if (caster == null) { // no one is near or close return(0); } // the less the squared distance, the closer the target // less means better in evaluators return((int)(caster.GetDistanceSq(target) * 10)); // round the float to one digit after the dot }
/// <summary> /// AI heal spells /// </summary> public static int MostWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (target is Unit) { // try to select the most wounded var unit = (Unit)target; var missingHealth = unit.MaxHealth - unit.Health; // cap at the max that the spell can heal // else weaker creatures might never get healed, simply because they can't lose as much health return -Math.Min(missingHealth, effectHandler.CalcDamageValue()); } return int.MaxValue; }
/// <summary> /// Only select targets that have at least half of what the effect can heal /// </summary> public static void IsWoundedEnough(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (target is Unit) { Unit unit = (Unit)target; if (unit.MaxHealth - unit.Health >= effectHandler.CalcDamageValue() / 2) { return; } } failedReason = SpellFailedReason.AlreadyAtFullHealth; }
public static void IsAllied(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { //if (targets.Cast.Caster is Character && target is Character) //{ // var caster = (Character)targets.Cast.Caster; // if (!caster.IsAlliedWith(target)) // { // failedReason = SpellFailedReason.TargetNotInParty; // } //} if (!effectHandler.Cast.CasterObject.IsAlliedWith(target)) { failedReason = SpellFailedReason.TargetNotInParty; } }
public static void IsHostile(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (!effectHandler.Cast.CasterObject.MayAttack((IFactionMember)target)) { failedReason = SpellFailedReason.TargetFriendly; } else { if (target.CanBeHarmed) { return; } failedReason = SpellFailedReason.NotHere; } }
public override bool IsTargetValid(FightActor actor, SpellEffectHandler handler) { if (Caster) { actor = handler.Caster; } if (actor is CharacterFighter) { return(Required ? (int)((CharacterFighter)actor).Character.BreedId == Breed : (int)((CharacterFighter)actor).Character.BreedId != Breed); } else { return(Required ? (int)BreedEnum.MONSTER == Breed : (int)BreedEnum.MONSTER != Breed); } }
/// <summary> /// Is caster behind target? /// </summary> public static void IsCasterBehind(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { var caster = effectHandler.Cast.CasterObject; if (!caster.IsBehind(target)) { failedReason = SpellFailedReason.NotBehind; } else { var harmful = effectHandler.Cast.Spell.HasHarmfulEffects; if (harmful != caster.MayAttack(target)) { failedReason = harmful ? SpellFailedReason.TargetFriendly : SpellFailedReason.TargetEnemy; } } }
public override void Execute() { if (!this.m_initialized) { this.Initialize(); } SpellEffectHandler[] handlers = this.Handlers; for (int i = 0; i < handlers.Length; i++) { SpellEffectHandler spellEffectHandler = handlers[i]; if (spellEffectHandler is DefaultSpellEffect && (int)spellEffectHandler.Effect.EffectId != 1160) { string dump = string.Format("{0}[{1}] : EffectId = {2} ; Target = {3} ; AffectedCells = {4} \n", this.Spell.Template.Name, i, spellEffectHandler.Effect.EffectId, spellEffectHandler.Targets.ToString(), string.Join("/", spellEffectHandler.AffectedCells.Select(x => x.Id))); System.IO.File.AppendAllText("spell_effects.txt", dump); } spellEffectHandler.Apply(); } }
/// <summary> /// Only select targets that have at least half of what the effect can heal /// </summary> public static void IsWoundedEnough(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { if (target is Unit) { // useful heal spell: Amount to be healed is greater or equal half of what the spell can heal // Select anyone with that problem var unit = (Unit)target; var missingHealth = unit.MaxHealth - unit.Health; if (missingHealth >= effectHandler.CalcDamageValue() / 2) { // good choice return; } } // not wounded or not wounded enough failedReason = SpellFailedReason.AlreadyAtFullHealth; }
/// <summary> /// AI heal spells. /// This evaluator demonstrates how to losen constraints - i.e. don't go for the best choice, but go for anyone that satisfies some condition. /// </summary> public static int AnyWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (target is Unit) { // useful heal spell: Amount to be healed is greater or equal half of what the spell can heal // Select anyone with that problem var unit = (Unit)target; var missingHealth = unit.MaxHealth - unit.Health; if (missingHealth >= effectHandler.CalcDamageValue() / 2) { // good choice return -1; } // not so good choice return 0; } // should never happen return int.MaxValue; }
/// <summary>Is caster behind target?</summary> public static void IsCasterBehind(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { WorldObject casterObject = effectHandler.Cast.CasterObject; if (!casterObject.IsBehind(target)) { failedReason = SpellFailedReason.NotBehind; } else { bool hasHarmfulEffects = effectHandler.Cast.Spell.HasHarmfulEffects; if (hasHarmfulEffects == casterObject.MayAttack((IFactionMember)target)) { return; } failedReason = hasHarmfulEffects ? SpellFailedReason.TargetFriendly : SpellFailedReason.TargetEnemy; } }
/// <summary> /// AI heal spells. /// This evaluator demonstrates how to losen constraints - i.e. don't go for the best choice, but go for anyone that satisfies some condition. /// </summary> public static int AnyWoundedEvaluator(SpellEffectHandler effectHandler, WorldObject target) { if (target is Unit) { // useful heal spell: Amount to be healed is greater or equal half of what the spell can heal // Select anyone with that problem var unit = (Unit)target; var missingHealth = unit.MaxHealth - unit.Health; if (missingHealth >= effectHandler.CalcDamageValue() / 2) { // good choice return(-1); } // not so good choice return(0); } // should never happen return(int.MaxValue); }
public static void IsInFrontAndHostile(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { IsInFrontOfCaster(effectHandler, target, ref failedReason, IsHostile); }
public static int RandomEvaluator(SpellEffectHandler effectHandler, WorldObject target) { return Utility.Random(0, int.MaxValue); }
/// <summary> /// /// </summary> public static void IsNotPlayer(SpellEffectHandler effectHandler, WorldObject target, ref SpellFailedReason failedReason) { failedReason = target is Character ? SpellFailedReason.TargetIsPlayer : SpellFailedReason.Ok; }