Hi everyone,
Apologies if there is already an established answer to this somewhere - there likely is, since the functionality I am after already exists on several games I regularly play on BGA. (Eg Russian Railroads, the currently-alpha Castles of Burgundy, and probably lots more). But I'm new to the BGA framework and am yet to see anything that looks like it will answer this.
I'm trying to implement Deus (in the *very* early stages - haven't even started the UI view yet!), which I picked in part because it's not a particularly complex game in the sense of having lots of rules and moving parts. But there are potentially complex chains of decisions that players will take on their turn, which typically will involve:
- playing a card
- choosing how to pay for it (since you can always substitute money for other resources)
- choosing where to put the corresponding building
- activating the effects of previously-played cards, many of which will involve decisions (eg moving pieces, or whether to pay resources for VP...)
I have a fairly good outline in my head of how I could do this by simply implementing different actions and having each one send a request to the server, have it update the game state via the database and return the notification to the client. But this would obviously mean that the player couldn't "undo" any steps of their turn, and also that all other players would see the "progress" of every player's turn in the logs. I think it would be a better user experience to do it like the above-mentioned games do, where while only the active player is making decisions, they should do everything client-side and with the option to "wind their turn back" (unseen by the other players) at any point, then finally "lock this in" by submitting the move to the server and triggering all the notifications of what happened on their turn.
I have looked at (although not yet understood in depth) the part of the cookbook on "client state" - and that certainly seems like it could be useful for updating the UI while the player plays, without yet submitting anything to the server. But what I'm really unclear on is how to record the entire sequence of choices and submit that as an "action" in one go.
I can see how it might work for simple cases like the one discussed in the link above, ie. where you choose a worker then choose where it goes, because then you have essentially 2 discrete pieces of information to send to the server. But in Deus (and I assume in lots of other similar games) there are essentially (not really of course) an "infinite" number of things that can happen, and I can't think how to handle this. (Other than by simply having the client calculate all the needed changes in the game-state and send that to the server - but that's obviously no good even though it would probably seem to work for most players, because there's nothing to stop a cheater making a request that says "I now have 100 more coins and 50 more VP" and have the server believe that.)
What I really think I'm looking for is a way to "save" on the client side a bunch of server requests, without actually submitting them, then basically submit them all one after the other, so that the server can check legality of the entire sequence and update the database as it goes along (and presumably roll back if any of the actions are illegal - not sure if the database transaction model will make that work automatically or not) and then send all the relevant notifications back to all players at the end. But I'm not sure how to achieve this in the BGA framework.
Thanks for reading, I hope you've understood my question - but if not please feel free to ask for clarifications. (Although not code snippets, I haven't started to code any of this yet, or even the state machine - I'm just trying to get an outline in my head of what to do before starting any code!) I look forward to some good answers!
Apologies if there is already an established answer to this somewhere - there likely is, since the functionality I am after already exists on several games I regularly play on BGA. (Eg Russian Railroads, the currently-alpha Castles of Burgundy, and probably lots more). But I'm new to the BGA framework and am yet to see anything that looks like it will answer this.
I'm trying to implement Deus (in the *very* early stages - haven't even started the UI view yet!), which I picked in part because it's not a particularly complex game in the sense of having lots of rules and moving parts. But there are potentially complex chains of decisions that players will take on their turn, which typically will involve:
- playing a card
- choosing how to pay for it (since you can always substitute money for other resources)
- choosing where to put the corresponding building
- activating the effects of previously-played cards, many of which will involve decisions (eg moving pieces, or whether to pay resources for VP...)
I have a fairly good outline in my head of how I could do this by simply implementing different actions and having each one send a request to the server, have it update the game state via the database and return the notification to the client. But this would obviously mean that the player couldn't "undo" any steps of their turn, and also that all other players would see the "progress" of every player's turn in the logs. I think it would be a better user experience to do it like the above-mentioned games do, where while only the active player is making decisions, they should do everything client-side and with the option to "wind their turn back" (unseen by the other players) at any point, then finally "lock this in" by submitting the move to the server and triggering all the notifications of what happened on their turn.
I have looked at (although not yet understood in depth) the part of the cookbook on "client state" - and that certainly seems like it could be useful for updating the UI while the player plays, without yet submitting anything to the server. But what I'm really unclear on is how to record the entire sequence of choices and submit that as an "action" in one go.
I can see how it might work for simple cases like the one discussed in the link above, ie. where you choose a worker then choose where it goes, because then you have essentially 2 discrete pieces of information to send to the server. But in Deus (and I assume in lots of other similar games) there are essentially (not really of course) an "infinite" number of things that can happen, and I can't think how to handle this. (Other than by simply having the client calculate all the needed changes in the game-state and send that to the server - but that's obviously no good even though it would probably seem to work for most players, because there's nothing to stop a cheater making a request that says "I now have 100 more coins and 50 more VP" and have the server believe that.)
What I really think I'm looking for is a way to "save" on the client side a bunch of server requests, without actually submitting them, then basically submit them all one after the other, so that the server can check legality of the entire sequence and update the database as it goes along (and presumably roll back if any of the actions are illegal - not sure if the database transaction model will make that work automatically or not) and then send all the relevant notifications back to all players at the end. But I'm not sure how to achieve this in the BGA framework.
Thanks for reading, I hope you've understood my question - but if not please feel free to ask for clarifications. (Although not code snippets, I haven't started to code any of this yet, or even the state machine - I'm just trying to get an outline in my head of what to do before starting any code!) I look forward to some good answers!