Player Stats and Levelling - UQcsse3200/2024-studio-2 GitHub Wiki

CombatStatsComponent

The CombatStatsComponent class is part of the com.csse3200.game.components package and is designed to manage various combat-related attributes for game entities, such as health, strength, and speed. This component is especially useful for entities that engage in combat, including players, bosses, and other characters.

Class Overview

The CombatStatsComponent class is responsible for:

Managing combat stats such as health, strength, defense, and speed.

Handling combat interactions, such as reducing health upon being attacked.

Managing player level, experience, and hunger.

Attributes

Basic Stats

maxHealth: The maximum health of the entity. health: The current health of the entity.

hunger: The current hunger level of the entity, up to a maximum of maxHunger.

strength: The strength attribute, influencing attack damage.

defense: The defense attribute, reducing damage taken.

speed: The speed attribute, influencing movement and potentially dodge rate.

Leveling and Experience

experience: Current experience points, which can increase with combat and other actions.

level: Current level of the entity, capped at maxLevel.

maxExperience: Experience points required to level up.

maxLevel: Maximum level achievable, defaulted to 10 for players. Entity Type Flags

isPlayer: A boolean indicating if the entity is the player.

isBoss: A boolean indicating if the entity is a boss.

Methods

Health Management

getHealth(): Returns current health.

setHealth(int health): Sets the health, capping it at maxHealth and not allowing negative values.

addHealth(int change): Increases or decreases health by a specified amount. Hunger Management

getHunger(): Returns current hunger.

setHunger(int hunger): Sets hunger, capping at maxHunger.

addHunger(int change): Adjusts hunger by a specified amount.

Level and Experience

getExperience(): Returns current experience points.

setExperience(int experience): Sets experience, with player-specific leveling logic.

addExperience(int experience): Adds or removes experience points, with leveling logic for players.

getLevel(): Returns current level.

setLevel(int level): Sets the entity's level, capped at maxLevel.

addLevel(int level): Increases or decreases level.

Health and Level Reduction

If the player's health reaches 0, the following actions occur:

  • The player's level is halved (rounded ip if necessary).
  • All player stats (such as strength, defense, and speed) are reduced to fit the new level, meaning they are recalculated based on the lower level to ensure balance in gameplay.

Example Scenario

If the player is at level 10 and their health drops to 0:

  1. Their level will decrease to 5.
  2. Stats like strength and defense will be updated according to the stats appropriate for level 5, reducing their effectiveness in combat until they regain their previous level.