netrunner icon indicating copy to clipboard operation
netrunner copied to clipboard

Dev question: forcing synchronous prompts

Open nealterrell opened this issue 11 years ago • 3 comments

I am fooling around with damage increase/prevention hookups to allow interactions for The Cleaners, Plascrete Carapace, etc. My first attempt has been to add an event to the (damage) effect, BEFORE the damage is dealt, allowing event listeners to set a state variable to increase or decrease damage by a particular amount. This works well for The Cleaners: when the :pre-damage event fires, The Cleaners calls my new (damage-bonus) function to set a state variable increasing :meat damage by 1. The (damage) function uses this state variable to deal +1 meat damage from any source. Success!

To implement Plascrete Carapace or any other pay-to-reduce card, I thought to listen for the :pre-damage event, and respond by showing the runner a prompt to select how much damage to absorb with the carapace. My first attempt showed the prompt to the Corp; whoops. The second attempt shows the prompt to the Runner, but the (damage) routine (triggered by the meat damage card, e.g., Scorched Earth) continues without waiting for the prompt to resolve. I am guessing this is because the prompt is run asynchronously; the :pre-damage event fires, Plascrete's listener shows the prompt and returns back to the damage function, which deals the 4 damage before the Runner can select the prevention amount.

@mtgred , am I missing any tech here that would help with this implementation? Is there a way to force a function which shows a prompt to NOT return until the prompt resolves? If not, do you have any other thoughts on how to handle damage prevention? My only other idea is to show a "Continue" button to the Corp each time damage is done, giving a clear window for the Runner to spend Plascrete Tokens, trigger Feedback Filter, etc.

nealterrell avatar May 18 '15 23:05 nealterrell

I don't have anything substantive other than to say this would be a tremendous improvement! Keep up the great work, Neal!!

JoelCFC25 avatar May 19 '15 15:05 JoelCFC25

There is currently no way to stop the execution of card abilities. A new interruption mechanism needs to be added.

What I had in mind for damage prevention and other type of prevention (eg. Zaibatsu Loyalty) is to keep a:prevent hashmap at the root the game-state. That hashmap would keep track of the number cards in play that can prevent certain type of event (eg: :meat :net :expose). When such an event occurs, the :prevent hashmap is checked to see of there are cards that can prevent it. In case there are, it prompts the player to use any prevent abilities he whishes before resolving the other ability.

Cards that can prevent abilities would have a :prevent array (eg. :prevent [:brain :net] for Feedback Filter). When the card is installed (or rezzed) or leave play (or unrezzed) , the :prevent hashmap is updated based on the keys in the :prevent array.

I actually started writing some prevention code 2 weeks ago but didn't have time to continue with all the bug reports and the new server migration. So feel free to implement it if you want.

mtgred avatar May 22 '15 14:05 mtgred

Thanks @mtgred, I have made good progress on this issue and will have some code to check in soon. I am using your hashmap to trigger a "Prevent?" prompt when damage is done. The actual damage code is moved into a (resolve-damage) function which will only fire once the prompt is done, fixing the issue I had with my approach.

nealterrell avatar May 28 '15 16:05 nealterrell