mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Card: add IsEquippedBy like isEnchantedBy from GameEntity
CardPredicates: use isEquippedBy and isEnchantedBy for Predicate<Card>
This commit is contained in:
@@ -473,13 +473,9 @@ public class ComputerUtilCombat {
|
|||||||
public static int totalDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
public static int totalDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
||||||
int damage = 0;
|
int damage = 0;
|
||||||
|
|
||||||
if (attacker.isEquipped()) {
|
if (attacker.isEquippedBy("Godsend") && !defenders.isEmpty()) {
|
||||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
|
||||||
if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) {
|
|
||||||
defenders.remove(0);
|
defenders.remove(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Card defender : defenders) {
|
for (final Card defender : defenders) {
|
||||||
damage += ComputerUtilCombat.dealsDamageAsBlocker(attacker, defender);
|
damage += ComputerUtilCombat.dealsDamageAsBlocker(attacker, defender);
|
||||||
@@ -495,11 +491,9 @@ public class ComputerUtilCombat {
|
|||||||
public static int totalFirstStrikeDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
public static int totalFirstStrikeDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
||||||
int damage = 0;
|
int damage = 0;
|
||||||
|
|
||||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
if (attacker.isEquippedBy("Godsend") && !defenders.isEmpty()) {
|
||||||
if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) {
|
|
||||||
defenders.remove(0);
|
defenders.remove(0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (final Card defender : defenders) {
|
for (final Card defender : defenders) {
|
||||||
damage += ComputerUtilCombat.predictDamageByBlockerWithoutDoubleStrike(attacker, defender);
|
damage += ComputerUtilCombat.predictDamageByBlockerWithoutDoubleStrike(attacker, defender);
|
||||||
@@ -1527,13 +1521,9 @@ public class ComputerUtilCombat {
|
|||||||
// check whether the attacker will be destroyed by triggered abilities before First Strike damage
|
// check whether the attacker will be destroyed by triggered abilities before First Strike damage
|
||||||
public static boolean canDestroyAttackerBeforeFirstStrike(final Card attacker, final Card blocker, final Combat combat,
|
public static boolean canDestroyAttackerBeforeFirstStrike(final Card attacker, final Card blocker, final Combat combat,
|
||||||
final boolean withoutAbilities) {
|
final boolean withoutAbilities) {
|
||||||
if (blocker.isEquipped()) {
|
if (blocker.isEquippedBy("Godsend")) {
|
||||||
for (Card equipment : blocker.getEquippedBy(false)) {
|
|
||||||
if (equipment.getName().equals("Godsend")) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
if (attacker.hasKeyword("Indestructible") || ComputerUtil.canRegenerate(attacker.getController(), attacker)) {
|
if (attacker.hasKeyword("Indestructible") || ComputerUtil.canRegenerate(attacker.getController(), attacker)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1747,13 +1737,9 @@ public class ComputerUtilCombat {
|
|||||||
|
|
||||||
public static boolean canDestroyBlockerBeforeFirstStrike(final Card blocker, final Card attacker, final boolean withoutAbilities) {
|
public static boolean canDestroyBlockerBeforeFirstStrike(final Card blocker, final Card attacker, final boolean withoutAbilities) {
|
||||||
|
|
||||||
if (attacker.isEquipped()) {
|
if (attacker.isEquippedBy("Godsend")) {
|
||||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
|
||||||
if (equipment.getName().equals("Godsend")) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attacker.getName().equals("Elven Warhounds")) {
|
if (attacker.getName().equals("Elven Warhounds")) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -664,17 +664,9 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
//some auras aren't useful in multiples
|
//some auras aren't useful in multiples
|
||||||
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
||||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
prefList = CardLists.filter(prefList,
|
||||||
@Override
|
Predicates.not(CardPredicates.isEnchantedBy(attachSource.getName()))
|
||||||
public boolean apply(final Card c) {
|
);
|
||||||
for (Card aura : c.getEnchantedBy(false)) {
|
|
||||||
if (aura.getName().equals(attachSource.getName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c = ComputerUtilCard.getBestAI(prefList);
|
c = ComputerUtilCard.getBestAI(prefList);
|
||||||
@@ -723,15 +715,11 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// don't equip creatures that don't gain anything
|
// don't equip creatures that don't gain anything
|
||||||
if (card.hasSVar("NonStackingAttachEffect")) {
|
if (card.hasSVar("NonStackingAttachEffect") && newTarget.isEquippedBy(equipment.getName())) {
|
||||||
for (Card equipment : newTarget.getEquippedBy(false)) {
|
|
||||||
if (equipment.getName().equals(card.getName())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -958,26 +946,10 @@ public class AttachAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
//some auras/equipments aren't useful in multiples
|
//some auras/equipments aren't useful in multiples
|
||||||
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
if (attachSource.hasSVar("NonStackingAttachEffect")) {
|
||||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
prefList = CardLists.filter(prefList, Predicates.not(Predicates.or(
|
||||||
@Override
|
CardPredicates.isEquippedBy(attachSource.getName()),
|
||||||
public boolean apply(final Card c) {
|
CardPredicates.isEnchantedBy(attachSource.getName())
|
||||||
if (c.isEquipped()) {
|
)));
|
||||||
for (Card equipment : c.getEquippedBy(false)) {
|
|
||||||
if (equipment.getName().equals(attachSource.getName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (c.isEnchanted()) {
|
|
||||||
for (Card aura : c.getEnchantedBy(false)) {
|
|
||||||
if (aura.getName().equals(attachSource.getName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't pump cards that will die.
|
// Don't pump cards that will die.
|
||||||
|
|||||||
@@ -2281,6 +2281,14 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
public final boolean isEquippedBy(Card c) {
|
public final boolean isEquippedBy(Card c) {
|
||||||
return FCollection.hasElement(equippedBy, c);
|
return FCollection.hasElement(equippedBy, c);
|
||||||
}
|
}
|
||||||
|
public final boolean isEquippedBy(final String cardName) {
|
||||||
|
for (final Card card : getEquippedBy(false)) {
|
||||||
|
if (card.getName().equals(cardName)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public final CardCollectionView getFortifiedBy(boolean allowModify) {
|
public final CardCollectionView getFortifiedBy(boolean allowModify) {
|
||||||
return CardCollection.getView(fortifiedBy, allowModify);
|
return CardCollection.getView(fortifiedBy, allowModify);
|
||||||
@@ -3926,14 +3934,9 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
}
|
}
|
||||||
} else if (property.equals("NameNotEnchantingEnchantedPlayer")) {
|
} else if (property.equals("NameNotEnchantingEnchantedPlayer")) {
|
||||||
Player enchantedPlayer = source.getEnchantingPlayer();
|
Player enchantedPlayer = source.getEnchantingPlayer();
|
||||||
if (enchantedPlayer == null) {
|
if (enchantedPlayer == null || enchantedPlayer.isEnchantedBy(getName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (Card c : enchantedPlayer.getEnchantedBy(false)) {
|
|
||||||
if (getName().equals(c.getName())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (property.equals("NotAttachedTo")) {
|
} else if (property.equals("NotAttachedTo")) {
|
||||||
if (equipping == source || source.equals(enchanting) || fortifying == source) {
|
if (equipping == source || source.equals(enchanting) || fortifying == source) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -171,6 +171,24 @@ public final class CardPredicates {
|
|||||||
};
|
};
|
||||||
} // getColor()
|
} // getColor()
|
||||||
|
|
||||||
|
public static final Predicate<Card> isEquippedBy(final String name) {
|
||||||
|
return new Predicate<Card>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(final Card c) {
|
||||||
|
return c.isEquippedBy(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Predicate<Card> isEnchantedBy(final String name) {
|
||||||
|
return new Predicate<Card>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(final Card c) {
|
||||||
|
return c.isEnchantedBy(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public static final Predicate<Card> hasCMC(final int cmc) {
|
public static final Predicate<Card> hasCMC(final int cmc) {
|
||||||
return new Predicate<Card>() {
|
return new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user