1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-05 17:00:10 -09:00

fixed ConcurrentUpdateException with multi-threaded ai

This commit is contained in:
BetaSteward 2012-01-24 22:50:18 -05:00
parent e05024351f
commit 23616432e4
9 changed files with 51 additions and 28 deletions
Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai
Mage.Sets/src/mage/sets/innistrad
Mage/src/mage/abilities

View file

@ -227,7 +227,7 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
// Start with X = {1}
for (int i = 1; i < numAvailable; i++) {
Ability newAbility = ability.copy();
newAbility.addManaCost(new GenericManaCost(i));
newAbility.getManaCostsToPay().add(new GenericManaCost(i));
allActions.add(newAbility);
}
}

View file

@ -128,5 +128,10 @@ class HarvestPyreCost extends CostImpl<HarvestPyreCost> implements VariableCost
public HarvestPyreCost copy() {
return new HarvestPyreCost(this);
}
@Override
public void setAmount(int amount) {
amountPaid = amount;
}
}

View file

@ -37,5 +37,6 @@ import mage.filter.FilterMana;
public interface VariableCost {
public int getAmount();
public void setAmount(int amount);
public void setFilter(FilterMana filter);
}

View file

@ -88,7 +88,12 @@ public class PayVariableLoyaltyCost extends CostImpl<PayVariableLoyaltyCost> imp
return amountPaid;
}
@Override
@Override
public void setAmount(int amount) {
amountPaid = amount;
}
@Override
public void setFilter(FilterMana filter) {
}

View file

@ -93,7 +93,12 @@ public class TapVariableTargetCost extends CostImpl<TapVariableTargetCost> imple
return amountPaid;
}
@Override
@Override
public void setAmount(int amount) {
amountPaid = amount;
}
@Override
public void setFilter(FilterMana filter) {
}

View file

@ -41,6 +41,7 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
public ManaCosts<T> getUnpaidVariableCosts();
public List<VariableCost> getVariableCosts();
public int getX();
public void setX(int x);
public void load(String mana);
public List<String> getSymbols();

View file

@ -28,6 +28,7 @@
package mage.abilities.costs.mana;
import java.util.*;
import mage.Constants.ColoredManaSymbol;
import mage.Mana;
import mage.abilities.Ability;
@ -39,8 +40,6 @@ import mage.players.ManaPool;
import mage.players.Player;
import mage.target.Targets;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -195,6 +194,13 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return amount;
}
@Override
public void setX(int x) {
List<VariableCost> variableCosts = getVariableCosts();
if (!variableCosts.isEmpty())
variableCosts.get(0).setAmount(x);
}
@Override
public void setPayment(Mana mana) {
}

View file

@ -96,7 +96,12 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
return payment.count() / multiplier;
}
@Override
@Override
public void setAmount(int amount) {
payment.setColorless(amount);
}
@Override
public boolean testPay(Mana testMana) {
return true;
}

View file

@ -32,8 +32,6 @@ import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
import mage.abilities.effects.common.ExileSourceEffect;
@ -42,29 +40,28 @@ import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
/**
* @author nantuko
*/
public class FlashbackAbility extends ActivatedAbilityImpl<FlashbackAbility> {
public FlashbackAbility(ManaCosts costs, Constants.TimingRule timingRule) {
super(Constants.Zone.GRAVEYARD, new FlashbackEffect(), costs);
public FlashbackAbility(Cost cost, Constants.TimingRule timingRule) {
super(Constants.Zone.GRAVEYARD, new FlashbackEffect(), cost);
this.timing = timingRule;
this.usesStack = false;
this.addEffect(new CreateDelayedTriggeredAbilityEffect(new FlashbackTriggeredAbility()));
}
@Override
public boolean activate(Game game, boolean noMana) {
Card card = game.getCard(sourceId);
if (card != null) {
getEffects().get(0).setTargetPointer(new FixedTarget(card.getId()));
return super.activate(game, noMana);
}
return false;
}
// @Override
// public boolean activate(Game game, boolean noMana) {
// Card card = game.getCard(sourceId);
// if (card != null) {
// getEffects().get(0).setTargetPointer(new FixedTarget(card.getId()));
// return super.activate(game, noMana);
// }
// return false;
// }
public FlashbackAbility(final FlashbackAbility ability) {
super(ability);
@ -109,15 +106,13 @@ class FlashbackEffect extends OneShotEffect<FlashbackEffect> {
@Override
public boolean apply(Game game, Ability source) {
Card target = (Card) game.getObject(targetPointer.getFirst(source));
if (target != null) {
Player controller = game.getPlayer(target.getOwnerId());
Card card = (Card) game.getObject(source.getSourceId());
if (card != null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
target.getSpellAbility().getManaCostsToPay().clear();
for (Cost cost: source.getManaCostsToPay()) {
target.getSpellAbility().getManaCostsToPay().add((ManaCost) cost.copy());
}
return controller.cast(target.getSpellAbility(), game, true);
int amount = source.getManaCostsToPay().getX();
card.getSpellAbility().getManaCostsToPay().setX(amount);
return controller.cast(card.getSpellAbility(), game, true);
}
}
return false;