internal CogContext(CastContext cc, SimpleStringDelegate descrtrv) { if (cc.unit != null) { loc = cc.unit.Location; spell = cc.spell; context = cc.context; name = cc.name; sfr = cc.sfr; spell = cc.spell; if (descrtrv != null) { targetDesc = descrtrv(context) + " "; } } }
/// <summary> /// Creates a behavior to cast an on ground spell by name on the location occupied by the specified unit /// </summary> /// <param name="spell"></param> /// <param name="onUnit"></param> /// <param name="requirements"></param> /// <param name="waitForSpell"></param> /// <returns></returns> public static Composite CastOnGround(string spellName, UnitSelectionDelegate onUnit, SimpleBooleanDelegate requirements, bool waitForSpell = true) { if (spellName == null || onUnit == null || requirements == null) return new ActionAlwaysFail(); SpellFindDelegate ssd = (object ctx, out SpellFindResults sfr) => { if (! SpellManager.FindSpell(spellName, out sfr)) { AddUndefinedSpell(spellName); return false; } return true; }; #if ERR return new PrioritySelector( ctx => new CastContext(ctx, ssd, onUnit), new PrioritySelector( ctx => new CogContext(ctx as CastContext, desc => string.Format("on {0} @ {1:F1}%", desc.CastContext().unit.SafeName(), desc.CastContext().unit.HealthPercent)), ContextCastOnGround(requirements, waitForSpell) ) ); #else return new PrioritySelector( ctx => { CastContext cc = new CastContext(ctx, ssd, onUnit); CogContext cog = new CogContext(cc, desc => string.Format("on {0} @ {1:F1}%", cc.unit.SafeName(), cc.unit.HealthPercent)); return cog; }, ContextCastOnGround(requirements, waitForSpell) ); #endif }