Master of the Wild Hunt - reworked to use single damage dialog instead multiple calls, added card hints (related to #9827);

This commit is contained in:
Oleg Agafonov 2024-10-24 15:32:48 +04:00
parent 2d9ac4e732
commit 0fbd9bb60f

View file

@ -5,14 +5,13 @@ import mage.abilities.Ability;
import mage.abilities.common.OnEventTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.hint.ValueHint;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.TappedPredicate;
import mage.game.Game;
@ -27,12 +26,10 @@ import java.util.List;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, JayDi85
*/
public final class MasterOfTheWildHunt extends CardImpl {
private static WolfToken wolfToken = new WolfToken();
public MasterOfTheWildHunt(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{G}{G}");
this.subtype.add(SubType.HUMAN);
@ -42,11 +39,13 @@ public final class MasterOfTheWildHunt extends CardImpl {
this.toughness = new MageInt(3);
// At the beginning of your upkeep, create a 2/2 green Wolf creature token.
this.addAbility(new OnEventTriggeredAbility(EventType.UPKEEP_STEP_PRE, "beginning of your upkeep", new CreateTokenEffect(wolfToken)));
this.addAbility(new OnEventTriggeredAbility(EventType.UPKEEP_STEP_PRE, "beginning of your upkeep",
new CreateTokenEffect(new WolfToken())));
// {T}: Tap all untapped Wolf creatures you control. Each Wolf tapped this way deals damage equal to its power to target creature. That creature deals damage equal to its power divided as its controller chooses among any number of those Wolves.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new MasterOfTheWildHuntEffect(), new TapSourceCost());
ability.addTarget(new TargetCreaturePermanent());
ability.addHint(new ValueHint("Untapped wolfs you control", new PermanentsOnBattlefieldCount(MasterOfTheWildHuntEffect.filter)));
this.addAbility(ability);
}
@ -62,7 +61,7 @@ public final class MasterOfTheWildHunt extends CardImpl {
class MasterOfTheWildHuntEffect extends OneShotEffect {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
protected static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.add(SubType.WOLF.getPredicate());
@ -85,21 +84,51 @@ class MasterOfTheWildHuntEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
List<UUID> wolves = new ArrayList<>();
List<Permanent> wolves = new ArrayList<>();
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null && game.getBattlefield().countAll(filter, source.getControllerId(), game) > 0) {
if (target == null) {
return false;
}
Player player = game.getPlayer(target.getControllerId());
if (player == null) {
return false;
}
// Tap all untapped Wolf creatures you control
// Each Wolf tapped this way deals damage equal to its power to target creature
if (game.getBattlefield().countAll(filter, source.getControllerId(), game) > 0) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
permanent.tap(source, game);
target.damage(permanent.getPower().getValue(), permanent.getId(), source, game);
wolves.add(permanent.getId());
}
Player player = game.getPlayer(target.getControllerId());
if (player != null) {
player.assignDamage(target.getPower().getValue(), wolves, "Wolf", target.getId(), source, game);
return true;
wolves.add(permanent);
}
}
return false;
if (wolves.isEmpty()) {
return true;
}
// That creature deals damage equal to its power divided as its controller chooses among any number of those Wolves
int totalDamage = target.getPower().getValue();
List<String> messages = new ArrayList<>();
wolves.forEach(permanent -> {
String info = String.format("%s (%s/%s)",
permanent.getLogName(),
permanent.getPower().getValue(),
permanent.getToughness().getValue()
);
messages.add(info);
});
List<Integer> damagesList = player.getMultiAmount(Outcome.Damage, messages, 0, totalDamage, totalDamage, MultiAmountType.DAMAGE, game);
if (damagesList.size() == wolves.size()) {
for (int i = 0; i < wolves.size(); i++) {
wolves.get(0).damage(damagesList.get(0), target.getId(), source, game, false, true);
}
} else {
throw new IllegalArgumentException("Wrong code usage: getMultiAmount must return same size");
}
return true;
}
}