octgn / OCTGN

Online Card and Tabletop Gaming Network
http://www.octgn.net
Other
355 stars 129 forks source link

Allow python to change a pile's controller #1165

Closed db0 closed 10 years ago

db0 commented 10 years ago

Some of my games allow and require that one player often manipulates the deck and hand of their opponent very often. Until now I've been dealing with this by simply moving cards around as required, but with the future plans to block manipulation of cards one does not control this is going to become almost impossible to do via scripting, even via remoteCall, due to the complexities of changing control within a script and changing control of a card outside the table.

As such I'd like to request a more elegant solution for all such issues, which is to exposing the API for changing a pile's controller to python, something like pile.setController(player).

This way I can request a remoteCall() a change of pile control to the pile's controller during my script execution, and then return it once it's has finished.

kellyelton commented 10 years ago

A remotecall isn't synchronous though. On Dec 23, 2013 4:33 AM, "Divided by Zer0" notifications@github.com wrote:

Some of my games allow and require that one player often manipulates the deck and hand of their opponent. Until now I've been dealing with this by simply moving cards around as required, but with the future plans to block manipulation of cards one does not control this is going to become almost impossible to do via scripting, even via remoteCall, due to the complexities of changing control within a script and changing control of a card outside the table.

As such I'd like to request a more elegant solution for all such issues, which is to exposing the API for changing a pile's controller to python, something like pile.setController(player).

This way I can request a remoteCall() a change of pile control to the pile's controller during my script execution, and then return it once it's has finished.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165 .

db0 commented 10 years ago

I know, but I can work around this by doing something like

remoteCall(player,'grabPileControl',[pile,me])
count = 0
while pile.controller != me: 
   update()
   count += 1
   if count >= 10: 
      notify("Error blah blah")
      return
# rest of script

I'm already doing something like this in one of my games and changing card control. Of course I'm not sure how much it will break once the controller block is in effect, so this might also require a working sleep() function.

db0 commented 10 years ago

Alternatively, perhaps it could be a good idea to provide an API which changes controller or a card/pile and doesn't return until that is resolved. This could allow scripts to be able to execute without async calls?

So, for example, if OCTGN provided an API called changePileController(newPlayer, pile) which sent a remote call (if required) to a pile's controller to change control to newPlayer and only returned when that change was complete, I would be able to use that API in my script, without having to use ugly while loops.

kellyelton commented 10 years ago

Yeah but these kinds of solutions are really just bandaids and really only compound other issues. On Dec 23, 2013 4:45 AM, "Divided by Zer0" notifications@github.com wrote:

I know, but I can work around this by doing something like

remoteCall(player,'grabPileControl',[pile,me]) count = 0 while pile.controller != me: update() count += 1 if count >= 10: notify("Error blah blah") return

rest of script

I'm already doing something like this in one of my games and changing card control. Of course I'm not server how much it will break once the controller block is in effect, so this might also require a working sleep() function.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165#issuecomment-31112973 .

db0 commented 10 years ago

I'm not sure why you consider them bandaids. They are the only working solutions in the framework provided. If I can't manipulate a card I do not control, then I need to grab control first, and if that needs an async call, I need to wait for it to finish.

I'd love to have something that doesn't require these kind of hacks but it's not up to me.

kellyelton commented 10 years ago

Why not execute everything on the other users client, why force the first client to wait? On Dec 23, 2013 4:55 AM, "Divided by Zer0" notifications@github.com wrote:

I'm not sure why you consider them bandaids. They are the only working solutions in the framework provided. If I can't manipulate a card I do not control, then I need to grab control and if that needs an async call, I need to wait for it to finish.

I'd love to have something that doesn't require these kind of hacks but it's not up to me.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165#issuecomment-31113319 .

db0 commented 10 years ago

Because the script requires one or more inputs from the active player, depending on the cards manipulated, which can then trigger further inputs or scripts and so on.

The only other option would be to split one script into 3+ parts and then ping-pong their executions between the players, but this seems even more awkward. Even so, if it comes to this, at least with being able to change the pile controller I'll be able to reduce the ping-pong to only 3 times.

kellyelton commented 10 years ago

But doable. Remotecall was made for that. That's the whole point of the call On Dec 23, 2013 6:04 AM, "Divided by Zer0" notifications@github.com wrote:

Because the script requires one or more inputs from the active player, depending on the cards manipulated, which can then trigger further inputs or scripts and so on.

The only other option would be to split one script into 3-5 parts and then ping-pong their executions between the players, but this seems even more awkward.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165#issuecomment-31115785 .

db0 commented 10 years ago

It's doable but unnecessarily complex without a way to change a pile controller. This would just simplify things for developers doing complex manipulations while allowing them to stay within the expected framework. It would also significantly reduce network congestion but reducing the amount of remoteCalls and shared variables sent around.

kellyelton commented 10 years ago

I really think the problem is already solvable. Someone will look into this at some point, would help if you had a specific use case with some example code though. On Dec 23, 2013 6:11 AM, "Divided by Zer0" notifications@github.com wrote:

It's doable but unnecessarily complex without a way to change a pile controller. This would just simplify things for developers doing complex manipulations while allowing them to stay within the expected framework.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165#issuecomment-31116052 .

db0 commented 10 years ago

I can work around the limitation myself as it is as I always do. The issue is that the solution is just going to be unnecessarily complex and full of remoteCalls and setting/grabbing of shared variables (and thus a giant PITA for me). I can provide the current code but I'm not sure what help it would be.

This is not so much about solving something I cannot do, it's about providing tools to developers to make more functional/elegant and less bloated/resource hungry code.

kellyelton commented 10 years ago

I think you're wrong, but like I said well look into it. On Dec 23, 2013 6:21 AM, "Divided by Zer0" notifications@github.com wrote:

I can work around the limitation myself as it is as I always do. The issue is that the solution is just going to be unnecessarily complex and full of remoteCalls and setting/grabbing of shared variables. I can provide the current codehttps://github.com/db0/Android-Netrunner-OCTGN/blob/master/o8g/Scripts/actions.py#L1263but I'm not sure what help it would be.

This is not so much about solving something I cannot do, it's about providing tools to developers to make more functional/elegant and less bloated/resource hungry code.

— Reply to this email directly or view it on GitHubhttps://github.com/kellyelton/OCTGN/issues/1165#issuecomment-31116381 .

brine commented 10 years ago

Group.setController() already exists

db0 commented 10 years ago

Oh shit, Indeed there is! Must have slipped by me. Thanks