Skip to content

Healing Tool

Rowan Gray edited this page Oct 15, 2023 · 8 revisions

Introduction

The Healing Tool is a component of the game that allows players to interact with entities and heal them. To heal any entity such as turret or wall after damage, we need to press B to select the hammer, and then press key 1 thru 0 depending on where it is positioned in the hotbar. We click on the heal icon to activate the healing component and then click on either wall or turret to heal the health. The heal tool uses the cost of the component and the percentage of health that needs healing to calculate the total cost of healing a structure. This makes it equivalent to picking up and replacing the item, however it is more convenient. The formula is as follows.

healCost = Math.ceil(structureCost * (health - maxHealth)/maxHealth);

This is repeated for each resource that the structure requires.

Class

The Healing Tool is a subclass of the Tool class and is responsible for healing entities in the game. Below, we'll dive into the details of the code.

The HealTool extends the Tool class allowing it to be interacted with through the build hammer in game. It should not be created manually in the game. It is automatically created in the StructurePickerComponent and its config can be modified in the structure_tools.json file. The cost defined in the config file is not used by the HealTool since the cost is instead calculated depending on the structure interacted with.

Purpose

The purpose of adding healing feature in the game is to basically enable players to strengthen their defence during gameplay. Be it preventing the walls from collapsing or the turrets from getting damaged, the healing tool handles it all.

Testing

The healing feature was tested by placing the gates and turrets near enemies and luring them to attack those. Since enemies' attack reduced the health of both of these entities, we were able to heal these entities to maximum by clicking 3 and T-Key respectively, then clicking on the heal icon, and finally clicking on the entity that we wanted to heal. We had sufficient resources while doing so.

A test class was also created which tests both the canInteract and peformInteraction methods extensively.

Clone this wiki locally