forked from External/mage
* Regeneration abilities improved:
* Fixed that regeneration shield isn't added to permanent on aura sacrifice cost (example: Stamina, Carapace, see #2221); * Fixed that regeneration shields accumulated in attached aura instead permanent (bug example: re-attached aura gives old shields to new permanent, see #6846); * Added card hint with regeneration shields amount (#6846);
This commit is contained in:
parent
516a4104f1
commit
00411b4a9b
7 changed files with 411 additions and 99 deletions
|
|
@ -1,63 +1,49 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.AttachmentType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author jeff
|
||||
*/
|
||||
public class RegenerateAttachedEffect extends ReplacementEffectImpl {
|
||||
public class RegenerateAttachedEffect extends OneShotEffect {
|
||||
|
||||
protected AttachmentType attachmentType;
|
||||
|
||||
public RegenerateAttachedEffect(AttachmentType attachmentType) {
|
||||
super(Duration.EndOfTurn, Outcome.Regenerate);
|
||||
super(Outcome.Regenerate);
|
||||
this.attachmentType = attachmentType;
|
||||
this.setText();
|
||||
}
|
||||
|
||||
public RegenerateAttachedEffect(final RegenerateAttachedEffect effect) {
|
||||
super(effect);
|
||||
this.attachmentType = effect.attachmentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
//20110204 - 701.11
|
||||
Permanent permanent = game.getPermanent(source.getSourceId());
|
||||
// must use lki cause attachment can be sacrificed to activate regen
|
||||
Permanent attachment = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
||||
if (attachment == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent permanent = game.getPermanent(attachment.getAttachedTo());
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
Permanent equipped = game.getPermanent(permanent.getAttachedTo());
|
||||
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());
|
||||
RegenerateTargetEffect regenEffect = new RegenerateTargetEffect();
|
||||
regenEffect.setTargetPointer(new FixedTarget(permanent, game));
|
||||
game.addEffect(regenEffect, source);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -65,32 +51,6 @@ public class RegenerateAttachedEffect extends ReplacementEffectImpl {
|
|||
return new RegenerateAttachedEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
Permanent equipment = game.getPermanent(source.getSourceId());
|
||||
if (equipment != null) {
|
||||
Permanent equipped = game.getPermanent(equipment.getAttachedTo());
|
||||
if (equipped != null) {
|
||||
UUID equippedID = equipped.getId();
|
||||
if (event.getAmount() == 0 && event.getTargetId().equals(equippedID) && !this.used) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
staticText = "Regenerate " + attachmentType.verb().toLowerCase(Locale.ENGLISH) + " creature";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue