/// <summary> /// Get targets at the given position and return a targeting context /// with all extra information. The pattern will be rotated by /// the attack direction in order to produce correct targeted positions. /// If the attacker is null, the attack us considered anonymous. /// TODO: /// The targeted layer should be passed as a parameter. /// Having the block layer be defined on the provider is fine. /// </summary> public AttackTargetingContext GetTargets( Entity attacker, Layers targetLayer, IntVector2 attackerPosition, IntVector2 attackDirection) { var context = new AttackTargetingContext( targetContexts: _pattern.MakeContexts(attackerPosition, attackDirection).ToList(), pattern: _pattern, targetedLayer: targetLayer, blockLayer: _blockLayer ); _map(context); return(context); }
/// <summary> /// Leaves the first target context in the given targeting contexts for which the entity /// can be attacked. The targeting context will be emptied if there are no such entities. /// </summary> public static void SingleSimpleMap(AttackTargetingContext context) { var first = context.targetContexts.Where( c => _IsAttackableTarget_AndSetTransformAndAttackness(c, context.targetedLayer, context.blockLayer)).FirstOrDefault(); if (first != null) { context.targetContexts[0] = first; context.targetContexts.RemoveRange(1, context.targetContexts.Count - 1); } else { context.targetContexts.Clear(); } }
/// <summary> /// This map should be used by most weapons that make use of pattern's features. /// This map should be used if your weapon may target more than 1 entity at a time. /// </summary> public static void MultiDefaultMap(AttackTargetingContext context) { SetTargetEntitiesAndBlocks(context.targetContexts, context.targetedLayer, context.blockLayer); context.targetContexts = context.targetContexts.Where(_IsAttackableOrBlock).ToList(); if (context.targetContexts.Count == 0) { return; } context.targetContexts = DiscardUnreachable(context.targetContexts, context.pattern) .Where(c => !_IsBlock(c, context.blockLayer)) .ToList(); if (context.targetContexts.Count == 0) { return; } context.targetContexts = TakeAll_ThatCanBeAttacked_ByDefault(context.targetContexts); }