We're building out an asynchronous PVP system in which a player can attack another player of a similar power range. So I've set up a system in which our game has a leaderboard that tracks a player's power. This works great. I have a Cloudscript call "GetOpponent()", which gets the nearest 20 players around the player and returns one randomly to attack. This also works great.
However there's some additional limitiations that I'm trying to add to the system. An attack time limit and a basic building requirement, i.e. only allow valid opponents who haven't been attacked in the last 5 minutes or so, and only allow opponents who have a minimum number of buildings to attack. In order to track this data I have a simple json blob, combatInfo, stored in in the playerData for a given player. combatInfo has a lastAttackedTime property, and a buildingCount property that get updated when a player is attacked and when their buildings get modified.
This also all works fine.
But the problem is that in order sort the possible opponents I need to call a GetUserTitleData on each one. Theres a few other API calls as well, for instance the minimum time until attacked again is stored in title data. Basically, my problem is that I'm running in to the cloudscript API call limit as soon as I get more than 3 or 4 opponents, and even if I manage to optimize the required calls perfectly I calculate the most I could do would be basically 10 possible opponents which will not really give us the range we need. My other option is to move this to the client and pass the client the list of possible opponents and then have the client query them in order to find a valid opponent, but this seems even more inefficent as now I have additional queries coming from the client and I'd prefer to keep the entire call on the server. Another option (which I'm trying to avoid) is a custom server as otherwise working with the cloudscript is great.
Finally would porting my scripts to functions impact these limits, seems like there's no API call limits there? Although non-trivial, we do plan to port everything to functions eventually regardless.