mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[AVR] Miracle keyword
This commit is contained in:
parent
be10728058
commit
0f950dbc50
4 changed files with 199 additions and 11 deletions
|
@ -108,7 +108,10 @@ public class SystemUtil {
|
|||
private static void swapWithAnyCard(Game game, Player player, Card card, Constants.Zone zone) {
|
||||
if (zone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||
card.putOntoBattlefield(game, Constants.Zone.OUTSIDE, null, player.getId());
|
||||
} else {
|
||||
} else if (zone.equals(Constants.Zone.LIBRARY)) {
|
||||
game.setZone(card.getId(), Constants.Zone.LIBRARY);
|
||||
player.getLibrary().putOnTop(card, game);
|
||||
} else {
|
||||
card.moveToZone(zone, null, game, false);
|
||||
}
|
||||
logger.info("Added card to player's " + zone.toString() + ": " + card.getName() +", player = " + player.getName());
|
||||
|
|
67
Mage/src/mage/abilities/keyword/MiracleAbility.java
Normal file
67
Mage/src/mage/abilities/keyword/MiracleAbility.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.keyword;
|
||||
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.abilities.costs.Cost;
|
||||
|
||||
/**
|
||||
* Miracle ability:
|
||||
* You may cast this card for its miracle cost when you draw it if it's the first card you drew this turn.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public class MiracleAbility extends StaticAbility<MiracleAbility> {
|
||||
|
||||
private static final String staticRule = " (You may cast this card for its miracle cost when you draw it if it's the first card you drew this turn.)";
|
||||
|
||||
private String ruleText;
|
||||
|
||||
public MiracleAbility(Cost cost) {
|
||||
super(Zone.BATTLEFIELD, null);
|
||||
addCost(cost);
|
||||
ruleText = "Miracle" + cost.getText() + staticRule;
|
||||
}
|
||||
|
||||
public MiracleAbility(MiracleAbility miracleAbility) {
|
||||
super(miracleAbility);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return ruleText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiracleAbility copy() {
|
||||
return new MiracleAbility(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,10 @@ package mage.game;
|
|||
|
||||
import mage.Constants.*;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.*;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.common.ChancellorAbility;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffects;
|
||||
|
@ -64,16 +67,15 @@ import mage.players.Players;
|
|||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.TargetPlayer;
|
||||
import mage.watchers.Watcher;
|
||||
import mage.watchers.common.CastSpellLastTurnWatcher;
|
||||
import mage.watchers.common.MiracleWatcher;
|
||||
import mage.watchers.common.MorbidWatcher;
|
||||
import mage.watchers.common.PlayerDamagedBySourceWatcher;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.watchers.common.PlayerDamagedBySourceWatcher;
|
||||
|
||||
public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializable {
|
||||
|
||||
|
@ -497,12 +499,12 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
saveState();
|
||||
}
|
||||
|
||||
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
|
||||
state.getWatchers().add(new PlayerDamagedBySourceWatcher(playerId));
|
||||
}
|
||||
state.getWatchers().add(new MorbidWatcher());
|
||||
state.getWatchers().add(new CastSpellLastTurnWatcher());
|
||||
|
||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||
state.getWatchers().add(new PlayerDamagedBySourceWatcher(playerId));
|
||||
}
|
||||
state.getWatchers().add(new MorbidWatcher());
|
||||
state.getWatchers().add(new CastSpellLastTurnWatcher());
|
||||
state.getWatchers().add(new MiracleWatcher());
|
||||
|
||||
//20100716 - 103.5
|
||||
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
|
||||
|
|
116
Mage/src/mage/watchers/common/MiracleWatcher.java
Normal file
116
Mage/src/mage/watchers/common/MiracleWatcher.java
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.watchers.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.Constants.WatcherScope;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCost;
|
||||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.keyword.MiracleAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.WatcherImpl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Counts amount of cards drawn this turn by players.
|
||||
* Asks players about Miracle ability to be activated if it the first card drawn this turn.
|
||||
*
|
||||
* @author noxx
|
||||
*/
|
||||
public class MiracleWatcher extends WatcherImpl<MiracleWatcher> {
|
||||
|
||||
private Map<UUID, Integer> amountOfCardsDrawnThisTurn = new HashMap<UUID, Integer>();
|
||||
|
||||
public MiracleWatcher() {
|
||||
super("MiracleWatcher", WatcherScope.GAME);
|
||||
}
|
||||
|
||||
public MiracleWatcher(final MiracleWatcher watcher) {
|
||||
super(watcher);
|
||||
for (Entry<UUID, Integer> entry: watcher.amountOfCardsDrawnThisTurn.entrySet()) {
|
||||
amountOfCardsDrawnThisTurn.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DREW_CARD) {
|
||||
UUID playerId = event.getPlayerId();
|
||||
if (playerId != null) {
|
||||
Integer amount = amountOfCardsDrawnThisTurn.get(playerId);
|
||||
if (amount == null) {
|
||||
amount = Integer.valueOf(1);
|
||||
} else {
|
||||
amount = Integer.valueOf(amount+1);
|
||||
}
|
||||
amountOfCardsDrawnThisTurn.put(playerId, amount);
|
||||
if (amount == 1) {
|
||||
checkMiracleAbility(event, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMiracleAbility(GameEvent event, Game game) {
|
||||
Card card = game.getCard(event.getTargetId());
|
||||
if (card != null) {
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
if (ability instanceof MiracleAbility) {
|
||||
Player controller = game.getPlayer(ability.getControllerId());
|
||||
ManaCosts<ManaCost> manaCostsToPay = ability.getManaCostsToPay();
|
||||
if (controller != null && controller.chooseUse(Constants.Outcome.Benefit, "Use Miracle " + manaCostsToPay.getText() + "?", game)) {
|
||||
if (manaCostsToPay.pay(ability, game, ability.getSourceId(), ability.getControllerId(), false)) {
|
||||
controller.cast(card.getSpellAbility(), game, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
amountOfCardsDrawnThisTurn.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MiracleWatcher copy() {
|
||||
return new MiracleWatcher(this);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue