mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- CNS: Added Brago's Representative
This commit is contained in:
@@ -1811,6 +1811,18 @@ public class ComputerUtil {
|
|||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String vote(Player ai, List<String> options, String logic) {
|
||||||
|
if (logic == null) {
|
||||||
|
return Aggregates.random(options);
|
||||||
|
} else {
|
||||||
|
switch (logic) {
|
||||||
|
case "GraceOrCondemnation":
|
||||||
|
return ai.getCreaturesInPlay().size() > ai.getOpponent().getCreaturesInPlay().size() ? "Grace" : "Condemnation";
|
||||||
|
default: return Iterables.getFirst(options, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Card> getSafeTargets(final Player ai, SpellAbility sa, List<Card> validCards) {
|
public static List<Card> getSafeTargets(final Player ai, SpellAbility sa, List<Card> validCards) {
|
||||||
List<Card> safeCards = new ArrayList<Card>(validCards);
|
List<Card> safeCards = new ArrayList<Card>(validCards);
|
||||||
safeCards = CardLists.filter(safeCards, new Predicate<Card>() {
|
safeCards = CardLists.filter(safeCards, new Predicate<Card>() {
|
||||||
@@ -1935,4 +1947,5 @@ public class ComputerUtil {
|
|||||||
|
|
||||||
return bestBoardPosition;
|
return bestBoardPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -367,6 +367,12 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return chosen;
|
return chosen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String vote(SpellAbility sa, String prompt, List<String> options) {
|
||||||
|
String result = ComputerUtil.vote(player, options, sa.getParam("AILogic"));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
|
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
package forge.game.ability.effects;
|
package forge.game.ability.effects;
|
||||||
|
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.game.ability.AbilityFactory;
|
import forge.game.ability.AbilityFactory;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.ability.SpellAbilityEffect;
|
import forge.game.ability.SpellAbilityEffect;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerController;
|
|
||||||
import forge.game.spellability.AbilitySub;
|
import forge.game.spellability.AbilitySub;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
public class VoteEffect extends SpellAbilityEffect {
|
public class VoteEffect extends SpellAbilityEffect {
|
||||||
@@ -29,7 +33,7 @@ public class VoteEffect extends SpellAbilityEffect {
|
|||||||
@Override
|
@Override
|
||||||
public void resolve(SpellAbility sa) {
|
public void resolve(SpellAbility sa) {
|
||||||
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
final List<Player> tgtPlayers = getTargetPlayers(sa);
|
||||||
final String voteType = sa.getParam("VoteType");
|
final List<String> voteType = Arrays.asList(sa.getParam("VoteType").split(","));
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
// starting with the activator
|
// starting with the activator
|
||||||
int pSize = tgtPlayers.size();
|
int pSize = tgtPlayers.size();
|
||||||
@@ -37,29 +41,49 @@ public class VoteEffect extends SpellAbilityEffect {
|
|||||||
while (tgtPlayers.contains(activator) && !activator.equals(Iterables.getFirst(tgtPlayers, null))) {
|
while (tgtPlayers.contains(activator) && !activator.equals(Iterables.getFirst(tgtPlayers, null))) {
|
||||||
tgtPlayers.add(pSize - 1, tgtPlayers.remove(0));
|
tgtPlayers.add(pSize - 1, tgtPlayers.remove(0));
|
||||||
}
|
}
|
||||||
int choice1 = 0;
|
ArrayListMultimap<String, Player> votes = ArrayListMultimap.create();
|
||||||
int choice2 = 0;
|
|
||||||
|
|
||||||
for (final Player p : tgtPlayers) {
|
for (final Player p : tgtPlayers) {
|
||||||
final boolean result = p.getController().chooseBinary(sa, sa.getHostCard() + "Vote:", PlayerController.BinaryChoiceType.valueOf(voteType));
|
int voteAmount = p.getAmountOfKeyword("You get an additional vote.") + 1;
|
||||||
if (result) {
|
for (int i = 0; i < voteAmount; i++) {
|
||||||
choice1++;
|
final String result = p.getController().vote(sa, sa.getHostCard() + "Vote:", voteType);
|
||||||
|
votes.put(result, p);
|
||||||
|
host.getGame().getAction().nofityOfValue(sa, p, result + "\r\nCurrent Votes:" + votes, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<String> subAbs = Lists.newArrayList();
|
||||||
|
final List<String> mostVotes = getMostVotes(votes);
|
||||||
|
if (sa.hasParam("Tied") && mostVotes.size() > 1) {
|
||||||
|
subAbs.add(sa.getParam("Tied"));
|
||||||
} else {
|
} else {
|
||||||
choice2++;
|
for (String type : mostVotes) {
|
||||||
|
subAbs.add(sa.getParam("Vote" + type));
|
||||||
}
|
}
|
||||||
host.getGame().getAction().nofityOfValue(sa, p, voteType.split("Or")[result ? 0 : 1], null);
|
|
||||||
}
|
|
||||||
String subAb;
|
|
||||||
if (choice1 > choice2) {
|
|
||||||
subAb = sa.getParam("FirstChoice");
|
|
||||||
} else if (choice1 < choice2) {
|
|
||||||
subAb = sa.getParam("SecondChoice");
|
|
||||||
} else {
|
|
||||||
subAb = sa.getParam("Tied");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (final String subAb : subAbs) {
|
||||||
final SpellAbility action = AbilityFactory.getAbility(host.getSVar(subAb), host);
|
final SpellAbility action = AbilityFactory.getAbility(host.getSVar(subAb), host);
|
||||||
action.setActivatingPlayer(sa.getActivatingPlayer());
|
action.setActivatingPlayer(sa.getActivatingPlayer());
|
||||||
((AbilitySub) action).setParent(sa);
|
((AbilitySub) action).setParent(sa);
|
||||||
AbilityUtils.resolve(action);
|
AbilityUtils.resolve(action);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getMostVotes(ArrayListMultimap<String, Player> votes) {
|
||||||
|
List<String> most = Lists.newArrayList();
|
||||||
|
int amount = 0;
|
||||||
|
for (String voteType : votes.keySet()) {
|
||||||
|
int voteAmount = votes.get(voteType).size();
|
||||||
|
if (voteAmount == amount) {
|
||||||
|
most.add(voteType);
|
||||||
|
} else if (voteAmount > amount) {
|
||||||
|
amount = voteAmount;
|
||||||
|
most.clear();
|
||||||
|
most.add(voteType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return most;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2790,6 +2790,16 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
return 1 << tokenDoublers; // pow(a,0) = 1; pow(a,1) = a
|
return 1 << tokenDoublers; // pow(a,0) = 1; pow(a,1) = a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getAmountOfKeyword(final String k) {
|
||||||
|
int count = 0;
|
||||||
|
for (String kw : this.getKeywords()) {
|
||||||
|
if (kw.equals(k)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
public void onCleanupPhase() {
|
public void onCleanupPhase() {
|
||||||
for (Card c : getCardsIn(ZoneType.Hand)) {
|
for (Card c : getCardsIn(ZoneType.Hand)) {
|
||||||
c.setDrawnThisTurn(false);
|
c.setDrawnThisTurn(false);
|
||||||
|
|||||||
@@ -64,8 +64,6 @@ public abstract class PlayerController {
|
|||||||
OddsOrEvens,
|
OddsOrEvens,
|
||||||
UntapOrLeaveTapped,
|
UntapOrLeaveTapped,
|
||||||
UntapTimeVault,
|
UntapTimeVault,
|
||||||
GraceOrCondemnation,
|
|
||||||
DeathOrTorture,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Game game;
|
protected final Game game;
|
||||||
@@ -178,6 +176,7 @@ public abstract class PlayerController {
|
|||||||
return chooseSomeType(kindOfType, sa, validTypes, invalidTypes, false);
|
return chooseSomeType(kindOfType, sa, validTypes, invalidTypes, false);
|
||||||
}
|
}
|
||||||
public abstract String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes, boolean isOptional);
|
public abstract String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes, boolean isOptional);
|
||||||
|
public abstract String vote(SpellAbility sa, String prompt, List<String> options);
|
||||||
public abstract Pair<CounterType,String> chooseAndRemoveOrPutCounter(Card cardWithCounter);
|
public abstract Pair<CounterType,String> chooseAndRemoveOrPutCounter(Card cardWithCounter);
|
||||||
public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question);
|
public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question);
|
||||||
public abstract List<Card> getCardsToMulligan(boolean isCommander, Player firstPlayer);
|
public abstract List<Card> getCardsToMulligan(boolean isCommander, Player firstPlayer);
|
||||||
|
|||||||
@@ -446,6 +446,11 @@ public class PlayerControllerForTests extends PlayerController {
|
|||||||
return chooseItem(validTypes);
|
return chooseItem(validTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String vote(SpellAbility sa, String prompt, List<String> options) {
|
||||||
|
return chooseItem(options);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaperCard chooseSinglePaperCard(SpellAbility sa, String message, Predicate<PaperCard> cpp, String name) {
|
public PaperCard chooseSinglePaperCard(SpellAbility sa, String message, Predicate<PaperCard> cpp, String name) {
|
||||||
throw new IllegalStateException("Erring on the side of caution here...");
|
throw new IllegalStateException("Erring on the side of caution here...");
|
||||||
|
|||||||
@@ -571,6 +571,11 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
return SGuiChoose.one("Choose a " + kindOfType.toLowerCase() + " type", validTypes);
|
return SGuiChoose.one("Choose a " + kindOfType.toLowerCase() + " type", validTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String vote(SpellAbility sa, String prompt, List<String> options) {
|
||||||
|
return SGuiChoose.one(prompt, options);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
|
* @see forge.game.player.PlayerController#confirmReplacementEffect(forge.card.replacement.ReplacementEffect, forge.card.spellability.SpellAbility, java.lang.String)
|
||||||
*/
|
*/
|
||||||
@@ -793,6 +798,9 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
case Protection:
|
case Protection:
|
||||||
String choser = StringUtils.capitalize(mayBeYou(target));
|
String choser = StringUtils.capitalize(mayBeYou(target));
|
||||||
return String.format("%s %s protection from %s", choser, Lang.joinVerb(choser, "choose"), value);
|
return String.format("%s %s protection from %s", choser, Lang.joinVerb(choser, "choose"), value);
|
||||||
|
case Vote:
|
||||||
|
String chooser = StringUtils.capitalize(mayBeYou(target));
|
||||||
|
return String.format("%s %s %s", chooser, Lang.joinVerb(chooser, "vote"), value);
|
||||||
default:
|
default:
|
||||||
return String.format("%s effect's value for %s is %s", sa.getHostCard().getName(), mayBeYou(target), value);
|
return String.format("%s effect's value for %s is %s", sa.getHostCard().getName(), mayBeYou(target), value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user