mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
Merge pull request #1980 from spjspj/master
spjspj - Fix possible npe for Clockspinning and change return code fr…
This commit is contained in:
commit
70981f09a4
2 changed files with 31 additions and 26 deletions
|
@ -66,7 +66,7 @@ public class Clockspinning extends CardImpl {
|
|||
this.getSpellAbility().addTarget(new TargetPermanentOrSuspendedCard());
|
||||
this.getSpellAbility().addEffect(new ClockspinningAddOrRemoveCounterEffect());
|
||||
}
|
||||
|
||||
|
||||
public Clockspinning(final Clockspinning 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)) {
|
||||
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);
|
||||
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
|
||||
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
|
||||
return effect.apply(game, source);
|
||||
|
||||
if (counter != null) {
|
||||
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
|
||||
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
|
||||
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);
|
||||
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
|
||||
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
|
||||
return effect.apply(game, source);
|
||||
if (counter != null) {
|
||||
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
|
||||
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
|
||||
effect.apply(game, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -82,28 +82,26 @@ 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) {
|
||||
newCounter.remove(newCounter.getCount());
|
||||
}
|
||||
newCounter.add(calculated);
|
||||
int before = permanent.getCounters().getCount(counter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
int numberAdded = permanent.getCounters().getCount(counter.getName()) - before;
|
||||
affectedTargets++;
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
|
||||
+ numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
|
||||
}
|
||||
Counter newCounter = counter.copy();
|
||||
int calculated = amount.calculate(game, source, this);
|
||||
if (calculated > 0 && newCounter.getCount() > 0) {
|
||||
newCounter.remove(newCounter.getCount());
|
||||
}
|
||||
newCounter.add(calculated);
|
||||
int before = permanent.getCounters().getCount(counter.getName());
|
||||
permanent.addCounters(newCounter, game);
|
||||
int numberAdded = permanent.getCounters().getCount(counter.getName()) - before;
|
||||
affectedTargets++;
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
|
||||
+ numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
|
||||
}
|
||||
} else if (player != null) {
|
||||
Counter newCounter = counter.copy();
|
||||
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue