The City Constructor Demo is based on a more advanced login/register system which also checks email's and IP Addresses to prevent a single user registering more than one account.
It also says the time since the player last logged in, it has a daily reward, and the player can create buildings, upgrade them, move them and sell them. It is the most secure of all of the demos as everything is checked server-side (on the Command Sequences).
As you would expect, it is the most complex system out of all of the demos. If you want a similar system in your game we would still advise building apon the Login Demo. Using this demo might give you a head start, but it might be more difficult for you to understand which slows down your development speed.
Make sure you have setup the demo before you try using it.
Once you have setup the demo, you can delete the 'DeleteMe' object from the scene. (It is a child of the canvas)
The City Constructor Demo can be found at:
Assets>Database Control Pro>Demos>Main Demos>City Constructor Demo>DCP City Constructor Demo
The City Constructor Demo uses the Smooth UI animation system to translate the UI elements on and off the screen.
The UI is split up into the Menu UI, the in-game UI and the loading UI in a similar way to the Third Person Demo. All of the code is distributed over multiple scripts and objects, but it should be clear which are the more important ones. As usual, all code is well commented to help explain how the demo works.
The Structure of the Database:
First play the demo, register an account and create a few buildings. Then Open the Setup Window and View the Database which you set the demo up with.
The Database should look something like this:
In this demo, every row is not a single account. Instead every account has a main row followed by rows for each building.
The Structure of the Player's main row:
The first column stores the player's username.
The second column stores the player's email.
The third column stores the player's IP Address which they registered the account with.
The fourth colmn stores the player's password.
The fifth column stores the player's money.
The sixth column stores the player's level.
Columns 7,8,9,10,11 and 12 store the time since the player last ran a sequence (used to calculate time after player logs in) in the form Year, Month, Day, Hour, Minute and Second (Milliseconds ignored).
Columns 13, 14 and 15 store the time the player last claimed the daily reward (blank if never claimed) in the form Year, Month and Day.
The 16th column stores the number of buildings the player has so the Command Sequence know how many lines to loop through, bellow the player's line in order to go through all of the player's buildings.
The Structure of one of the Player's building rows:
The first three columns are blank so the 'Register' Command Sequence can easily loop through player usernames, email addresses and IP addresses to make sure a registering player has different values for these.
The fourth column stores the building type. 0 for House, 1 for Factory and 2 for Bank.
The fifth column stores the building's level number.
The sixth column stores the building's position in the scene.
If it is a factory, columns 7, 8, 9, 10, 11, 12 and 13 store the time when the factories money was last collected in the form Year, Month, Day, Hour, Minute, Second and Millisecond.
The Command Sequences:
The City Constructor Demo comes with 9 Command Sequences. All of the sequences check everything server-side (except the position of the buildings). These sequences are explained in more detail when you open the sequence and look at the 'Readme' Command.
1. Register: This sequence checks the submitted username is not already in use. If it is then an error is returned. If it is not the the IP Address and submitted email address are also compared with the other values in the database. If they are already in the database an error is returned for the game to say 'You already have an account!', otherwise the registration is successful and a new row is added to the database with the player's details.
2. Login: This sequence checks the submitted username and password. If they are correct then the player data string is put together and returned. This means working out the time since the last request and the time since the last claimed daily reward (to tell if one can be claimed now or not) and combining it with the players level and money. Then the sequence loops through all of the building rows adding on the building data.
3. Build: This sequence is run when the player wants to create a new building. The amount of money is retrieved from the player's main row in the database and if there is enough money, a new row is inserted into the database for the created building.
4. Upgrade: This sequence is run when the player wants to upgrade an existing building. The amount of money needed to upgrade is caluclated in the sequence and the player's money is checked to make sure there is enough. Other things are also checked including the player level (to make sure it is high enough). If all of these conditions are satisfied, Success is returned and the level number on the building's row in the database is increased.
5. Move: This is the simplest of all the sequences as the position of the buildings is not checked in any sequences as it is less important. Instead the building numer is checked to make sure it is a valid building. If it is then the building position string is replaced and Success is returned.
6. Sell: This sequence makes sure the building is valid, adds up all of the upgrade costs of the building to find the total amount ever spent on it. This value is halved to give the sell price. If all conditions are satisfied, the building's row is deleted from the database, and Success is returned while increasig the player's money (and checking it doesn't exceed the maximum amount).
7. Collect: This sequence checks the submitted building number corresponds to a factory. It finds the difference in time since the building's money was last collected and works out the amount it must have generated from this while limiting it based on the factory's level. It then updates the time when it was last collected to now and adds the generated money to the players money while checking the player's money does not exceed the maximum amount.
8. Level Up: This sequence is run by the game's code after building or upgrading to check for a level up. The sequence iterates through the player buildings, checking for houses. It uses the level of the houses to work out the number of people they contain. This allows it to calculate the total population of the city. It uses the players current level number to work out the population requuired to level up. If the population is high enough it returns Success and adds 1 to the player's level.
9. Claim Daily Reward: This sequence works out the time since the Daily Reward was last claimed. If it was a different day, the date in the database is updated, the player money is increased by 100, the player money is limited to its maximum (if required) and 'Success' is retured.