mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
* Reworked GainControlAllEffect that fixed a problem of Varchild, Betrayer of Kjeldor gaining control of creatures entering the battlefield after the Varchild left the battlefield.
This commit is contained in:
parent
3c727eb06b
commit
12c4bacc07
7 changed files with 97 additions and 45 deletions
|
|
@ -1,44 +1,42 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author fenhl
|
||||
*/
|
||||
public class GainControlAllEffect extends ContinuousEffectImpl {
|
||||
public class GainControlAllEffect extends OneShotEffect {
|
||||
|
||||
private final FilterPermanent filter;
|
||||
private final UUID controllingPlayerId;
|
||||
private final Duration duration;
|
||||
|
||||
public GainControlAllEffect(Duration duration, FilterPermanent filter) {
|
||||
this(duration, filter, null);
|
||||
}
|
||||
|
||||
public GainControlAllEffect(Duration duration, FilterPermanent filter, UUID controllingPlayerId) {
|
||||
super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
|
||||
super(Outcome.GainControl);
|
||||
this.filter = filter;
|
||||
this.duration = duration;
|
||||
this.controllingPlayerId = controllingPlayerId;
|
||||
this.staticText = "Gain control of " + filter.getMessage();
|
||||
}
|
||||
|
||||
public GainControlAllEffect(final GainControlAllEffect effect) {
|
||||
super(effect);
|
||||
this.filter = effect.filter.copy();
|
||||
this.duration = effect.duration;
|
||||
this.controllingPlayerId = effect.controllingPlayerId;
|
||||
}
|
||||
|
||||
|
|
@ -49,23 +47,13 @@ public class GainControlAllEffect extends ContinuousEffectImpl {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
|
||||
if (permanent != null) {
|
||||
if (controllingPlayerId == null) {
|
||||
permanent.changeControllerId(source.getControllerId(), game);
|
||||
} else {
|
||||
permanent.changeControllerId(controllingPlayerId, game);
|
||||
}
|
||||
|
||||
}
|
||||
for (Permanent permanent : game.getBattlefield()
|
||||
.getActivePermanents(filter,
|
||||
source.getControllerId(), source.getSourceId(), game)) {
|
||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, controllingPlayerId);
|
||||
effect.setTargetPointer(new FixedTarget(permanent, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Gain control of ").append(filter.getMessage());
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue