Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLB] Implement Season of Gathering and Pawprints mechanic #12617

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

jimga150
Copy link
Contributor

#11853
My current implementation requires pawprint cards to also set a min and max number of modes according to what logically could be chosen (0 and 5, for this and what will be the other four bloomburrow "Season of" cards).
In playtesting, the maxModes being set to 5 isnt required, since i added switches to check against the pawprint count instead of the mode count, but for some reason if i don't set the maxModes to 5 (default is 1), my tests all fail like this:

[ERROR] Failures: 
[ERROR]   PawPrintsTest.test_Choose113:36->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1599->CardTestPlayerAPIImpl.assertTargetsCount:1585 (Targets of PlayerA) Count are not equal (found [Memnite]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<1>
[ERROR]   PawPrintsTest.test_Choose122:212->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1598->CardTestPlayerAPIImpl.assertChoicesCount:1576 (Choices of PlayerA) Count are not equal (found [Artifact, Enchantment]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<2>
[ERROR]   PawPrintsTest.test_Choose123:70->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1598->CardTestPlayerAPIImpl.assertChoicesCount:1576 (Choices of PlayerA) Count are not equal (found [Enchantment]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<1>
[ERROR]   PawPrintsTest.test_Choose1x5:146->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1599->CardTestPlayerAPIImpl.assertTargetsCount:1585 (Targets of PlayerA) Count are not equal (found [Memnite, Memnite, Memnite, Memnite]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<4>
[ERROR]   PawPrintsTest.test_Choose2111:113->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1599->CardTestPlayerAPIImpl.assertTargetsCount:1585 (Targets of PlayerA) Count are not equal (found [Memnite, Memnite, Memnite]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<3>
[ERROR]   PawPrintsTest.test_Choose23:176->CardTestPlayerAPIImpl.execute:296->CardTestPlayerAPIImpl.assertAllCommandsUsed:1598->CardTestPlayerAPIImpl.assertChoicesCount:1576 (Choices of PlayerA) Count are not equal (found [Artifact]). Some inner choose dialogs can be set up only in strict mode. expected:<0> but was:<1>
[INFO] 
[ERROR] Tests run: 6, Failures: 6, Errors: 0, Skipped: 0

Which suggests that for some reason, the choice/target ingesting code is getting clogged. I'm not sure why, since i haven't had any luck trying to use breakpoints in maven run configurations.

Copy link
Contributor

@xenohedron xenohedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me! I'll let another dev take a look before merging. Thanks for the test cases.

@@ -19,6 +19,7 @@ public class Mode implements Serializable {
protected final Effects effects;
protected String flavorWord;
protected Cost cost = null;
protected int pawPrintValue = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add comment on usage of "magic number"

@@ -119,4 +121,17 @@ public Mode withCost(Cost cost) {
public Cost getCost() {
return cost;
}

public void setPawPrintValue(int pawPrintValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of having separate "set" and "with" methods? I would just have the "with" method, the return can be ignored if not needed

@@ -53,6 +55,7 @@ public Modes() {
this.put(currentMode.getId(), currentMode);
this.minModes = 1;
this.maxModes = 1;
this.maxPawPrints = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment here as well

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 logic smells bed. Must be 0 by default. And other code checks must use > 0.

Mode mode = get(modeId);

if (mode.getPawPrintValue() < 0 && this.getMaxPawPrints() >= 0){
throw new RuntimeException("Selected mode has no pawprint value, but this Modes object requires pawprint modes!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't throw RuntimeException, use something like IllegalStateException

Copy link
Member

@JayDi85 JayDi85 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it’s verify check and can be added to card constructor time instead runtime. As example: modes.addMode - after new mode added make sure modes amount with paw equal to total modes amount or zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For info:

  • verify check -- can be called from card constructor (by card, ability, effect or other data setup). There are some verify tests that call constructor for all cards and tokens. So such errors will be catches by tests as fast as possible.
  • runtime check -- can be called from real game only.

Copy link
Contributor Author

@jimga150 jimga150 Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, are you asking for both here? I moved the runtime check pointed to in this thread to a check in addMode() to catch it earlier.

Mage/src/main/java/mage/abilities/Modes.java Show resolved Hide resolved
/**
* @author jimga150
*/
public enum ControlledCreaturesGreatestPower implements DynamicValue {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GreatestPowerAmongControlledCreaturesValue already exists

(and is a good example of stream, mapToInt, sum as a cleaner style)

Copy link
Member

@JayDi85 JayDi85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require some code style and check logic changes. See related comments.

@@ -2217,6 +2217,10 @@ public Mode chooseMode(Modes modes, Ability source, Game game) {
continue AvailableMode;
}
}
if (modes.getMaxPawPrints() >= 0 && modes.getSelectedPawPrints() + mode.getPawPrintValue() > modes.getMaxPawPrints()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must put paw checks inside getAvailableModes, not outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chooseMode is where the max modes check is, so it seemed symmetrical to place the max pawprints check here too. should the max modes check move to getAvailableModes too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to add paw check to getMaxMode. getAvailableModes must use paw check too, not getMaxMode.

@@ -2572,6 +2572,11 @@ public Mode chooseMode(Modes modes, Ability source, Game game) {
}
}

if (modes.getMaxPawPrints() >= 0 && modes.getSelectedPawPrints() + mode.getPawPrintValue() > modes.getMaxPawPrints()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking for my reference #12617 (comment)

@@ -2082,6 +2082,10 @@ public Mode chooseMode(Modes modes, Ability source, Game game) {
int needMode = Integer.parseInt(modesSet.get(0));
int i = 1;
for (Mode mode : modes.getAvailableModes(source, game)) {
if (modes.getMaxPawPrints() >= 0 && modes.getSelectedPawPrints() + mode.getPawPrintValue() > modes.getMaxPawPrints()){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linking for my reference #12617 (comment)

@@ -32,9 +32,11 @@ public class Modes extends LinkedHashMap<UUID, Mode> implements Copyable<Modes>
private final List<UUID> selectedModes = new ArrayList<>(); // all selected modes (this + duplicate), use getSelectedModes all the time to keep modes order
private final Map<UUID, Mode> selectedDuplicateModes = new LinkedHashMap<>(); // for 2x selects: additional selected modes
private final Map<UUID, UUID> selectedDuplicateToOriginalModeRefs = new LinkedHashMap<>(); // for 2x selects: stores ref from duplicate to original mode
private int selectedPawPrints = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s dynamic value from selected modes, no need to store it inside.

@@ -53,6 +55,7 @@ public Modes() {
this.put(currentMode.getId(), currentMode);
this.minModes = 1;
this.maxModes = 1;
this.maxPawPrints = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 logic smells bed. Must be 0 by default. And other code checks must use > 0.

Mode mode = get(modeId);

if (mode.getPawPrintValue() < 0 && this.getMaxPawPrints() >= 0){
throw new RuntimeException("Selected mode has no pawprint value, but this Modes object requires pawprint modes!");
Copy link
Member

@JayDi85 JayDi85 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it’s verify check and can be added to card constructor time instead runtime. As example: modes.addMode - after new mode added make sure modes amount with paw equal to total modes amount or zero.

@jimga150
Copy link
Contributor Author

Is there a way to retrigger travis builds? this one looks like it was a transient error

Copy link
Contributor

@xenohedron xenohedron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor followup correction needed, otherwise I think this is ready to go

String message = "Choose mode (selected " + modes.getSelectedModes().size() + " of " + modes.getMaxModes(game, source)
+ ", min " + modes.getMinModes() + ")";
String message;
if (modes.getMaxPawPrints() < 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be modes.getMaxPawPrints() == 0 now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, missed this and another check when converting the pattern to 0 -> non-pawprints

}
}

// done button for "for up" choices only
boolean canEndChoice = modes.getSelectedModes().size() >= modes.getMinModes() || modes.isMayChooseNone();
boolean canEndChoice = (modes.getSelectedModes().size() >= modes.getMinModes() && modes.getMaxPawPrints() < 0) ||
(modes.getSelectedPawPrints() >= modes.getMaxPawPrints() && modes.getMaxPawPrints() >= 0) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be updated now that max paw prints = 0 indicates no pawprints

@xenohedron xenohedron merged commit e976920 into magefree:master Aug 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants