forked from External/mage
...
This commit is contained in:
parent
df642c2bd5
commit
3fa0e8b8f4
544 changed files with 13327 additions and 3074 deletions
|
|
@ -29,7 +29,9 @@
|
|||
package mage.game.stack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.Zone;
|
||||
|
|
@ -46,6 +48,14 @@ import mage.players.Player;
|
|||
*/
|
||||
public class SpellStack extends Stack<StackObject> {
|
||||
|
||||
public SpellStack () {}
|
||||
|
||||
public SpellStack(final SpellStack stack) {
|
||||
for (StackObject spell: stack) {
|
||||
this.push(spell.copy());
|
||||
}
|
||||
}
|
||||
|
||||
//resolve top StackObject
|
||||
public void resolve(Game game) {
|
||||
StackObject top = this.peek();
|
||||
|
|
@ -59,7 +69,6 @@ public class SpellStack extends Stack<StackObject> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean counter(UUID objectId, UUID sourceId, Game game) {
|
||||
StackObject stackObject = getStackObject(objectId);
|
||||
if (stackObject != null) {
|
||||
|
|
@ -76,32 +85,34 @@ public class SpellStack extends Stack<StackObject> {
|
|||
|
||||
public boolean replaceEvent(GameEvent event, Game game) {
|
||||
boolean caught = false;
|
||||
List<ReplacementEffect> rEffects = new ArrayList<ReplacementEffect>();
|
||||
Map<ReplacementEffect, Ability> rEffects = new LinkedHashMap<ReplacementEffect, Ability>();
|
||||
for (StackObject stackObject: this) {
|
||||
for (Ability ability: stackObject.getAbilities()) {
|
||||
if (ability.getZone() == Zone.STACK) {
|
||||
for (Effect effect: ability.getEffects()) {
|
||||
if (effect instanceof ReplacementEffect) {
|
||||
if (((ReplacementEffect)effect).applies(event, game))
|
||||
rEffects.add((ReplacementEffect) effect);
|
||||
if (((ReplacementEffect)effect).applies(event, ability, game))
|
||||
rEffects.put((ReplacementEffect) effect, ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rEffects.size() > 0) {
|
||||
List<ReplacementEffect> effects = new ArrayList(rEffects.keySet());
|
||||
int index;
|
||||
if (rEffects.size() == 1) {
|
||||
caught = rEffects.get(0).replaceEvent(event, game);
|
||||
index = 0;
|
||||
}
|
||||
else {
|
||||
Player player = game.getPlayer(event.getPlayerId());
|
||||
caught = rEffects.get(player.chooseEffect(rEffects, game)).replaceEvent(event, game);
|
||||
index = player.chooseEffect(effects, game);
|
||||
}
|
||||
caught = effects.get(index).replaceEvent(event, rEffects.get(effects.get(index)), game);
|
||||
}
|
||||
return caught;
|
||||
}
|
||||
|
||||
|
||||
public StackObject getStackObject(UUID id) {
|
||||
for (StackObject stackObject: this) {
|
||||
if (stackObject.getId().equals(id))
|
||||
|
|
@ -109,4 +120,8 @@ public class SpellStack extends Stack<StackObject> {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SpellStack copy() {
|
||||
return new SpellStack(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue