* Regeneration abilities - added card hint about activated and used regeneration;

This commit is contained in:
Oleg Agafonov 2020-08-01 21:29:08 +04:00
parent 4ba7c18d43
commit c7595ca476
15 changed files with 244 additions and 87 deletions

View file

@ -1,8 +1,5 @@
package mage.cards.a;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.ActivateAsSorceryActivatedAbility;
@ -26,6 +23,8 @@ import mage.game.permanent.Permanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
* @author Styxo
*/
@ -82,7 +81,7 @@ class AnakinSkywalkerEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null) {
permanent.regenerate(source.getSourceId(), game);
permanent.regenerate(source, game);
return new TransformSourceEffect(true).apply(game, source);
}
return false;

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.ActivateOnlyByOpponentActivatedAbility;
@ -11,17 +9,14 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.CantBeRegeneratedSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author escplan9 (Derek Monturo - dmontur1 at gmail dot com)
*/
public final class ClergyOfTheHolyNimbus extends CardImpl {
@ -66,7 +61,7 @@ class ClergyOfTheHolyNimbusReplacementEffect extends ReplacementEffectImpl {
Permanent ClergyOfTheHolyNimbus = game.getPermanent(event.getTargetId());
if (ClergyOfTheHolyNimbus != null
&& event.getAmount() == 0) { // 1=noRegen
if (ClergyOfTheHolyNimbus.regenerate(source.getSourceId(), game)) {
if (ClergyOfTheHolyNimbus.regenerate(source, game)) {
game.informPlayers(source.getSourceObject(game).getName() + " has been regenerated.");
return true;
}

View file

@ -1,7 +1,5 @@
package mage.cards.k;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.ActivateOnlyByOpponentActivatedAbility;
@ -12,23 +10,20 @@ import mage.abilities.effects.common.CantBeRegeneratedSourceEffect;
import mage.abilities.keyword.FlankingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class KnightOfTheHolyNimbus extends CardImpl {
public KnightOfTheHolyNimbus(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{W}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}{W}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.REBEL);
this.subtype.add(SubType.KNIGHT);
@ -72,7 +67,7 @@ class KnightOfTheHolyNimbusReplacementEffect extends ReplacementEffectImpl {
Permanent knightOfTheHolyNimbus = game.getPermanent(event.getTargetId());
if (knightOfTheHolyNimbus != null
&& event.getAmount() == 0) { // 1=noRegen
if (knightOfTheHolyNimbus.regenerate(source.getSourceId(), game)) {
if (knightOfTheHolyNimbus.regenerate(source, game)) {
game.informPlayers(source.getSourceObject(game).getName() + " has been regenerated.");
return true;
}

View file

@ -1,7 +1,5 @@
package mage.cards.m;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -12,11 +10,7 @@ import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.Predicates;
@ -27,8 +21,9 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.common.TargetControlledCreaturePermanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class MossbridgeTroll extends CardImpl {
@ -81,7 +76,7 @@ class MossbridgeTrollReplacementEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent mossbridgeTroll = game.getPermanent(event.getTargetId());
if (mossbridgeTroll != null && event.getAmount() == 0) { // 1=noRegen
return mossbridgeTroll.regenerate(source.getSourceId(), game);
return mossbridgeTroll.regenerate(source, game);
}
return false;
}

View file

@ -1,7 +1,5 @@
package mage.cards.r;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
@ -14,23 +12,24 @@ import mage.constants.*;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author Plopman
*/
public final class Regeneration extends CardImpl {
public Regeneration(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{G}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}");
this.subtype.add(SubType.AURA);
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.AddAbility));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// {G}: Regenerate enchanted creature.
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new RegenerateAttachedEffect(AttachmentType.AURA), new ManaCostsImpl("{G}")));
}

View file

@ -1,7 +1,5 @@
package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -17,14 +15,15 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetOpponent;
import java.util.UUID;
/**
*
* @author Ketsuban
*/
public final class SoldeviSentry extends CardImpl {
public SoldeviSentry(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[] { CardType.ARTIFACT, CardType.CREATURE }, "{1}");
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{1}");
this.subtype.add(SubType.SOLDIER);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
@ -53,7 +52,7 @@ class SoldeviSentryEffect extends RegenerateSourceEffect {
//20110204 - 701.11
Player opponent = game.getPlayer(source.getFirstTarget());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.regenerate(this.getId(), game)) {
if (permanent != null && permanent.regenerate(source, game)) {
if (opponent != null) {
if (opponent.chooseUse(Outcome.DrawCard, "Draw a card?", source, game)) {
opponent.drawCards(1, source.getSourceId(), game);

View file

@ -0,0 +1,33 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* Source must be attached to permanent
*
* @author JayDi85
*/
public class AttachedToPermanentCondition implements Condition {
final UUID permanentId;
public AttachedToPermanentCondition(UUID permanentId) {
this.permanentId = permanentId;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent attachment = game.getPermanent(source.getSourceId());
Permanent permanent = game.getPermanent(this.permanentId);
if (attachment != null && permanent != null) {
return permanent.getAttachments().contains(attachment.getId());
}
return false;
}
}

View file

@ -2,8 +2,11 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.Condition;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.hint.Hint;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -12,7 +15,7 @@ import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, JayDi85
*/
public class InfoEffect extends OneShotEffect {
@ -36,10 +39,66 @@ public class InfoEffect extends OneShotEffect {
}
public static void addInfoToPermanent(Game game, Ability source, Permanent permanent, String info) {
addInfoToPermanent(game, source, permanent, info, Duration.WhileOnBattlefield);
}
/**
* Add temporary information string to permanent (visible in rules list)
*
* @param game
* @param source
* @param permanent
* @param info
* @param duration
*/
public static void addInfoToPermanent(Game game, Ability source, Permanent permanent, String info, Duration duration) {
// add simple static info to permanent's rules
SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect(info));
GainAbilityTargetEffect gainAbilityEffect = new GainAbilityTargetEffect(ability, Duration.WhileOnBattlefield);
gainAbilityEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(gainAbilityEffect, source);
GainAbilityTargetEffect gainEffect = new GainAbilityTargetEffect(ability, duration);
gainEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(gainEffect, source);
}
/**
* Add temporary card hint to permanent (visible in rules list)
*
* @param game
* @param source
* @param permanent
* @param cardHint
* @param duration
*/
public static void addCardHintToPermanent(Game game, Ability source, Permanent permanent, Hint cardHint, Duration duration) {
SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("hint"));
ability.setRuleVisible(false);
ability.addHint(cardHint);
GainAbilityTargetEffect gainEffect = new GainAbilityTargetEffect(ability, duration);
gainEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(gainEffect, source);
}
/**
* Add temporary card hint to permanent (visible in rules list)
* Will be visible on conditional only
*
* @param game
* @param source
* @param permanent
* @param cardHint
* @param duration
* @param condition
*/
public static void addCardHintToPermanentConditional(Game game, Ability source, Permanent permanent, Hint cardHint, Duration duration, Condition condition) {
SimpleStaticAbility ability = new SimpleStaticAbility(Zone.BATTLEFIELD, new InfoEffect("hint"));
ability.setRuleVisible(false);
ability.addHint(cardHint);
GainAbilityTargetEffect gainEffect = new GainAbilityTargetEffect(ability, duration);
gainEffect.setTargetPointer(new FixedTarget(permanent, game));
ConditionalContinuousEffect conditionalEffect = new ConditionalContinuousEffect(gainEffect, condition, "test");
conditionalEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(conditionalEffect, source);
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
@ -10,7 +9,6 @@ import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author LevelX2
*/
public class RegenerateAllEffect extends OneShotEffect {
@ -18,7 +16,7 @@ public class RegenerateAllEffect extends OneShotEffect {
private final FilterPermanent filter;
public RegenerateAllEffect(FilterPermanent filter) {
super(Outcome.DestroyPermanent);
super(Outcome.Regenerate);
this.filter = filter;
staticText = "Regenerate each " + filter.getMessage();
}
@ -42,5 +40,4 @@ public class RegenerateAllEffect extends OneShotEffect {
}
return true;
}
}

View file

@ -1,8 +1,5 @@
package mage.abilities.effects.common;
import java.util.Locale;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.constants.AttachmentType;
@ -12,6 +9,9 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import java.util.Locale;
import java.util.UUID;
/**
* @author jeff
*/
@ -37,13 +37,29 @@ public class RegenerateAttachedEffect extends ReplacementEffectImpl {
return false;
}
Permanent equipped = game.getPermanent(permanent.getAttachedTo());
if (equipped != null && equipped.regenerate(this.getId(), game)) {
if (equipped != null && equipped.regenerate(source, game)) {
this.used = true;
return true;
}
return false;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
return;
}
Permanent equipped = game.getPermanent(permanent.getAttachedTo());
if (equipped == null) {
return;
}
RegenerateSourceEffect.initRegenerationInfoWhileAttached(game, source, equipped.getId());
}
@Override
public RegenerateAttachedEffect copy() {
return new RegenerateAttachedEffect(this);

View file

@ -1,17 +1,20 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.abilities.condition.common.AttachedToPermanentCondition;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.abilities.hint.ConditionHint;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class RegenerateSourceEffect extends ReplacementEffectImpl {
@ -34,13 +37,20 @@ public class RegenerateSourceEffect extends ReplacementEffectImpl {
public boolean apply(Game game, Ability source) {
//20110204 - 701.11
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null && permanent.regenerate(this.getId(), game)) {
if (permanent != null && permanent.regenerate(source, game)) {
this.used = true;
return true;
}
return false;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
RegenerateSourceEffect.initRegenerationInfo(game, source, source.getSourceId());
}
@Override
public RegenerateSourceEffect copy() {
return new RegenerateSourceEffect(this);
@ -50,14 +60,57 @@ public class RegenerateSourceEffect extends ReplacementEffectImpl {
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
return apply(game, source);
}
@Override
public boolean checksEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DESTROY_PERMANENT;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
//20110204 - 701.11c - event.getAmount() is used to signal if regeneration is allowed
return event.getAmount() == 0 && event.getTargetId().equals(source.getSourceId()) && !this.used;
}
public static void initRegenerationInfo(Game game, Ability source, UUID permanentId) {
// enable regen info
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
game.getState().setValue(CardUtil.getCardZoneString("RegenerationActivated", permanent.getId(), game), Boolean.TRUE);
InfoEffect.addCardHintToPermanent(game, source, permanent,
new ConditionHint(RegeneratingCanBeUsedCondition.instance, "Permanent will be regenerated instead destroy"),
Duration.EndOfTurn
);
}
}
public static void initRegenerationInfoWhileAttached(Game game, Ability source, UUID permanentId) {
// enable regen info for attached permanent
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
game.getState().setValue(CardUtil.getCardZoneString("RegenerationActivated", permanent.getId(), game), Boolean.TRUE);
InfoEffect.addCardHintToPermanentConditional(game, source, permanent,
new ConditionHint(RegeneratingCanBeUsedCondition.instance, "Permanent will be regenerated instead destroy"),
Duration.EndOfTurn,
new AttachedToPermanentCondition(permanent.getId())
);
}
}
}
enum RegeneratingCanBeUsedCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
Boolean shieldActivated = (Boolean) game.getState().getValue(CardUtil.getCardZoneString("RegenerationActivated", permanent.getId(), game));
return shieldActivated != null && shieldActivated;
}
return false;
}
}

View file

@ -1,7 +1,5 @@
package mage.abilities.effects.common;
import java.util.Locale;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ReplacementEffectImpl;
@ -13,8 +11,9 @@ import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.Target;
import java.util.Locale;
/**
*
* @author maurer.it_at_gmail.com
*/
public class RegenerateTargetEffect extends ReplacementEffectImpl {
@ -31,13 +30,20 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl {
public boolean apply(Game game, Ability source) {
//20110204 - 701.11
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent != null && permanent.regenerate(this.getId(), game)) {
if (permanent != null && permanent.regenerate(source, game)) {
this.used = true;
return true;
}
return false;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
RegenerateSourceEffect.initRegenerationInfo(game, source, targetPointer.getFirst(game, source));
}
@Override
public RegenerateTargetEffect copy() {
return new RegenerateTargetEffect(this);
@ -76,5 +82,4 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl {
}
return sb.toString();
}
}

View file

@ -10,9 +10,15 @@ import java.io.Serializable;
*/
public interface Hint extends Serializable {
// It's a constant hint for cards/permanents (e.g. visible all the time)
// If you want to use a temporary hint for permanent then possible solutions availeable:
// 1. Add card hint to gained ability (ability create code);
// 2. Add constant text: InfoEffect.addInfoToPermanent
// 3. Add dynamic card hint: InfoEffect.addCardHintToPermanent
// TODO: add card hint for ActivateIfConditionActivatedAbility
// * remove my turn condition from cards construction
// * test condition texts (add alternative texts to donditions like getHintText?)
// * test condition texts (add alternative texts to conditions like getHintText?)
// * add auto-capitalize of first symbol
// * add support of compound conditions
// see https://github.com/magefree/mage/issues/5497

View file

@ -1,8 +1,5 @@
package mage.game.permanent;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
@ -13,6 +10,10 @@ import mage.game.Controllable;
import mage.game.Game;
import mage.game.GameState;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public interface Permanent extends Card, Controllable {
void setOriginalControllerId(UUID controllerId);
@ -148,11 +149,11 @@ public interface Permanent extends Card, Controllable {
boolean sacrifice(UUID sourceId, Game game);
boolean regenerate(UUID sourceId, Game game);
boolean regenerate(Ability source, Game game);
boolean fight(Permanent fightTarget, Ability source, Game game);
boolean fight(Permanent fightTarget, Ability source, Game game,boolean batchTrigger);
boolean fight(Permanent fightTarget, Ability source, Game game, boolean batchTrigger);
boolean entersBattlefield(UUID sourceId, Game game, Zone fromZone, boolean fireEvent);

View file

@ -1,7 +1,5 @@
package mage.game.permanent;
import java.io.Serializable;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -40,6 +38,9 @@ import mage.util.GameLog;
import mage.util.ThreadLocalStringBuilder;
import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -797,7 +798,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.attachedTo = attachToObjectId;
this.attachedToZoneChangeCounter = game.getState().getZoneChangeCounter(attachToObjectId);
for (Ability ability : this.getAbilities()) {
for (Iterator<Effect> ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext();) {
for (Iterator<Effect> ite = ability.getEffects(game, EffectType.CONTINUOUS).iterator(); ite.hasNext(); ) {
ContinuousEffect effect = (ContinuousEffect) ite.next();
game.getContinuousEffects().setOrder(effect);
// It's important to update the timestamp of the copied effect in ContinuousEffects because it does the action
@ -1171,13 +1172,17 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
}
@Override
public boolean regenerate(UUID sourceId, Game game) {
public boolean regenerate(Ability source, Game game) {
//20110930 - 701.12
if (!game.replaceEvent(GameEvent.getEvent(EventType.REGENERATE, objectId, sourceId, controllerId))) {
if (!game.replaceEvent(GameEvent.getEvent(EventType.REGENERATE, objectId, source.getSourceId(), controllerId))) {
this.tap(game);
this.removeFromCombat(game);
this.removeAllDamage(game);
game.fireEvent(GameEvent.getEvent(EventType.REGENERATED, objectId, sourceId, controllerId));
// remove regen info
game.getState().setValue(CardUtil.getCardZoneString("RegenerationActivated", this.getId(), game), Boolean.FALSE);
game.fireEvent(GameEvent.getEvent(EventType.REGENERATED, objectId, source.getSourceId(), controllerId));
return true;
}
return false;