Merge branch 'master' into master

This commit is contained in:
Zzooouhh 2017-12-22 23:17:20 +01:00 committed by GitHub
commit 6fae8ef606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 1721 additions and 503 deletions

View file

@ -0,0 +1,52 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.designations.DesignationType;
import mage.game.Game;
/**
*
* @author LvelX2
*/
public enum CitysBlessingCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
return game.getPlayer(source.getControllerId()).hasDesignation(DesignationType.CITYS_BLESSING);
}
@Override
public String toString() {
return "If you have the city's blessing";
}
}

View file

@ -0,0 +1,77 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.keyword;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.designations.CitysBlessing;
import mage.designations.DesignationType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class AscendEffect extends OneShotEffect {
public AscendEffect() {
super(Outcome.Detriment);
staticText = "Ascend (If you control ten or more permanents, you get the city's blessing for the rest of the game.)<br>";
}
public AscendEffect(final AscendEffect effect) {
super(effect);
}
@Override
public AscendEffect copy() {
return new AscendEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_ARTIFACT_CREATURE_ENCHANTMENT_OR_LAND, controller.getId(), game) > 9) {
if (!controller.hasDesignation(DesignationType.CITYS_BLESSING)) {
controller.addDesignation(new CitysBlessing());
game.informPlayers(controller.getLogName() + " gets the city's blessing for the rest of the game.");
} else {
game.informPlayers(controller.getLogName() + " already has the city's blessing.");
}
} else {
game.informPlayers(controller.getLogName() + " does not get the city's blessing.");
}
return true;
}
return false;
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.designations;
/**
*
* @author LevelX2
*/
public class CitysBlessing extends Designation {
public CitysBlessing() {
super(DesignationType.CITYS_BLESSING, "RIX");
}
}

View file

