forked from External/mage
Refactor: replaced sourceId by source and introduced source param in some methods;
This commit is contained in:
parent
2bb472607b
commit
db239a1055
3205 changed files with 7080 additions and 6795 deletions
|
|
@ -60,7 +60,6 @@ public interface Target extends Serializable {
|
|||
|
||||
List<? extends Target> getTargetOptions(Ability source, Game game);
|
||||
|
||||
//methods for non-targets
|
||||
boolean canChoose(UUID sourceControllerId, Game game);
|
||||
|
||||
Set<UUID> possibleTargets(UUID sourceControllerId, Game game);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import mage.constants.Zone;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.TargetEvent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -72,7 +73,7 @@ public class TargetCard extends TargetObject {
|
|||
switch (zone) {
|
||||
case HAND:
|
||||
for (Card card : player.getHand().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
|
|
@ -82,7 +83,7 @@ public class TargetCard extends TargetObject {
|
|||
break;
|
||||
case GRAVEYARD:
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
|
|
@ -92,7 +93,7 @@ public class TargetCard extends TargetObject {
|
|||
break;
|
||||
case LIBRARY:
|
||||
for (Card card : player.getLibrary().getUniqueCards(game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
if (filter.match(card, game)) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
|
|
@ -104,7 +105,7 @@ public class TargetCard extends TargetObject {
|
|||
break;
|
||||
case EXILED:
|
||||
for (Card card : game.getExile().getPermanentExile().getCards(game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
if (filter.match(card, player.getId(), game)) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
|
|
@ -141,21 +142,21 @@ public class TargetCard extends TargetObject {
|
|||
switch (zone) {
|
||||
case HAND:
|
||||
for (Card card : player.getHand().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GRAVEYARD:
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LIBRARY:
|
||||
for (Card card : player.getLibrary().getUniqueCards(game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
if (filter.match(card, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
|
|
@ -164,7 +165,7 @@ public class TargetCard extends TargetObject {
|
|||
break;
|
||||
case EXILED:
|
||||
for (Card card : game.getExile().getPermanentExile().getCards(game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
if (filter.match(card, sourceId, sourceControllerId, game)) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
|
|
@ -179,7 +180,7 @@ public class TargetCard extends TargetObject {
|
|||
.filter(card -> filter.match(card, sourceId, sourceControllerId, game))
|
||||
.collect(Collectors.toList());
|
||||
for (Card card : possibleCards) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.TargetEvent;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
|
|
@ -223,12 +224,12 @@ public abstract class TargetImpl implements Target {
|
|||
if (getMaxNumberOfTargets() == 0 || targets.size() < getMaxNumberOfTargets()) {
|
||||
if (!targets.containsKey(id)) {
|
||||
if (source != null && !skipEvent && shouldReportEvents) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) {
|
||||
if (!game.replaceEvent(new TargetEvent(id, source))) {
|
||||
targets.put(id, 0);
|
||||
rememberZoneChangeCounter(id, game);
|
||||
chosen = targets.size() >= getNumberOfTargets();
|
||||
if (!skipEvent && shouldReportEvents) {
|
||||
game.addSimultaneousEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId()));
|
||||
game.addSimultaneousEvent(GameEvent.getEvent(GameEvent.EventType.TARGETED, id, source, source.getControllerId()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -261,12 +262,12 @@ public abstract class TargetImpl implements Target {
|
|||
amount += targets.get(id);
|
||||
}
|
||||
if (source != null && !skipEvent && shouldReportEvents) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(EventType.TARGET, id, source.getSourceId(), source.getControllerId()))) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, id, source, source.getControllerId()))) {
|
||||
targets.put(id, amount);
|
||||
rememberZoneChangeCounter(id, game);
|
||||
chosen = targets.size() >= getNumberOfTargets();
|
||||
if (!skipEvent && shouldReportEvents) {
|
||||
game.fireEvent(GameEvent.getEvent(EventType.TARGETED, id, source.getSourceId(), source.getControllerId()));
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TARGETED, id, source, source.getControllerId()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -336,7 +337,7 @@ public abstract class TargetImpl implements Target {
|
|||
continue; // it's not legal so continue to have a look at other targeted objects
|
||||
}
|
||||
}
|
||||
if (!notTarget && game.replaceEvent(GameEvent.getEvent(EventType.TARGET, targetId, source.getSourceId(), source.getControllerId()))) {
|
||||
if (!notTarget && game.replaceEvent(new TargetEvent(targetId, source))) {
|
||||
// replacedTargets++;
|
||||
illegalTargets.add(targetId);
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class Targets extends ArrayList<Target> {
|
|||
}
|
||||
// Check if there are some rules for targets are violated, if so reset the targets and start again
|
||||
if (this.getUnchosen().isEmpty()
|
||||
&& game.replaceEvent(new GameEvent(GameEvent.EventType.TARGETS_VALID, source.getSourceId(), source.getSourceId(), source.getControllerId()), source)) {
|
||||
&& game.replaceEvent(new GameEvent(GameEvent.EventType.TARGETS_VALID, source.getSourceId(), source, source.getControllerId()), source)) {
|
||||
//game.restoreState(state, "Targets");
|
||||
clearChosen();
|
||||
}
|
||||
|
|
@ -110,6 +110,8 @@ public class Targets extends ArrayList<Target> {
|
|||
}
|
||||
|
||||
/**
|
||||
* For target choose
|
||||
*
|
||||
* Checks if there are enough targets that can be chosen. Should only be
|
||||
* used for Ability targets since this checks for protection, shroud etc.
|
||||
*
|
||||
|
|
@ -123,6 +125,8 @@ public class Targets extends ArrayList<Target> {
|
|||
}
|
||||
|
||||
/**
|
||||
* For non target choose (e.g. cost pay)
|
||||
*
|
||||
* Checks if there are enough objects that can be selected. Should not be
|
||||
* used for Ability targets since this does not check for protection, shroud
|
||||
* etc.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import mage.constants.Zone;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.TargetEvent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
|
|
@ -56,12 +57,12 @@ public class TargetCardInHand extends TargetCard {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID playerId, Game game) {
|
||||
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
Player player = game.getPlayer(playerId);
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
if (player != null) {
|
||||
for (Card card : player.getHand().getCards(filter, sourceId, playerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, playerId))) {
|
||||
for (Card card : player.getHand().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +76,7 @@ public class TargetCardInHand extends TargetCard {
|
|||
Player player = game.getPlayer(sourceControllerId);
|
||||
if (player != null) {
|
||||
for (Card card : player.getHand().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class TargetCardInLibrary extends TargetCard {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, UUID playerId, UUID targetPlayerId, Game game) {
|
||||
public boolean choose(Outcome outcome, UUID playerId, UUID targetPlayerId, Game game) { // TODO: wtf sourceId named as targetPlayerId?!
|
||||
Player player = game.getPlayer(playerId);
|
||||
Player targetPlayer = game.getPlayer(targetPlayerId);
|
||||
if (targetPlayer == null) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import mage.constants.Zone;
|
|||
import mage.filter.FilterCard;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.TargetEvent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
|
|
@ -100,7 +101,7 @@ public class TargetCardInOpponentsGraveyard extends TargetCard {
|
|||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
|
|
@ -125,7 +126,7 @@ public class TargetCardInOpponentsGraveyard extends TargetCard {
|
|||
if (player != null) {
|
||||
Set<UUID> targetsInThisGraveyeard = new HashSet<>();
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
targetsInThisGraveyeard.add(card.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import mage.filter.FilterCard;
|
|||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.TargetEvent;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ public class TargetCardInYourGraveyard extends TargetCard {
|
|||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ public class TargetCardInYourGraveyard extends TargetCard {
|
|||
}
|
||||
int possibleTargets = 0;
|
||||
for (Card card : player.getGraveyard().getCards(filter, sourceId, sourceControllerId, game)) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.TARGET, card.getId(), sourceId, sourceControllerId))) {
|
||||
if (sourceId == null || isNotTarget() || !game.replaceEvent(new TargetEvent(card, sourceId, sourceControllerId))) {
|
||||
possibleTargets++;
|
||||
if (possibleTargets >= this.minNumberOfTargets) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -58,9 +58,7 @@ public class FixedTarget implements TargetPointer {
|
|||
* @param game
|
||||
*/
|
||||
public FixedTarget(Permanent permanent, Game game) {
|
||||
this.targetId = permanent.getId();
|
||||
this.zoneChangeCounter = permanent.getZoneChangeCounter(game);
|
||||
this.initialized = true;
|
||||
this(permanent.getId(), game);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue