1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-13 01:01:11 -09:00

Address issues identified in code review

This commit is contained in:
Thomas Winwood 2019-04-19 12:41:25 +01:00
parent 8db00d34de
commit 67b48dbea7

View file

@ -1,5 +1,6 @@
package mage.cards.r; package mage.cards.r;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
@ -19,7 +20,6 @@ import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -76,20 +76,24 @@ class RogueSkycaptainEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId()); Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (controller != null && permanent != null) { if (controller != null && permanent != null) {
new AddCountersSourceEffect(CounterType.WAGE.createInstance(), true).apply(game, source); new AddCountersSourceEffect(CounterType.WAGE.createInstance(), true).apply(game, source);
Cost cost = new GenericManaCost(2 * permanent.getCounters(game).getCount(CounterType.WAGE)); Cost cost = new GenericManaCost(2 * permanent.getCounters(game).getCount(CounterType.WAGE));
if (!cost.pay(source, game, controller.getId(), controller.getId(), false)) { if (!cost.pay(source, game, controller.getId(), controller.getId(), false)) {
new RemoveAllCountersSourceEffect(CounterType.WAGE).apply(game, source); new RemoveAllCountersSourceEffect(CounterType.WAGE).apply(game, source);
Target target = new TargetOpponent(true); Player opponent;
target.choose(Outcome.GainControl, source.getControllerId(), source.getSourceId(), game); Set<UUID> opponents = game.getOpponents(controller.getId());
Player opponent = game.getPlayer(target.getFirstTarget()); if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
target.setNotTarget(true);
target.choose(Outcome.GainControl, source.getControllerId(), source.getSourceId(), game);
opponent = game.getPlayer(target.getFirstTarget());
}
if (opponent != null) { if (opponent != null) {
permanent.changeControllerId(controller.getId(), game); permanent.changeControllerId(opponent.getId(), game);
} }
} }
return true; return true;