/// <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())); }
/// <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; }
/// <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) { // 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> /// 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> /// 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; }