mirror of
https://github.com/correl/mage.git
synced 2024-12-26 19:16:54 +00:00
Fix Approach of the Second Sun
This commit is contained in:
parent
79648eb7ea
commit
db18af0161
1 changed files with 32 additions and 29 deletions
|
@ -1,8 +1,7 @@
|
||||||
package mage.cards.a;
|
package mage.cards.a;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
@ -61,10 +60,11 @@ class ApproachOfTheSecondSunEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
Spell spell = game.getStack().getSpell(source.getSourceId());
|
||||||
|
if (controller != null && spell != null) {
|
||||||
ApproachOfTheSecondSunWatcher watcher
|
ApproachOfTheSecondSunWatcher watcher
|
||||||
= (ApproachOfTheSecondSunWatcher) game.getState().getWatchers().get(ApproachOfTheSecondSunWatcher.class.getName(), source.getControllerId());
|
= (ApproachOfTheSecondSunWatcher) game.getState().getWatchers().get(ApproachOfTheSecondSunWatcher.class.getName());
|
||||||
if (watcher != null && watcher.getApproachesCast() > 1) {
|
if (watcher != null && watcher.getApproachesCast(controller.getId()) > 1 && spell.getFromZone() == Zone.HAND) {
|
||||||
// Win the game
|
// Win the game
|
||||||
controller.won(game);
|
controller.won(game);
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,23 +72,20 @@ class ApproachOfTheSecondSunEffect extends OneShotEffect {
|
||||||
controller.gainLife(7, game);
|
controller.gainLife(7, game);
|
||||||
|
|
||||||
// Put this into the library as the 7th from the top
|
// Put this into the library as the 7th from the top
|
||||||
Spell spell = game.getStack().getSpell(source.getSourceId());
|
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
|
||||||
if (spell != null) {
|
if (spellCard != null) {
|
||||||
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
|
List<Card> top6 = new ArrayList<>();
|
||||||
if (spellCard != null) {
|
// Cut the top 6 cards off into a temporary array
|
||||||
List<Card> top6 = new ArrayList<>();
|
for (int i = 0; i < 6 && controller.getLibrary().hasCards(); ++i) {
|
||||||
// Cut the top 6 cards off into a temporary array
|
top6.add(controller.getLibrary().removeFromTop(game));
|
||||||
for (int i = 0; i < 6 && controller.getLibrary().hasCards(); ++i) {
|
}
|
||||||
top6.add(controller.getLibrary().removeFromTop(game));
|
// Put this card (if the ability came from an ApproachOfTheSecondSun spell card) on top
|
||||||
}
|
controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, true, true);
|
||||||
// Put this card (if the ability came from an ApproachOfTheSecondSun spell card) on top
|
|
||||||
controller.moveCardToLibraryWithInfo(spellCard, source.getSourceId(), game, Zone.STACK, true, true);
|
|
||||||
|
|
||||||
// put the top 6 we took earlier back on top (going in reverse order this time to get them back
|
// put the top 6 we took earlier back on top (going in reverse order this time to get them back
|
||||||
// on top in the proper order)
|
// on top in the proper order)
|
||||||
for (int i = top6.size() - 1; i >= 0; --i) {
|
for (int i = top6.size() - 1; i >= 0; --i) {
|
||||||
controller.getLibrary().putOnTop(top6.get(i), game);
|
controller.getLibrary().putOnTop(top6.get(i), game);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,29 +97,35 @@ class ApproachOfTheSecondSunEffect extends OneShotEffect {
|
||||||
|
|
||||||
class ApproachOfTheSecondSunWatcher extends Watcher {
|
class ApproachOfTheSecondSunWatcher extends Watcher {
|
||||||
|
|
||||||
private int approachesCast = 0;
|
private Map<UUID, Integer> approachesCast = new HashMap<>();
|
||||||
|
|
||||||
public ApproachOfTheSecondSunWatcher() {
|
public ApproachOfTheSecondSunWatcher() {
|
||||||
super(ApproachOfTheSecondSunWatcher.class.getName(), WatcherScope.PLAYER);
|
super(ApproachOfTheSecondSunWatcher.class.getName(), WatcherScope.GAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApproachOfTheSecondSunWatcher(final ApproachOfTheSecondSunWatcher watcher) {
|
public ApproachOfTheSecondSunWatcher(final ApproachOfTheSecondSunWatcher watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
approachesCast = watcher.approachesCast;
|
approachesCast = new HashMap<>(approachesCast);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getPlayerId().equals(this.getControllerId())) {
|
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||||
Spell spell = game.getStack().getSpell(event.getSourceId());
|
Spell spell = game.getStack().getSpell(event.getSourceId());
|
||||||
if (spell != null && spell.getName().equals("Approach of the Second Sun")) {
|
if (spell != null && spell.getName().equals("Approach of the Second Sun")) {
|
||||||
++approachesCast;
|
int cast = getApproachesCast(event.getPlayerId());
|
||||||
|
approachesCast.put(event.getPlayerId(), cast + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getApproachesCast() {
|
public int getApproachesCast(UUID player) {
|
||||||
return approachesCast;
|
Integer cast = approachesCast.get(player);
|
||||||
|
if (cast == null) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return cast;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue