mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Rework player zone message building for ability effects
This commit is contained in:
@@ -25,14 +25,16 @@ import forge.game.spellability.AbilitySub;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.net.FServer;
|
||||
import forge.util.Expressions;
|
||||
import forge.util.Lang;
|
||||
import forge.util.TextUtil;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class AbilityUtils {
|
||||
|
||||
public static CounterType getCounterType(String name, SpellAbility sa) throws Exception {
|
||||
CounterType counterType;
|
||||
if ("ReplacedCounterType".equals(name)) {
|
||||
@@ -1361,4 +1363,38 @@ public class AbilityUtils {
|
||||
}
|
||||
return CardFactoryUtil.xCount(c, s);
|
||||
}
|
||||
|
||||
public static String createPlayerZoneMessage(Player player, ZoneType zoneType, String prefix) {
|
||||
return createPlayerZoneMessage(player, zoneType, prefix, null);
|
||||
}
|
||||
public static String createPlayerZoneMessage(Player player, ZoneType zoneType, String prefix, String suffix) {
|
||||
StringBuilder message = new StringBuilder();
|
||||
|
||||
String owner;
|
||||
if (player.getLobbyPlayer() == FServer.instance.getLobby().getGuiPlayer()) {
|
||||
owner = "your";
|
||||
}
|
||||
else {
|
||||
owner = Lang.getPossesive(player.getName());
|
||||
}
|
||||
|
||||
if (prefix != null && !prefix.isEmpty()) {
|
||||
message.append(prefix);
|
||||
if (!prefix.endsWith(" ")) {
|
||||
message.append(" ");
|
||||
}
|
||||
message.append(owner);
|
||||
}
|
||||
else {
|
||||
message.append(owner.substring(0, 1).toUpperCase() + owner.substring(1));
|
||||
}
|
||||
|
||||
message.append(" " + TextUtil.splitCompoundWord(zoneType.toString(), TextUtil.PhraseCase.Lower));
|
||||
|
||||
if (suffix != null && !suffix.isEmpty()) {
|
||||
message.append(" " + suffix);
|
||||
}
|
||||
|
||||
return message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import forge.util.Lang;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
public class DigEffect extends SpellAbilityEffect {
|
||||
|
||||
@Override
|
||||
protected String getStackDescription(SpellAbility sa) {
|
||||
final Card host = sa.getSourceCard();
|
||||
@@ -184,13 +183,14 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
else if (allButOne) {
|
||||
movedCards.addAll(valid);
|
||||
String prompt;
|
||||
String prefix;
|
||||
if (destZone2.equals(ZoneType.Library) && (libraryPosition2 == 0)) {
|
||||
prompt = "Choose a card to leave on top of {player's} library";
|
||||
prefix = "Choose a card to leave on top of ";
|
||||
}
|
||||
else {
|
||||
prompt = "Choose a card to leave in {player's} " + destZone2.name();
|
||||
prefix = "Choose a card to leave in ";
|
||||
}
|
||||
String prompt = AbilityUtils.createPlayerZoneMessage(p, destZone2, prefix);
|
||||
|
||||
Card chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, false, p);
|
||||
movedCards.remove(chosen);
|
||||
@@ -201,15 +201,16 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
}
|
||||
else {
|
||||
int j = 0;
|
||||
String prompt = "Choose a card to put into ";
|
||||
String prefix = "Choose a card to put into ";
|
||||
if (destZone1.equals(ZoneType.Library)) {
|
||||
if (libraryPosition == -1) {
|
||||
prompt = "Choose a card to put on the bottom of {player's} library";
|
||||
prefix = "Choose a card to put on the bottom of ";
|
||||
}
|
||||
else if (libraryPosition == 0) {
|
||||
prompt = "Choose a card to put on top of {player's} library";
|
||||
prefix = "Choose a card to put on top of ";
|
||||
}
|
||||
}
|
||||
String prompt = AbilityUtils.createPlayerZoneMessage(p, destZone1, prefix);
|
||||
|
||||
while ((j < destZone1ChangeNum) || (anyNumber && (j < numToDig))) {
|
||||
// let user get choice
|
||||
@@ -218,7 +219,7 @@ public class DigEffect extends SpellAbilityEffect {
|
||||
chosen = chooser.getController().chooseSingleEntityForEffect(valid, sa, prompt, anyNumber || optional, p);
|
||||
}
|
||||
else {
|
||||
chooser.getController().notifyOfValue(sa, null, "No valid cards");
|
||||
chooser.getController().notifyOfValue(sa, null, AbilityUtils.createPlayerZoneMessage(p, destZone1, "No valid cards in "));
|
||||
}
|
||||
|
||||
if (chosen == null) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import forge.game.Game;
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.GameObject;
|
||||
import forge.game.GameType;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.effects.CharmEffect;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardShields;
|
||||
@@ -357,14 +358,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (canUseSelectCardsInput) {
|
||||
InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(isOptional ? 0 : 1, 1, options);
|
||||
input.setCancelAllowed(isOptional);
|
||||
input.setMessage(formatMessage(title, targetedPlayer));
|
||||
input.setMessage(title);
|
||||
input.showAndWait();
|
||||
return Iterables.getFirst(input.getSelected(), null);
|
||||
}
|
||||
|
||||
return isOptional ? GuiChoose.oneOrNone(title, options) : GuiChoose.one(title, options);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int chooseNumber(SpellAbility sa, String title, int min, int max) {
|
||||
final Integer[] choices = new Integer[max + 1 - min];
|
||||
@@ -457,11 +458,11 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.game.player.PlayerController#reveal(java.lang.String, java.util.List, forge.game.zone.ZoneType, forge.game.player.Player)
|
||||
*/
|
||||
@Override
|
||||
public void reveal(Collection<Card> cards, ZoneType zone, Player owner, String message) {
|
||||
if (StringUtils.isBlank(message)) {
|
||||
message = "Looking at cards in {player's} " + zone.name();
|
||||
public void reveal(Collection<Card> cards, ZoneType zoneType, Player owner, String messagePrefix) {
|
||||
if (StringUtils.isBlank(messagePrefix)) {
|
||||
messagePrefix = "Looking at cards in ";
|
||||
}
|
||||
GuiChoose.reveal(formatMessage(message, owner), cards);
|
||||
GuiChoose.reveal(AbilityUtils.createPlayerZoneMessage(owner, zoneType, messagePrefix), cards);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -832,13 +833,6 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
GuiDialog.message(message, sa.getSourceCard() == null ? "" : sa.getSourceCard().getName());
|
||||
}
|
||||
|
||||
private String formatMessage(String message, Object related) {
|
||||
if(related instanceof Player && message.indexOf("{player") >= 0)
|
||||
message = message.replace("{player}", mayBeYou(related)).replace("{player's}", Lang.getPossesive(mayBeYou(related)));
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
// These are not much related to PlayerController
|
||||
private String formatNotificationMessage(SpellAbility sa, GameObject target, String value) {
|
||||
if (sa.getApi() == null || sa.getSourceCard() == null) {
|
||||
|
||||
Reference in New Issue
Block a user