/// <summary> /// Apply the effects of the action to the target /// </summary> /// <param name="log"></param> /// <param name="context"></param> protected virtual void ApplyEffects(IActionLog log, EffectContext context) { foreach (var effect in Effects) { effect.Apply(log, context); } }
public override bool Apply(IActionLog log, EffectContext context) { // TODO: Test for immunity HitPoints hP = context?.Target?.GetData <HitPoints>(); if (hP != null) { // Calculate damage (taking account of target resistances/vulnerabilities) double damage = Damage * DamageType.MultiplierFor(context.Target); // Apply damage hP.Value -= damage; // Kill the target (if applicable) if (hP.Value <= 0) { Vector position = context.Target.GetData <MapData>()?.Position ?? Vector.Unset; context.SFX.Trigger(SFXKeywords.Bang, position); // Destroy! Equipped equipped = context.Target.GetData <Equipped>(); if (equipped != null) { // Drop held items! equipped.DropAll(context.Target, context); } context.Target.Delete(); } return(true); } else { return(false); } }
/// <summary> /// Apply the self-effects of the action, targetting the actor performing /// the action /// </summary> /// <param name="log"></param> /// <param name="context"></param> protected virtual void ApplySelfEffects(IActionLog log, EffectContext context) { context.Target = context.Actor; foreach (var effect in SelfEffects) { effect.Apply(log, context); } }
public override bool Apply(IActionLog log, EffectContext context) { if (context.Target != null) { context.Target.GetData <DisableActions>(true).LifeSpan += 1; return(true); } return(false); }
public override bool Apply(IActionLog log, EffectContext context) { if (UseTargetPosition) { context.SFX.Trigger(KeyWord, context.Target?.GetData <MapData>()?.Position ?? Vector.Unset, Direction); } else { context.SFX.Trigger(KeyWord, Position, Direction); } return(true); }
/// <summary> /// Drop all items in this /// </summary> /// <param name="dropper"></param> /// <param name="context"></param> /// <returns></returns> public bool DropAll(Element dropper, EffectContext context) { bool result = false; foreach (var slot in Slots) { if (slot.DropItem(dropper, context)) { result = true; } } return(result); }
/// <summary> /// Enact this action /// </summary> /// <param name="log"></param> /// <param name="context"></param> /// <returns></returns> public virtual bool Enact(IActionLog log, EffectContext context) { // Populate context: context = PrePopulateContext(context); if (Attempt(log, context)) { // Apply effects: ApplyEffects(log, context); ApplySelfEffects(log, context); return(true); } return(false); }
protected override void ApplyEffects(IActionLog log, EffectContext context) { if (Target != null) { var elements = Target.Contents.ToList(); foreach (var element in elements) { if (CanTarget(element)) { context.Target = element; base.ApplyEffects(log, context); } } } }
public override bool Apply(IActionLog log, EffectContext context) { int n = (int)Power; //TODO: Account for target mass? Element mover = context.Target; if (mover.IsDeleted || (mover.GetData <Inertia>()?.Fixed ?? false)) { return(false); // Target is immovable or deleted } if (mover != null) { bool moved = false; for (int i = 0; i < n; i++) { //Move element: MapData mD = mover.GetData <MapData>(); if (mD != null && mD.MapCell != null) { //SFX - Temp? Move elsewhere? /*Vector sfxPos = mD.Position; * Vector actorPos = context.Actor?.GetData<MapData>()?.Position ?? Vector.Unset; * if (actorPos.IsValid()) sfxPos = sfxPos.MoveTowards(actorPos, 0.3); * context.SFX.Trigger(SFXKeywords.Bash, sfxPos);*/ // Dust trail: context.SFX.Trigger(SFXKeywords.Dust, mD.Position); MapCell newCell = mD.MapCell.AdjacentCellInDirection(Direction); if (newCell != null && (mover.GetData <MapCellCollider>()?.CanEnter(newCell) ?? false)) { newCell.PlaceInCell(mover); moved = true; } } } if (moved && context.State is RLState) { var rlState = (RLState)context.State; rlState.DelayAITurn(); // Allow for a slight pause to register the movement } return(moved); } return(false); }
/// <summary> /// Drop the item held in this slot. /// This will remove the item from the slot. If the /// item is a PickUp it will be added back to the map. /// </summary> /// <param name="dropper">The element dropping the item</param> /// <param name="context">The current context</param> /// <returns></returns> public bool DropItem(Element dropper, EffectContext context) { if (Item != null) { if (Item.HasData <PickUp>() && context.State is MapState) //TODO: Work for other states? { MapData mD = dropper.GetData <MapData>(); if (mD.MapCell != null) { mD.MapCell.PlaceInCell(Item); } context.State.Elements.Add(Item); } Item = null; return(true); } return(false); }
protected override void ApplyEffects(IActionLog log, EffectContext context) { // Apply to all viable elements in all targeted cells foreach (MapCell cell in Target) { // Create a copy so that modifications to cell contents // don't screw up the enumeration: var elements = cell.Contents.ToList(); foreach (var element in elements) { if (CanTarget(element)) { context.Target = element; base.ApplyEffects(log, context); } } } }
public override bool Apply(IActionLog log, EffectContext context) { Element mover = context.Target; if (mover != null) { //Move element: MapData mD = mover.GetData <MapData>(); if (mD != null && mD.MapCell != null) { context.SFX.Trigger(SFXKeywords.Dust, mD.Position); MapCell newCell = context.Map[MoveTo]; if (newCell != null && (mover.GetData <MapCellCollider>()?.CanEnter(newCell) ?? true)) { newCell.PlaceInCell(mover); return(true); } } } return(false); }
public override bool Apply(IActionLog log, EffectContext context) { Element target = context.Target; if (target != null) { MapData mD = target.GetData <MapData>(); if (mD != null && mD.MapCell != null) { Vector sfxPos = mD.Position; Vector actorPos = context.Actor?.GetData <MapData>()?.Position ?? Vector.Unset; if (actorPos.IsValid()) { sfxPos = sfxPos.MoveTowards(actorPos, 0.3); } context.SFX.Trigger(SFXKeywords.Bash, sfxPos); return(true); } } return(false); }
public override bool Apply(IActionLog log, EffectContext context) { PickUp pickUp = context.Target?.GetData <PickUp>(); if (pickUp != null) // Can pick up { // Does it still exist on the map? MapData mD = context.Target.GetData <MapData>(); if (mD?.MapCell != null) { // TEMP? // Add to equipped: Equipped equipped = context.Actor?.GetData <Equipped>(); if (equipped != null && equipped.Equip(context.Target)) { mD.MapCell.RemoveFromCell(context.Target); context.State.Elements.Remove(context.Target); } // TODO: Add to inventory as well as/instead? } } return(false); }
public abstract bool Apply(IActionLog log, EffectContext context);
protected override EffectContext PrePopulateContext(EffectContext context) { // Overwrite the default target with the one defined by this action: context.Target = Target; return(base.PrePopulateContext(context)); }
public override bool Apply(IActionLog log, EffectContext context) { context.Actor.Orientation = OrientTo; //TODO: Make optional whether is applied to the actor or target? return(true); }
/// <summary> /// Attempt the action. Returns true if successful, false if not. /// Should be overridden to check skill levels etc. /// </summary> /// <param name="log"></param> /// <param name="context"></param> /// <returns></returns> public virtual bool Attempt(IActionLog log, EffectContext context) { return(true); }
public override bool Enact(IActionLog log, EffectContext context) { return(base.Enact(log, context)); }
/// <summary> /// Populate the context data before attempting to execute the action /// </summary> /// <param name="context"></param> protected virtual EffectContext PrePopulateContext(EffectContext context) { return(context); }