mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Reimplemented CastSpellLastTurnWatcher. Possible fix for Issue 337. (but still doesn't work correctly because of wrong behavior in game state copying).
This commit is contained in:
parent
21f9633486
commit
8a74175d21
3 changed files with 39 additions and 9 deletions
|
@ -46,6 +46,13 @@ public class NoSpellsWereCastLastTurnCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
||||
return watcher.getAmountOfSpellsCastOnPrevTurn() == 0;
|
||||
// if any player cast spell, return false
|
||||
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
|
||||
if (count > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// no one cast spell this turn
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,13 @@ public class TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
||||
return watcher.getAmountOfSpellsCastOnPrevTurn() >= 2;
|
||||
// if any player cast more than two spells, return true
|
||||
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
|
||||
if (count >= 2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// no one cast two or more spells this turn
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,18 @@ import mage.game.Game;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author nantuko, BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatcher> {
|
||||
|
||||
private int amountOfSpellsCastOnPrevTurn;
|
||||
private int amountOfSpellsCastOnCurrentTurn;
|
||||
private Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<UUID, Integer>();
|
||||
private Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<UUID, Integer>();
|
||||
|
||||
public CastSpellLastTurnWatcher() {
|
||||
super("CastSpellLastTurnWatcher", WatcherScope.GAME);
|
||||
|
@ -55,17 +59,29 @@ public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatch
|
|||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||
amountOfSpellsCastOnCurrentTurn++;
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
Integer amount = amountOfSpellsCastOnCurrentTurn.get(playerId);
|
||||
if (amount == null) {
|
||||
amount = Integer.valueOf(1);
|
||||
} else {
|
||||
amount = Integer.valueOf(amount+1);
|
||||
}
|
||||
amountOfSpellsCastOnCurrentTurn.put(playerId, amount);
|
||||
//Card card = game.getCard(event.getSourceId());
|
||||
//System.out.println("CAST: " + card.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
amountOfSpellsCastOnPrevTurn = amountOfSpellsCastOnCurrentTurn;
|
||||
amountOfSpellsCastOnCurrentTurn = 0;
|
||||
amountOfSpellsCastOnPrevTurn.clear();
|
||||
amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn);
|
||||
amountOfSpellsCastOnCurrentTurn.clear();
|
||||
}
|
||||
|
||||
public int getAmountOfSpellsCastOnPrevTurn() {
|
||||
public Map<UUID, Integer> getAmountOfSpellsCastOnPrevTurn() {
|
||||
return amountOfSpellsCastOnPrevTurn;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue