{"_id":"59a9f7b428ab5f000f23956f","category":{"_id":"59a9f7b328ab5f000f23954c","version":"59a9f7b328ab5f000f23954a","project":"543b9b0065bf840e00b473d5","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-11-10T14:14:26.569Z","from_sync":false,"order":1,"slug":"player-base","title":"Gameplay"},"user":"543b9aa865bf840e00b473d1","project":"543b9b0065bf840e00b473d5","parentDoc":null,"version":{"_id":"59a9f7b328ab5f000f23954a","project":"543b9b0065bf840e00b473d5","__v":1,"createdAt":"2017-09-02T00:13:39.834Z","releaseDate":"2017-09-02T00:13:39.834Z","categories":["59a9f7b328ab5f000f23954b","59a9f7b328ab5f000f23954c","59a9f7b328ab5f000f23954d","59a9f7b328ab5f000f23954e","59a9f7b328ab5f000f23954f","59a9f7b328ab5f000f239550","59a9f7b328ab5f000f239551","59a9f7b328ab5f000f239552","59a9f7b328ab5f000f239553","59a9f7b328ab5f000f239554","59a9f7b328ab5f000f239555","59a9f7b328ab5f000f239556","59a9f7b328ab5f000f239557"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"7.2.0","version":"7.2"},"githubsync":"","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-11-10T14:16:01.473Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Reminder - Keep Daily Backups\",\n  \"body\": \"When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"What is the shield?\"\n}\n[/block]\nIn popular free-to-play city building games, players can purchase a shield element which protects their base from attacks for a certain period of time and costs a large amount of rare currency. This helps developers monetize their battle strategy games with additional ways to spend real currency in the game.\n\nAs part of the early release schedule we've included the Player Base Shield feature. As of now, this is purely decorative. The HUD menu item and the store menu are included for developers to use if they would like.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/49aa171-Screen_Shot_2016-11-18_at_11.19.32_PM.png\",\n        \"Screen Shot 2016-11-18 at 11.19.32 PM.png\",\n        1113,\n        524,\n        \"#608f40\"\n      ],\n      \"caption\": \"Store shield menu. Click to view larger.\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Want to use player shields in your game?\"\n}\n[/block]\nAs a quick work around to activate shields for player bases - connect the store buttons to deduct the gem amounts and then save the values to the Player save file. For example:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"###Shield###\\nSHIELD_STATUS\\nON\\nSHIELD_TIME_LENGTH\\n6 hours\\nSHIELD_START_TIME\\n11/11/2016 11:59 GMT\",\n      \"language\": \"text\",\n      \"name\": null\n    }\n  ]\n}\n[/block]\nFor example, added to the end of an example player map file.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"###StartofFile###\\n###PosStruct###\\nWeapon,ArcherTower,160,2,1024,452.5\\nWeapon,Cannon,186,2,384,0\\nBuilding,Barrel,190,3,-768,362\\nBuilding,Vault,192,3,0,362\\n###GridStruct###\\n###Construction###\\n###Removables###\\n###RemovableTimers###\\n###Numerics###\\n193,185,189\\n0.00,0\\n0,0,0,0,0,0,0,0,0,0\\n0,0,0,0,0,0,0,0,0,0\\n0,0,0,0,0,0,0,0,0,0\\n###Stats###\\n193,1326,1,0,0,100,100000,97400,85,505000,505000,500,True,True,True,True,True\\n11/11/2016 3:49:16 PM\\n###Shield###\\nSHIELD_STATUS\\nON\\nSHIELD_TIME_LENGTH\\n6 hours\\nSHIELD_START_TIME\\n11/11/2016 11:59 GMT\\n###EndofFile###\\n\",\n      \"language\": \"text\",\n      \"name\": \"sample_player_id.txt\"\n    }\n  ]\n}\n[/block]\nAfter that, we recommend editing the Stats.cs script to display this shield data from the player ID. Edit the SaveLoad scripting to load the shield value like the player status are imported on load. After - you should see the shield value added to the HUD among the other player stats after load:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/469ed5c-Screen_Shot_2016-11-18_at_11.18.35_PM.png\",\n        \"Screen Shot 2016-11-18 at 11.18.35 PM.png\",\n        603,\n        354,\n        \"#6ba535\"\n      ],\n      \"caption\": \"Shield HUD example. Click to view larger.\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Remember to update the UI with ((Stats)stats).UpdateUI();\",\n  \"body\": \"The kit is optimized so that UI updates are not occurring regularly without purpose. If you ever update the stats in any of your scripting - make sure to add ((Stats)stats).UpdateUI(); at the end to make sure your changes are visible.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Online Server Sync - PvP Shielded Player Avoidance (PHP)\"\n}\n[/block]\nThe following is an example of additional PHP code for get_match.php (part of the Online Server Sync demo scripts) to check if a player map has a shield active, and if so, has the shield time passed?\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?\\n\\n\\n// Instructions:\\n// Integrate the following code into the random player map locator function\\n// Return the player map if no shield is active, otherwise loop to the next\\n//\\n\\n// What player file are you checking?\\n$random_player_data_file = \\\"random_player_data.txt\\\"; //e.g. XaG13gajd.txt\\n\\n// Function to get the line after\\nfunction getLineAfter($file_path, $line) {\\n    $lines = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\\n    if (($key = array_search($line, $lines)) !== false && isset($lines[$key + 1])) {\\n        return $lines[$key + 1];\\n    }\\n    return null;\\n}\\n// End of function\\n\\n\\n\\n\\n// Check player data for shield line\\nif(getLineAfter($random_player_data_file, 'SHIELD_STATUS')==\\\"ON\\\"){\\n  \\n  \\n  // Get the variables after (lenght of time purchased and the start time\\n  $shield_length = getLineAfter($random_player_data_file, 'SHIELD_TIME_LENGTH');\\n  $shield_start_time = getLineAfter($random_player_data_file, 'SHIELD_START_TIME');\\n  \\n  \\n  // Calculate time\\n  $time = strtotime($shield_start_time); \\t// Convert start time of the shield\\n\\t$when_does_the_shield_end = strtotime('+'.$shield_length, $time); // Convert ending time of the shield\\n  \\n  \\n  // Check if the time has passed\\n  if (time() > $when_does_the_shield_end) {\\n    //\\n    // shield is done -- player can be attacked - return the player data \\n    // \\n\\t} else {\\n    //\\n    // shield is still active - loop to check next player\\n    //\\n  }\\n  \\n}\\n\\n\\n?>\",\n      \"language\": \"php\",\n      \"name\": \"get_match.php\"\n    }\n  ]\n}\n[/block]\nWith the existing Unity scripting in the Complete Kit - nothing additional is necessary to begin testing shields in your game other than connecting the buttons to Player save data as mentioned above.","excerpt":"","slug":"shield","type":"basic","title":"Shield"}
[block:callout] { "type": "success", "title": "Reminder - Keep Daily Backups", "body": "When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work." } [/block] [block:api-header] { "type": "basic", "title": "What is the shield?" } [/block] In popular free-to-play city building games, players can purchase a shield element which protects their base from attacks for a certain period of time and costs a large amount of rare currency. This helps developers monetize their battle strategy games with additional ways to spend real currency in the game. As part of the early release schedule we've included the Player Base Shield feature. As of now, this is purely decorative. The HUD menu item and the store menu are included for developers to use if they would like. [block:image] { "images": [ { "image": [ "https://files.readme.io/49aa171-Screen_Shot_2016-11-18_at_11.19.32_PM.png", "Screen Shot 2016-11-18 at 11.19.32 PM.png", 1113, 524, "#608f40" ], "caption": "Store shield menu. Click to view larger." } ] } [/block] [block:api-header] { "type": "basic", "title": "Want to use player shields in your game?" } [/block] As a quick work around to activate shields for player bases - connect the store buttons to deduct the gem amounts and then save the values to the Player save file. For example: [block:code] { "codes": [ { "code": "###Shield###\nSHIELD_STATUS\nON\nSHIELD_TIME_LENGTH\n6 hours\nSHIELD_START_TIME\n11/11/2016 11:59 GMT", "language": "text", "name": null } ] } [/block] For example, added to the end of an example player map file. [block:code] { "codes": [ { "code": "###StartofFile###\n###PosStruct###\nWeapon,ArcherTower,160,2,1024,452.5\nWeapon,Cannon,186,2,384,0\nBuilding,Barrel,190,3,-768,362\nBuilding,Vault,192,3,0,362\n###GridStruct###\n###Construction###\n###Removables###\n###RemovableTimers###\n###Numerics###\n193,185,189\n0.00,0\n0,0,0,0,0,0,0,0,0,0\n0,0,0,0,0,0,0,0,0,0\n0,0,0,0,0,0,0,0,0,0\n###Stats###\n193,1326,1,0,0,100,100000,97400,85,505000,505000,500,True,True,True,True,True\n11/11/2016 3:49:16 PM\n###Shield###\nSHIELD_STATUS\nON\nSHIELD_TIME_LENGTH\n6 hours\nSHIELD_START_TIME\n11/11/2016 11:59 GMT\n###EndofFile###\n", "language": "text", "name": "sample_player_id.txt" } ] } [/block] After that, we recommend editing the Stats.cs script to display this shield data from the player ID. Edit the SaveLoad scripting to load the shield value like the player status are imported on load. After - you should see the shield value added to the HUD among the other player stats after load: [block:image] { "images": [ { "image": [ "https://files.readme.io/469ed5c-Screen_Shot_2016-11-18_at_11.18.35_PM.png", "Screen Shot 2016-11-18 at 11.18.35 PM.png", 603, 354, "#6ba535" ], "caption": "Shield HUD example. Click to view larger." } ] } [/block] [block:callout] { "type": "info", "title": "Remember to update the UI with ((Stats)stats).UpdateUI();", "body": "The kit is optimized so that UI updates are not occurring regularly without purpose. If you ever update the stats in any of your scripting - make sure to add ((Stats)stats).UpdateUI(); at the end to make sure your changes are visible." } [/block] [block:api-header] { "type": "basic", "title": "Online Server Sync - PvP Shielded Player Avoidance (PHP)" } [/block] The following is an example of additional PHP code for get_match.php (part of the Online Server Sync demo scripts) to check if a player map has a shield active, and if so, has the shield time passed? [block:code] { "codes": [ { "code": "<?\n\n\n// Instructions:\n// Integrate the following code into the random player map locator function\n// Return the player map if no shield is active, otherwise loop to the next\n//\n\n// What player file are you checking?\n$random_player_data_file = \"random_player_data.txt\"; //e.g. XaG13gajd.txt\n\n// Function to get the line after\nfunction getLineAfter($file_path, $line) {\n $lines = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);\n if (($key = array_search($line, $lines)) !== false && isset($lines[$key + 1])) {\n return $lines[$key + 1];\n }\n return null;\n}\n// End of function\n\n\n\n\n// Check player data for shield line\nif(getLineAfter($random_player_data_file, 'SHIELD_STATUS')==\"ON\"){\n \n \n // Get the variables after (lenght of time purchased and the start time\n $shield_length = getLineAfter($random_player_data_file, 'SHIELD_TIME_LENGTH');\n $shield_start_time = getLineAfter($random_player_data_file, 'SHIELD_START_TIME');\n \n \n // Calculate time\n $time = strtotime($shield_start_time); \t// Convert start time of the shield\n\t$when_does_the_shield_end = strtotime('+'.$shield_length, $time); // Convert ending time of the shield\n \n \n // Check if the time has passed\n if (time() > $when_does_the_shield_end) {\n //\n // shield is done -- player can be attacked - return the player data \n // \n\t} else {\n //\n // shield is still active - loop to check next player\n //\n }\n \n}\n\n\n?>", "language": "php", "name": "get_match.php" } ] } [/block] With the existing Unity scripting in the Complete Kit - nothing additional is necessary to begin testing shields in your game other than connecting the buttons to Player save data as mentioned above.