It is currently 20 Apr 2024, 04:19
   
Text Size

add optional parameter to clone effect

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

add optional parameter to clone effect

Postby pfps » 01 Jan 2019, 16:01

Cards like Vesuva have an optional enter the battlefield effect.
Right now this is done in two stages: first select the option and then
select the card for the effect. If instead the effect is optional then this
can be done in one step.

However, the clone effect (CloneEffect) does not have an optional parameter.
Adding an optional parameter is easy and supports the improvement to UI
mechanics for cards like Vesuva.

A final change improves the mechanics of the optional choice. Right now,
optionally choosing a single entity for effect (chooseSingleEntityForEffect)
when the selection is a card from the player's hand or the battlefield turns
into optionally choosing zero or one cards (InputSelectEntitiesFromList with
min 0 and max 1 and then allowing cancelling). I think that this is not
ideal and there should instead be a minimum of 1. The UI difference is that
in the current situation OK can be used to "cancel" the selection. With the
change, the cancel button is needed to cancel the selection.

The changes for the above are minimal (and I already have done them). What
I haven't done is add the new parameter for the documentation on the clone
effect.
pfps
 
Posts: 53
Joined: 09 Jan 2015, 14:34
Has thanked: 0 time
Been thanked: 7 times

Re: add optional parameter to clone effect

Postby pfps » 01 Jan 2019, 16:12

Here is the diff of the changes that I made (hopefully not too mangled).

git diff
diff --git a/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java b/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java
index 39c1a9637d..1bf207b010 100644
--- a/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java
+++ b/forge-game/src/main/java/forge/game/ability/effects/CloneEffect.java
@@ -62,6 +62,7 @@ public class CloneEffect extends SpellAbilityEffect {

// find cloning source i.e. thing to be copied
Card cardToCopy = null;
+ boolean optional = sa.hasParam("Optional");

if (sa.hasParam("Choices")) {
ZoneType choiceZone = ZoneType.Battlefield;
@@ -72,7 +73,8 @@ public class CloneEffect extends SpellAbilityEffect {
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), activator, host);

String title = sa.hasParam("ChoiceTitle") ? sa.getParam("ChoiceTitle") : "Choose a card ";
- cardToCopy = activator.getController().chooseSingleEntityForEffect(choices, sa, title, false);
+ cardToCopy = activator.getController().chooseSingleEntityForEffect(choices, sa, title, optional);
+ optional = false ;
} else if (sa.hasParam("Defined")) {
List<Card> cloneSources = AbilityUtils.getDefinedCards(host, sa.getParam("Defined"), sa);
if (!cloneSources.isEmpty()) {
@@ -85,7 +87,6 @@ public class CloneEffect extends SpellAbilityEffect {
return;
}

- final boolean optional = sa.hasParam("Optional");
if (optional && !host.getController().getController().confirmAction(sa, null, "Do you want to copy " + cardToCopy + "?")) {
return;
}
diff --git a/forge-gui/res/cardsfolder/v/vesuva.txt b/forge-gui/res/cardsfolder/v/vesuva.txt
index 609ef29457..145da9be48 100644
--- a/forge-gui/res/cardsfolder/v/vesuva.txt
+++ b/forge-gui/res/cardsfolder/v/vesuva.txt
@@ -1,8 +1,8 @@
Name:Vesuva
ManaCost:no cost
Types:Land
-K:ETBReplacement:Copy:DBCopy:Optional
-SVar:DBCopy:DB$ Clone | Choices$ Land.Other | IntoPlayTapped$ True | SpellDescription$ You may have CARDNAME enter the battlefield tapped as a copy of any land on the battlefield.
+K:ETBReplacement:Copy:DBCopy
+SVar:DBCopy:DB$ Clone | Choices$ Land.Other | Optional$ True | IntoPlayTapped$ True | SpellDescription$ You may have CARDNAME enter the battlefield tapped as a copy of any land on the battlefield.
SVar:NeedsToPlay:Land.YouDontCtrl+notnamedVesuva,Land.YouCtrl+nonLegendary+notnamedVesuva
SVar:Picture:http://www.wizards.com/global/images/magic/general/vesuva.jpg
Oracle:You may have Vesuva enter the battlefield tapped as a copy of any land on the battlefield.
diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java
index b26a3954f6..f0a3b3d7bc 100644
--- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java
+++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java
@@ -431,7 +431,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
reveal(delayedReveal.getCards(), delayedReveal.getZone(), delayedReveal.getOwner(),
delayedReveal.getMessagePrefix());
}
- final InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(this, isOptional ? 0 : 1, 1,
+ final InputSelectEntitiesFromList<T> input = new InputSelectEntitiesFromList<T>(this, 1, 1,
optionList, sa);
input.setCancelAllowed(isOptional);
input.setMessage(MessageUtil.formatMessage(title, player, targetedPlayer));
pfps
 
Posts: 53
Joined: 09 Jan 2015, 14:34
Has thanked: 0 time
Been thanked: 7 times


Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 95 guests


Who is online

In total there are 95 users online :: 0 registered, 0 hidden and 95 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 95 guests

Login Form