Merge pull request #1980 from spjspj/master

spjspj - Fix possible npe for Clockspinning and change return code fr…
This commit is contained in:
spjspj 2016-06-09 01:28:36 +10:00
commit 70981f09a4
2 changed files with 31 additions and 26 deletions

View file

@ -159,27 +159,34 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, permanent);
if (counter != null) {
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
effect.apply(game, source);
}
}
return true;
}
if (player != null && card != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
Counter counter = selectCounterType(game, source, card);
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, card);
if (counter != null) {
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
effect.apply(game, source);
}
}
return true;
}
return false;
}

View file

@ -82,14 +82,13 @@ public class AddCountersTargetEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
if (controller != null && sourceObject != null && counter != null) {
int affectedTargets = 0;
for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid);
Player player = game.getPlayer(uuid);
Card card = game.getCard(targetPointer.getFirst(game, source));
if (permanent != null) {
if (counter != null) {
Counter newCounter = counter.copy();
int calculated = amount.calculate(game, source, this);
if (calculated > 0 && newCounter.getCount() > 0) {
@ -104,7 +103,6 @@ public class AddCountersTargetEffect extends OneShotEffect {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
+ numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
}
}
} else if (player != null) {
Counter newCounter = counter.copy();
newCounter.add(amount.calculate(game, source, this));
@ -114,7 +112,7 @@ public class AddCountersTargetEffect extends OneShotEffect {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
+ counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName());
}
} else if (card != null && counter != null) {
} else if (card != null) {
card.addCounters(counter.getName(), counter.getCount(), game);
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder("Added ").append(counter.getCount()).append(" ").append(counter.getName())