Okay, so I'm trying to work out exactly how buying a card works in terms of, exactly what do you do? I keep thinking I can write it down, but keep realising I have issues when I try and express it at a completely fundamental level.
I'm thinking it's something like the below. It works like a dominion card itself, you do everything in order and if you can't do it, you keep going.
Buy:
-coin equal to the cost of the card currently
Gain a copy of the card
Now this might seem elementary, but issues start occuring when we put it in context of a buy phase.
Choose card I want to buy.
If (chosen card is in the supply AND chosen card costs less than my total coin available)
-1 Buy
Do Buy
Is that all correct so far? Then the next question is, when does a 'when buy' effect happen? Presumably before one starts resolving the buy effect itself, correct? If not, when? Then just for a second suppose we had the following reaction: When you buy a card, you may reveal and discard this. If you do, buy a card. At first, it looks fairly innocent, okay it's a reaction that gives a badly worded +buy. Except, does it? Have I spent any coin yet? Is this slightly unintuitive resolution technically correct, just a bit weird, or do I actually need to move some stuff around in my psuedocode?
I keep thinking this should be really elementary, but yet can't quite formulate exactly what should happen. Anyone want to help?