mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Refactored counters on permanents counting
Added BecomeMonstrousTriggeredAbility Added Target and Filter class for creature an opponent controls
This commit is contained in:
parent
0c89b81da0
commit
2aec9f2ca7
77 changed files with 331 additions and 172 deletions
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class BecomesMonstrousTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
protected FilterCreaturePermanent filter = new FilterCreaturePermanent();
|
||||
|
||||
public BecomesMonstrousTriggeredAbility(Effect effect) {
|
||||
super(Zone.BATTLEFIELD, effect, false);
|
||||
}
|
||||
|
||||
public BecomesMonstrousTriggeredAbility(final BecomesMonstrousTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BecomesMonstrousTriggeredAbility copy() {
|
||||
return new BecomesMonstrousTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.BECOMES_MONSTROUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (filter.match(permanent, sourceId, controllerId, game)
|
||||
&& (permanent.getControllerId().equals(this.controllerId))) {
|
||||
for (Effect effect : this.getEffects()) {
|
||||
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "Whenever " + filter.getMessage() + " becomes monstrous, " + super.getRule();
|
||||
}
|
||||
}
|
||||
|
|
@ -7,15 +7,15 @@ import mage.counters.CounterType;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class CountersCount implements DynamicValue {
|
||||
public class CountersSourceCount implements DynamicValue {
|
||||
|
||||
private final CounterType counter;
|
||||
|
||||
public CountersCount(CounterType counter) {
|
||||
public CountersSourceCount(CounterType counter) {
|
||||
this.counter = counter;
|
||||
}
|
||||
|
||||
public CountersCount(final CountersCount countersCount) {
|
||||
public CountersSourceCount(final CountersSourceCount countersCount) {
|
||||
this.counter = countersCount.counter;
|
||||
}
|
||||
|
||||
|
|
@ -29,8 +29,8 @@ public class CountersCount implements DynamicValue {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CountersCount copy() {
|
||||
return new CountersCount(this);
|
||||
public CountersSourceCount copy() {
|
||||
return new CountersSourceCount(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -46,6 +46,11 @@ public class FightTargetsEffect extends OneShotEffect {
|
|||
super(Outcome.Damage);
|
||||
}
|
||||
|
||||
public FightTargetsEffect(String effectText) {
|
||||
this();
|
||||
this.staticText = effectText;
|
||||
}
|
||||
|
||||
public FightTargetsEffect(final FightTargetsEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import mage.counters.CounterType;
|
|||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
|
|
@ -144,17 +145,21 @@ public class AddCountersTargetEffect extends OneShotEffect {
|
|||
sb.append("s");
|
||||
}
|
||||
sb.append(" on ");
|
||||
|
||||
Target target = mode.getTargets().get(0);
|
||||
if (target.getNumberOfTargets() == 0) {
|
||||
sb.append("up to ");
|
||||
}
|
||||
|
||||
// TODO: add normal text infrastructure for target pointers
|
||||
if (mode.getTargets().size() > 0) {
|
||||
String targetName = mode.getTargets().get(0).getTargetName();
|
||||
if (!targetName.startsWith("another")) {
|
||||
if (target.getMaxNumberOfTargets() > 1 || target.getNumberOfTargets() == 0) {
|
||||
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName());
|
||||
} else {
|
||||
if (!target.getTargetName().startsWith("another")) {
|
||||
sb.append("target ");
|
||||
}
|
||||
sb.append(targetName);
|
||||
} else {
|
||||
sb.append("it");
|
||||
sb.append(target.getTargetName());
|
||||
}
|
||||
|
||||
if (amount.getMessage().length() > 0) {
|
||||
sb.append(" for each ").append(amount.getMessage());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
package mage.filter.common;
|
||||
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class FilterOpponentsCreaturePermanent extends FilterCreaturePermanent {
|
||||
|
||||
public FilterOpponentsCreaturePermanent() {
|
||||
this("creature an opponent controls");
|
||||
}
|
||||
|
||||
public FilterOpponentsCreaturePermanent(String name) {
|
||||
super(name);
|
||||
this.add(new ControllerPredicate(TargetController.OPPONENT));
|
||||
|
||||
}
|
||||
|
||||
public FilterOpponentsCreaturePermanent(String subtype, String name) {
|
||||
super(subtype, name);
|
||||
this.add(new ControllerPredicate(TargetController.OPPONENT));
|
||||
}
|
||||
|
||||
public FilterOpponentsCreaturePermanent(final FilterOpponentsCreaturePermanent filter) {
|
||||
super(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FilterOpponentsCreaturePermanent copy() {
|
||||
return new FilterOpponentsCreaturePermanent(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -24,8 +24,7 @@
|
|||
* 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.target.common;
|
||||
|
||||
import mage.constants.Zone;
|
||||
|
|
@ -57,7 +56,11 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
public TargetCreatureOrPlayer(int numTargets) {
|
||||
this(numTargets, numTargets, new FilterCreatureOrPlayer());
|
||||
}
|
||||
|
||||
|
||||
public TargetCreatureOrPlayer(FilterCreatureOrPlayer filter) {
|
||||
this(1, 1, filter);
|
||||
}
|
||||
|
||||
public TargetCreatureOrPlayer(int numTargets, int maxNumTargets) {
|
||||
this(numTargets, maxNumTargets, new FilterCreatureOrPlayer());
|
||||
}
|
||||
|
|
@ -123,8 +126,9 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if there are enough {@link Permanent} or {@link Player} that can be chosen. Should only be used
|
||||
* for Ability targets since this checks for protection, shroud etc.
|
||||
* Checks if there are enough {@link Permanent} or {@link Player} that can
|
||||
* be chosen. Should only be used for Ability targets since this checks for
|
||||
* protection, shroud etc.
|
||||
*
|
||||
* @param sourceId - the target event source
|
||||
* @param sourceControllerId - controller of the target event source
|
||||
|
|
@ -135,7 +139,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
int count = 0;
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, game)) {
|
||||
count++;
|
||||
|
|
@ -144,7 +148,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
|
|
@ -156,8 +160,9 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks if there are enough {@link Permanent} or {@link Player} that can be selected. Should not be used
|
||||
* for Ability targets since this does not check for protection, shroud etc.
|
||||
* Checks if there are enough {@link Permanent} or {@link Player} that can
|
||||
* be selected. Should not be used for Ability targets since this does not
|
||||
* check for protection, shroud etc.
|
||||
*
|
||||
* @param sourceControllerId - controller of the select event
|
||||
* @param game
|
||||
|
|
@ -166,7 +171,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
@Override
|
||||
public boolean canChoose(UUID sourceControllerId, Game game) {
|
||||
int count = 0;
|
||||
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && filter.match(player, game)) {
|
||||
count++;
|
||||
|
|
@ -175,7 +180,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
if (filter.match(permanent, null, sourceControllerId, game)) {
|
||||
count++;
|
||||
if (count >= this.minNumberOfTargets) {
|
||||
|
|
@ -190,7 +195,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
MageObject targetSource = game.getObject(sourceId);
|
||||
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null
|
||||
&& player.canBeTargetedBy(targetSource, sourceControllerId, game)
|
||||
|
|
@ -198,7 +203,7 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
possibleTargets.add(playerId);
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)
|
||||
&& filter.getCreatureFilter().match(permanent, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
|
|
@ -210,13 +215,13 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
for (UUID playerId: game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null && filter.getPlayerFilter().match(player, game)) {
|
||||
possibleTargets.add(playerId);
|
||||
}
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getCreatureFilter(), sourceControllerId, game)) {
|
||||
if (filter.getCreatureFilter().match(permanent, null, sourceControllerId, game)) {
|
||||
possibleTargets.add(permanent.getId());
|
||||
}
|
||||
|
|
@ -227,12 +232,11 @@ public class TargetCreatureOrPlayer extends TargetImpl {
|
|||
@Override
|
||||
public String getTargetedName(Game game) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (UUID targetId: getTargets()) {
|
||||
for (UUID targetId : getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null) {
|
||||
sb.append(permanent.getLogName()).append(" ");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Player player = game.getPlayer(targetId);
|
||||
if (player != null) {
|
||||
sb.append(player.getLogName()).append(" ");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.target.common;
|
||||
|
||||
import mage.filter.common.FilterOpponentsCreaturePermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Styxo
|
||||
*/
|
||||
public class TargetOpponentsCreaturePermanent extends TargetCreaturePermanent {
|
||||
|
||||
public TargetOpponentsCreaturePermanent() {
|
||||
this(1, 1, new FilterOpponentsCreaturePermanent(), false);
|
||||
}
|
||||
|
||||
public TargetOpponentsCreaturePermanent(int numTargets) {
|
||||
this(numTargets, numTargets, new FilterOpponentsCreaturePermanent(), false);
|
||||
}
|
||||
|
||||
public TargetOpponentsCreaturePermanent(int minNumTargets, int maxNumTargets) {
|
||||
this(minNumTargets, maxNumTargets, new FilterOpponentsCreaturePermanent(), false);
|
||||
}
|
||||
|
||||
public TargetOpponentsCreaturePermanent(FilterOpponentsCreaturePermanent filter) {
|
||||
super(1, 1, filter, false);
|
||||
}
|
||||
|
||||
public TargetOpponentsCreaturePermanent(int minNumTargets, int maxNumTargets, FilterOpponentsCreaturePermanent filter, boolean notTarget) {
|
||||
super(minNumTargets, maxNumTargets, filter, notTarget);
|
||||
this.targetName = filter.getMessage();
|
||||
}
|
||||
|
||||
public TargetOpponentsCreaturePermanent(final TargetOpponentsCreaturePermanent target) {
|
||||
super(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetOpponentsCreaturePermanent copy() {
|
||||
return new TargetOpponentsCreaturePermanent(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue