mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
rewrote some streams and optionals
This commit is contained in:
parent
d0bf77cedf
commit
594ffa2754
29 changed files with 199 additions and 273 deletions
|
|
@ -41,6 +41,7 @@ import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.target.TargetPlayer;
|
import mage.target.TargetPlayer;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -110,8 +111,8 @@ class AbeyanceEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
|
if (ability.isPresent() && !(ability.get() instanceof ActivatedManaAbilityImpl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
import mage.game.events.GameEvent.EventType;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -108,8 +109,8 @@ class DampingMatrixEffect extends ReplacementEffectImpl {
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
MageObject object = game.getObject(event.getSourceId());
|
MageObject object = game.getObject(event.getSourceId());
|
||||||
if (object instanceof Permanent && filter.match((Permanent)object, game)) {
|
if (object instanceof Permanent && filter.match((Permanent)object, game)) {
|
||||||
Ability ability = object.getAbilities().get(event.getTargetId());
|
Optional<Ability> ability = object.getAbilities().get(event.getTargetId());
|
||||||
if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
|
if (ability.isPresent() && !(ability.get() instanceof ActivatedManaAbilityImpl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,16 +44,16 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
public class FaithsFetters extends CardImpl {
|
public class FaithsFetters extends CardImpl {
|
||||||
|
|
||||||
public FaithsFetters(UUID ownerId, CardSetInfo setInfo) {
|
public FaithsFetters(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{W}");
|
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}");
|
||||||
this.subtype.add("Aura");
|
this.subtype.add("Aura");
|
||||||
|
|
||||||
// Enchant permanent
|
// Enchant permanent
|
||||||
|
|
@ -114,12 +114,11 @@ class FaithsFettersEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
Permanent enchantment = game.getPermanent(source.getSourceId());
|
Permanent enchantment = game.getPermanent(source.getSourceId());
|
||||||
if (enchantment != null && enchantment.getAttachedTo().equals(event.getSourceId())) {
|
if (enchantment != null && enchantment.getAttachedTo().equals(event.getSourceId())) {
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null) {
|
if (ability.isPresent() && ability.get().getAbilityType() != AbilityType.MANA) {
|
||||||
if (ability.getAbilityType() != AbilityType.MANA) {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.cards.h;
|
package mage.cards.h;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
|
@ -35,14 +34,13 @@ import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||||
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.*;
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.constants.Outcome;
|
|
||||||
import mage.constants.TurnPhase;
|
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author fireshoes
|
* @author fireshoes
|
||||||
|
|
@ -106,8 +104,8 @@ class HandToHandEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
|
if (ability.isPresent() && !(ability.get() instanceof ActivatedManaAbilityImpl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.cards.m;
|
package mage.cards.m;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.condition.common.KickedCondition;
|
import mage.abilities.condition.common.KickedCondition;
|
||||||
|
|
@ -50,6 +49,9 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
|
|
@ -109,8 +111,8 @@ class MoltenDisasterSplitSecondEffect extends ContinuousRuleModifyingEffectImpl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
|
if (ability.isPresent() && !(ability.get() instanceof ActivatedManaAbilityImpl)) {
|
||||||
if (KickedCondition.instance.apply(game, source)) {
|
if (KickedCondition.instance.apply(game, source)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.cards.p;
|
package mage.cards.p;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.AsEntersBattlefieldAbility;
|
import mage.abilities.common.AsEntersBattlefieldAbility;
|
||||||
|
|
@ -36,14 +35,13 @@ import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||||
import mage.abilities.effects.common.NameACardEffect;
|
import mage.abilities.effects.common.NameACardEffect;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.*;
|
||||||
import mage.constants.CardType;
|
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.constants.Outcome;
|
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jeffwadsworth, nox
|
* @author jeffwadsworth, nox
|
||||||
|
|
@ -99,9 +97,9 @@ class PithingNeedleEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
MageObject object = game.getObject(event.getSourceId());
|
MageObject object = game.getObject(event.getSourceId());
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null && object != null) {
|
if (ability.isPresent() && object != null) {
|
||||||
if (ability.getAbilityType() != AbilityType.MANA
|
if (ability.get().getAbilityType() != AbilityType.MANA
|
||||||
&& object.getName().equals(game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY))) {
|
&& object.getName().equals(game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
package org.mage.test.cards.watchers;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import mage.game.permanent.Permanent;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by IGOUDT on 30-3-2017.
|
||||||
|
*/
|
||||||
|
public class KiraGreatGlassSpinnerTest extends CardTestPlayerBase {
|
||||||
|
private final String kira = "Kira, Great Glass-Spinner";
|
||||||
|
private final String shock = "Shock";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void counterFirst(){
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Ugin, the Spirit Dragon"); // starts with 7 Loyality counters
|
||||||
|
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, kira);
|
||||||
|
addCard(Zone.HAND, playerA, shock);
|
||||||
|
addCard(Zone.HAND, playerA, shock);
|
||||||
|
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+2: {source} deals 3 damage to target creature or player.", kira);
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
|
||||||
|
execute();
|
||||||
|
|
||||||
|
Permanent _kira = getPermanent(kira, playerA.getId());
|
||||||
|
Assert.assertNotNull(_kira);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,6 +29,7 @@ package mage.abilities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.keyword.ProtectionAbility;
|
import mage.abilities.keyword.ProtectionAbility;
|
||||||
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
||||||
|
|
@ -245,7 +246,7 @@ public interface Abilities<T extends Ability> extends List<T>, Serializable {
|
||||||
* @param abilityId
|
* @param abilityId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
T get(UUID abilityId);
|
Optional<T> get(UUID abilityId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO The usage of this method seems redundant to that of
|
* TODO The usage of this method seems redundant to that of
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.abilities;
|
package mage.abilities;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
||||||
import mage.abilities.costs.Cost;
|
import mage.abilities.costs.Cost;
|
||||||
import mage.abilities.keyword.ProtectionAbility;
|
import mage.abilities.keyword.ProtectionAbility;
|
||||||
|
|
@ -44,6 +37,8 @@ import mage.game.Game;
|
||||||
import mage.util.ThreadLocalStringBuilder;
|
import mage.util.ThreadLocalStringBuilder;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param <T>
|
* @param <T>
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -277,12 +272,7 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsRule(T ability) {
|
public boolean containsRule(T ability) {
|
||||||
for (T test : this) {
|
return stream().anyMatch(rule -> rule.getRule().equals(ability.getRule()));
|
||||||
if (ability.getRule().equals(test.getRule())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -301,32 +291,16 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(UUID abilityId) {
|
public boolean containsKey(UUID abilityId) {
|
||||||
for (T ability : this) {
|
return stream().anyMatch(ability -> ability.getId().equals(abilityId));
|
||||||
if (ability.getId().equals(abilityId)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsClass(Class classObject) {
|
public boolean containsClass(Class classObject) {
|
||||||
for (T ability : this) {
|
return stream().anyMatch(ability -> ability.getClass().equals(classObject));
|
||||||
if (ability.getClass().equals(classObject)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Optional<T> get(UUID abilityId) {
|
||||||
public T get(UUID abilityId) {
|
return stream().filter(ability -> ability.getId().equals(abilityId)).findFirst();
|
||||||
for (T ability : this) {
|
|
||||||
if (ability.getId().equals(abilityId)) {
|
|
||||||
return ability;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.abilities;
|
package mage.abilities;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.costs.Cost;
|
import mage.abilities.costs.Cost;
|
||||||
import mage.abilities.costs.Costs;
|
import mage.abilities.costs.Costs;
|
||||||
|
|
@ -49,6 +46,11 @@ import mage.target.Target;
|
||||||
import mage.target.Targets;
|
import mage.target.Targets;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Practically everything in the game is started from an Ability. This interface
|
* Practically everything in the game is started from an Ability. This interface
|
||||||
* describes what an Ability is composed of at the highest level.
|
* describes what an Ability is composed of at the highest level.
|
||||||
|
|
|
||||||
|
|
@ -28,20 +28,21 @@
|
||||||
|
|
||||||
package mage.abilities;
|
package mage.abilities;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class DelayedTriggeredAbilities extends AbilitiesImpl<DelayedTriggeredAbility> {
|
public class DelayedTriggeredAbilities extends AbilitiesImpl<DelayedTriggeredAbility> {
|
||||||
|
|
||||||
public DelayedTriggeredAbilities() {}
|
public DelayedTriggeredAbilities() {
|
||||||
|
}
|
||||||
|
|
||||||
public DelayedTriggeredAbilities(final DelayedTriggeredAbilities abilities) {
|
public DelayedTriggeredAbilities(final DelayedTriggeredAbilities abilities) {
|
||||||
super(abilities);
|
super(abilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,9 +53,9 @@ import mage.game.events.GameEvent;
|
||||||
|
|
||||||
public void checkTriggers(GameEvent event, Game game) {
|
public void checkTriggers(GameEvent event, Game game) {
|
||||||
if (this.size() > 0) {
|
if (this.size() > 0) {
|
||||||
for (Iterator<DelayedTriggeredAbility> it = this.iterator();it.hasNext();) {
|
for (Iterator<DelayedTriggeredAbility> it = this.iterator(); it.hasNext(); ) {
|
||||||
DelayedTriggeredAbility ability = it.next();
|
DelayedTriggeredAbility ability = it.next();
|
||||||
if (ability.getDuration()== Duration.Custom){
|
if (ability.getDuration() == Duration.Custom) {
|
||||||
if (ability.isInactive(game)) {
|
if (ability.isInactive(game)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split Second
|
* Split Second
|
||||||
*
|
*
|
||||||
|
|
@ -66,8 +68,8 @@ class SplitSecondEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) {
|
||||||
Ability ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
Optional<Ability> ability = game.getAbility(event.getTargetId(), event.getSourceId());
|
||||||
if (ability != null && !(ability instanceof ActivatedManaAbilityImpl)) {
|
if (ability != null && !(ability.get() instanceof ActivatedManaAbilityImpl)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import mage.util.ThreadLocalStringBuilder;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -109,13 +110,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int count(FilterCard filter, Game game) {
|
public int count(FilterCard filter, Game game) {
|
||||||
int result = 0;
|
return (int) stream().filter(cardId -> filter.match(game.getCard(cardId), game)).count();
|
||||||
for (UUID cardId : this) {
|
|
||||||
if (filter.match(game.getCard(cardId), game)) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -150,14 +145,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Card> getCards(FilterCard filter, Game game) {
|
public Set<Card> getCards(FilterCard filter, Game game) {
|
||||||
Set<Card> cards = new LinkedHashSet<>();
|
return stream().map(game::getCard).filter(card -> filter.match(card, game)).collect(Collectors.toSet());
|
||||||
for (UUID card : this) {
|
|
||||||
boolean match = filter.match(game.getCard(card), game);
|
|
||||||
if (match) {
|
|
||||||
cards.add(game.getCard(card));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import mage.util.RandomUtil;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -160,13 +161,7 @@ public abstract class ExpansionSet implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SetCardInfo> findCardInfoByClass(Class<?> clazz) {
|
public List<SetCardInfo> findCardInfoByClass(Class<?> clazz) {
|
||||||
ArrayList<SetCardInfo> result = new ArrayList<>();
|
return cards.stream().filter(info -> info.getCardClass().equals(clazz)).collect(Collectors.toList());
|
||||||
for (SetCardInfo info : cards) {
|
|
||||||
if (info.getCardClass().equals(clazz)) {
|
|
||||||
result.add(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Card> create15CardBooster() {
|
public List<Card> create15CardBooster() {
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,10 @@
|
||||||
package mage.counters;
|
package mage.counters;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -122,12 +122,9 @@ public class Counters extends HashMap<String, Counter> implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<BoostCounter> getBoostCounters() {
|
public List<BoostCounter> getBoostCounters() {
|
||||||
List<BoostCounter> boosters = new ArrayList<>();
|
return values().stream().
|
||||||
for (Counter counter : this.values()) {
|
filter(counter -> counter instanceof BoostCounter).
|
||||||
if (counter instanceof BoostCounter) {
|
map(counter -> (BoostCounter) counter).
|
||||||
boosters.add((BoostCounter) counter);
|
collect(Collectors.toList());
|
||||||
}
|
|
||||||
}
|
|
||||||
return boosters;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageItem;
|
import mage.MageItem;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
|
@ -50,11 +42,7 @@ import mage.cards.Cards;
|
||||||
import mage.cards.MeldCard;
|
import mage.cards.MeldCard;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.constants.Duration;
|
import mage.constants.*;
|
||||||
import mage.constants.MultiplayerAttackOption;
|
|
||||||
import mage.constants.PlayerAction;
|
|
||||||
import mage.constants.RangeOfInfluence;
|
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.counters.Counters;
|
import mage.counters.Counters;
|
||||||
import mage.game.combat.Combat;
|
import mage.game.combat.Combat;
|
||||||
import mage.game.command.Commander;
|
import mage.game.command.Commander;
|
||||||
|
|
@ -77,6 +65,9 @@ import mage.players.Players;
|
||||||
import mage.util.MessageToClient;
|
import mage.util.MessageToClient;
|
||||||
import mage.util.functions.ApplyToPermanent;
|
import mage.util.functions.ApplyToPermanent;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public interface Game extends MageItem, Serializable {
|
public interface Game extends MageItem, Serializable {
|
||||||
|
|
||||||
MatchType getGameType();
|
MatchType getGameType();
|
||||||
|
|
@ -128,7 +119,7 @@ public interface Game extends MageItem, Serializable {
|
||||||
|
|
||||||
Card getCard(UUID cardId);
|
Card getCard(UUID cardId);
|
||||||
|
|
||||||
Ability getAbility(UUID abilityId, UUID sourceId);
|
Optional<Ability> getAbility(UUID abilityId, UUID sourceId);
|
||||||
|
|
||||||
void setZone(UUID objectId, Zone zone);
|
void setZone(UUID objectId, Zone zone);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -503,12 +503,12 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Ability getAbility(UUID abilityId, UUID sourceId) {
|
public Optional<Ability> getAbility(UUID abilityId, UUID sourceId) {
|
||||||
MageObject object = getObject(sourceId);
|
MageObject object = getObject(sourceId);
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
return object.getAbilities().get(abilityId);
|
return object.getAbilities().get(abilityId);
|
||||||
}
|
}
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
|
@ -2336,10 +2336,10 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator it = gameCards.entrySet().iterator();
|
Iterator<Entry<UUID, Card>> it = gameCards.entrySet().iterator();
|
||||||
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Entry<UUID, Card> entry = (Entry<UUID, Card>) it.next();
|
Entry<UUID, Card> entry = it.next();
|
||||||
Card card = entry.getValue();
|
Card card = entry.getValue();
|
||||||
if (card.getOwnerId().equals(playerId)) {
|
if (card.getOwnerId().equals(playerId)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.game.command;
|
package mage.game.command;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.ObjectColor;
|
import mage.ObjectColor;
|
||||||
import mage.abilities.Abilities;
|
import mage.abilities.Abilities;
|
||||||
|
|
@ -48,18 +44,22 @@ import mage.game.Game;
|
||||||
import mage.game.events.ZoneChangeEvent;
|
import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.util.GameLog;
|
import mage.util.GameLog;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Commander implements CommandObject {
|
public class Commander implements CommandObject {
|
||||||
|
|
||||||
private final Card sourceObject;
|
private final Card sourceObject;
|
||||||
private final Abilities<Ability> abilites = new AbilitiesImpl<>();
|
private final Abilities<Ability> abilities = new AbilitiesImpl<>();
|
||||||
|
|
||||||
public Commander(Card card) {
|
public Commander(Card card) {
|
||||||
this.sourceObject = card;
|
this.sourceObject = card;
|
||||||
abilites.add(new CastCommanderAbility(card));
|
abilities.add(new CastCommanderAbility(card));
|
||||||
for (Ability ability : card.getAbilities()) {
|
for (Ability ability : card.getAbilities()) {
|
||||||
if (!(ability instanceof SpellAbility)) {
|
if (!(ability instanceof SpellAbility)) {
|
||||||
Ability newAbility = ability.copy();
|
Ability newAbility = ability.copy();
|
||||||
abilites.add(newAbility);
|
abilities.add(newAbility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +134,7 @@ public class Commander implements CommandObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Abilities<Ability> getAbilities() {
|
public Abilities<Ability> getAbilities() {
|
||||||
return abilites;
|
return abilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.game.command;
|
package mage.game.command;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.ObjectColor;
|
import mage.ObjectColor;
|
||||||
|
|
@ -46,6 +44,11 @@ import mage.game.Game;
|
||||||
import mage.game.events.ZoneChangeEvent;
|
import mage.game.events.ZoneChangeEvent;
|
||||||
import mage.util.GameLog;
|
import mage.util.GameLog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
|
|
@ -92,7 +95,7 @@ public class Emblem implements CommandObject {
|
||||||
this.sourceObject = sourceObject;
|
this.sourceObject = sourceObject;
|
||||||
if (sourceObject instanceof Card) {
|
if (sourceObject instanceof Card) {
|
||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
name = ((Card) sourceObject).getSubtype(null).toString();
|
name = sourceObject.getSubtype(null).toString();
|
||||||
}
|
}
|
||||||
if (expansionSetCodeForImage.isEmpty()) {
|
if (expansionSetCodeForImage.isEmpty()) {
|
||||||
expansionSetCodeForImage = ((Card) sourceObject).getExpansionSetCode();
|
expansionSetCodeForImage = ((Card) sourceObject).getExpansionSetCode();
|
||||||
|
|
|
||||||
|
|
@ -103,22 +103,20 @@ public class Battlefield implements Serializable {
|
||||||
* @return count
|
* @return count
|
||||||
*/
|
*/
|
||||||
public int count(FilterPermanent filter, UUID sourceId, UUID sourcePlayerId, Game game) {
|
public int count(FilterPermanent filter, UUID sourceId, UUID sourcePlayerId, Game game) {
|
||||||
int count;
|
|
||||||
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
|
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
|
||||||
count = (int) field.values()
|
return (int) field.values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(permanent -> filter.match(permanent, sourceId, sourcePlayerId, game)
|
.filter(permanent -> filter.match(permanent, sourceId, sourcePlayerId, game)
|
||||||
&& permanent.isPhasedIn())
|
&& permanent.isPhasedIn())
|
||||||
.count();
|
.count();
|
||||||
} else {
|
} else {
|
||||||
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
|
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
|
||||||
count = (int) field.values()
|
return (int) field.values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(permanent -> range.contains(permanent.getControllerId())
|
.filter(permanent -> range.contains(permanent.getControllerId())
|
||||||
&& filter.match(permanent, sourceId, sourcePlayerId, game)
|
&& filter.match(permanent, sourceId, sourcePlayerId, game)
|
||||||
&& permanent.isPhasedIn()).count();
|
&& permanent.isPhasedIn()).count();
|
||||||
}
|
}
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -319,20 +317,18 @@ public class Battlefield implements Serializable {
|
||||||
* @see Permanent
|
* @see Permanent
|
||||||
*/
|
*/
|
||||||
public List<Permanent> getActivePermanents(FilterPermanent filter, UUID sourcePlayerId, UUID sourceId, Game game) {
|
public List<Permanent> getActivePermanents(FilterPermanent filter, UUID sourcePlayerId, UUID sourceId, Game game) {
|
||||||
List<Permanent> active = new ArrayList<>();
|
|
||||||
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
|
if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) {
|
||||||
active = field.values()
|
return field.values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(perm -> perm.isPhasedIn() && filter.match(perm, sourceId, sourcePlayerId, game))
|
.filter(perm -> perm.isPhasedIn() && filter.match(perm, sourceId, sourcePlayerId, game))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else {
|
} else {
|
||||||
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
|
Set<UUID> range = game.getPlayer(sourcePlayerId).getInRange();
|
||||||
active = field.values()
|
return field.values()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(perm -> perm.isPhasedIn() && range.contains(perm.getControllerId())
|
.filter(perm -> perm.isPhasedIn() && range.contains(perm.getControllerId())
|
||||||
&& filter.match(perm, sourceId, sourcePlayerId, game)).collect(Collectors.toList());
|
&& filter.match(perm, sourceId, sourcePlayerId, game)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
return active;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.game.stack;
|
package mage.game.stack;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
|
|
@ -60,6 +58,11 @@ import mage.game.permanent.PermanentCard;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.util.GameLog;
|
import mage.util.GameLog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -331,8 +334,8 @@ public class Spell extends StackObjImpl implements Card {
|
||||||
* determine whether card was kicked or not. E.g. Desolation Angel
|
* determine whether card was kicked or not. E.g. Desolation Angel
|
||||||
*/
|
*/
|
||||||
private void updateOptionalCosts(int index) {
|
private void updateOptionalCosts(int index) {
|
||||||
Ability abilityOrig = spellCards.get(index).getAbilities().get(spellAbilities.get(index).getId());
|
spellCards.get(index).getAbilities().get(spellAbilities.get(index).getId()).ifPresent(abilityOrig ->
|
||||||
if (abilityOrig != null) {
|
{
|
||||||
for (Object object : spellAbilities.get(index).getOptionalCosts()) {
|
for (Object object : spellAbilities.get(index).getOptionalCosts()) {
|
||||||
Cost cost = (Cost) object;
|
Cost cost = (Cost) object;
|
||||||
for (Cost costOrig : abilityOrig.getOptionalCosts()) {
|
for (Cost costOrig : abilityOrig.getOptionalCosts()) {
|
||||||
|
|
@ -346,7 +349,7 @@ public class Spell extends StackObjImpl implements Card {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,26 +27,16 @@
|
||||||
*/
|
*/
|
||||||
package mage.players;
|
package mage.players;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayDeque;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.FilterCard;
|
import mage.filter.FilterCard;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.util.RandomUtil;
|
import mage.util.RandomUtil;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
|
@ -182,11 +172,7 @@ public class Library implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Card> getCards(Game game) {
|
public List<Card> getCards(Game game) {
|
||||||
List<Card> cards = new ArrayList<>();
|
return library.stream().map(game::getCard).collect(Collectors.toList());
|
||||||
for (UUID cardId : library) {
|
|
||||||
cards.add(game.getCard(cardId));
|
|
||||||
}
|
|
||||||
return cards;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Card> getTopCards(Game game, int amount) {
|
public Set<Card> getTopCards(Game game, int amount) {
|
||||||
|
|
@ -214,13 +200,7 @@ public class Library implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int count(FilterCard filter, Game game) {
|
public int count(FilterCard filter, Game game) {
|
||||||
int result = 0;
|
return (int) library.stream().filter(cardId -> filter.match(game.getCard(cardId), game)).count();
|
||||||
for (UUID card : library) {
|
|
||||||
if (filter.match(game.getCard(card), game)) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmptyDraw() {
|
public boolean isEmptyDraw() {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import mage.abilities.dynamicvalue.common.StaticValue;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -142,12 +143,7 @@ public abstract class TargetAmount extends TargetImpl {
|
||||||
t.addTarget(targetId, n, source, game, true);
|
t.addTarget(targetId, n, source, game, true);
|
||||||
if (t.remainingAmount > 0) {
|
if (t.remainingAmount > 0) {
|
||||||
if (targets.size() > 1) {
|
if (targets.size() > 1) {
|
||||||
Set<UUID> newTargets = new HashSet<>();
|
Set<UUID> newTargets = targets.stream().filter(newTarget -> !newTarget.equals(targetId)).collect(Collectors.toSet());
|
||||||
for (UUID newTarget: targets) {
|
|
||||||
if (!newTarget.equals(targetId)) {
|
|
||||||
newTargets.add(newTarget);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addTargets(t, newTargets, options, source, game);
|
addTargets(t, newTargets, options, source, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package mage.target;
|
package mage.target;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import mage.MageItem;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
|
|
@ -38,6 +36,11 @@ import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -200,11 +203,7 @@ public class TargetCard extends TargetObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Game game) {
|
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Game game) {
|
||||||
Set<UUID> possibleTargets = new HashSet<>();
|
return cards.getCards(filter,game).stream().map(MageItem::getId).collect(Collectors.toSet());
|
||||||
for (Card card : cards.getCards(filter, game)) {
|
|
||||||
possibleTargets.add(card.getId());
|
|
||||||
}
|
|
||||||
return possibleTargets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,16 @@
|
||||||
*/
|
*/
|
||||||
package mage.target;
|
package mage.target;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.filter.FilterPlayer;
|
import mage.filter.FilterPlayer;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -158,12 +159,7 @@ public class TargetPlayer extends TargetImpl {
|
||||||
if (getNumberOfTargets() == 0 && targets.isEmpty()) {
|
if (getNumberOfTargets() == 0 && targets.isEmpty()) {
|
||||||
return true; // 0 targets selected is valid
|
return true; // 0 targets selected is valid
|
||||||
}
|
}
|
||||||
for (UUID playerId : targets.keySet()) {
|
return targets.keySet().stream().anyMatch(playerId -> canTarget(playerId, source, game));
|
||||||
if (canTarget(playerId, source, game)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.target;
|
package mage.target;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.FilterSpell;
|
import mage.filter.FilterSpell;
|
||||||
|
|
@ -37,6 +34,11 @@ import mage.game.Game;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -112,13 +114,10 @@ public class TargetSpell extends TargetObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||||
Set<UUID> possibleTargets = new HashSet<>();
|
return game.getStack().stream()
|
||||||
for (StackObject stackObject : game.getStack()) {
|
.filter(stackObject -> canBeChosen(stackObject, sourceId, sourceControllerId, game))
|
||||||
if (canBeChosen(stackObject, sourceId, sourceControllerId, game)) {
|
.map(StackObject::getId)
|
||||||
possibleTargets.add(stackObject.getId());
|
.collect(Collectors.toSet());
|
||||||
}
|
|
||||||
}
|
|
||||||
return possibleTargets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,16 @@
|
||||||
*/
|
*/
|
||||||
package mage.target;
|
package mage.target;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
|
@ -51,13 +53,7 @@ public class Targets extends ArrayList<Target> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Target> getUnchosen() {
|
public List<Target> getUnchosen() {
|
||||||
List<Target> unchosen = new ArrayList<>();
|
return stream().filter(target -> !target.isChosen()).collect(Collectors.toList());
|
||||||
for (Target target : this) {
|
|
||||||
if (!target.isChosen()) {
|
|
||||||
unchosen.add(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unchosen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearChosen() {
|
public void clearChosen() {
|
||||||
|
|
@ -67,12 +63,7 @@ public class Targets extends ArrayList<Target> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChosen() {
|
public boolean isChosen() {
|
||||||
for (Target target : this) {
|
return stream().allMatch(Target::isChosen);
|
||||||
if (!target.isChosen()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean choose(Outcome outcome, UUID playerId, UUID sourceId, Game game) {
|
public boolean choose(Outcome outcome, UUID playerId, UUID sourceId, Game game) {
|
||||||
|
|
@ -122,12 +113,8 @@ public class Targets extends ArrayList<Target> {
|
||||||
public boolean stillLegal(Ability source, Game game) {
|
public boolean stillLegal(Ability source, Game game) {
|
||||||
// 608.2
|
// 608.2
|
||||||
// The spell or ability is countered if all its targets, for every instance of the word "target," are now illegal
|
// The spell or ability is countered if all its targets, for every instance of the word "target," are now illegal
|
||||||
int illegalCount = 0;
|
int illegalCount = (int) stream().filter(target -> !target.isLegal(source, game)).count();
|
||||||
for (Target target : this) {
|
|
||||||
if (!target.isLegal(source, game)) {
|
|
||||||
illegalCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// it is legal when either there is no target or not all targets are illegal
|
// it is legal when either there is no target or not all targets are illegal
|
||||||
return this.isEmpty() || this.size() != illegalCount;
|
return this.isEmpty() || this.size() != illegalCount;
|
||||||
}
|
}
|
||||||
|
|
@ -142,12 +129,7 @@ public class Targets extends ArrayList<Target> {
|
||||||
* @return - true if enough valid targets exist
|
* @return - true if enough valid targets exist
|
||||||
*/
|
*/
|
||||||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||||
for (Target target : this) {
|
return stream().allMatch(target -> target.canChoose(sourceId, sourceControllerId, game));
|
||||||
if (!target.canChoose(sourceId, sourceControllerId, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -160,12 +142,7 @@ public class Targets extends ArrayList<Target> {
|
||||||
* @return - true if enough valid objects exist
|
* @return - true if enough valid objects exist
|
||||||
*/
|
*/
|
||||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||||
for (Target target : this) {
|
return stream().allMatch(target -> target.canChoose(sourceControllerId, game));
|
||||||
if (!target.canChoose(sourceControllerId, game)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getFirstTarget() {
|
public UUID getFirstTarget() {
|
||||||
|
|
@ -174,7 +151,6 @@ public class Targets extends ArrayList<Target> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Targets copy() {
|
public Targets copy() {
|
||||||
return new Targets(this);
|
return new Targets(this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,27 +28,27 @@
|
||||||
|
|
||||||
package mage.target.common;
|
package mage.target.common;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
|
import mage.constants.Zone;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
import mage.filter.FilterAbility;
|
import mage.filter.FilterAbility;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
import mage.target.TargetObject;
|
import mage.target.TargetObject;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class TargetActivatedOrTriggeredAbility extends TargetObject {
|
public class TargetActivatedOrTriggeredAbility extends TargetObject {
|
||||||
|
|
||||||
public TargetActivatedOrTriggeredAbility() {
|
public TargetActivatedOrTriggeredAbility() {
|
||||||
this.minNumberOfTargets = 1;
|
this.minNumberOfTargets = 1;
|
||||||
this.maxNumberOfTargets = 1;
|
this.maxNumberOfTargets = 1;
|
||||||
this.zone = Zone.STACK;
|
this.zone = Zone.STACK;
|
||||||
|
|
@ -78,12 +78,9 @@ public class TargetActivatedOrTriggeredAbility extends TargetObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||||
for (StackObject stackObject : game.getStack()) {
|
return game.getStack()
|
||||||
if (isActivatedOrTriggeredAbility(stackObject)) {
|
.stream()
|
||||||
return true;
|
.anyMatch(TargetActivatedOrTriggeredAbility::isActivatedOrTriggeredAbility);
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -93,13 +90,10 @@ public class TargetActivatedOrTriggeredAbility extends TargetObject {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||||
Set<UUID> possibleTargets = new HashSet<>();
|
return game.getStack().stream()
|
||||||
for (StackObject stackObject : game.getStack()) {
|
.filter(TargetActivatedOrTriggeredAbility::isActivatedOrTriggeredAbility)
|
||||||
if (isActivatedOrTriggeredAbility(stackObject)) {
|
.map(stackObject -> stackObject.getStackAbility().getId())
|
||||||
possibleTargets.add(stackObject.getStackAbility().getId());
|
.collect(Collectors.toSet());
|
||||||
}
|
|
||||||
}
|
|
||||||
return possibleTargets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -117,9 +111,9 @@ public class TargetActivatedOrTriggeredAbility extends TargetObject {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (stackObject instanceof Ability) {
|
if (stackObject instanceof Ability) {
|
||||||
Ability ability = (Ability)stackObject;
|
Ability ability = (Ability) stackObject;
|
||||||
return ability.getAbilityType() == AbilityType.TRIGGERED
|
return ability.getAbilityType() == AbilityType.TRIGGERED
|
||||||
|| ability.getAbilityType() == AbilityType.ACTIVATED;
|
|| ability.getAbilityType() == AbilityType.ACTIVATED;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@
|
||||||
*/
|
*/
|
||||||
package mage.target.common;
|
package mage.target.common;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
|
@ -39,8 +37,10 @@ import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.target.TargetCard;
|
import mage.target.TargetCard;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
||||||
|
|
@ -82,8 +82,7 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canTarget(UUID id, Ability source, Game game
|
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||||
) {
|
|
||||||
Permanent permanent = game.getPermanent(id);
|
Permanent permanent = game.getPermanent(id);
|
||||||
if (permanent != null) {
|
if (permanent != null) {
|
||||||
return filter.match(permanent, game);
|
return filter.match(permanent, game);
|
||||||
|
|
@ -93,8 +92,7 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game
|
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||||
) {
|
|
||||||
//return super.possibleTargets(sourceControllerId, game); //To change body of generated methods, choose Tools | Templates.
|
//return super.possibleTargets(sourceControllerId, game); //To change body of generated methods, choose Tools | Templates.
|
||||||
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, game);
|
Set<UUID> possibleTargets = super.possibleTargets(sourceControllerId, game);
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
||||||
|
|
@ -106,8 +104,7 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game
|
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||||
) {
|
|
||||||
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
|
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
|
||||||
MageObject targetSource = game.getObject(sourceId);
|
MageObject targetSource = game.getObject(sourceId);
|
||||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(), sourceControllerId, game)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue