mirror of
https://github.com/correl/mage.git
synced 2024-11-28 03:00:13 +00:00
Refactor: added miss Ability source in some choose methods
This commit is contained in:
parent
09a4294466
commit
5474787641
11 changed files with 34 additions and 28 deletions
|
@ -762,9 +762,9 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
if (targets.isEmpty()) {
|
||||
return super.choose(outcome, cards, target, game);
|
||||
return super.choose(outcome, cards, target, source, game);
|
||||
}
|
||||
if (!target.doneChoosing()) {
|
||||
for (UUID targetId : targets) {
|
||||
|
|
|
@ -2030,7 +2030,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
log.debug("choose 2");
|
||||
if (cards == null || cards.isEmpty()) {
|
||||
return true;
|
||||
|
@ -2043,9 +2043,9 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
abilityControllerId = target.getAbilityController();
|
||||
}
|
||||
|
||||
List<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), game));
|
||||
List<Card> cardChoices = new ArrayList<>(cards.getCards(target.getFilter(), abilityControllerId, source, game));
|
||||
while (!target.doneChoosing()) {
|
||||
Card card = pickTarget(abilityControllerId, cardChoices, outcome, target, null, game);
|
||||
Card card = pickTarget(abilityControllerId, cardChoices, outcome, target, source, game);
|
||||
if (card != null) {
|
||||
target.add(card.getId(), game);
|
||||
cardChoices.remove(card);
|
||||
|
|
|
@ -261,12 +261,12 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
if (this.isHuman()) {
|
||||
if (cards.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, game);
|
||||
Set<UUID> possibleTargets = target.possibleTargets(playerId, cards, source, game);
|
||||
if (possibleTargets.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
target.add(targetId, game);
|
||||
return true;
|
||||
}
|
||||
return super.choose(outcome, cards, target, game);
|
||||
return super.choose(outcome, cards, target, source, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -700,7 +700,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
if (gameInCheckPlayableState(game)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -719,8 +719,8 @@ public class HumanPlayer extends PlayerImpl {
|
|||
}
|
||||
|
||||
while (canRespond()) {
|
||||
boolean required = target.isRequired(null, game);
|
||||
int count = cards.count(target.getFilter(), abilityControllerId, game);
|
||||
boolean required = target.isRequired(source != null ? source.getSourceId() : null, game);
|
||||
int count = cards.count(target.getFilter(), abilityControllerId, source, game);
|
||||
if (count == 0
|
||||
|| target.getTargets().size() >= target.getNumberOfTargets()) {
|
||||
required = false;
|
||||
|
@ -729,7 +729,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
List<UUID> chosenTargets = target.getTargets();
|
||||
List<UUID> possibleTargets = new ArrayList<>();
|
||||
for (UUID cardId : cards) {
|
||||
if (target.canTarget(abilityControllerId, cardId, null, cards, game)) {
|
||||
if (target.canTarget(abilityControllerId, cardId, source, cards, game)) {
|
||||
possibleTargets.add(cardId);
|
||||
}
|
||||
}
|
||||
|
@ -738,7 +738,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
required = false;
|
||||
}
|
||||
|
||||
UUID responseId = target.tryToAutoChoose(abilityControllerId, null, game, possibleTargets);
|
||||
UUID responseId = target.tryToAutoChoose(abilityControllerId, source, game, possibleTargets);
|
||||
|
||||
if (responseId == null) {
|
||||
Map<String, Serializable> options = getOptions(target, null);
|
||||
|
@ -761,7 +761,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
if (target.getTargets().contains(responseId)) { // if already included remove it with
|
||||
target.remove(responseId);
|
||||
} else {
|
||||
if (target.canTarget(abilityControllerId, responseId, null, cards, game)) {
|
||||
if (target.canTarget(abilityControllerId, responseId, source, cards, game)) {
|
||||
target.add(responseId, game);
|
||||
if (target.doneChoosing()) {
|
||||
return true;
|
||||
|
@ -802,7 +802,7 @@ public class HumanPlayer extends PlayerImpl {
|
|||
|
||||
while (canRespond()) {
|
||||
boolean required = target.isRequiredExplicitlySet() ? target.isRequired() : target.isRequired(source);
|
||||
int count = cards.count(target.getFilter(), abilityControllerId, game);
|
||||
int count = cards.count(target.getFilter(), abilityControllerId, source, game);
|
||||
if (count == 0
|
||||
|| target.getTargets().size() >= target.getNumberOfTargets()) {
|
||||
required = false;
|
||||
|
|
|
@ -3965,9 +3965,7 @@ public class TestPlayer implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards,
|
||||
TargetCard target, Game game
|
||||
) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
assertAliasSupportInChoices(false);
|
||||
if (!choices.isEmpty()) {
|
||||
|
||||
|
@ -3995,7 +3993,7 @@ public class TestPlayer implements Player {
|
|||
continue;
|
||||
}
|
||||
if (hasObjectTargetNameOrAlias(card, targetName)) {
|
||||
if (target.isNotTarget() || target.canTarget(card.getId(), game)) {
|
||||
if (target.isNotTarget() || target.canTarget(card.getId(), source, game)) {
|
||||
target.add(card.getId(), game);
|
||||
targetFound = true;
|
||||
break;
|
||||
|
@ -4013,7 +4011,7 @@ public class TestPlayer implements Player {
|
|||
}
|
||||
|
||||
this.chooseStrictModeFailed("choice", game, getInfo(target));
|
||||
return computerPlayer.choose(outcome, cards, target, game);
|
||||
return computerPlayer.choose(outcome, cards, target, source, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -835,7 +835,7 @@ public class PlayerStub implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public class FilterPermanent extends FilterObject<Permanent> implements FilterIn
|
|||
if (!this.match(permanent, game) || !permanent.isPhasedIn()) {
|
||||
return false;
|
||||
}
|
||||
ObjectSourcePlayer<Permanent> osp = new ObjectSourcePlayer<Permanent>(permanent, playerId, source);
|
||||
ObjectSourcePlayer<Permanent> osp = new ObjectSourcePlayer<>(permanent, playerId, source);
|
||||
return extraPredicates.stream().allMatch(p -> p.apply(osp, game));
|
||||
}
|
||||
|
||||
|
|
|
@ -625,7 +625,11 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
boolean choose(Outcome outcome, Target target, Ability source, Game game, Map<String, Serializable> options);
|
||||
|
||||
boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game); // TODO: remove to use choose with "Ability source"
|
||||
// TODO: remove to use choose with "Ability source"
|
||||
default boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
return choose(outcome, cards, target, null, game);
|
||||
}
|
||||
boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game);
|
||||
|
||||
boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game);
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class StubPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
|
||||
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) {
|
||||
cards.getCards(game).stream().map(MageItem::getId).forEach(cardId -> target.add(cardId, game));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -211,8 +211,8 @@ public class TargetCard extends TargetObject {
|
|||
return possibleTargets;
|
||||
}
|
||||
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Game game) {
|
||||
return cards.getCards(filter, game).stream().map(MageItem::getId).collect(Collectors.toSet());
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Ability source, Game game) {
|
||||
return cards.getCards(filter, sourceControllerId, source, game).stream().map(MageItem::getId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,10 +88,14 @@ public class TargetCardInYourGraveyard extends TargetCard {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Game game) {
|
||||
public Set<UUID> possibleTargets(UUID sourceControllerId, Cards cards, Ability source, Game game) {
|
||||
Set<UUID> possibleTargets = new HashSet<>();
|
||||
Player player = game.getPlayer(sourceControllerId);
|
||||
for (Card card : cards.getCards(filter, game)) {
|
||||
if (player == null) {
|
||||
return possibleTargets;
|
||||
}
|
||||
|
||||
for (Card card : cards.getCards(filter, sourceControllerId, source, game)) {
|
||||
if (player.getGraveyard().getCards(game).contains(card)) {
|
||||
possibleTargets.add(card.getId());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue