mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
refactor explore effect
This commit is contained in:
parent
0d4f004049
commit
a2e64280e5
2 changed files with 46 additions and 75 deletions
|
|
@ -3,7 +3,6 @@ package mage.abilities.effects.keyword;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
|
|
@ -20,62 +19,22 @@ import java.util.UUID;
|
|||
*/
|
||||
public class ExploreSourceEffect extends OneShotEffect {
|
||||
|
||||
// "it explores. <i>(Reveal the top card of your library. Put that card into
|
||||
// your hand if it's a land. Otherwise, put a +1/+1 counter on this creature,
|
||||
// then put the card back or put it into your graveyard.)</i>";
|
||||
private static final String RULE_TEXT_START = "explores.";
|
||||
private static final String RULE_TEXT_HINT = "<i>(Reveal the top card of your library. "
|
||||
private static final String REMINDER_TEXT = ". <i>(Reveal the top card of your library. "
|
||||
+ "Put that card into your hand if it's a land. Otherwise, put a +1/+1 counter on "
|
||||
+ "this creature, then put the card back or put it into your graveyard.)</i>";
|
||||
|
||||
public static String getRuleText(boolean showAbilityHint) {
|
||||
return getRuleText(showAbilityHint, null);
|
||||
}
|
||||
|
||||
public static String getRuleText(boolean showAbilityHint, String whosExplores) {
|
||||
|
||||
String res = whosExplores;
|
||||
if (res == null) {
|
||||
res = "it";
|
||||
}
|
||||
|
||||
res += " " + RULE_TEXT_START;
|
||||
|
||||
if (showAbilityHint) {
|
||||
res += " " + RULE_TEXT_HINT;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private String sourceName = "it";
|
||||
private boolean showAbilityHint = true;
|
||||
|
||||
public ExploreSourceEffect() {
|
||||
this(true);
|
||||
this(true, "it");
|
||||
}
|
||||
|
||||
public ExploreSourceEffect(boolean showAbilityHint) {
|
||||
this(showAbilityHint, null);
|
||||
}
|
||||
|
||||
public ExploreSourceEffect(boolean showAbilityHint, String whosExplores) {
|
||||
public ExploreSourceEffect(boolean showAbilityHint, String explorerText) {
|
||||
super(Outcome.Benefit);
|
||||
|
||||
this.showAbilityHint = showAbilityHint;
|
||||
if (whosExplores != null) {
|
||||
this.sourceName = whosExplores;
|
||||
}
|
||||
setText();
|
||||
// triggered ability text gen will replace {this} with "it" where applicable
|
||||
staticText = "{this} explores" + (showAbilityHint ? REMINDER_TEXT : "");
|
||||
}
|
||||
|
||||
protected ExploreSourceEffect(final ExploreSourceEffect effect) {
|
||||
super(effect);
|
||||
this.showAbilityHint = effect.showAbilityHint;
|
||||
this.sourceName = effect.sourceName;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
this.staticText = getRuleText(this.showAbilityHint, this.sourceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -89,43 +48,37 @@ public class ExploreSourceEffect extends OneShotEffect {
|
|||
}
|
||||
|
||||
public static boolean explorePermanent(Game game, UUID permanentId, Ability source) {
|
||||
Boolean cardWasRevealed = false;
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(permanentId);
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
Player permanentController = game.getPlayer(source.getControllerId());
|
||||
if (permanentController == null) {
|
||||
if (controller == null || permanent == null) {
|
||||
return false;
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.EXPLORED, permanentId, source, permanent.getControllerId()));
|
||||
if (permanentController.getLibrary().hasCards()) {
|
||||
Card card = permanentController.getLibrary().getFromTop(game);
|
||||
Cards cards = new CardsImpl();
|
||||
cards.add(card);
|
||||
permanentController.revealCards("Explored card", cards, game);
|
||||
cardWasRevealed = true;
|
||||
if (card != null) {
|
||||
if (card.isLand(game)) {
|
||||
permanentController.moveCards(card, Zone.HAND, source, game);
|
||||
Card card = controller.getLibrary().getFromTop(game);
|
||||
if (card != null) {
|
||||
controller.revealCards("Explored card", new CardsImpl(card), game);
|
||||
if (card.isLand(game)) {
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
} else {
|
||||
addCounter(game, permanent, source);
|
||||
if (controller.chooseUse(Outcome.Neutral, "Put " + card.getLogName() + " in your graveyard?", source, game)) {
|
||||
controller.moveCards(card, Zone.GRAVEYARD, source, game);
|
||||
} else {
|
||||
if (game.getState().getZone(permanentId) == Zone.BATTLEFIELD) { // needed in case LKI object is used
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
|
||||
}
|
||||
if (permanentController.chooseUse(Outcome.Neutral, "Put " + card.getLogName() + " in your graveyard?", source, game)) {
|
||||
permanentController.moveCards(card, Zone.GRAVEYARD, source, game);
|
||||
} else {
|
||||
game.informPlayers(permanentController.getLogName() + " leaves " + card.getLogName() + " on top of their library.");
|
||||
}
|
||||
game.informPlayers(controller.getLogName() + " leaves " + card.getLogName() + " on top of their library.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cardWasRevealed
|
||||
&& game.getState().getZone(permanentId) == Zone.BATTLEFIELD) {
|
||||
} else {
|
||||
// If no card is revealed, most likely because that player's library is empty,
|
||||
// the exploring creature receives a +1/+1 counter.
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
|
||||
addCounter(game, permanent, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void addCounter(Game game, Permanent permanent, Ability source) {
|
||||
if (game.getState().getZone(permanent.getId()) == Zone.BATTLEFIELD) { // needed in case LKI object is used
|
||||
permanent.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities.effects.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
|
|
@ -10,17 +11,24 @@ import mage.game.Game;
|
|||
*/
|
||||
public class ExploreTargetEffect extends OneShotEffect {
|
||||
|
||||
private static final String REMINDER_TEXT = ". <i>(Reveal the top card of your library. "
|
||||
+ "Put that card into your hand if it's a land. Otherwise, put a +1/+1 counter on "
|
||||
+ "that creature, then put the card back or put it into your graveyard.)</i>";
|
||||
|
||||
private final boolean withReminderText;
|
||||
|
||||
public ExploreTargetEffect() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public ExploreTargetEffect(boolean showAbilityHint) {
|
||||
public ExploreTargetEffect(boolean withReminderText) {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = ExploreSourceEffect.getRuleText(showAbilityHint);
|
||||
this.withReminderText = withReminderText;
|
||||
}
|
||||
|
||||
protected ExploreTargetEffect(final ExploreTargetEffect effect) {
|
||||
super(effect);
|
||||
this.withReminderText = effect.withReminderText;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -32,4 +40,14 @@ public class ExploreTargetEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
return ExploreSourceEffect.explorePermanent(game, getTargetPointer().getFirst(game, source), source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
return getTargetPointer().describeTargets(mode.getTargets(), "it")
|
||||
+ " explores" + (withReminderText ? REMINDER_TEXT : "") ;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue