mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 14:02:05 -08:00
[LTR] Add tom bombadil (#10244)
This commit is contained in:
parent
b1b0cd7d40
commit
493ca37eac
4 changed files with 345 additions and 0 deletions
|
|
@ -0,0 +1,84 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.constants.ComparisonType;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
* Condition which counts the number of a particular kind of counter on
|
||||
* permanents, and sees if it exceeds or falls short of a threshold
|
||||
*
|
||||
* @author alexander-novo
|
||||
*/
|
||||
|
||||
public class CountersOnPermanentsCondition implements Condition {
|
||||
// Which permanents to consider counters on
|
||||
public final FilterPermanent filter;
|
||||
// Which counter type to count
|
||||
public final CounterType counterType;
|
||||
// Whether to check if the number of counters exceeds or falls short of the
|
||||
// threshold
|
||||
public final ComparisonType comparisonType;
|
||||
// The threshold to compare against
|
||||
public final int threshold;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param filter Which permanents to consider counters on
|
||||
* @param counterType Which counter type to count
|
||||
* @param comparisonType Whether to check if the number of counters exceeds or
|
||||
* falls short of the threshold
|
||||
* @param threshold The threshold to compare against
|
||||
*/
|
||||
public CountersOnPermanentsCondition(FilterPermanent filter, CounterType counterType, ComparisonType comparisonType,
|
||||
int threshold) {
|
||||
this.filter = filter;
|
||||
this.counterType = counterType;
|
||||
this.comparisonType = comparisonType;
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int totalCounters = 0;
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(this.filter,
|
||||
source.getControllerId(), source, game)) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getName().equals(this.counterType.getName())) {
|
||||
totalCounters += counter.getCount();
|
||||
if (ComparisonType.compare(totalCounters, this.comparisonType, this.threshold)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String comparisonText;
|
||||
switch (this.comparisonType) {
|
||||
case MORE_THAN:
|
||||
comparisonText = String.format("%d or more", threshold + 1);
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
comparisonText = String.format("%d or fewer", threshold - 1);
|
||||
break;
|
||||
case FEWER_THAN:
|
||||
comparisonText = String.format("%d", threshold);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("comparison rules for " + this.comparisonType + " missing");
|
||||
|
||||
}
|
||||
return "there are " + comparisonText + this.counterType.getName() + " counters among "
|
||||
+ this.filter.getMessage();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package mage.abilities.hint.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.hint.Hint;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.ComparisonType;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.CounterType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.abilities.condition.common.CountersOnPermanentsCondition;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A hint which keeps track of how many counters of a specific type there are
|
||||
* among some type of permanents
|
||||
*
|
||||
* @author alexander-novo
|
||||
*/
|
||||
public class CountersOnPermanentsHint implements Hint {
|
||||
|
||||
// Which permanents to consider counters on
|
||||
public final FilterPermanent filter;
|
||||
// Which counter type to count
|
||||
public final CounterType counterType;
|
||||
|
||||
/**
|
||||
* @param filter Which permanents to consider counters on
|
||||
* @param counterType Which counter type to count
|
||||
*/
|
||||
public CountersOnPermanentsHint(FilterPermanent filter, CounterType counterType) {
|
||||
this.filter = filter;
|
||||
this.counterType = counterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy parameters from a {@link CountersOnPermanentsCondition}
|
||||
*/
|
||||
public CountersOnPermanentsHint(CountersOnPermanentsCondition condition) {
|
||||
this.filter = condition.filter;
|
||||
this.counterType = condition.counterType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Game game, Ability ability) {
|
||||
int totalCounters = 0;
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(this.filter,
|
||||
ability.getControllerId(), ability, game)) {
|
||||
for (Counter counter : permanent.getCounters(game).values()) {
|
||||
if (counter.getName().equals(this.counterType.getName())) {
|
||||
totalCounters += counter.getCount();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return this.counterType.getName() + " counters among " + this.filter.getMessage() + ": " + totalCounters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hint copy() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue