Skip to content

Commit

Permalink
added effect to random, addressing #246
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed May 29, 2015
1 parent 9c88b2a commit 8059bde
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cardshifter-core/src/main/resources/groovy/EffectDelegate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class EffectDelegate {
}]
}

private void targetedAction(EntityConsumer action, Object who, String desc) {
private Object targetedAction(EntityConsumer action, Object who, String desc) {
String targetStr = '';
Closure closure = null;
if (who instanceof String) {
Expand All @@ -153,6 +153,22 @@ class EffectDelegate {
Entity entity = entityLookup(source, who as String)
action.perform(source, entity)
}
} else if (who instanceof Integer) {
return [random: {Closure filter ->
FilterDelegate filterDelegate = FilterDelegate.fromClosure(filter)
Closure randomizedAction = {Entity source, Entity target ->
List<Entity> targets = filterDelegate.findMatching(source)
int count = who as int
Collections.shuffle(targets, source.game.random)
println "Targeting $who random of $targets with $desc"
targets.stream().limit(count).forEachOrdered({Entity dst ->
action.perform(source, dst)
})
}
description.append(desc.replace('%who%', "$who random $filterDelegate.description"))
description.append('\n')
closures.add(randomizedAction)
}]
} else if (who instanceof Closure) {
FilterDelegate filter = FilterDelegate.fromClosure(who as Closure)
targetStr = filter.description
Expand Down

0 comments on commit 8059bde

Please sign in to comment.