Attack Effects - UQcsse3200/2024-studio-1 GitHub Wiki
Overview
Animal attacks can apply special effects like knockback, poison, or stun. These effects add depth and complexity to combat, forcing players to adjust their strategies. To understand the configuration of effects, got to the NPC Configuration page.
Types of Effects
Each effect type has its own implementation, but all share a common Effect
interface, ensuring consistency and extensibility across different effects.
Knockback
Forces the player back, temporarily stunning them.
Configurations:
force
: Float for knockback force applied.
Poison
Gradually reduces the player's health over time.
Configurations:
duration
: Float for the length of poison effect in seconds.damagePerSecond
: Integer for damage per second dealt by the poison.
Stun
Freezes the player in place for a short duration.
Configurations:
duration
: Float for the length of stun effect in seconds.
Effect Application
Effects are instantiated by the EffectFactory
based on configurations defined in the NPCs.json
file. Once created, they are managed by the EffectComponent
attached to the target entity, while it is visualised by an EffectEntity
layer on top of the target entity.
Workflow:
- Attack Execution: When an animal performs an attack, it may include one or more effects in its configuration.
- Effect Creation: The
EffectFactory
reads the effect configurations and creates correspondingEffect
instances. - Applying Effects: The
EffectComponent
on the target entity adds these effects, triggering their application. - Visual Representation: For effects with visuals (e.g., stun, poison),
EffectEntity
instances are created to display animations above the affected entity. - Effect Management: The
EffectComponent
updates each active effect every game tick, checking for expiration and handling their removal, while also listening for a disposal callback fromEffectEntity
after the effect duration has passed, in order to dispose of the entity if necessary.
Example Configuration
Below is the an example configuration for bear, which uses a combination of knockback and stun effects given as a list to the attack configuration's 'effects' variable:
"melee": {
"range": 1.7,
"rate": 1,
"effects": [
{
"type": "KNOCKBACK",
"force": 3
},
{
"type": "STUN",
"duration": 1
}
]
}