mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 06:22:01 -08:00
commit
1f607e7429
115 changed files with 2138 additions and 501 deletions
|
|
@ -47,6 +47,7 @@ import mage.abilities.effects.common.ManaEffect;
|
|||
import mage.abilities.keyword.FlashbackAbility;
|
||||
import mage.abilities.mana.ActivatedManaAbilityImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.command.Emblem;
|
||||
|
|
@ -886,14 +887,28 @@ public abstract class AbilityImpl implements Ability {
|
|||
|
||||
@Override
|
||||
public boolean canChooseTarget(Game game) {
|
||||
if (this instanceof SpellAbility) {
|
||||
if (SpellAbilityType.SPLIT_FUSED.equals(((SpellAbility) this).getSpellAbilityType())) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null) {
|
||||
return canChooseTargetAbility(((SplitCard) card).getLeftHalfCard().getSpellAbility(), game, getControllerId())
|
||||
&& canChooseTargetAbility(((SplitCard) card).getRightHalfCard().getSpellAbility(), game, getControllerId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return canChooseTargetAbility(this, game, getControllerId());
|
||||
}
|
||||
|
||||
private static boolean canChooseTargetAbility(Ability ability, Game game, UUID controllerId) {
|
||||
int found = 0;
|
||||
for (Mode mode : getModes().values()) {
|
||||
if (mode.getTargets().canChoose(sourceId, controllerId, game)) {
|
||||
for (Mode mode : ability.getModes().values()) {
|
||||
if (mode.getTargets().canChoose(ability.getSourceId(), ability.getControllerId(), game)) {
|
||||
found++;
|
||||
if (getModes().isEachModeMoreThanOnce()) {
|
||||
if (ability.getModes().isEachModeMoreThanOnce()) {
|
||||
return true;
|
||||
}
|
||||
if (found >= getModes().getMinModes()) {
|
||||
if (found >= ability.getModes().getMinModes()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,12 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.effects.common.cost;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.ComparisonType;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.ComparisonType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.common.FilterNonlandCard;
|
||||
import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
|
||||
|
|
@ -39,13 +38,15 @@ import mage.game.Game;
|
|||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetCardInHand;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author fireshoes - Original Code
|
||||
* @author JRHerlehy - Implement as seperate class
|
||||
* <p>
|
||||
* Allows player to choose to cast as card from hand without paying its mana cost.
|
||||
* </p>
|
||||
* <p>
|
||||
* Allows player to choose to cast as card from hand without paying its mana
|
||||
* cost.
|
||||
* </p>
|
||||
*/
|
||||
public class CastWithoutPayingManaCostEffect extends OneShotEffect {
|
||||
|
||||
|
|
@ -73,19 +74,27 @@ public class CastWithoutPayingManaCostEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
|
||||
if (controller == null) return false;
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Target target = new TargetCardInHand(filter);
|
||||
if (target.canChoose(source.getSourceId(), controller.getId(), game) &&
|
||||
controller.chooseUse(outcome, "Cast a card with converted mana cost " + manaCost +
|
||||
" or less from your hand without paying its mana cost?", source, game)) {
|
||||
if (target.canChoose(source.getSourceId(), controller.getId(), game)
|
||||
&& controller.chooseUse(outcome, "Cast a card with converted mana cost " + manaCost
|
||||
+ " or less from your hand without paying its mana cost?", source, game)) {
|
||||
Card cardToCast = null;
|
||||
boolean cancel = false;
|
||||
while (controller.canRespond() && !cancel) {
|
||||
if (controller.chooseTarget(outcome, target, source, game)) {
|
||||
cardToCast = game.getCard(target.getFirstTarget());
|
||||
if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game)) {
|
||||
cancel = true;
|
||||
if (cardToCast != null) {
|
||||
if (cardToCast.getSpellAbility() == null) {
|
||||
Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
|
||||
cancel = true;
|
||||
}
|
||||
if (cardToCast.getSpellAbility().canChooseTarget(game)) {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cancel = true;
|
||||
|
|
|
|||
|
|
@ -119,6 +119,8 @@ public abstract class SplitCard extends CardImpl {
|
|||
case SPLIT_RIGHT:
|
||||
return this.getRightHalfCard().cast(game, fromZone, ability, controllerId);
|
||||
default:
|
||||
this.getLeftHalfCard().getSpellAbility().setControllerId(controllerId);
|
||||
this.getRightHalfCard().getSpellAbility().setControllerId(controllerId);
|
||||
return super.cast(game, fromZone, ability, controllerId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -966,8 +966,13 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
if (game == null || ability == null) {
|
||||
return false;
|
||||
}
|
||||
ability.setControllerId(getId());
|
||||
if (ability.getSpellAbilityType() != SpellAbilityType.BASE) {
|
||||
ability = chooseSpellAbilityForCast(ability, game, noMana);
|
||||
if (ability == null) {
|
||||
// No ability could be cast (selected), probably because of no valid targets (happens often if a card can be cast by an effect).
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//20091005 - 601.2a
|
||||
if (ability.getSourceId() == null) {
|
||||
|
|
@ -1241,22 +1246,35 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
|
||||
for (Ability ability : object.getAbilities()) {
|
||||
if (ability instanceof SpellAbility) {
|
||||
if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
|
||||
if (zone == Zone.HAND) {
|
||||
// Fix so you don't need to choose Fuse twice
|
||||
useable.clear();
|
||||
useable.put(ability.getId(), (SpellAbility) ability);
|
||||
switch (((SpellAbility) ability).getSpellAbilityType()) {
|
||||
case SPLIT_FUSED:
|
||||
if (zone == Zone.HAND) {
|
||||
if (((SpellAbility) ability).canChooseTarget(game)) {
|
||||
useable.put(ability.getId(), (SpellAbility) ability);
|
||||
}
|
||||
}
|
||||
case SPLIT:
|
||||
if (((SplitCard) object).getLeftHalfCard().getSpellAbility().canChooseTarget(game)) {
|
||||
useable.put(((SplitCard) object).getLeftHalfCard().getSpellAbility().getId(), ((SplitCard) object).getLeftHalfCard().getSpellAbility());
|
||||
}
|
||||
if (((SplitCard) object).getRightHalfCard().getSpellAbility().canChooseTarget(game)) {
|
||||
useable.put(((SplitCard) object).getRightHalfCard().getSpellAbility().getId(), ((SplitCard) object).getRightHalfCard().getSpellAbility());
|
||||
}
|
||||
return useable;
|
||||
} else {
|
||||
// Fuse only allowed from hand
|
||||
continue;
|
||||
}
|
||||
case SPLIT_AFTERMATH:
|
||||
if (zone == Zone.GRAVEYARD) {
|
||||
if (((SplitCard) object).getRightHalfCard().getSpellAbility().canChooseTarget(game)) {
|
||||
useable.put(((SplitCard) object).getRightHalfCard().getSpellAbility().getId(), ((SplitCard) object).getRightHalfCard().getSpellAbility());
|
||||
}
|
||||
} else {
|
||||
if (((SplitCard) object).getLeftHalfCard().getSpellAbility().canChooseTarget(game)) {
|
||||
useable.put(((SplitCard) object).getLeftHalfCard().getSpellAbility().getId(), ((SplitCard) object).getLeftHalfCard().getSpellAbility());
|
||||
}
|
||||
}
|
||||
return useable;
|
||||
default:
|
||||
useable.put(ability.getId(), (SpellAbility) ability);
|
||||
}
|
||||
if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT
|
||||
|| ((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_AFTERMATH) {
|
||||
continue;
|
||||
}
|
||||
useable.put(ability.getId(), (SpellAbility) ability);
|
||||
}
|
||||
}
|
||||
return useable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue