In this post I want to share how we approached attributes early on in a “Puzzle and Dragons” clone.

Let’s start with a representation of a character:

Screen Shot 2015-07-14 at 7.10.27 AM


This JSON is part of a larger RPG database JSON file that is loaded at runtime.  When a character is spawned, either in menus or dungeon, the common PAD formulas are used to determine the current character stats based on the dungeon level (for enemies) or the current experience from the save file (for human player).


Now lets take a look at the character class.
  The above code introduces the RpgAttribute class.
The RpgAttribute class is used both by character and player.  Player basically holds a list of characters.  This is useful for the human player, where the health is a sum of all of the characters health values.  In PAD, human characters do not die individually, it is the player that dies when the cumulative health reaches zero.

Attribute usage is pretty simple.  To retrieve the current value you would call Health.CurrentValue, to change the health value you would call Health.Plus(x) or Health.Minus(x).  The onChange callback is handy in this situation; when you alter the health value, the onChange callback is invoked where you can update the visual representation of health, such as the health bar.  Similarly, the onZero callback of the human player’s health attribute signals defeat.

Screen Shot 2015-07-14 at 7.38.46 AM


And here is how the human player’s health value gets affected.

Screen Shot 2015-07-14 at 7.44.00 AM


The enemy is treated a little differently.  Instead of manipulating the enemy player’s health, we manipulate the enemy character’s health directly.  That is because enemy characters can be killed one by one, unlike human characters.

Screen Shot 2015-07-14 at 7.47.34 AM


In the next post, we will take a look at special abilities.

Related Articles

WAK: MQTT for IoT – Brief Documentation

Read about MQTT here. Setting up your scene: 1. Create a GameObject. 2. Add the following scripts: ConnectionBroker, DesktopClient, and…


Here are answers to questions a potential user asked recently. Previous: OAuth2 in Unity

OAuth Overview in Unity

Below is one of the OAuth flows available in the WAK OAuth Token Interceptor asset. Next: WAK FAQ 1 Previous: Switching WAK…