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

@ -66,7 +66,7 @@ public class Clockspinning extends CardImpl {
this.getSpellAbility().addTarget(new TargetPermanentOrSuspendedCard()); this.getSpellAbility().addTarget(new TargetPermanentOrSuspendedCard());
this.getSpellAbility().addEffect(new ClockspinningAddOrRemoveCounterEffect()); this.getSpellAbility().addEffect(new ClockspinningAddOrRemoveCounterEffect());
} }
public Clockspinning(final Clockspinning card) { public Clockspinning(final Clockspinning card) {
super(card); super(card);
} }
@ -159,26 +159,33 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) { if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(); RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source); effect.apply(game, source);
} else { } else {
Counter counter = selectCounterType(game, source, permanent); Counter counter = selectCounterType(game, source, permanent);
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); if (counter != null) {
return effect.apply(game, source); AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
effect.apply(game, source);
}
} }
return true;
} }
if (player != null && card != null) { if (player != null && card != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) { if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
Counter counter = selectCounterType(game, source, card); Counter counter = selectCounterType(game, source, card);
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter); RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source); effect.apply(game, source);
} else { } else {
Counter counter = selectCounterType(game, source, card); Counter counter = selectCounterType(game, source, card);
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter); if (counter != null) {
effect.setTargetPointer(new FixedTarget(source.getFirstTarget())); AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
return effect.apply(game, source); effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
effect.apply(game, source);
}
} }
return true;
} }
return false; return false;

View file

@ -82,28 +82,26 @@ public class AddCountersTargetEffect extends OneShotEffect {
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());
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) { if (controller != null && sourceObject != null && counter != null) {
int affectedTargets = 0; int affectedTargets = 0;
for (UUID uuid : targetPointer.getTargets(game, source)) { for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid); Permanent permanent = game.getPermanent(uuid);
Player player = game.getPlayer(uuid); Player player = game.getPlayer(uuid);
Card card = game.getCard(targetPointer.getFirst(game, source)); Card card = game.getCard(targetPointer.getFirst(game, source));
if (permanent != null) { if (permanent != null) {
if (counter != null) { Counter newCounter = counter.copy();
Counter newCounter = counter.copy(); int calculated = amount.calculate(game, source, this);
int calculated = amount.calculate(game, source, this); if (calculated > 0 && newCounter.getCount() > 0) {
if (calculated > 0 && newCounter.getCount() > 0) { newCounter.remove(newCounter.getCount());
newCounter.remove(newCounter.getCount()); }
} newCounter.add(calculated);
newCounter.add(calculated); int before = permanent.getCounters().getCount(counter.getName());
int before = permanent.getCounters().getCount(counter.getName()); permanent.addCounters(newCounter, game);
permanent.addCounters(newCounter, game); int numberAdded = permanent.getCounters().getCount(counter.getName()) - before;
int numberAdded = permanent.getCounters().getCount(counter.getName()) - before; affectedTargets++;
affectedTargets++; if (!game.isSimulation()) {
if (!game.isSimulation()) { game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts " + numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
+ numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
}
} }
} else if (player != null) { } else if (player != null) {
Counter newCounter = counter.copy(); Counter newCounter = counter.copy();
@ -114,7 +112,7 @@ public class AddCountersTargetEffect extends OneShotEffect {
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts " game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
+ counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName()); + 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); card.addCounters(counter.getName(), counter.getCount(), game);
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(new StringBuilder("Added ").append(counter.getCount()).append(" ").append(counter.getName()) game.informPlayers(new StringBuilder("Added ").append(counter.getCount()).append(" ").append(counter.getName())