@ -5,6 +5,10 @@
*/
package mage.designations;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -14,6 +18,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.text.TextPart;
import mage.cards.FrameStyle;
import mage.constants.CardType;
import mage.constants.SubType;
@ -23,11 +28,6 @@ import mage.game.events.ZoneChangeEvent;
import mage.util.GameLog;
import mage.util.SubTypeList;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.UUID;
/**
*
* @author LevelX2
@ -40,27 +40,35 @@ public abstract class Designation implements MageObject {
private static ManaCostsImpl emptyCost = new ManaCostsImpl();
private String name;
private DesignationType designationType;
private UUID id;
private FrameStyle frameStyle;
private Abilities<Ability> abilites = new AbilitiesImpl<>();
private String expansionSetCodeForImage;
private final boolean unique; // can a designation be added multiple times (false) or only once to an object (true)
public Designation(String name, String expansionSetCode) {
this.name = name;
public Designation(DesignationType designationType, String expansionSetCode) {
this(designationType, expansionSetCode, true);
}
public Designation(DesignationType designationType, String expansionSetCode, boolean unique) {
this.name = designationType.name();
this.designationType = designationType;
this.id = UUID.randomUUID();
this.frameStyle = FrameStyle.M15_NORMAL;
this.expansionSetCodeForImage = expansionSetCode;
this.unique = unique;
}
public Designation(final Designation designation) {
this.id = designation.id;
this.name = designation.name;
this.designationType = designation.designationType;
this.frameStyle = designation.frameStyle;
this.abilites = designation.abilites.copy();
this.unique = designation.unique;
}
public abstract void start(Game game, UUID controllerId);
@Override
public FrameStyle getFrameStyle() {
return frameStyle;
@ -110,6 +118,10 @@ public abstract class Designation implements MageObject {
return this.id;
}
public DesignationType getDesignationType() {
return designationType;
}
public void setExpansionSetCodeForImage(String expansionSetCodeForImage) {
this.expansionSetCodeForImage = expansionSetCodeForImage;
}
@ -218,4 +230,38 @@ public abstract class Designation implements MageObject {
@Override
public void removePTCDA() {
}
/**
*
* @param game
* @param controllerId
*/
public void start(Game game, UUID controllerId) {
}
@Override
public boolean isAllCreatureTypes() {
return false;
}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public boolean isUnique() {
return unique;
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.designations;
/**
*
* @author LevelX2
*/
public enum DesignationType {
THE_MONARCH("The Monarch"),
CITYS_BLESSING("City's Blessing");
private final String text;
DesignationType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}

View file

@ -27,14 +27,11 @@
*/
package mage.designations;
import java.util.List;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.BeginningOfEndStepTriggeredAbility;
import mage.abilities.effects.common.BecomesMonarchTargetEffect;
import mage.abilities.effects.common.DrawCardTargetEffect;
import mage.abilities.text.TextPart;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.game.Game;
@ -50,40 +47,10 @@ import mage.target.targetpointer.FixedTarget;
public class Monarch extends Designation {
public Monarch() {
super("The Monarch", "CN2");
super(DesignationType.THE_MONARCH, "CN2");
addAbility(new MonarchDrawTriggeredAbility());
addAbility(new MonarchDealsCombatDamageToAPlayerTriggeredAbility());
}
/**
*
* @param game
* @param controllerId
*/
@Override
public void start(Game game, UUID controllerId) {
}
@Override
public boolean isAllCreatureTypes() {
return false;
}
@Override
public void setIsAllCreatureTypes(boolean value) {
}
@Override
public List<TextPart> getTextParts() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public TextPart addTextPart(TextPart textPart) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
// At the beginning of the monarchs end step, that player draws a card

View file

@ -34,6 +34,7 @@ public final class StaticFilters {
public static final FilterNonlandCard FILTER_CARD_A_NON_LAND = new FilterNonlandCard("a nonland card");
public static final FilterCard FILTER_CARD_ARTIFACT_OR_CREATURE = new FilterCard("artifact or creature card");
public static final FilterPermanent FILTER_PERMANENT = new FilterPermanent();
public static final FilterCreaturePermanent FILTER_ARTIFACT_CREATURE_PERMANENT = new FilterArtifactCreaturePermanent();
public static final FilterPermanent FILTER_PERMANENT_ARTIFACT_OR_CREATURE = new FilterPermanent("artifact or creature");
public static final FilterPermanent FILTER_PERMANENT_ARTIFACT_CREATURE_OR_ENCHANTMENT = new FilterPermanent("artifact, creature, or enchantment");
@ -42,6 +43,7 @@ public final class StaticFilters {
public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT = new FilterControlledPermanent();
public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT_ARTIFACT = new FilterControlledArtifactPermanent();
public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT_ARTIFACT_OR_CREATURE = new FilterControlledPermanent("artifact or creature you control");
public static final FilterControlledPermanent FILTER_CONTROLLED_PERMANENT_LAND = new FilterControlledLandPermanent();
public static final FilterPermanent FILTER_OPPONENTS_PERMANENT = new FilterPermanent("permanent an opponent controls");
public static final FilterPermanent FILTER_OPPONENTS_PERMANENT_CREATURE = new FilterCreaturePermanent("creature an opponent controls");

View file

@ -1020,6 +1020,7 @@ public abstract class GameImpl implements Game, Serializable {
}
watchers.add(new MorbidWatcher());
watchers.add(new CastSpellLastTurnWatcher());
watchers.add(new CastSpellYourLastTurnWatcher());
watchers.add(new PlayerLostLifeWatcher());
watchers.add(new BlockedAttackerWatcher());
watchers.add(new DamageDoneWatcher());

View file

@ -45,7 +45,25 @@ public class SaprolingToken extends Token {
final static private List<String> tokenImageSets = new ArrayList<>();
static {
tokenImageSets.addAll(Arrays.asList("10E", "ALA", "DDE", "DDH", "DDJ", "M12", "M13", "M14", "MM2", "MMA", "RTR", "C15", "MM3", "C16", "CMA"));
tokenImageSets.addAll(Arrays.asList(
"10E",
"ALA",
"DDE",
"DDH",
"DDJ",
"M12",
"M13",
"M14",
"MM2",
"MM3",
"MMA",
"RTR",
"C15",
"MM3",
"C16", // 2 different token images...
"CMA",
"VMA", // 2 different token, one with DIFFERENT stats, "Saproling Burst" create different token, see https://scryfall.com/card/tvma/12
"E02"));
}
public SaprolingToken() {

View file

@ -62,6 +62,8 @@ import mage.constants.RangeOfInfluence;
import mage.constants.Zone;
import mage.counters.Counter;
import mage.counters.Counters;
import mage.designations.Designation;
import mage.designations.DesignationType;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.Graveyard;
@ -840,4 +842,11 @@ public interface Player extends MageItem, Copyable<Player> {
boolean addTargets(Ability ability, Game game);
String getHistory();
boolean hasDesignation(DesignationType designationName);
void addDesignation(Designation designation);
List<Designation> getDesignations();
}

View file

@ -62,6 +62,8 @@ import static mage.constants.Zone.LIBRARY;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.designations.Designation;
import mage.designations.DesignationType;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
@ -199,6 +201,8 @@ public abstract class PlayerImpl implements Player, Serializable {
protected UserData userData;
protected MatchPlayer matchPlayer;
protected List<Designation> designations = new ArrayList<>();
/**
* During some steps we can't play anything
*/
@ -300,6 +304,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.castSourceIdManaCosts = player.castSourceIdManaCosts;
this.castSourceIdCosts = player.castSourceIdCosts;
this.payManaMode = player.payManaMode;
this.designations.addAll(player.designations);
}
@Override
@ -363,6 +369,9 @@ public abstract class PlayerImpl implements Player, Serializable {
this.castSourceIdManaCosts = player.getCastSourceIdManaCosts();
this.castSourceIdCosts = player.getCastSourceIdCosts();
this.designations.clear();
this.designations.addAll(player.getDesignations());
// Don't restore!
// this.storedBookmark
// this.usersAllowedToSeeHandCards
@ -435,6 +444,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.castSourceIdManaCosts = null;
this.castSourceIdCosts = null;
this.getManaPool().init(); // needed to remove mana that not empties on step change from previous game if left
this.designations.clear();
}
/**
@ -3624,9 +3635,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public boolean scry(int value, Ability source,
Game game
) {
public boolean scry(int value, Ability source, Game game) {
game.informPlayers(getLogName() + " scries " + value);
Cards cards = new CardsImpl();
cards.addAll(getLibrary().getTopCards(game, value));
@ -3659,4 +3668,25 @@ public abstract class PlayerImpl implements Player, Serializable {
return "no available";
}
@Override
public boolean hasDesignation(DesignationType designationName) {
for (Designation designation : designations) {
if (designation.getDesignationType().equals(designationName)) {
return true;
}
}
return false;
}
@Override
public void addDesignation(Designation designation) {
if (!designation.isUnique() || !this.hasDesignation(designation.getDesignationType())) {
designations.add(designation);
}
}
@Override
public List<Designation> getDesignations() {
return designations;
}
}

View file

@ -0,0 +1,94 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.watchers.common;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
import java.util.*;
import java.util.Map.Entry;
/**
* @author nantuko, BetaSteward_at_googlemail.com (spjspj)
*/
public class CastSpellYourLastTurnWatcher extends Watcher {
private final Map<UUID, Integer> amountOfSpellsCastOnPrevTurn = new HashMap<>();
private final Map<UUID, Integer> amountOfSpellsCastOnCurrentTurn = new HashMap<>();
private UUID lastActivePlayer = null;
public CastSpellYourLastTurnWatcher() {
super(CastSpellYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
}
public CastSpellYourLastTurnWatcher(final CastSpellYourLastTurnWatcher watcher) {
super(watcher);
for (Entry<UUID, Integer> entry : watcher.amountOfSpellsCastOnCurrentTurn.entrySet()) {
amountOfSpellsCastOnCurrentTurn.put(entry.getKey(), entry.getValue());
}
for (Entry<UUID, Integer> entry : watcher.amountOfSpellsCastOnPrevTurn.entrySet()) {
amountOfSpellsCastOnPrevTurn.put(entry.getKey(), entry.getValue());
}
}
@Override
public void watch(GameEvent event, Game game) {
lastActivePlayer = game.getActivePlayerId();
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
UUID playerId = event.getPlayerId();
if (playerId != null && lastActivePlayer != null && playerId == lastActivePlayer) {
amountOfSpellsCastOnCurrentTurn.putIfAbsent(playerId, 0);
amountOfSpellsCastOnCurrentTurn.compute(playerId, (k, a) -> a + 1);
}
}
}
@Override
public void reset() {
if (amountOfSpellsCastOnPrevTurn != null
&& lastActivePlayer != null
&& amountOfSpellsCastOnPrevTurn.get(lastActivePlayer) != null) {
amountOfSpellsCastOnPrevTurn.remove(lastActivePlayer);
}
amountOfSpellsCastOnPrevTurn.putAll(amountOfSpellsCastOnCurrentTurn);
amountOfSpellsCastOnCurrentTurn.clear();
lastActivePlayer = null;
}
public Integer getAmountOfSpellsCastOnPlayersTurn(UUID playerId) {
return amountOfSpellsCastOnPrevTurn.getOrDefault(playerId, 0);
}
@Override
public CastSpellYourLastTurnWatcher copy() {
return new CastSpellYourLastTurnWatcher(this);
}
}

View file

@ -0,0 +1,83 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.watchers.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
/**
*
* @author LevelX2 (spjspj)
*/
public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
private final HashMap<UUID, List<Permanent>> enteringBattlefield = new HashMap<>();
private final HashMap<UUID, List<Permanent>> enteringBattlefieldLastTurn = new HashMap<>();
private UUID lastActivePlayer = null;
public PermanentsEnteredBattlefieldYourLastTurnWatcher() {
super(PermanentsEnteredBattlefieldYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME);
}
public PermanentsEnteredBattlefieldYourLastTurnWatcher(final PermanentsEnteredBattlefieldYourLastTurnWatcher watcher) {
super(watcher);
this.enteringBattlefield.putAll(watcher.enteringBattlefield);
this.enteringBattlefieldLastTurn.putAll(watcher.enteringBattlefieldLastTurn);
}
@Override
public PermanentsEnteredBattlefieldYourLastTurnWatcher copy() {
return new PermanentsEnteredBattlefieldYourLastTurnWatcher(this);
}
@Override
public void watch(GameEvent event, Game game) {
lastActivePlayer = game.getActivePlayerId();
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
Permanent perm = game.getPermanentEntering(event.getTargetId());
if (perm == null) {
perm = game.getPermanent(event.getTargetId());
}
if (perm != null) {
List<Permanent> permanents;
if (!enteringBattlefield.containsKey(perm.getControllerId())) {
permanents = new ArrayList<>();
enteringBattlefield.put(perm.getControllerId(), permanents);
} else {
permanents = enteringBattlefield.get(perm.getControllerId());
}
permanents.add(perm.copy()); // copy needed because attributes like color could be changed later
}
}
}
@Override
public void reset() {
if (enteringBattlefieldLastTurn != null
&& lastActivePlayer != null
&& enteringBattlefieldLastTurn.get(lastActivePlayer) != null) {
enteringBattlefieldLastTurn.remove(lastActivePlayer);
}
enteringBattlefieldLastTurn.putAll(enteringBattlefield);
enteringBattlefield.clear();
lastActivePlayer = null;
}
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {
if (game.getActivePlayerId() == playerId) {
return enteringBattlefield.get(playerId);
}
return enteringBattlefieldLastTurn.get(playerId);
}
}