mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Lifetime Pass Holder and RolledToVisitAttraction trigger condition.
Consolidated rollToVisitAttractions logic back into RollDiceEffect.
This commit is contained in:
@@ -117,6 +117,7 @@ public enum AbilityKey {
|
||||
ReplacementResult("ReplacementResult"),
|
||||
ReplacementResultMap("ReplacementResultMap"),
|
||||
Result("Result"),
|
||||
RolledToVisitAttractions("RolledToVisitAttractions"),
|
||||
RoomName("RoomName"),
|
||||
Scheme("Scheme"),
|
||||
ScryBottom("ScryBottom"),
|
||||
|
||||
@@ -68,9 +68,13 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
}
|
||||
|
||||
public static int rollDiceForPlayer(SpellAbility sa, Player player, int amount, int sides) {
|
||||
return rollDiceForPlayer(sa, player, amount, sides, 0, 0, null);
|
||||
boolean toVisitAttractions = sa != null && sa.hasParam("ToVisitYourAttractions");
|
||||
return rollDiceForPlayer(sa, player, amount, sides, 0, 0, null, toVisitAttractions);
|
||||
}
|
||||
private static int rollDiceForPlayer(SpellAbility sa, Player player, int amount, int sides, int ignore, int modifier, List<Integer> rollsResult) {
|
||||
public static int rollDiceForPlayerToVisitAttractions(Player player) {
|
||||
return rollDiceForPlayer(null, player, 1, 6, 0, 0, null, true);
|
||||
}
|
||||
private static int rollDiceForPlayer(SpellAbility sa, Player player, int amount, int sides, int ignore, int modifier, List<Integer> rollsResult, boolean toVisitAttractions) {
|
||||
Map<Player, Integer> ignoreChosenMap = Maps.newHashMap();
|
||||
|
||||
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(player);
|
||||
@@ -84,6 +88,7 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
case Updated: {
|
||||
amount = (int) repParams.get(AbilityKey.Number);
|
||||
ignore = (int) repParams.get(AbilityKey.Ignore);
|
||||
//noinspection unchecked
|
||||
ignoreChosenMap = (Map<Player, Integer>) repParams.get(AbilityKey.IgnoreChosen);
|
||||
break;
|
||||
}
|
||||
@@ -130,7 +135,7 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
if (amount > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String rollResults = StringUtils.join(naturalRolls, ", ");
|
||||
String resultMessage = sa.hasParam("ToVisitYourAttractions") ? "lblAttractionRollResult" : "lblPlayerRolledResult";
|
||||
String resultMessage = toVisitAttractions ? "lblAttractionRollResult" : "lblPlayerRolledResult";
|
||||
sb.append(Localizer.getInstance().getMessage(resultMessage, player, rollResults));
|
||||
if (!ignored.isEmpty()) {
|
||||
sb.append("\r\n").append(Localizer.getInstance().getMessage("lblIgnoredRolls",
|
||||
@@ -158,15 +163,17 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
countMaxRolls++;
|
||||
}
|
||||
}
|
||||
if (sa.hasParam("EvenOddResults")) {
|
||||
sa.setSVar("EvenResults", Integer.toString(evenResults));
|
||||
sa.setSVar("OddResults", Integer.toString(oddResults));
|
||||
}
|
||||
if (sa.hasParam("DifferentResults")) {
|
||||
sa.setSVar("DifferentResults", Integer.toString(differentResults));
|
||||
}
|
||||
if (sa.hasParam("MaxRollsResults")) {
|
||||
sa.setSVar("MaxRolls", Integer.toString(countMaxRolls));
|
||||
if (sa != null) {
|
||||
if (sa.hasParam("EvenOddResults")) {
|
||||
sa.setSVar("EvenResults", Integer.toString(evenResults));
|
||||
sa.setSVar("OddResults", Integer.toString(oddResults));
|
||||
}
|
||||
if (sa.hasParam("DifferentResults")) {
|
||||
sa.setSVar("DifferentResults", Integer.toString(differentResults));
|
||||
}
|
||||
if (sa.hasParam("MaxRollsResults")) {
|
||||
sa.setSVar("MaxRolls", Integer.toString(countMaxRolls));
|
||||
}
|
||||
}
|
||||
total += modifier;
|
||||
|
||||
@@ -177,6 +184,7 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
runParams.put(AbilityKey.Sides, sides);
|
||||
runParams.put(AbilityKey.Modifier, modifier);
|
||||
runParams.put(AbilityKey.Result, roll);
|
||||
runParams.put(AbilityKey.RolledToVisitAttractions, toVisitAttractions);
|
||||
runParams.put(AbilityKey.Number, player.getNumRollsThisTurn() - amount + rollNum);
|
||||
player.getGame().getTriggerHandler().runTrigger(TriggerType.RolledDie, runParams, false);
|
||||
rollNum++;
|
||||
@@ -184,6 +192,7 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(player);
|
||||
runParams.put(AbilityKey.Sides, sides);
|
||||
runParams.put(AbilityKey.Result, rolls);
|
||||
runParams.put(AbilityKey.RolledToVisitAttractions, toVisitAttractions);
|
||||
player.getGame().getTriggerHandler().runTrigger(TriggerType.RolledDieOnce, runParams, false);
|
||||
|
||||
return total;
|
||||
@@ -219,7 +228,7 @@ public class RollDiceEffect extends SpellAbilityEffect {
|
||||
final int ignore = AbilityUtils.calculateAmount(host, sa.getParamOrDefault("IgnoreLower", "0"), sa);
|
||||
|
||||
List<Integer> rolls = new ArrayList<>();
|
||||
int total = rollDiceForPlayer(sa, player, amount, sides, ignore, modifier, rolls);
|
||||
int total = rollDiceForPlayer(sa, player, amount, sides, ignore, modifier, rolls, sa.hasParam("ToVisitYourAttractions"));
|
||||
|
||||
if (sa.hasParam("UseHighestRoll")) {
|
||||
total = Collections.max(rolls);
|
||||
|
||||
@@ -33,6 +33,7 @@ import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.ability.effects.DetachedCardEffect;
|
||||
import forge.game.ability.effects.RollDiceEffect;
|
||||
import forge.game.card.*;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
import forge.game.event.*;
|
||||
@@ -3835,67 +3836,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
||||
}
|
||||
}
|
||||
public void rollToVisitAttractions() {
|
||||
//Essentially a retread of RollDiceEffect.rollDiceForPlayer, but without the parts that require a spell ability.
|
||||
int amount = 1, sides = 6, ignore = 0;
|
||||
Map<Player, Integer> ignoreChosenMap = Maps.newHashMap();
|
||||
|
||||
final Map<AbilityKey, Object> repParams = AbilityKey.mapFromAffected(this);
|
||||
repParams.put(AbilityKey.Number, amount);
|
||||
repParams.put(AbilityKey.Ignore, ignore);
|
||||
repParams.put(AbilityKey.IgnoreChosen, ignoreChosenMap);
|
||||
|
||||
if(getGame().getReplacementHandler().run(ReplacementType.RollDice, repParams) == ReplacementResult.Updated) {
|
||||
amount = (int) repParams.get(AbilityKey.Number);
|
||||
ignore = (int) repParams.get(AbilityKey.Ignore);
|
||||
//noinspection unchecked
|
||||
ignoreChosenMap = (Map<Player, Integer>) repParams.get(AbilityKey.IgnoreChosen);
|
||||
}
|
||||
if (amount == 0)
|
||||
return;
|
||||
int total = 0;
|
||||
List<Integer> naturalRolls = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
int roll = MyRandom.getRandom().nextInt(sides) + 1;
|
||||
// Play the die roll sound
|
||||
getGame().fireEvent(new GameEventRollDie());
|
||||
roll();
|
||||
naturalRolls.add(roll);
|
||||
total += roll;
|
||||
}
|
||||
|
||||
naturalRolls.sort(null);
|
||||
|
||||
List<Integer> ignored = new ArrayList<>();
|
||||
// Ignore the lowest rolls
|
||||
if (ignore > 0) {
|
||||
for (int i = ignore - 1; i >= 0; --i) {
|
||||
total -= naturalRolls.get(i);
|
||||
ignored.add(naturalRolls.get(i));
|
||||
naturalRolls.remove(i);
|
||||
}
|
||||
}
|
||||
// Player chooses to ignore rolls
|
||||
for (Player chooser : ignoreChosenMap.keySet()) {
|
||||
for (int ig = 0; ig < ignoreChosenMap.get(chooser); ig++) {
|
||||
Integer ign = chooser.getController().chooseRollToIgnore(naturalRolls);
|
||||
total -= ign;
|
||||
ignored.add(ign);
|
||||
naturalRolls.remove(ign);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String rollResults = StringUtils.join(naturalRolls, ", ");
|
||||
String resultMessage = "lblAttractionRollResult";
|
||||
sb.append(Localizer.getInstance().getMessage(resultMessage, this, rollResults));
|
||||
if (!ignored.isEmpty()) {
|
||||
sb.append("\r\n").append(Localizer.getInstance().getMessage("lblIgnoredRolls",
|
||||
StringUtils.join(ignored, ", ")));
|
||||
}
|
||||
getGame().getAction().notifyOfValue(null, this, sb.toString(), null);
|
||||
|
||||
this.visitAttractions(total);
|
||||
this.visitAttractions(RollDiceEffect.rollDiceForPlayerToVisitAttractions(this));
|
||||
}
|
||||
|
||||
public void addDeclaresAttackers(long ts, Player p) {
|
||||
|
||||
@@ -24,6 +24,10 @@ public class TriggerRolledDie extends Trigger {
|
||||
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Player))) {
|
||||
return false;
|
||||
}
|
||||
if (hasParam("RolledToVisitAttractions")) {
|
||||
if (!(boolean) runParams.getOrDefault(AbilityKey.RolledToVisitAttractions, false))
|
||||
return false;
|
||||
}
|
||||
if (hasParam("ValidResult")) {
|
||||
String[] params = getParam("ValidResult").split(",");
|
||||
int result = (int) runParams.get(AbilityKey.Result);
|
||||
|
||||
@@ -21,6 +21,10 @@ public class TriggerRolledDieOnce extends Trigger {
|
||||
if (!matchesValidParam("ValidPlayer", runParams.get(AbilityKey.Player))) {
|
||||
return false;
|
||||
}
|
||||
if (hasParam("RolledToVisitAttractions")) {
|
||||
if (!(boolean) runParams.getOrDefault(AbilityKey.RolledToVisitAttractions, false))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user