Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions forge-game/src/main/java/forge/game/combat/AttackConstraints.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.stream.Collectors;

import com.google.common.collect.*;
import forge.util.IterableUtil;
import org.apache.commons.lang3.tuple.Pair;

import forge.game.GameEntity;
Expand Down Expand Up @@ -95,7 +96,7 @@ public Pair<Map<Card, GameEntity>, Integer> getLegalAttackers() {
) || (
types.contains(AttackRestrictionType.NEED_GREATER_POWER) && myMax <= 1
)) {
reqs.removeAll(findAll(reqs, attacker));
reqs.removeIf(findAll(attacker));
attackersToRemove.add(attacker);
}
}
Expand All @@ -117,7 +118,7 @@ public Pair<Map<Card, GameEntity>, Integer> getLegalAttackers() {
}
myPossibleAttackers.removeAll(attackersToRemove);
for (final Card toRemove : attackersToRemove) {
reqs.removeAll(findAll(reqs, toRemove));
reqs.removeIf(findAll(toRemove));
}

// First, successively try each creature that must attack alone.
Expand All @@ -134,7 +135,7 @@ public Pair<Map<Card, GameEntity>, Integer> getLegalAttackers() {
possible.put(attackMap, violations);
}
// remove them from the requirements, as they'll not be relevant to this calculation any more
reqs.removeAll(findAll(reqs, attacker));
reqs.removeIf(findAll(attacker));
}
}

Expand Down Expand Up @@ -211,14 +212,14 @@ private List<Map<Card, GameEntity>> collectLegalAttackers(final Map<Card, GameEn
if (!requirement.getCausesToAttack().isEmpty()) {
final List<Attack> clonedReqs = deepClone(reqs);
for (final Entry<Card, Collection<StaticAbility>> causesToAttack : requirement.getCausesToAttack().asMap().entrySet()) {
for (final Attack a : findAll(reqs, causesToAttack.getKey())) {
for (final Attack a : IterableUtil.filter(reqs, findAll(causesToAttack.getKey()))) {
a.requirements += causesToAttack.getValue().size();
}
}
// if maximum < no of possible attackers, try both with and without this creature
if (isLimited) {
// try without
clonedReqs.removeAll(findAll(clonedReqs, req.attacker));
clonedReqs.removeIf(findAll(req.attacker));
final CardCollection clonedReserved = new CardCollection(reserved);
result.addAll(collectLegalAttackers(myAttackers, clonedReqs, clonedReserved, localMaximum));
haveTriedWithout = true;
Expand All @@ -234,7 +235,7 @@ private List<Map<Card, GameEntity>> collectLegalAttackers(final Map<Card, GameEn
final Attack match = findFirst(reqs, predicateRestriction);
if (match == null) {
// no match: remove this creature completely
reqs.removeAll(findAll(reqs, req.attacker));
reqs.removeIf(findAll(req.attacker));
continue outer;
}
// found one! add it to reserve and lower local maximum
Expand All @@ -245,7 +246,7 @@ private List<Map<Card, GameEntity>> collectLegalAttackers(final Map<Card, GameEn
if (!haveTriedWithout && isLimited) {
// try without
final List<Attack> clonedReqs = deepClone(reqs);
clonedReqs.removeAll(findAll(clonedReqs, req.attacker));
clonedReqs.removeIf(findAll(req.attacker));
final CardCollection clonedReserved = new CardCollection(reserved);
result.addAll(collectLegalAttackers(myAttackers, clonedReqs, clonedReserved, localMaximum));
haveTriedWithout = true;
Expand All @@ -255,7 +256,7 @@ private List<Map<Card, GameEntity>> collectLegalAttackers(final Map<Card, GameEn
// finally: add the creature
myAttackers.put(req.attacker, req.defender);
toDefender.merge(req.defender, 1, Integer::sum);
reqs.removeAll(findAll(reqs, req.attacker));
reqs.removeIf(findAll(req.attacker));
reserved.remove(req.attacker);
localMaximum--;

Expand Down Expand Up @@ -355,8 +356,8 @@ private static Attack findFirst(final List<Attack> reqs, final Predicate<Card> p
private static Attack findFirst(final List<Attack> reqs, final Card attacker) {
return findFirst(reqs, attacker::equals);
}
private static Collection<Attack> findAll(final List<Attack> reqs, final Card attacker) {
return Collections2.filter(reqs, input -> input.attacker.equals(attacker));
private static Predicate<Attack> findAll(final Card attacker) {
return input -> input.attacker.equals(attacker);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final boolean performTest(final Map<AbilityKey, Object> runParams) {
if (hasParam("ValidResult")) {
String[] params = getParam("ValidResult").split(",");
int result = (int) runParams.get(AbilityKey.Result);
if (hasParam("Natural")) {
if (hasParam("Natural") && runParams.containsKey(AbilityKey.NaturalResult)) {
result = (int) runParams.get(AbilityKey.NaturalResult);
}
for (String param : params) {
Expand Down
2 changes: 1 addition & 1 deletion forge-gui/res/cardsfolder/b/baron_helmut_zemo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Name:Baron Helmut Zemo
ManaCost:B B B
Types:Legendary Creature Human Noble Villain
PT:3/3
T:Mode$ SpellCast | ValidCard$ Card.Black+wasCastFromYourHand | Execute$ TrigConnive | TriggerDescription$ Whenever you cast a black spell from your hand, CARDNAME connives.
T:Mode$ SpellCast | ValidCard$ Card.Black+wasCastFromYourHand | TriggerZones$ Battlefield | Execute$ TrigConnive | TriggerDescription$ Whenever you cast a black spell from your hand, CARDNAME connives.
SVar:TrigConnive:DB$ Connive
A:AB$ Play | Cost$ ExileFromGrave<1+/Card.Black+withTotalManaSymbols_Black_GE15> | CostDesc$ Exile any number of black cards from your graveyard with fifteen or more black mana symbols among their mana costs: | Boast$ True | Defined$ ExiledWith | ValidSA$ Spell | WithoutManaCost$ True | CopyCard$ True | Amount$ 3 | Optional$ True | SpellDescription$ Copy those exiled cards. You may cast up to three of the copies without paying their mana costs. (Activate only if this creature attacked this turn and only once each turn.)
DeckHas:Ability$Graveyard
Expand Down
2 changes: 1 addition & 1 deletion forge-gui/src/main/java/forge/gui/events/UiEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface UiEvent extends Event {

public abstract <T> T visit(IUiEventVisitor<T> visitor);
<T> T visit(IUiEventVisitor<T> visitor);
}