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

Refactor DIY 3 code #330

Open
LunarTides opened this issue Oct 9, 2023 · 0 comments
Open

Refactor DIY 3 code #330

LunarTides opened this issue Oct 9, 2023 · 0 comments
Labels
impact: low Low impact priority: low Low priority scope: card The issue is related to 1 or more cards. time: short Estimated time: 1-3 hours. type: improvement Improvement to an already existing feature
Milestone

Comments

@LunarTides
Copy link
Owner

// Testing your solution.
// TODO: All this code is bad. Please fix it.
let target = self;
let correctParameters = false;
let potentiallyCancelled = false;
// Make sure the parameters are correct
game.functions.event.addListener("TargetSelectionStarts", (_unknownVal) => {
const val = _unknownVal as EventValue<"TargetSelectionStarts">;
// Don't check for `prompt` since there is no correct prompt
const [prompt, card, forceSide, forceClass, flags] = val;
correctParameters = (
card == self &&
forceSide == "any" &&
forceClass == "minion" &&
flags.length == 0
);
// The `TargetSelectionStarts` event fired. This means that the card has a chance of being cancelled.
potentiallyCancelled = true;
return "destroy";
}, 1);
// Find the target
game.functions.event.addListener("TargetSelected", (_unknownVal) => {
const val = _unknownVal as EventValue<"TargetSelected">;
if (!(val[0] === self)) return false;
// At this point we know that the card wasn't cancelled, since the `TargetSelected` event doesn't fire if the card is cancelled
target = val[1] as Card;
potentiallyCancelled = false;
return "destroy";
}, 1);
solution();
// This only happens if the `TargetSelectionStarts` event fired, but not `TargetSelected`.
// That only happens if the card was cancelled after the `TargetSelectionStarts` event fired
if (potentiallyCancelled) {
game.pause("You cancelled the card. The verification process depends on a minion actually being killed. Try again.\n");
return game.constants.REFUND;
}
const solved = (
target !== self &&
target.getHealth() <= 0 &&
correctParameters &&
game.graveyard.some(p => p.includes(target))
);
game.interact.verifyDIYSolution(solved, "3.ts");
if (!solved) return game.constants.REFUND;
return true;

@LunarTides LunarTides added priority: low Low priority time: short Estimated time: 1-3 hours. scope: card The issue is related to 1 or more cards. type: improvement Improvement to an already existing feature impact: low Low impact labels Oct 9, 2023
@LunarTides LunarTides added this to the 2.0 milestone Oct 9, 2023
@LunarTides LunarTides modified the milestones: 2.0, 3.0 Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
impact: low Low impact priority: low Low priority scope: card The issue is related to 1 or more cards. time: short Estimated time: 1-3 hours. type: improvement Improvement to an already existing feature
Projects
None yet
Development

No branches or pull requests

1 participant