Defense Walls

👍

Reminder - Keep Daily Backups

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.

What are defensive walls?

When playing strategy games like Clash of Clans where players can attack other players, it's important to find a way to defend your village from attacking players.

429

Example walls. Click to view larger.

The City Building Kit demo includes two types of wall examples, stone and wooden walls. (Plus lots more free bonus art for more wall themes is included in our highest package available for purchase from CityBuildingKit.com)

Unlike the defensive structures, walls don't have any actual value in offensive defense and unlike the resource or military buildings walls don't have any storage value for the player. This category of the shop is only meant for PvP battle protection like the Cloak category. (And possibly decoration value too)

Shop Menu

Here's a screenshot of the shop menu for the military buildings.

636

Click to view larger.

The examples seen in the image below allow the player to build long wall segments like Stone Wall NE or Stone Wall NW, or larger corner segments like Stone Tower or the flagpole Wooden End NE

753

Click to view larger.

Where to find the wall store menu in Unity?

Open the game scene hierarchy and locate the ScrollView in Canvas > ModalsWindows > ShopWindows > ShopGroup > StorePanel > BottomGroup > Content > Content. Look at the below screenshot.

403

UIAnchor. Click to view larger.

Store Item

All of the store details seen in the below screenshot are taken from the Assets/CityBuildingKit/Resources/Assets/WallsCategory.asset file and loaded by Scripts/Creators/BaseCreator.cs (details below on what part of the script does this)

483

Breakdown of the information shown to players in the store.

From Image AboveDescription
NameThis is the Name variable
Time to BuildThe TimeToBuild variable (in minutes). How long the structure will take to to be created.
PriceThe Price variable.
CurrencyThe Currency variable (Either Gold, Mana, or Gems) You could change this to whatever currency you will have in your game and also add additional currencies.
DescriptionShows the Description text variable.
Xp AwardExperience obtained per build
HPLife points of structure
Up Ratio
Id of big iconMain Icon of store
Id of small iconsmall icon of info
Id of icon on buy buttonicon of buy button
Id of black big IconMain Icon of store ( no available item version )
Max Count of this itemMax. amount allowed per current
IdItem id
LevelLevel of item
AssetGame unit prefab
Damage PointsDamage points
Fire RateFire Rate

Wall Element WallsCategory.asset Example

Here's an example of one of the wall elements used by the centralized creator script Scripts/Creators/BaseCreator.cs

705

A closer look at WallsCategory SO (ScriptableObject) file

If you look closely in the above SO, you could use whatever currency you want in your game, in the demo we have two placeholders called Gold and Mana. (Plus one rare currency called Crystal Gems which you could use to upsell for special wall types)

Further above in the SO you'll see the TimeToBuild (in minutes) has been set to 0 in the City Building Kit demo for all wall segments.

369

This follows popular free-to-play strategy gameplay models by allowing the player to construct large wall segments in a relatively short period of time with the only pre-req being each wall segment is expensive.

The built is instantaneous, but the player still needs an available Dobbit to make the construction as the walls still need to pass the 3 tests of VerifyConditions() in BaseCreator.cs. You could skip this last test by adjusting the last test to ignore wall elements.

Also the Life value is not used in the earlier City Building Kit 6.0 version. Automated pathfinding for units in that version does not actively attack walls but treats them as an obstacle to avoid. Because of this, do not surround your buildings completely without an entrance. Later releases of the City Building Kit use the Life element in your XML file to actively attack wall segments.

BaseCreator.cs - Where the SO is loaded into

In Scripts/Creators/BaseCreator.cs the wall data from your SO file (seen above) is loaded using a common system for all the structures like resource buildings, defense buildings, walls, decorations, and other buildings. Here's an excerpt from BaseCreator.cs of the SO data load for walls:

protected void GetWallsXML()//reads buildings XML
	{
		List<WallCategoryLevels> wallCategoryLevels = ShopData.Instance.WallsCategoryData.category;
		List<WallsCategory> wallCategoryData = wallCategoryLevels.SelectMany(level => level.levels).Where(c => c.level == _structuressWithLevel).ToList();
		
		
		foreach (WallsCategory structureItem in wallCategoryData)
		{
			dictionary = new Dictionary<string, string>();
			dictionary.Add("Name", structureItem.GetName()); // put this in the dictionary.
			dictionary.Add("Currency", structureItem.Currency.ToString());
			dictionary.Add("Price", structureItem.Price.ToString());
			dictionary.Add("TimeToBuild", structureItem.TimeToBuild.ToString());
			dictionary.Add("HP", structureItem.HP.ToString());
			dictionary.Add("XpAward", structureItem.XpAward.ToString());
			dictionary.Add("UpRatio", structureItem.UpRatio.ToString()); 
			structures.Add(dictionary);
		}
	}

When the data is loaded, the store panels are updated with the appropriate information.

Construction limits with XP levels

Read the Gameplay > XP and Levels documentation page for more details. Game players could have a maximum of two gold mines at level one until the player reaches level two, in which the maximum increases to five (or whatever value you choose -- read XP and Levels documentation for more details)

158

1/2 gold mines built. Maximum not reached.

161

2/2 maximum reached, can't build more

This is relevant to mention now because the menu items are greyed out for buildings that the player can no longer build until they increase their base level through other ways of gaining XP. The function UpdateLabelStats() DEPRECATED FUNCTION / UNUSED

What happens when the buy button is clicked for a building?

When the player clicks one of the buttons to build a building in the store, first one of the building functions is triggered. ( Look at Shop Menu > Resource Generators: What happens when the buy button is clicked for a building? section ), since it is exactly the same process. )

VerifyConditions()

Can the player build this structure? In Scripts/Creators/BaseCreator.cs the VerifyConditions() script takes over once the store button has been pushed to determine if the following conditions are met and canBuild is set to true. ( Look at Shop Menu > Resource Generators: VerifyConditions() section, since it is exactly the same process. )