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.
Battle defense
During battle, defensive weapon buildings are the only ones which can actively protect your village and destroy enemy troops.
Shop Menu
Here's a screenshot of the shop menu for the defensive weapon structures.
There are six examples included in the game, however the three main examples we recommend learning from are the Cannon, Archer Tower, and Catapult.
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.
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.
From Image Above | Description |
---|---|
Name | This is the Name variable |
Time to Build | The TimeToBuild variable (in minutes). How long the structure will take to to be created. |
Price | The Price variable. |
Currency | The 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. |
Description | Shows the Description text variable. |
Xp Award | Experience obtained per build |
HP | Life points of structure |
Up Ratio | |
Id of big icon | Main Icon of store |
Id of small icon | small icon of info |
Id of icon on buy button | icon of buy button |
Id of black big Icon | Main Icon of store ( no available item version ) |
Max Count of this item | Max. amount allowed per current |
Id | Item id |
Level | Level of item |
Asset | Game unit prefab |
Damage Points | Damage points |
Fire Rate | Fire Rate |
Damage Type | Splash / Normal |
Target Type | None / Ground / Air / Dual |
Preferred Target | Any |
Damage Bonus | bonus 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.
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)
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.
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
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)
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. )
Updated less than a minute ago