* C17 Enchantment Curses - Fixed a bug that could create game errors (index out of bounds).

This commit is contained in:
LevelX2 2017-08-17 21:36:55 +02:00
parent 0affb45264
commit db93e3f672
16 changed files with 179 additions and 159 deletions

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game;
import mage.game.match.MatchImpl;

View file

@ -158,7 +158,7 @@ public final class CombatUtil {
public static CombatInfo blockWithGoodTrade(Game game, List<Permanent> attackers, List<Permanent> blockers) {
UUID attackerId = game.getCombat().getAttackerId();
UUID attackerId = game.getCombat().getAttackingPlayerId();
UUID defenderId = game.getCombat().getDefenders().iterator().next();
if (attackerId == null || defenderId == null) {
log.warn("Couldn't find attacker or defender: " + attackerId + ' ' + defenderId);
@ -295,7 +295,7 @@ public final class CombatUtil {
public static CombatInfo blockWithGoodTrade2(Game game, List<Permanent> attackers, List<Permanent> blockers) {
UUID attackerId = game.getCombat().getAttackerId();
UUID attackerId = game.getCombat().getAttackingPlayerId();
UUID defenderId = game.getCombat().getDefenders().iterator().next();
if (attackerId == null || defenderId == null) {
log.warn("Couldn't find attacker or defender: " + attackerId + ' ' + defenderId);

View file

@ -108,7 +108,7 @@ class AdmiralAckbarTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return game.getCombat().getAttackers().size() >= 2 && game.getCombat().getAttackerId().equals(getControllerId());
return game.getCombat().getAttackers().size() >= 2 && game.getCombat().getAttackingPlayerId().equals(getControllerId());
}
@Override

View file

@ -84,7 +84,7 @@ public class CitadelSiege extends CardImpl {
public void adjustTargets(Ability ability, Game game) {
if (this.getAbilities().contains(ability) && ability.getRule().startsWith("&bull Dragons")) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that player controls");
filter.add(new ControllerIdPredicate(game.getCombat().getAttackerId()));
filter.add(new ControllerIdPredicate(game.getCombat().getAttackingPlayerId()));
ability.getTargets().clear();
ability.addTarget(new TargetCreaturePermanent(filter));
}

View file

@ -49,6 +49,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.UntapAllControllerEffect;
import mage.filter.StaticFilters;
import mage.filter.common.FilterNonlandPermanent;
import mage.game.combat.CombatGroup;
import mage.players.Player;
/**
@ -69,9 +70,7 @@ public class CurseOfBounty extends CardImpl {
// Whenever enchanted player is attacked, untap all nonland permanents you control.
// Each opponent attacking that player untaps all nonland permanents he or she controls.
Ability ability = new CurseOfBountyTriggeredAbility();
ability.addEffect(new UntapAllControllerEffect(new FilterNonlandPermanent()));
this.addAbility(ability);
this.addAbility(new CurseOfBountyTriggeredAbility());
}
public CurseOfBounty(final CurseOfBounty card) {
@ -87,7 +86,7 @@ public class CurseOfBounty extends CardImpl {
class CurseOfBountyTriggeredAbility extends TriggeredAbilityImpl {
public CurseOfBountyTriggeredAbility() {
super(Zone.BATTLEFIELD, new UntapAllNonlandsTargetEffect(), false);
super(Zone.BATTLEFIELD, new UntapAllControllerEffect(new FilterNonlandPermanent()), false);
}
public CurseOfBountyTriggeredAbility(final CurseOfBountyTriggeredAbility ability) {
@ -101,18 +100,22 @@ class CurseOfBountyTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId());
UUID controller = this.getControllerId();
if (enchantment != null
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
Player controller = game.getPlayer(getControllerId());
if (controller != null && enchantment != null
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
if (!game.getCombat().getAttackerId().equals(controller)) {
for (Effect effect: this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
if (group.getDefenderId().equals(enchantment.getAttachedTo())) {
if (controller.hasOpponent(game.getCombat().getAttackingPlayerId(), game)) {
Effect effect = new UntapAllNonlandsTargetEffect();
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
this.addEffect(effect);
}
return true;
}
}
}
return false;
}

View file

@ -102,7 +102,7 @@ class CurseOfChaosTriggeredAbility extends TriggeredAbilityImpl {
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
for (Effect effect: this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
}
return true;
}

View file

@ -27,10 +27,12 @@
*/
package mage.cards.c;
import mage.abilities.Ability;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.CreateTokenTargetEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -39,15 +41,14 @@ import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.ZombieToken;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.CreateTokenTargetEffect;
import mage.game.permanent.token.ZombieToken;
/**
*
@ -66,9 +67,7 @@ public class CurseOfDisturbance extends CardImpl {
this.addAbility(new EnchantAbility(auraTarget.getTargetName()));
// Whenever enchanted player is attacked, create a 2/2 black Zombie creature token. Each opponent attacking that player does the same.
Ability ability = new CurseOfDisturbanceTriggeredAbility();
ability.addEffect(new CreateTokenEffect(new ZombieToken()));
this.addAbility(ability);
this.addAbility(new CurseOfDisturbanceTriggeredAbility());
}
public CurseOfDisturbance(final CurseOfDisturbance card) {
@ -84,7 +83,7 @@ public class CurseOfDisturbance extends CardImpl {
class CurseOfDisturbanceTriggeredAbility extends TriggeredAbilityImpl {
public CurseOfDisturbanceTriggeredAbility() {
super(Zone.BATTLEFIELD, new CreateTokenTargetEffect(new ZombieToken()), false);
super(Zone.BATTLEFIELD, new CreateTokenEffect(new ZombieToken()), false);
}
public CurseOfDisturbanceTriggeredAbility(final CurseOfDisturbanceTriggeredAbility ability) {
@ -98,18 +97,22 @@ class CurseOfDisturbanceTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId());
UUID controller = this.getControllerId();
if (enchantment != null
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
Player controller = game.getPlayer(getControllerId());
if (controller != null && enchantment != null
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
if (!game.getCombat().getAttackerId().equals(controller)) {
for (Effect effect: this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
if (group.getDefenderId().equals(enchantment.getAttachedTo())) {
if (controller.hasOpponent(game.getCombat().getAttackingPlayerId(), game)) {
Effect effect = new CreateTokenTargetEffect(new ZombieToken());
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
this.addEffect(effect);
}
return true;
}
}
}
return false;
}

View file

@ -102,7 +102,7 @@ class CurseOfInertiaTriggeredAbility extends TriggeredAbilityImpl {
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
TargetPermanent target = new TargetPermanent();
target.setTargetController(game.getCombat().getAttackerId());
target.setTargetController(game.getCombat().getAttackingPlayerId());
addTarget(target);
return true;
}

View file

@ -28,8 +28,8 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.CreateTokenTargetEffect;
@ -46,6 +46,7 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.GoldToken;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.targetpointer.FixedTarget;
@ -67,9 +68,7 @@ public class CurseOfOpulence extends CardImpl {
// Whenever enchanted player is attacked, create a colorless artifact token named Gold.
// It has "sacrifice this artifact: Add one mana of any color to your mana pool." Each opponent attacking that player does the same.
Ability ability = new CurseOfOpulenceTriggeredAbility();
ability.addEffect(new CreateTokenEffect(new GoldToken()));
this.addAbility(ability);
this.addAbility(new CurseOfOpulenceTriggeredAbility());
}
public CurseOfOpulence(final CurseOfOpulence card) {
@ -85,7 +84,7 @@ public class CurseOfOpulence extends CardImpl {
class CurseOfOpulenceTriggeredAbility extends TriggeredAbilityImpl {
public CurseOfOpulenceTriggeredAbility() {
super(Zone.BATTLEFIELD, new CreateTokenTargetEffect(new GoldToken()), false);
super(Zone.BATTLEFIELD, new CreateTokenEffect(new GoldToken()), false);
}
public CurseOfOpulenceTriggeredAbility(final CurseOfOpulenceTriggeredAbility ability) {
@ -99,13 +98,18 @@ class CurseOfOpulenceTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId());
if (enchantment != null
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
Player controller = game.getPlayer(getControllerId());
if (controller != null && enchantment != null
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
if (group.getDefenderId().equals(enchantment.getAttachedTo())) {
this.getEffects().setTargetPointer(new FixedTarget(enchantment.getAttachedTo()));
if (controller.hasOpponent(game.getCombat().getAttackingPlayerId(), game)) {
Effect effect = new CreateTokenTargetEffect(new GoldToken());
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
this.addEffect(effect);
}
return true;
}
}

View file

@ -108,7 +108,7 @@ class CurseOfShallowTriggeredAbility extends TriggeredAbilityImpl {
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
}
return true;
}

View file

@ -27,10 +27,12 @@
*/
package mage.cards.c;
import mage.abilities.Ability;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.DrawCardTargetEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -39,14 +41,13 @@ import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPlayer;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.DrawCardTargetEffect;
/**
*
@ -65,9 +66,7 @@ public class CurseOfVerbosity extends CardImpl {
this.addAbility(new EnchantAbility(auraTarget.getTargetName()));
// Whenever enchanted player is attacked, draw a card. Each opponent attacking that player does the same.
Ability ability = new CurseOfVerbosityTriggeredAbility();
ability.addEffect(new DrawCardSourceControllerEffect(1));
this.addAbility(ability);
this.addAbility(new CurseOfVerbosityTriggeredAbility());
}
public CurseOfVerbosity(final CurseOfVerbosity card) {
@ -83,7 +82,7 @@ public class CurseOfVerbosity extends CardImpl {
class CurseOfVerbosityTriggeredAbility extends TriggeredAbilityImpl {
public CurseOfVerbosityTriggeredAbility() {
super(Zone.BATTLEFIELD, new DrawCardTargetEffect(1), false);
super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), false);
}
public CurseOfVerbosityTriggeredAbility(final CurseOfVerbosityTriggeredAbility ability) {
@ -97,18 +96,22 @@ class CurseOfVerbosityTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId());
UUID controller = this.getControllerId();
if (enchantment != null
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
Player controller = game.getPlayer(getControllerId());
if (controller != null && enchantment != null
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
if (!game.getCombat().getAttackerId().equals(controller)) {
for (Effect effect: this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
if (group.getDefenderId().equals(enchantment.getAttachedTo())) {
if (controller.hasOpponent(game.getCombat().getAttackingPlayerId(), game)) {
Effect effect = new DrawCardTargetEffect(1);
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
this.addEffect(effect);
}
return true;
}
}
}
return false;
}

View file

@ -27,7 +27,6 @@
*/
package mage.cards.c;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
@ -47,6 +46,8 @@ import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.GainLifeTargetEffect;
import mage.game.combat.CombatGroup;
import mage.players.Player;
/**
*
@ -65,9 +66,7 @@ public class CurseOfVitality extends CardImpl {
this.addAbility(new EnchantAbility(auraTarget.getTargetName()));
// Whenever enchanted player is attacked, you gain 2 life. Each opponent attacking that player does the same.
Ability ability = new CurseOfVitalityTriggeredAbility();
ability.addEffect(new GainLifeEffect(2));
this.addAbility(ability);
this.addAbility(new CurseOfVitalityTriggeredAbility());
}
public CurseOfVitality(final CurseOfVitality card) {
@ -83,7 +82,7 @@ public class CurseOfVitality extends CardImpl {
class CurseOfVitalityTriggeredAbility extends TriggeredAbilityImpl {
public CurseOfVitalityTriggeredAbility() {
super(Zone.BATTLEFIELD, new GainLifeTargetEffect(2), false);
super(Zone.BATTLEFIELD, new GainLifeEffect(2), false);
}
public CurseOfVitalityTriggeredAbility(final CurseOfVitalityTriggeredAbility ability) {
@ -97,18 +96,22 @@ class CurseOfVitalityTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId());
UUID controller = this.getControllerId();
if (enchantment != null
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
Player controller = game.getPlayer(getControllerId());
if (controller != null && enchantment != null
&& enchantment.getAttachedTo() != null
&& game.getCombat().getPlayerDefenders(game).contains(enchantment.getAttachedTo())) {
if (!game.getCombat().getAttackerId().equals(controller)) {
for (Effect effect: this.getEffects()) {
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackerId()));
}
for (CombatGroup group : game.getCombat().getBlockingGroups()) {
if (group.getDefenderId().equals(enchantment.getAttachedTo())) {
if (controller.hasOpponent(game.getCombat().getAttackingPlayerId(), game)) {
Effect effect = new GainLifeTargetEffect(2);
effect.setTargetPointer(new FixedTarget(game.getCombat().getAttackingPlayerId()));
this.addEffect(effect);
}
return true;
}
}
}
return false;
}

View file

@ -83,7 +83,7 @@ class OverwhelmingInstinctTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return game.getCombat().getAttackers().size() >= 3 && game.getCombat().getAttackerId().equals(getControllerId());
return game.getCombat().getAttackers().size() >= 3 && game.getCombat().getAttackingPlayerId().equals(getControllerId());
}
@Override

View file

@ -56,7 +56,7 @@ public class AttacksWithCreaturesTriggeredAbility extends TriggeredAbilityImpl {
attackerCount++;
}
}
return attackerCount >= minAttackers && game.getCombat().getAttackerId().equals(getControllerId());
return attackerCount >= minAttackers && game.getCombat().getAttackingPlayerId().equals(getControllerId());
}
@Override

View file

@ -1414,7 +1414,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
public UUID getAttackerId() {
public UUID getAttackingPlayerId() {
return attackingPlayerId;
}

View file

@ -168,9 +168,14 @@ public abstract class MatchImpl implements Match {
MatchPlayer matchWinner = null;
for (MatchPlayer matchPlayer : players) {
if (!matchPlayer.hasQuit()) {
if (matchPlayer.getDeck() == null) {
logger.error("MatchPlayer's deck was null - matchId " + this.getId() + " - " + matchPlayer.getName());
matchPlayer.setQuit(true);
} else {
activePlayers++;
matchWinner = matchPlayer;
}
}
if (matchPlayer.getWins() >= options.getWinsNeeded()) {
matchPlayer.setMatchWinner(true);
endTime = new Date();