Package com.csse3200.game.components
Class CombatStatsComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.CombatStatsComponent
Component used to store information related to combat such as health, attack, etc. Any entities
which engage in combat should have an instance of this class registered. This class can be
extended for more specific combat needs.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCombatStatsComponent
(int health, int baseAttack, int attackMultiplier, boolean isImmune) Initializes a CombatStatsComponent with specified attributes.CombatStatsComponent
(int health, int baseAttack, int attackMultiplier, boolean isImmune, int lives) Initializes a CombatStatsComponent for a player with specified attributes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHealth
(int health) Adds to the player's health.void
addLife()
Adds one life to player lives.void
Inverts the entity's current immunity status.int
Returns the entity's total attack damage, which is the base attack damage multiplied by the attack multiplier.int
Returns the entity's attack multiplier.int
Returns the entity's base attack damage.int
Returns the entity's current health.Returns the entity's immunity status.int
getLives()
returns number of lives player has left.int
Returns the entity's maximum health.void
hit
(CombatStatsComponent attacker) Inflicts damage on the entity by reducing its health.isDead()
Returns true if the entity's health is 0 or less, indicating that it's dead; otherwise, returns false.void
Subtracts one life from player lives.void
setAttackMultiplier
(int attackMultiplier) Sets the entity's attack multiplier.void
setBaseAttack
(int attack) Sets the entity's base attack damage.void
setHealth
(int health) Sets the entity's health.void
setHealth
(int newHealth, boolean isHKeyPressed) sets the entity's health to maximum if H-Key is pressed on the keyboard.void
setImmunity
(boolean isImmune) Sets the entity's immunity status.void
setLives
(int lives) Sets the number of lives player has left.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
isImmune
-
-
Constructor Details
-
CombatStatsComponent
public CombatStatsComponent(int health, int baseAttack, int attackMultiplier, boolean isImmune) Initializes a CombatStatsComponent with specified attributes.- Parameters:
health
- The initial health of the entity.baseAttack
- The base attack damage of the entity.attackMultiplier
- The attack multiplier of the entity.isImmune
- A flag indicating whether the entity is immune to attacks.
-
CombatStatsComponent
public CombatStatsComponent(int health, int baseAttack, int attackMultiplier, boolean isImmune, int lives) Initializes a CombatStatsComponent for a player with specified attributes.- Parameters:
health
- The initial health of the entity.baseAttack
- The base attack damage of the entity.attackMultiplier
- The attack multiplier of the entity.isImmune
- A flag indicating whether the entity is immune to attacks.lives
- Number of lives the player has remaining.
-
-
Method Details
-
isDead
Returns true if the entity's health is 0 or less, indicating that it's dead; otherwise, returns false.- Returns:
- true if the entity is dead, false otherwise.
-
getHealth
public int getHealth()Returns the entity's current health.- Returns:
- The entity's health.
-
getMaxHealth
public int getMaxHealth()Returns the entity's maximum health.- Returns:
- The entity's maximum health.
-
setHealth
public void setHealth(int health) Sets the entity's health. Health cannot be less than 0. If health reaches 0, a death event is triggered after a delay.- Parameters:
health
- The new health value.
-
setHealth
public void setHealth(int newHealth, boolean isHKeyPressed) sets the entity's health to maximum if H-Key is pressed on the keyboard.- Parameters:
newHealth
- the new value of the users healthisHKeyPressed
- whether the H key is pressed
-
addHealth
public void addHealth(int health) Adds to the player's health. The amount added can be negative.- Parameters:
health
- The health to add.
-
getBaseAttack
public int getBaseAttack()Returns the entity's base attack damage.- Returns:
- The entity's base attack damage.
-
setBaseAttack
public void setBaseAttack(int attack) Sets the entity's base attack damage. Attack damage cannot be less than 0.- Parameters:
attack
- The new base attack damage value.
-
getAttackMultiplier
public int getAttackMultiplier()Returns the entity's attack multiplier.- Returns:
- The entity's attack multiplier.
-
setAttackMultiplier
public void setAttackMultiplier(int attackMultiplier) Sets the entity's attack multiplier. Attack multiplier cannot be less than 0.- Parameters:
attackMultiplier
- The new attack multiplier value.
-
getImmunity
Returns the entity's immunity status.- Returns:
- true if the entity is immune to attacks, false otherwise.
-
setImmunity
public void setImmunity(boolean isImmune) Sets the entity's immunity status.- Parameters:
isImmune
- true to make the entity immune to attacks, false otherwise.
-
changeImmunityStatus
public void changeImmunityStatus()Inverts the entity's current immunity status. -
getAttack
public int getAttack()Returns the entity's total attack damage, which is the base attack damage multiplied by the attack multiplier.- Returns:
- The entity's total attack damage.
-
setLives
public void setLives(int lives) Sets the number of lives player has left.- Parameters:
lives
- the number of lives to set
-
minusLife
public void minusLife()Subtracts one life from player lives. -
addLife
public void addLife()Adds one life to player lives. -
getLives
public int getLives()returns number of lives player has left.- Returns:
- number of lives
-
hit
Inflicts damage on the entity by reducing its health. If the entity is immune, no damage is applied.- Parameters:
attacker
- The entity causing the damage.
-