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.
-
Nested Class Summary
Nested Classes -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCombatStatsComponent
(int health, int hunger, int strength, int defense, int speed, int experience, boolean isPlayer, boolean isBoss, int level) CombatStatsComponent
(int health, int hunger, int strength, int defense, int speed, int experience, boolean isPlayer, boolean isBoss, int level, int curHealth, int curHunger) Constructor for CombatStatsComponent, initializing all combat-related attributes for an entity. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDefense
(int defense) Adds a specified amount to the entity's defense.void
addExperience
(int experience) Adds a specified amount to the entity's experience.void
addHealth
(int change) Adds a specified amount to the entity's health.void
addHunger
(int change) Adds a specified amount to the entity's hunger.void
addLevel
(int level) Add int to entity's levelvoid
addMaxHealth
(int health) void
addSpeed
(int speed) Adds a specified amount to the entity's speed.void
Adds a status effect to the entity.void
addStrength
(int strength) Adds a specified amount to the entity's strength.int
Returns the entity's defense.int
Returns the entity's experience.int
Returns the entity's health.int
Returns the entity's hunger.int
getLevel()
Returns the entity's level.int
Returns the entity's maximum experience.int
Returns the entity's maximum health.int
Returns the entity's maximum hunger.int
getSpeed()
Returns the entity's speed.int
Gets the duration of a StatusEffect typeint
Returns the entity's strength.boolean
Checks if the entity has any applied status effects.boolean
Checks if the entity has a specific status effect.void
hit
(CombatStatsComponent attacker) Simulates the entity being hit by an attacker.boolean
isBoss()
Returns true if the entity's is a boss, otherwise false.boolean
isDead()
Returns true if the entity has 0 health, otherwise false.boolean
isPlayer()
Returns true if the entity is a player, otherwise false.void
Removes a status effect from the entity.void
setDefense
(int defense) Sets the entity's defense.void
setExperience
(int experience) Sets the entity's experience.void
setHealth
(int health) Sets the entity's health.void
setHunger
(int hunger) Sets the entity's hunger.void
setLevel
(int level) Sets the entity's level.void
setSpeed
(int speed) Sets the entity's speed.void
setStrength
(int strength) Sets the entity's strength.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
CombatStatsComponent
public CombatStatsComponent(int health, int hunger, int strength, int defense, int speed, int experience, boolean isPlayer, boolean isBoss, int level, int curHealth, int curHunger) Constructor for CombatStatsComponent, initializing all combat-related attributes for an entity.- Parameters:
health
- Initial health valuehunger
- Initial hunger valuestrength
- Initial strength valuedefense
- Initial defense valuespeed
- Initial speed valueexperience
- Initial experience valueisPlayer
- Boolean indicating if this entity is the player
-
CombatStatsComponent
public CombatStatsComponent(int health, int hunger, int strength, int defense, int speed, int experience, boolean isPlayer, boolean isBoss, int level)
-
-
Method Details
-
isPlayer
public boolean isPlayer()Returns true if the entity is a player, otherwise false.- Returns:
- is entity player
-
isDead
public boolean isDead()Returns true if the entity has 0 health, otherwise false.- Returns:
- is entity dead
-
isBoss
public boolean isBoss()Returns true if the entity's is a boss, otherwise false.- Returns:
- is player dead
-
getHealth
public int getHealth()Returns the entity's health.- Returns:
- entity's health
-
setHealth
public void setHealth(int health) Sets the entity's health. Health has a minimum bound of 0 and cannot exceed maxHealth.- Parameters:
health
- health value to set
-
addHealth
public void addHealth(int change) Adds a specified amount to the entity's health. The amount can be negative to reduce health.- Parameters:
change
- the health to add (positive or negative)
-
getHunger
public int getHunger()Returns the entity's hunger.- Returns:
- entity's hunger
-
setHunger
public void setHunger(int hunger) Sets the entity's hunger. Hunger has a minimum bound of 0 and cannot exceed maxHunger.- Parameters:
hunger
- hunger value to set
-
addHunger
public void addHunger(int change) Adds a specified amount to the entity's hunger. The amount can be negative to reduce hunger.- Parameters:
change
- hunger to add (positive or negative)
-
getStrength
public int getStrength()Returns the entity's strength.- Returns:
- entity's strength
-
setStrength
public void setStrength(int strength) Sets the entity's strength. Strength has a minimum bound of 0.- Parameters:
strength
- Strength value to set
-
addStrength
public void addStrength(int strength) Adds a specified amount to the entity's strength. The amount can be negative to reduce strength.- Parameters:
strength
- strength to add (positive or negative)
-
getDefense
public int getDefense()Returns the entity's defense.- Returns:
- entity's defense
-
setDefense
public void setDefense(int defense) Sets the entity's defense. Defense has a minimum bound of 0.- Parameters:
defense
- defense value to set
-
addDefense
public void addDefense(int defense) Adds a specified amount to the entity's defense. The amount can be negative to reduce defense.- Parameters:
defense
- defense to add (positive or negative)
-
getSpeed
public int getSpeed()Returns the entity's speed.- Returns:
- entity's speed
-
setSpeed
public void setSpeed(int speed) Sets the entity's speed. Speed has a minimum bound of 0.- Parameters:
speed
- speed value to set
-
addSpeed
public void addSpeed(int speed) Adds a specified amount to the entity's speed. The amount can be negative to reduce speed.- Parameters:
speed
- speed to add (positive or negative)
-
getExperience
public int getExperience()Returns the entity's experience.- Returns:
- entity's experience
-
setExperience
public void setExperience(int experience) Sets the entity's experience. Experience has a minimum bound of 0. If the entity is a player, level up logic is applied once experience exceeds the maximum threshold.- Parameters:
experience
- experience value to set
-
addExperience
public void addExperience(int experience) Adds a specified amount to the entity's experience. The amount can be negative to reduce experience.- Parameters:
experience
- experience to add (positive or negative)
-
hit
Simulates the entity being hit by an attacker. The target's health is reduced based on the attacker's strength.- Parameters:
attacker
- CombatStatsComponent of the attacking entity
-
getMaxHealth
public int getMaxHealth()Returns the entity's maximum health.- Returns:
- entity's max health
-
addMaxHealth
public void addMaxHealth(int health) -
getMaxHunger
public int getMaxHunger()Returns the entity's maximum hunger.- Returns:
- entity's max hunger
-
getMaxExperience
public int getMaxExperience()Returns the entity's maximum experience.- Returns:
- entity's max experience
-
getLevel
public int getLevel()Returns the entity's level.- Returns:
- entity's level
-
setLevel
public void setLevel(int level) Sets the entity's level.- Parameters:
level
- sets entity's level
-
addLevel
public void addLevel(int level) Add int to entity's level- Parameters:
level
- adds int to the current level
-
addStatusEffect
Adds a status effect to the entity. Status effects can impact combat in different ways. For example, 'CONFUSED' may cause an entity to randomly attack, while 'BLEEDING' may cause gradual health loss over time.- Parameters:
effect
- The status effect to add
-
removeStatusEffect
Removes a status effect from the entity. This can be used to stop the negative impact of certain effects, such as stopping health loss from 'BLEEDING'.- Parameters:
effect
- The status effect to remove
-
hasStatusEffect
Checks if the entity has a specific status effect.- Parameters:
effect
- The status effect to check- Returns:
- true if the entity has the status effect, false otherwise
-
hasStatusEffect
public boolean hasStatusEffect()Checks if the entity has any applied status effects.- Returns:
- true if the entity has a status effect, false otherwise
-
getStatusEffectDuration
Gets the duration of a StatusEffect type- Parameters:
effect
- The status effect to check- Returns:
- the number of rounds a StatusEffect will be applied
-