use of mage.counters.CounterType in project mage by magefree.
the class MaulfistRevolutionaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
Counters counters = player.getCounters().copy();
for (Counter counter : counters.values()) {
CounterType counterType = CounterType.findByName(counter.getName());
Counter counterToAdd;
if (counterType != null) {
counterToAdd = counterType.createInstance();
} else {
counterToAdd = new Counter(counter.getName());
}
player.addCounters(counterToAdd, source.getControllerId(), source, game);
}
return true;
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
Counters counters = permanent.getCounters(game).copy();
for (Counter counter : counters.values()) {
CounterType counterType = CounterType.findByName(counter.getName());
Counter counterToAdd;
if (counterType != null) {
counterToAdd = counterType.createInstance();
} else {
counterToAdd = new Counter(counter.getName());
}
permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
}
}
return true;
}
return false;
}
use of mage.counters.CounterType in project mage by magefree.
the class SkyshipPlundererEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
Counters counters = player.getCounters().copy();
for (Counter counter : counters.values()) {
CounterType counterType = CounterType.findByName(counter.getName());
Counter counterToAdd;
if (counterType != null) {
counterToAdd = counterType.createInstance();
} else {
counterToAdd = new Counter(counter.getName());
}
player.addCounters(counterToAdd, source.getControllerId(), source, game);
}
return true;
}
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null) {
Counters counters = permanent.getCounters(game).copy();
for (Counter counter : counters.values()) {
CounterType counterType = CounterType.findByName(counter.getName());
Counter counterToAdd;
if (counterType != null) {
counterToAdd = counterType.createInstance();
} else {
counterToAdd = new Counter(counter.getName());
}
permanent.addCounters(counterToAdd, source.getControllerId(), source, game);
}
}
return true;
}
return false;
}
use of mage.counters.CounterType in project mage by magefree.
the class NestingGroundsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent fromPermanent = game.getPermanent(source.getFirstTarget());
Permanent toPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (fromPermanent == null || toPermanent == null || controller == null) {
return false;
}
Set<String> possibleChoices = new HashSet<>(fromPermanent.getCounters(game).keySet());
if (possibleChoices.size() == 0) {
return false;
}
Choice choice = new ChoiceImpl();
choice.setChoices(possibleChoices);
if (controller.choose(outcome, choice, game)) {
String chosen = choice.getChoice();
if (fromPermanent.getCounters(game).containsKey(chosen)) {
CounterType counterType = CounterType.findByName(chosen);
if (counterType != null) {
Counter counter = counterType.createInstance();
fromPermanent.removeCounters(counterType.getName(), 1, source, game);
toPermanent.addCounters(counter, source.getControllerId(), source, game);
return true;
}
}
}
return false;
}
use of mage.counters.CounterType in project mage by magefree.
the class TizerusChargerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null && source.getAbilityType() == AbilityType.STATIC) {
permanent = game.getPermanentEntering(source.getSourceId());
}
Player player = game.getPlayer(source.getControllerId());
if (permanent == null || player == null) {
return false;
}
SpellAbility spellAbility = (SpellAbility) getValue(EntersBattlefieldEffect.SOURCE_CAST_SPELL_ABILITY);
if (!(spellAbility instanceof EscapeAbility) || !spellAbility.getSourceId().equals(source.getSourceId()) || permanent.getZoneChangeCounter(game) != spellAbility.getSourceObjectZoneChangeCounter()) {
return false;
}
List<UUID> appliedEffects = (ArrayList<UUID>) this.getValue("appliedEffects");
CounterType counterType = player.chooseUse(outcome, "Choose +1/+1 or flying", null, "+1/+1", "Flying", source, game) ? CounterType.P1P1 : CounterType.FLYING;
permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game, appliedEffects);
return true;
}
use of mage.counters.CounterType in project mage by magefree.
the class KathrilAspectWarperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game) == 0) {
return false;
}
Set<CounterType> counterSet = player.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).stream().map(Card::getAbilities).flatMap(Collection::stream).map(this::checkAbility).collect(Collectors.toSet());
if (counterSet == null || counterSet.size() == 0) {
return false;
}
int countersAdded = 0;
for (CounterType counterType : counterSet) {
if (counterType == null) {
continue;
}
FilterControlledPermanent filter = new FilterControlledCreaturePermanent("creature to give a " + counterType + " counter");
Target target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
continue;
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
continue;
}
if (permanent.addCounters(counterType.createInstance(), source.getControllerId(), source, game)) {
countersAdded++;
}
}
if (countersAdded == 0) {
return false;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return true;
}
permanent.addCounters(CounterType.P1P1.createInstance(countersAdded), source.getControllerId(), source, game);
return true;
}
Aggregations