mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
fixed issue 94
This commit is contained in:
parent
766a412e67
commit
19481bf961
6 changed files with 118 additions and 12 deletions
|
@ -60,6 +60,8 @@ import mage.cards.Cards;
|
|||
import mage.cards.decks.Deck;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.filter.common.FilterAttackingCreature;
|
||||
import mage.filter.common.FilterBlockingCreature;
|
||||
import mage.filter.common.FilterCreatureForCombat;
|
||||
import mage.game.Game;
|
||||
import mage.game.draft.Draft;
|
||||
|
@ -74,7 +76,6 @@ import mage.target.TargetCard;
|
|||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetAttackingCreature;
|
||||
import mage.target.common.TargetCreatureOrPlayer;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.common.TargetDefender;
|
||||
|
||||
|
||||
|
@ -87,6 +88,8 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
|
|||
private final transient PlayerResponse response = new PlayerResponse();
|
||||
|
||||
protected static FilterCreatureForCombat filter = new FilterCreatureForCombat();
|
||||
protected static FilterAttackingCreature filterAttack = new FilterAttackingCreature();
|
||||
protected static FilterBlockingCreature filterBlock = new FilterBlockingCreature();
|
||||
protected static Choice replacementEffectChoice = new ChoiceImpl(true);
|
||||
private static Map<String, Serializable> staticOptions = new HashMap<String, Serializable>();
|
||||
|
||||
|
@ -95,7 +98,6 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
|
|||
replacementEffectChoice.setMessage("Choose replacement effect");
|
||||
staticOptions.put("UI.right.btn.text", "Done");
|
||||
}
|
||||
protected transient TargetCreaturePermanent targetCombat = new TargetCreaturePermanent(filter);
|
||||
|
||||
public HumanPlayer(String name, RangeOfInfluence range, int skill) {
|
||||
super(name, range);
|
||||
|
@ -498,14 +500,20 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
|
|||
public void selectAttackers(Game game) {
|
||||
game.getState().setPriorityPlayerId(getId());
|
||||
while (!abort) {
|
||||
targetCombat.getTargets().clear();
|
||||
game.fireSelectEvent(playerId, "Select attackers");
|
||||
waitForResponse();
|
||||
if (response.getBoolean() != null) {
|
||||
return;
|
||||
} else if (response.getUUID() != null) {
|
||||
if (targetCombat.canTarget(playerId, response.getUUID(), null, game)) {
|
||||
selectDefender(game.getCombat().getDefenders(), response.getUUID(), game);
|
||||
Permanent attacker = game.getPermanent(response.getUUID());
|
||||
if (attacker != null) {
|
||||
if (filter.match(attacker, null, playerId, game)) {
|
||||
selectDefender(game.getCombat().getDefenders(), attacker.getId(), game);
|
||||
}
|
||||
else if (filterAttack.match(attacker, null, playerId, game) && game.getStack().isEmpty()) {
|
||||
if (game.getState().getTriggered().isEmpty() && game.getState().getDelayed().isEmpty())
|
||||
game.getCombat().removeAttacker(attacker.getId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -530,14 +538,20 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
|
|||
public void selectBlockers(Game game) {
|
||||
game.getState().setPriorityPlayerId(getId());
|
||||
while (!abort) {
|
||||
targetCombat.getTargets().clear();
|
||||
game.fireSelectEvent(playerId, "Select blockers");
|
||||
waitForResponse();
|
||||
if (response.getBoolean() != null) {
|
||||
return;
|
||||
} else if (response.getUUID() != null) {
|
||||
if (targetCombat.canTarget(playerId, response.getUUID(), null, game)) {
|
||||
selectCombatGroup(response.getUUID(), game);
|
||||
Permanent blocker = game.getPermanent(response.getUUID());
|
||||
if (blocker != null) {
|
||||
if (filter.match(blocker, null, playerId, game)) {
|
||||
selectCombatGroup(blocker.getId(), game);
|
||||
}
|
||||
else if (filterBlock.match(blocker, null, playerId, game) && game.getStack().isEmpty()) {
|
||||
if (game.getState().getTriggered().isEmpty() && game.getState().getDelayed().isEmpty())
|
||||
game.getCombat().removeBlocker(blocker.getId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
55
Mage/src/mage/filter/common/FilterBlockingCreature.java
Normal file
55
Mage/src/mage/filter/common/FilterBlockingCreature.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.filter.common;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class FilterBlockingCreature extends FilterCreaturePermanent<FilterBlockingCreature> {
|
||||
|
||||
public FilterBlockingCreature() {
|
||||
this("Blocking creature");
|
||||
}
|
||||
|
||||
public FilterBlockingCreature(String name) {
|
||||
super(name);
|
||||
this.blocking = true;
|
||||
this.useBlocking = true;
|
||||
}
|
||||
|
||||
public FilterBlockingCreature(final FilterBlockingCreature filter) {
|
||||
super(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterBlockingCreature copy() {
|
||||
return new FilterBlockingCreature(this);
|
||||
}
|
||||
}
|
|
@ -389,6 +389,10 @@ public class GameState implements Serializable, Copyable<GameState> {
|
|||
return this.triggers;
|
||||
}
|
||||
|
||||
public DelayedTriggeredAbilities getDelayed() {
|
||||
return this.delayed;
|
||||
}
|
||||
|
||||
public ContinuousEffects getContinuousEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
|
|
@ -128,6 +128,11 @@ public class Combat implements Serializable, Copyable<Combat> {
|
|||
//20101001 - 508.1d
|
||||
checkAttackRequirements(player, game);
|
||||
player.selectAttackers(game);
|
||||
for (CombatGroup group: groups) {
|
||||
for (UUID attacker: group.getAttackers()) {
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ATTACKER_DECLARED, group.defenderId, attacker, attackerId));
|
||||
}
|
||||
}
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DECLARED_ATTACKERS, attackerId, attackerId));
|
||||
game.fireInformEvent(player.getName() + " attacks with " + groups.size() + " creatures");
|
||||
}
|
||||
|
@ -388,6 +393,35 @@ public class Combat implements Serializable, Copyable<Combat> {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeAttacker(UUID attackerId, Game game) {
|
||||
for (CombatGroup group : groups) {
|
||||
if (group.attackers.contains(attackerId)) {
|
||||
group.attackers.remove(attackerId);
|
||||
Permanent creature = game.getPermanent(attackerId);
|
||||
if (creature != null) {
|
||||
creature.setAttacking(false);
|
||||
creature.setTapped(false);
|
||||
}
|
||||
if (group.attackers.isEmpty()) {
|
||||
groups.remove(group);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeBlocker(UUID blockerId, Game game) {
|
||||
for (CombatGroup group : groups) {
|
||||
if (group.blockers.contains(blockerId)) {
|
||||
group.blockers.remove(blockerId);
|
||||
Permanent creature = game.getPermanent(blockerId);
|
||||
if (creature != null)
|
||||
creature.setBlocking(0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Combat copy() {
|
||||
return new Combat(this);
|
||||
|
|
|
@ -914,7 +914,6 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
if (attacker != null && attacker.canAttack(game)) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DECLARE_ATTACKER, defenderId, attackerId, playerId))) {
|
||||
game.getCombat().declareAttacker(attackerId, defenderId, game);
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.ATTACKER_DECLARED, defenderId, attackerId, playerId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue