mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
fixed some NPE's and other errors
This commit is contained in:
parent
c2df049383
commit
68391a7522
12 changed files with 82 additions and 15 deletions
|
@ -203,7 +203,9 @@ public class RateCard {
|
|||
maxSingleCount = Math.max(maxSingleCount, typeCount);
|
||||
}
|
||||
}
|
||||
return 2 * converted + 3 * (10 - SINGLE_PENALTY[maxSingleCount]/*-DOUBLE_PENALTY[doubleCount]*/);
|
||||
if (maxSingleCount > 5)
|
||||
maxSingleCount = 5;
|
||||
return 2 * converted + 3 * (10 - SINGLE_PENALTY[maxSingleCount]/*-DOUBLE_PENALTY[doubleCount]*/);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Binary file not shown.
|
@ -100,7 +100,7 @@ class HarvestPyreCost extends CostImpl<HarvestPyreCost> implements VariableCost
|
|||
Player player = game.getPlayer(controllerId);
|
||||
while (true) {
|
||||
target.clearChosen();
|
||||
if (target.choose(Outcome.Exile, controllerId, sourceId, game)) {
|
||||
if (target.canChoose(controllerId, game) && target.choose(Outcome.Exile, controllerId, sourceId, game)) {
|
||||
Card card = player.getGraveyard().get(target.getFirstTarget(), game);
|
||||
if (card != null) {
|
||||
player.getGraveyard().remove(card);
|
||||
|
|
|
@ -96,7 +96,7 @@ class PreeminentCaptainEffect extends OneShotEffect<PreeminentCaptainEffect> {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
TargetCardInHand target = new TargetCardInHand(new FilterSoldierCard());
|
||||
if (target.choose(getOutcome(), player.getId(), source.getSourceId(), game)) {
|
||||
if (target.canChoose(player.getId(), game) && target.choose(getOutcome(), player.getId(), source.getSourceId(), game)) {
|
||||
if (target.getTargets().size() > 0) {
|
||||
UUID cardId = target.getFirstTarget();
|
||||
Card card = player.getHand().get(cardId, game);
|
||||
|
|
|
@ -91,7 +91,7 @@ class MortisDogsEffect extends OneShotEffect<MortisDogsEffect> {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||
if (player != null) {
|
||||
if (player != null && sourcePermanent != null) {
|
||||
player.loseLife(sourcePermanent.getPower().getValue(), game);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -32,16 +32,19 @@ import mage.Constants.CardType;
|
|||
import mage.Constants.ColoredManaSymbol;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.AlternativeCostImpl;
|
||||
import mage.abilities.costs.mana.ColoredManaCost;
|
||||
import mage.abilities.effects.common.CreateTokenEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.token.SnakeToken;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
||||
|
@ -96,11 +99,17 @@ class CobraTrapWatcher extends WatcherImpl<CobraTrapWatcher> {
|
|||
if (condition == true) { // no need to check - condition has already occured
|
||||
return;
|
||||
}
|
||||
if (event.getType() == EventType.DESTROYED_PERMANENT
|
||||
&& !game.getPlayer(controllerId).getGraveyard().get(event.getTargetId(), game).getCardType().contains(CardType.CREATURE)
|
||||
&& game.getStack().getStackObject(event.getSourceId()) != null
|
||||
&& game.getOpponents(controllerId).contains(game.getStack().getStackObject(event.getSourceId()).getControllerId())) {
|
||||
condition = true;
|
||||
Player player = game.getPlayer(controllerId);
|
||||
if (player != null && event.getType() == EventType.DESTROYED_PERMANENT) {
|
||||
Permanent perm = (Permanent) game.getLastKnownInformation(event.getTargetId(), Zone.BATTLEFIELD);
|
||||
if (perm != null && !perm.getCardType().contains(CardType.CREATURE)) {
|
||||
if (game.getStack().size() > 0) {
|
||||
StackObject spell = game.getStack().getStackObject(event.getSourceId());
|
||||
if (spell != null && game.getOpponents(controllerId).contains(spell.getControllerId())) {
|
||||
condition = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,50 @@
|
|||
package org.mage.test.cards;
|
||||
|
||||
import mage.Constants;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class TestCobraTrap extends CardTestPlayerBase {
|
||||
|
||||
@Test
|
||||
public void testCard() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 2);
|
||||
addCard(Constants.Zone.HAND, playerA, "Cobra Trap");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Mountain", 3);
|
||||
addCard(Constants.Zone.HAND, playerB, "Stone Rain");
|
||||
|
||||
castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Stone Rain", "Forest");
|
||||
castSpell(2, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Cobra Trap");
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
assertPermanentCount(playerA, "Forest", 1);
|
||||
assertPermanentCount(playerA, "Snake", 4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCardNegative() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Forest", 2);
|
||||
addCard(Constants.Zone.HAND, playerA, "Cobra Trap");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerB, "Mountain", 3);
|
||||
addCard(Constants.Zone.HAND, playerB, "Stone Rain");
|
||||
|
||||
castSpell(2, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Cobra Trap");
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
assertLife(playerA, 20);
|
||||
assertLife(playerB, 20);
|
||||
assertPermanentCount(playerA, "Forest", 2);
|
||||
assertPermanentCount(playerA, "Snake", 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -58,7 +58,7 @@ class BloodthirstEffect extends OneShotEffect<BloodthirstEffect> {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
BloodthirstWatcher watcher = (BloodthirstWatcher) game.getState().getWatchers().get("DamagedOpponents", source.getControllerId());
|
||||
if (watcher.conditionMet()) {
|
||||
if (watcher != null && watcher.conditionMet()) {
|
||||
Permanent p = game.getPermanent(source.getSourceId());
|
||||
if (p != null) {
|
||||
p.addCounters(CounterType.P1P1.createInstance(amount), game);
|
||||
|
|
|
@ -96,7 +96,7 @@ class CascadeEffect extends OneShotEffect<CascadeEffect> {
|
|||
ExileZone exile = game.getExile().createZone(source.getSourceId(), player.getName() + " Cascade");
|
||||
int sourceCost = game.getObject(source.getSourceId()).getManaCost().convertedManaCost();
|
||||
do {
|
||||
card = player.getLibrary().getFromTop(game);
|
||||
card = player.getLibrary().removeFromTop(game);
|
||||
if (card == null)
|
||||
break;
|
||||
card.moveToExile(exile.getId(), exile.getName(), source.getId(), game);
|
||||
|
|
|
@ -489,7 +489,8 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
Ability spellAbility = game.getStack().getSpell(ability.getId()).getSpellAbility();
|
||||
if (spellAbility.activate(game, noMana)) {
|
||||
for (KickerAbility kicker: card.getAbilities().getKickerAbilities()) {
|
||||
kicker.activate(game, false);
|
||||
if (kicker.getCosts().canPay(ability.getSourceId(), playerId, game) && kicker.canChooseTarget(game))
|
||||
kicker.activate(game, false);
|
||||
}
|
||||
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spellAbility.getId(), spellAbility.getSourceId(), playerId);
|
||||
event.setZone(fromZone);
|
||||
|
@ -1209,7 +1210,10 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (AlternativeCost cost: ability.getAlternativeCosts()) {
|
||||
if (cost.isAvailable(game, ability) && cost.canPay(ability.getSourceId(), playerId, game))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,9 @@ public abstract class TargetObject<T extends TargetObject<T>> extends TargetImpl
|
|||
public String getTargetedName(Game game) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (UUID targetId: getTargets()) {
|
||||
sb.append(game.getObject(targetId).getName()).append(" ");
|
||||
MageObject object = game.getObject(targetId);
|
||||
if (object != null)
|
||||
sb.append(object.getName()).append(" ");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue