Defense Weapons Menu

👍

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 defense weapons?

When playing battle strategy games you'll always be able to build some sort of structure that defends your village or base from attacking players. In this case we've added a category in the store for you to place these defensive buildings.

The demo includes a few of these general buildings like the Archer tower or the Cannon. During gameplay they don't have much purpose but when you're attacking other players or other players are attacking your base - they play a huge role in defending your resources from being stolen.

686

Click to view larger.

Battle defense

During battle, defensive weapon buildings are the only ones which can actively protect your village and destroy enemy troops.

589

Battle defense preview.

Shop Menu

Here's a screenshot of the shop menu for the defensive weapon structures.

636

Click to view larger.

There are six examples included in the game, however the three main examples we recommend learning from are the Cannon, Archer Tower, and Catapult.

748

Click to view larger.

Where to find the defense 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 UI

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

Although the screenshot below is for another building type in the store, the details apply to all buildings including defensive weapons since the store uses centralized BaseCreator.cs script.

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
Damage TypeSplash / Normal
Target TypeNone / Ground / Air / Dual
Preferred TargetAny
Damage Bonusbonus points

WeaponCategory.asset Example

Here's an example of the simple cannon weapon in the ScriptableObject. The Scripts/Creators/BaseCreator.cs will use these settings.

532

A closer look at WeaponCategory 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)

372

In addition, you'll notice that like other buildings it has an HP value for battle and a time to build (measured in minutes) for construction plus a 100 XP award if the player builds this structure.

293

Additional expansions

There are other SO expansions we've prepared for developers but as of version 6.0 these are read by Scripts/Creators/BaseCreator.cs but are not scripted for use yet in either the Scripts/Weapons TurrentControllerBase.cs or WeaponAnimationController.cs

363

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 GetWeaponsXML()//reads buildings XML
	{
		List<WeaponCategoryLevels> weaponCategoryLevels = ShopData.Instance.WeaponCategoryData.category;
		List<WeaponCategory> weaponCategoryData = weaponCategoryLevels.SelectMany(level => level.levels).Where(c => c.level == _structuressWithLevel).ToList();
		
		
		foreach (WeaponCategory structureItem in weaponCategoryData)
		{
			dictionary = new Dictionary<string, string>();
			dictionary.Add("Name", structureItem.GetName()); // put this in the dictionary.
			dictionary.Add("Description", structureItem.Description); // 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("Range", structureItem.range.ToString());
			dictionary.Add("FireRate", structureItem.fireRate.ToString());
			dictionary.Add("DamageType", structureItem.damageType.ToString());
			dictionary.Add("TargetType", structureItem.targetType.ToString());
			dictionary.Add("PreferredTarget", structureItem.preferredTarget.ToString());
			dictionary.Add("DamageBonus", structureItem.damageBonus.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 store item?

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.

VerifyConditions() Test #1 - Maximum structures reached?

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. )

141

0 of 1 maximum structures built for the player's current level.