mirror of
https://github.com/correl/mage.git
synced 2025-03-16 09:16:26 -09: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
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
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
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher");
|
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.game.events.GameEvent;
|
||||||
import mage.watchers.WatcherImpl;
|
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> {
|
public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatcher> {
|
||||||
|
|
||||||
private int amountOfSpellsCastOnPrevTurn;
|
private Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<UUID, Integer>();
|
||||||
private int amountOfSpellsCastOnCurrentTurn;
|
private Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<UUID, Integer>();
|
||||||
|
|
||||||
public CastSpellLastTurnWatcher() {
|
public CastSpellLastTurnWatcher() {
|
||||||
super("CastSpellLastTurnWatcher", WatcherScope.GAME);
|
super("CastSpellLastTurnWatcher", WatcherScope.GAME);
|
||||||
|
@ -55,17 +59,29 @@ public class CastSpellLastTurnWatcher extends WatcherImpl<CastSpellLastTurnWatch
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
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
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
amountOfSpellsCastOnPrevTurn = amountOfSpellsCastOnCurrentTurn;
|
amountOfSpellsCastOnPrevTurn.clear();
|
||||||
amountOfSpellsCastOnCurrentTurn = 0;
|
amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn);
|
||||||
|
amountOfSpellsCastOnCurrentTurn.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmountOfSpellsCastOnPrevTurn() {
|
public Map<UUID, Integer> getAmountOfSpellsCastOnPrevTurn() {
|
||||||
return amountOfSpellsCastOnPrevTurn;
|
return amountOfSpellsCastOnPrevTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue