2.2 Components
Components define functionality and behaviour for entities
Component
Implemented in Version a2.0
class Component { }
Component is the base class for all components.
Component implements following methods:
| Method | Description |
|---|---|
| void OnUpdate() | Gets called every tick by the main method. Avoid using OnUpdate where possible. (Client-side only) |
| void OnInput(int input) | Gets called for every key that the player is pressing in a tick. (Client-side only) |
| void OnServerUpdate() | Gets called every tick by the main method. (Server-side only) |
| bool HasUpdate() | Must be set to return true if OnUpdate is implemented. |
| bool HasInput() | Must be set to return true if OnInput is implemented. |
| bool HasServerUpdate() | Must be set to return true if OnServerUpdate is implemented. |
InventoryComponent
Implemented in Version a2.0
class InventoryComponent : public Component { }
The InventoryComponent serves as a container to store items/resources
InventoryComponent additionally implements following methods:
| Method | Description |
|---|---|
| InventoryComponent(int size) | Creates a new InventoryComponent with the maximum amount of items passed by the parameter. |
| ~InventoryComponent() | Deletes the InventoryComponent. |
| void SetIndex(int index) | Set which slot is selected to be held. Zero-indexed. |
| int GetIndex(int index) | Gets the current selected slot. Zero-indexed. |
| Item* GetItem(int index) | Gets item from specified slot. |
| void SetItem(Item* item) | Sets and overrides the given slot. |
| int GetSize() | Gets maximum amount of items. |
InventoryComponent implements following private properties:
| Property | Description |
|---|---|
| Item* items | Item Container |
| int index | Selected slot. |
| int size | Maximum amount of items. |
PlayerItemComponent
Implemented in Version a2.0
class PlayerItemComponent : public Component { }
The PlayerItemComponent handles item interaction such as usage/attacking with an item.
PlayerItemComponent additionally implements/overrides following methods:
| Method | Description |
|---|---|
| void OnInput(int input) | Handles key presses for item usage. |
| bool HasInput() | Returns true. |
PlayerStatsComponent
Implemented in Version a2.0
class PlayerServer : public Entity { }
The PlayerServer entity functions in the same manner as the player client but removes visual rendering elements..
PlayerServer additionally implements following methods:
| Method | Description |
|---|---|
| PlayerStatsComponent(InventoryComponent* i) | Instantiates a PlayerStatsComponent, passing a pointer to the Player's InventoryComponent |
| ~PlayerStatsComponent() | Deletes the PlayerStatsComponent. |
| void OnUpdate() | Handles Regeneration of Player Stats. |
| bool HasUpdate() | Returns true. |
| void OnServerUpdate() | Handles Regeneration of Player Stats. |
| bool HasServerUpdate() | Returns true. |
| int GetStat(int stat) | Gets a stat. Use Stat enum to address the correct stat. |
| void SetStat(int stat, int value) | Sets a stat to the given value. Use Stat enum to address the correct stat. |
| void TakeDamage(int type, int amount) | Makes the player take a specified amount of damage with the supplied damageType (enum). |
| void Die(int type) | Kills player with supplied damageType (enum). Automatically called by TakeDamage on health <= 0 |
| void SetEffects(int size) | Creates a new effect array with the given size. |
| void AddEffect(int type, int duration, int strength) | Adds a new effect with the given effect type (enum), duration in seconds and strength of the effect. |
| bool GetEffect(int type, int* duration, int* strength) | Gets duration and strength of the effect specified by the type. Returns false if effect is not present and true if effect exists on the player. |
| void RemoveEffect(int type) | Removes specified effect. |
PlayerStatsComponent implements following private properties:
| Property | Description |
|---|---|
| int* effectTypes | Pointer to array containing effect types |
| int* effectDurations | Pointer to array containing effect durations |
| int* effectStrength | Pointer to array containing effect strength |
| int* stats | Pointer to array containing player stats |
| int effectAmmount | Stores effectTypes array size. |
| InventoryComponent* inventory | Pointer to player's inventory. |