mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Merge pull request #3042 from ingmargoudt/card_functions
move static function to CardImpl, and other api fixes
This commit is contained in:
commit
884ae83791
32 changed files with 177 additions and 296 deletions
|
|
@ -4,6 +4,8 @@ import mage.abilities.Abilities;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.keyword.ChangelingAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.FrameStyle;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SuperType;
|
||||
|
|
@ -132,4 +134,52 @@ public interface MageObject extends MageItem, Serializable {
|
|||
default boolean isWorld() {
|
||||
return getSuperType().contains(SuperType.WORLD);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether two cards share card types.
|
||||
*
|
||||
*
|
||||
* @param otherCard
|
||||
* @return
|
||||
*/
|
||||
default boolean shareTypes(Card otherCard) {
|
||||
|
||||
if (otherCard == null) {
|
||||
throw new IllegalArgumentException("Params can't be null");
|
||||
}
|
||||
|
||||
for (CardType type : getCardType()) {
|
||||
if (otherCard.getCardType().contains(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
default boolean shareSubtypes(Card otherCard, Game game) {
|
||||
|
||||
if (otherCard == null) {
|
||||
throw new IllegalArgumentException("Params can't be null");
|
||||
}
|
||||
|
||||
if (this.isCreature() && otherCard.isCreature()) {
|
||||
if (this.getAbilities().contains(ChangelingAbility.getInstance())
|
||||
|| this.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)
|
||||
|| otherCard.getAbilities().contains(ChangelingAbility.getInstance())
|
||||
|| otherCard.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (String subtype : this.getSubtype(game)) {
|
||||
if (otherCard.getSubtype(game).contains(subtype)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -126,7 +125,7 @@ class KinshipBaseEffect extends OneShotEffect {
|
|||
if (card != null) {
|
||||
Cards cards = new CardsImpl(card);
|
||||
controller.lookAtCards(sourcePermanent.getName(), cards, game);
|
||||
if (CardUtil.shareSubtypes(sourcePermanent, card, game)) {
|
||||
if (sourcePermanent.shareSubtypes(card, game)) {
|
||||
if (controller.chooseUse(outcome,new StringBuilder("Kinship - Reveal ").append(card.getLogName()).append('?').toString(), source, game)) {
|
||||
controller.revealCards(sourcePermanent.getName(), cards, game);
|
||||
for (Effect effect: kinshipEffects) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.continuous.BoostTargetEffect;
|
||||
|
|
@ -14,7 +13,6 @@ import mage.target.targetpointer.FixedTarget;
|
|||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
|
||||
|
|
@ -38,16 +36,12 @@ public class FlankingAbility extends TriggeredAbilityImpl {
|
|||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getTargetId().equals(this.getSourceId())) {
|
||||
Permanent permanent = game.getPermanent(event.getSourceId());
|
||||
if(permanent != null)
|
||||
{
|
||||
boolean hasFlankingAbility = false;
|
||||
for(Ability ability : permanent.getAbilities()){
|
||||
if(ability instanceof FlankingAbility){
|
||||
hasFlankingAbility = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!hasFlankingAbility){
|
||||
if (permanent != null) {
|
||||
boolean hasFlankingAbility =
|
||||
permanent.getAbilities().stream().anyMatch(ability -> ability instanceof FlankingAbility);
|
||||
|
||||
|
||||
if (!hasFlankingAbility) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(event.getSourceId()));
|
||||
}
|
||||
|
|
@ -68,5 +62,5 @@ public class FlankingAbility extends TriggeredAbilityImpl {
|
|||
return new FlankingAbility(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,20 +27,10 @@
|
|||
*/
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
import mage.abilities.costs.Costs;
|
||||
import mage.abilities.costs.CostsImpl;
|
||||
import mage.abilities.costs.OptionalAdditionalCost;
|
||||
import mage.abilities.costs.OptionalAdditionalCostImpl;
|
||||
import mage.abilities.costs.OptionalAdditionalSourceCosts;
|
||||
import mage.abilities.costs.*;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
|
|
@ -51,8 +41,9 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* 20121001 702.31. Kicker 702.31a Kicker is a static ability that functions
|
||||
* while the spell with kicker is on the stack. "Kicker [cost]" means "You may
|
||||
* pay an additional [cost] as you cast this spell." Paying a spell's kicker
|
||||
|
|
@ -80,7 +71,6 @@ import mage.players.Player;
|
|||
* 601.2c.
|
||||
*
|
||||
* @author LevelX2
|
||||
*
|
||||
*/
|
||||
public class KickerAbility extends StaticAbility implements OptionalAdditionalSourceCosts {
|
||||
|
||||
|
|
@ -159,10 +149,7 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo
|
|||
|
||||
public int getKickedCounter(Game game, Ability source) {
|
||||
String key = getActivationKey(source, "", game);
|
||||
if (activations.containsKey(key)) {
|
||||
return activations.get(key);
|
||||
}
|
||||
return 0;
|
||||
return activations.getOrDefault(key, 0);
|
||||
}
|
||||
|
||||
public boolean isKicked(Game game, Ability source, String costText) {
|
||||
|
|
@ -227,10 +214,10 @@ public class KickerAbility extends StaticAbility implements OptionalAdditionalSo
|
|||
&& player.chooseUse(Outcome.Benefit, "Pay " + times + kickerCost.getText(false) + " ?", ability, game)) {
|
||||
this.activateKicker(kickerCost, ability, game);
|
||||
if (kickerCost instanceof Costs) {
|
||||
for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext();) {
|
||||
for (Iterator itKickerCost = ((Costs) kickerCost).iterator(); itKickerCost.hasNext(); ) {
|
||||
Object kickerCostObject = itKickerCost.next();
|
||||
if ((kickerCostObject instanceof Costs) || (kickerCostObject instanceof CostsImpl)) {
|
||||
for (@SuppressWarnings("unchecked") Iterator<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext();) {
|
||||
for (@SuppressWarnings("unchecked") Iterator<Cost> itDetails = ((Costs) kickerCostObject).iterator(); itDetails.hasNext(); ) {
|
||||
addKickerCostsToAbility(itDetails.next(), ability, game);
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -27,24 +27,15 @@
|
|||
*/
|
||||
package mage.cards;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.util.RandomUtil;
|
||||
import mage.util.ThreadLocalStringBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializable {
|
||||
|
|
@ -129,13 +120,8 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
|
||||
@Override
|
||||
public int count(FilterCard filter, UUID playerId, Game game) {
|
||||
int result = 0;
|
||||
for (UUID card : this) {
|
||||
if (filter.match(game.getCard(card), playerId, game)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return (int) this.stream().filter(card -> filter.match(game.getCard(card), playerId, game)).count();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -143,13 +129,8 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
if (sourceId == null) {
|
||||
return count(filter, playerId, game);
|
||||
}
|
||||
int result = 0;
|
||||
for (UUID card : this) {
|
||||
if (filter.match(game.getCard(card), sourceId, playerId, game)) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return (int) this.stream().filter(card -> filter.match(game.getCard(card), sourceId, playerId, game)).count();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -182,7 +163,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
@Override
|
||||
public Set<Card> getCards(Game game) {
|
||||
Set<Card> cards = new LinkedHashSet<>();
|
||||
for (Iterator<UUID> it = this.iterator(); it.hasNext();) { // Changed to iterator because of ConcurrentModificationException
|
||||
for (Iterator<UUID> it = this.iterator(); it.hasNext(); ) { // Changed to iterator because of ConcurrentModificationException
|
||||
UUID cardId = it.next();
|
||||
|
||||
Card card = game.getCard(cardId);
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@
|
|||
*/
|
||||
package mage.target.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -62,7 +62,7 @@ public class TargetCreaturePermanentWithDifferentTypes extends TargetCreaturePer
|
|||
UUID targetId = (UUID) object;
|
||||
Permanent selectedCreature = game.getPermanent(targetId);
|
||||
if (!creature.getId().equals(selectedCreature.getId())) {
|
||||
if (CardUtil.shareSubtypes(creature, selectedCreature, game)) {
|
||||
if (creature.shareSubtypes(selectedCreature, game)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,8 @@ import mage.abilities.ActivatedAbility;
|
|||
import mage.abilities.SpellAbility;
|
||||
import mage.abilities.costs.VariableCost;
|
||||
import mage.abilities.costs.mana.*;
|
||||
import mage.abilities.keyword.ChangelingAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.CardType;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
|
@ -84,57 +82,9 @@ public final class CardUtil {
|
|||
"Trap", "Arcane"};
|
||||
public static final Set<String> NON_CREATURE_SUBTYPES = new HashSet<>(Arrays.asList(NON_CHANGELING_SUBTYPES_VALUES));
|
||||
|
||||
/**
|
||||
* Checks whether two cards share card types.
|
||||
*
|
||||
* @param card1
|
||||
* @param card2
|
||||
* @return
|
||||
*/
|
||||
public static boolean shareTypes(Card card1, Card card2) {
|
||||
|
||||
if (card1 == null || card2 == null) {
|
||||
throw new IllegalArgumentException("Params can't be null");
|
||||
}
|
||||
|
||||
for (CardType type : card1.getCardType()) {
|
||||
if (card2.getCardType().contains(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether two cards share card subtypes.
|
||||
*
|
||||
* @param card1
|
||||
* @param card2
|
||||
* @return
|
||||
*/
|
||||
public static boolean shareSubtypes(Card card1, Card card2, Game game) {
|
||||
|
||||
if (card1 == null || card2 == null) {
|
||||
throw new IllegalArgumentException("Params can't be null");
|
||||
}
|
||||
|
||||
if (card1.isCreature() && card2.isCreature()) {
|
||||
if (card1.getAbilities().contains(ChangelingAbility.getInstance())
|
||||
|| card1.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)
|
||||
|| card2.getAbilities().contains(ChangelingAbility.getInstance())
|
||||
|| card2.getSubtype(game).contains(ChangelingAbility.ALL_CREATURE_TYPE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (String subtype : card1.getSubtype(game)) {
|
||||
if (card2.getSubtype(game).contains(subtype)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase spell or ability cost to be paid.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue