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

Improved alternative cost from dynamic effects (it's like PR):

* Game: added multiple cards/effects support (old version supported only 1 effect per game);
 * Game: added combo support with split and adventure cards;
 * AI: computer can see and play cards with dynamic added alternative cost (like Bolas's Citadel);
 * UI: users can see playable cards with alternative cost.
This commit is contained in:
Oleg Agafonov 2019-12-14 19:09:25 +04:00
parent ddedabad85
commit a05da68493
6 changed files with 164 additions and 119 deletions
Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human
Mage.Tests/src/test/java/org/mage/test
Mage/src/main/java/mage

View file

@ -1742,7 +1742,7 @@ public class HumanPlayer extends PlayerImpl {
if (ability instanceof PlayLandAbility) {
return true;
}
if (!ability.getSourceId().equals(getCastSourceIdWithAlternateMana())
if (!getCastSourceIdWithAlternateMana().contains(ability.getSourceId())
&& ability.getManaCostsToPay().convertedManaCost() > 0) {
return true;
}

View file

@ -2374,20 +2374,25 @@ public class TestPlayer implements Player {
}
@Override
public UUID getCastSourceIdWithAlternateMana() {
public Set<UUID> getCastSourceIdWithAlternateMana() {
return computerPlayer.getCastSourceIdWithAlternateMana();
}
@Override
public ManaCosts getCastSourceIdManaCosts() {
public Map<UUID, ManaCosts<ManaCost>> getCastSourceIdManaCosts() {
return computerPlayer.getCastSourceIdManaCosts();
}
@Override
public Costs<Cost> getCastSourceIdCosts() {
public Map<UUID, Costs<Cost>> getCastSourceIdCosts() {
return computerPlayer.getCastSourceIdCosts();
}
@Override
public void clearCastSourceIdManaCosts() {
computerPlayer.clearCastSourceIdManaCosts();
}
@Override
public boolean isInPayManaMode() {
return computerPlayer.isInPayManaMode();

View file

@ -19,8 +19,8 @@ import mage.counters.Counter;
import mage.counters.Counters;
import mage.designations.Designation;
import mage.designations.DesignationType;
import mage.filter.FilterPermanent;
import mage.filter.FilterMana;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.Graveyard;
import mage.game.Table;
@ -1208,7 +1208,7 @@ public class PlayerStub implements Player {
}
@Override
public UUID getCastSourceIdWithAlternateMana() {
public Set<UUID> getCastSourceIdWithAlternateMana() {
return null;
}
@ -1218,15 +1218,20 @@ public class PlayerStub implements Player {
}
@Override
public ManaCosts getCastSourceIdManaCosts() {
public Map<UUID, Costs<Cost>> getCastSourceIdCosts() {
return null;
}
@Override
public Costs<Cost> getCastSourceIdCosts() {
public Map<UUID, ManaCosts<ManaCost>> getCastSourceIdManaCosts() {
return null;
}
@Override
public void clearCastSourceIdManaCosts() {
}
@Override
public void addPermissionToShowHandCards(UUID watcherUserId) {

View file

@ -63,7 +63,7 @@ public class SpellAbility extends ActivatedAbilityImpl {
*/
public boolean spellCanBeActivatedRegularlyNow(UUID playerId, Game game) {
MageObject object = game.getObject(sourceId);
if ((Boolean) game.getState().getValue("CastFromExileEnabled" + object.getId()) != null) {
if (game.getState().getValue("CastFromExileEnabled" + object.getId()) != null) {
return (Boolean) game.getState().getValue("CastFromExileEnabled" + object.getId()); // card like Chandra, Torch of Defiance +1 loyal ability)
}
return null != game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.CAST_AS_INSTANT, this, playerId, game) // check this first to allow Offering in main phase
@ -98,7 +98,7 @@ public class SpellAbility extends ActivatedAbilityImpl {
if (getSpellAbilityType() == SpellAbilityType.BASE_ALTERNATE) {
Player player = game.getPlayer(playerId);
if (player != null
&& getSourceId().equals(player.getCastSourceIdWithAlternateMana())) {
&& player.getCastSourceIdWithAlternateMana().contains(getSourceId())) {
return ActivationStatus.getFalse();
}
}

View file

@ -20,8 +20,8 @@ import mage.counters.Counter;
import mage.counters.Counters;
import mage.designations.Designation;
import mage.designations.DesignationType;
import mage.filter.FilterPermanent;
import mage.filter.FilterMana;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.Graveyard;
import mage.game.Table;
@ -851,11 +851,13 @@ public interface Player extends MageItem, Copyable<Player> {
*/
void setCastSourceIdWithAlternateMana(UUID sourceId, ManaCosts<ManaCost> manaCosts, Costs<Cost> costs);
UUID getCastSourceIdWithAlternateMana();
Set<UUID> getCastSourceIdWithAlternateMana();
ManaCosts<ManaCost> getCastSourceIdManaCosts();
Map<UUID, ManaCosts<ManaCost>> getCastSourceIdManaCosts();
Costs<Cost> getCastSourceIdCosts();
Map<UUID, Costs<Cost>> getCastSourceIdCosts();
void clearCastSourceIdManaCosts();
// permission handling to show hand cards
void addPermissionToShowHandCards(UUID watcherUserId);

View file

@ -32,8 +32,8 @@ import mage.counters.Counters;
import mage.designations.Designation;
import mage.designations.DesignationType;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.FilterMana;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.common.FilterCreatureForCombat;
import mage.filter.common.FilterCreatureForCombatBlock;
@ -160,9 +160,10 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean reachedNextTurnAfterLeaving = false;
// indicates that the spell with the set sourceId can be cast with an alternate mana costs (can also be no mana costs)
protected UUID castSourceIdWithAlternateMana;
protected ManaCosts<ManaCost> castSourceIdManaCosts;
protected Costs<Cost> castSourceIdCosts;
// support multiple cards with alternative mana cost
protected Set<UUID> castSourceIdWithAlternateMana = new HashSet<>();
protected Map<UUID, ManaCosts<ManaCost>> castSourceIdManaCosts = new HashMap<>();
protected Map<UUID, Costs<Cost>> castSourceIdCosts = new HashMap<>();
// indicates that the player is in mana payment phase
protected boolean payManaMode = false;
@ -271,9 +272,10 @@ public abstract class PlayerImpl implements Player, Serializable {
this.priorityTimeLeft = player.getPriorityTimeLeft();
this.reachedNextTurnAfterLeaving = player.reachedNextTurnAfterLeaving;
this.castSourceIdWithAlternateMana = player.castSourceIdWithAlternateMana;
this.castSourceIdManaCosts = player.castSourceIdManaCosts;
this.castSourceIdCosts = player.castSourceIdCosts;
this.castSourceIdWithAlternateMana.addAll(player.castSourceIdWithAlternateMana);
this.castSourceIdManaCosts.putAll(player.castSourceIdManaCosts);
this.castSourceIdCosts.putAll(player.castSourceIdCosts);
this.payManaMode = player.payManaMode;
this.phyrexianColors = player.phyrexianColors.copy();
@ -340,9 +342,12 @@ public abstract class PlayerImpl implements Player, Serializable {
this.turnControllers.clear();
this.turnControllers.addAll(player.getTurnControllers());
this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving();
this.castSourceIdWithAlternateMana = player.getCastSourceIdWithAlternateMana();
this.castSourceIdManaCosts = player.getCastSourceIdManaCosts();
this.castSourceIdCosts = player.getCastSourceIdCosts();
this.clearCastSourceIdManaCosts();
this.castSourceIdWithAlternateMana.addAll(player.getCastSourceIdWithAlternateMana());
this.castSourceIdManaCosts.putAll(player.getCastSourceIdManaCosts());
this.castSourceIdCosts.putAll(player.getCastSourceIdCosts());
this.phyrexianColors = player.getPhyrexianColors().copy();
this.designations.clear();
@ -417,9 +422,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.setLife(game.getLife(), game, (UUID) null);
this.setReachedNextTurnAfterLeaving(false);
this.castSourceIdWithAlternateMana = null;
this.castSourceIdManaCosts = null;
this.castSourceIdCosts = null;
this.clearCastSourceIdManaCosts();
this.getManaPool().init(); // needed to remove mana that not empties on step change from previous game if left
this.phyrexianColors = new FilterMana();
@ -444,9 +448,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.canPlayCardsFromGraveyard = false;
this.topCardRevealed = false;
this.alternativeSourceCosts.clear();
this.castSourceIdWithAlternateMana = null;
this.castSourceIdManaCosts = null;
this.castSourceIdCosts = null;
this.clearCastSourceIdManaCosts();
this.getManaPool().clearEmptyManaPoolRules();
this.phyrexianColors = new FilterMana();
}
@ -1061,26 +1063,33 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public void setCastSourceIdWithAlternateMana(UUID sourceId, ManaCosts<ManaCost> manaCosts, Costs<Cost> costs) {
castSourceIdWithAlternateMana = sourceId;
castSourceIdManaCosts = manaCosts;
castSourceIdCosts = costs;
castSourceIdWithAlternateMana.add(sourceId);
castSourceIdManaCosts.put(sourceId, manaCosts);
castSourceIdCosts.put(sourceId, costs);
}
@Override
public UUID getCastSourceIdWithAlternateMana() {
public Set<UUID> getCastSourceIdWithAlternateMana() {
return castSourceIdWithAlternateMana;
}
@Override
public Costs<Cost> getCastSourceIdCosts() {
public Map<UUID, Costs<Cost>> getCastSourceIdCosts() {
return castSourceIdCosts;
}
@Override
public ManaCosts getCastSourceIdManaCosts() {
public Map<UUID, ManaCosts<ManaCost>> getCastSourceIdManaCosts() {
return castSourceIdManaCosts;
}
@Override
public void clearCastSourceIdManaCosts() {
this.castSourceIdCosts.clear();
this.castSourceIdManaCosts.clear();
this.castSourceIdWithAlternateMana.clear();
}
@Override
public void setPayManaMode(boolean payManaMode) {
this.payManaMode = payManaMode;
@ -1144,11 +1153,13 @@ public abstract class PlayerImpl implements Player, Serializable {
}
// Update the zcc to the stack
ability.setSourceObjectZoneChangeCounter(game.getState().getZoneChangeCounter(ability.getSourceId()));
// ALTERNATIVE COST from dynamic effects
// some effects set sourceId to cast without paying mana costs or other costs
if (ability.getSourceId().equals(getCastSourceIdWithAlternateMana())) {
if (getCastSourceIdWithAlternateMana().contains(ability.getSourceId())) {
Ability spellAbility = spell.getSpellAbility();
ManaCosts alternateCosts = getCastSourceIdManaCosts();
Costs<Cost> costs = getCastSourceIdCosts();
ManaCosts alternateCosts = getCastSourceIdManaCosts().get(ability.getSourceId());
Costs<Cost> costs = getCastSourceIdCosts().get(ability.getSourceId());
if (alternateCosts == null) {
noMana = true;
} else {
@ -1162,7 +1173,8 @@ public abstract class PlayerImpl implements Player, Serializable {
spellAbility.getCosts().addAll(costs);
}
}
setCastSourceIdWithAlternateMana(null, null, null);
clearCastSourceIdManaCosts(); // TODO: test multiple alternative cost for different cards as same time
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL,
spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId, permittingObject);
game.fireEvent(event);
@ -3093,6 +3105,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
}
// ALTERNATIVE COST from source card (AlternativeCostSourceAbility)
for (Ability objectAbility : sourceObject.getAbilities()) {
if (objectAbility instanceof AlternativeCostSourceAbility) {
if (objectAbility.getCosts().canPay(copy, copy.getSourceId(), playerId, game)) {
@ -3100,7 +3113,27 @@ public abstract class PlayerImpl implements Player, Serializable {
}
}
}
return canPlayCardByAlternateCost(card, available, ability, game);
// ALTERNATIVE COST FROM dynamic effects
if (getCastSourceIdWithAlternateMana().contains(copy.getSourceId())) {
ManaCosts alternateCosts = getCastSourceIdManaCosts().get(copy.getSourceId());
Costs<Cost> costs = getCastSourceIdCosts().get(copy.getSourceId());
boolean canPutToPlay = true;
if (alternateCosts != null && !alternateCosts.canPay(copy, copy.getSourceId(), playerId, game)) {
canPutToPlay = false;
}
if (costs != null && !costs.canPay(copy, copy.getSourceId(), playerId, game)) {
canPutToPlay = false;
}
if (canPutToPlay) {
return true;
}
}
// ALTERNATIVE COST from source card (any AlternativeSourceCosts)
return canPlayCardByAlternateCost(card, available, copy, game);
}
return false;
}
@ -3991,7 +4024,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// identify cards from one owner
Cards cards = new CardsImpl();
UUID ownerId = null;
for (Iterator<Card> it = allCards.iterator(); it.hasNext();) {
for (Iterator<Card> it = allCards.iterator(); it.hasNext(); ) {
Card card = it.next();
if (cards.isEmpty()) {
ownerId = card.getOwnerId();