Alacrity Buffs
In game development and designing, creating a dynamic and engaging gameplay often involves introducing various effects and modifications to game entities. Buffs are a fundamental concept in achieving this, allowing you to apply temporary or permanent changes to an entity's attributes, properties, or behavior. Alacrity provides a robust framework for implementing buffs seamlessly within your game.
Understanding Buffs
Buffs are essentially effects that alter attributes or other characteristics of game entities. These effects can be positive, granting benefits like increased strength or enhanced speed, or negative, imposing penalties such as reduced health or decreased accuracy. The beauty of buffs lies in their dynamic nature -they can be temporary, lasting for a set duration, or permanent until explicitly removed-.
In Alacrity, buffs are a key mechanism for introducing diversity and complexity to your game's mechanics. Whether you're designing an RPG, strategy game, or any genre when entities evolve over time, buffs play a pivotal role in shaping gameplay experiences.
Buffs in Alacrity
Alacrity's approach to buffs simplifies the implementation of these effects while providing powerful customization options. Buffs can be applied to entities using various conditions, allowing for precise control over when and how they affect gameplay. From enhancing a character's abilities during combat to applying environmental effects, buffs can be tailored to meet your game's unique requirements.
Alacrity ensures that buffs seamlessly integrate with entities, attributes and other components of your game. Buffs can modify specific attributes or trigger complex behaviors based on the defined conditions and rules. This makes possible to create intricate interaction and mechanics, all managed through Alacrity's intuitive APIs.
Buff Creation and Application
In Alacrity, creating and applying buffs is a versatile process that can be approached from different angles. Buffs can be defined programmatically using the Rust or Lua APIs, offering flexibility and control. Alternatively, buffs can be specified declaratively within Alacrity Specs using Lua syntax, streamlining the design process.
This chapter will explore both avenues of buff creation, guiding you through practical examples and clear explanations. By the end, you'll have a solid understanding of how to implement buffs effectively within the Alacrity framework.
Whether you're aiming to create a complex spell system, introduce temporary power-ups, or add strategic debuffs, Alacrity's buff system empowers you to elevate your game's mechanics and offer players an engaging and immersive experience.
Let's dive into the world of buffs in Alacrity, discovering how these dynamic effects can transform your game entities and contribute to the richness of your gameplay.
Anatomy of a Buff
Buffs are composed of several fields that define their capabilities and behavior with in the simulation.
| Field | Type | Mandatory? |
|---|---|---|
| id | UUID | yes |
| blueprint | String | no |
| name | String | yes |
| description | String | yes |
| effect_id | u32 | yes |
| modifiers | HashMap<Uuid, Modifier> | yes |
| conditions | Vec<Condition> | no |
| effect_stack_policy | EffectStackPolicy | no |
| effect_stack_limit | u32 | no |
| expiration | Expiration | no |
| activation_time | Option<Instant> | no |
| stack_policy | StackPolicy | no |
| stack_limit | usize | yes |
| current_stack | usize | no |
| propagation_map | PropagationMap | no |
| version | String | no |
We will review all of these fields in detail below
ID
Each buff must have an unique ID that identifies it within the game world. IDs are UUIDs and they must be guaranteed to be unique. Library users are responsible from creating and providing these unique IDs, this is normally done while describing the buffs in the game specs.
💡 Tip
For additional guidance about how to properly generate these IDs please, refer to the Generating UUIDs guide.
Blueprint
When a buff is instantiated from a template or blueprint, this field will contain the ID that refers to said template or blueprint.
Name
This is a human-readable name for the buff, which can be used for display purposes, debugging, and other similar actions.
Description
A brief description of the buff, which can be used for documentation, tooltips and other similar purposes.
Effect ID
The buff's effect ID is used to define the effect that this buff will apply to the entity that it is affected by it.
The effect_id is used to avoid the stack up of different buffs that could apply
a similar kind of effect to the entity (like limiting the damage multiplier to
enemies of an specific kind). This behavior can still be controlled by the
effect_stack_policy field that can be set to different values that provide
different behaviors.
Modifiers
The modifiers that this buff is holding and that will modify the entity's attributes when the buff its applied to them.
ℹ️ Info
Modifiers are reviewed extensively in their own modifiers section later in the book
Conditions
A set of conditions that will be evaluated in order to determine if the buff should be applied or not to an entity based in a conditional expression written in Lua syntax using entity scopes.
ℹ️ Info
Conditions are reviewed extensively in their own conditions section later in the book
Effect Stack Policy
Determines how the buff will stack with other buffs that define the same
effect_id that this buff and that are applied simultaneously to the entity.
The available policies are defined in the table below
| Policy | Description |
|---|---|
| NoEffectStackable | The buff will not stack with other buffs of the same effect_id |
| LastReplace | This buff will replace the last buff applied to the entity that has the same effect_id |
| HigherValueReplace | This buff will replace other buffs applied to the entity that have the same effect_id and their values are lower than the value of this buff |
| LowerValueReplace | This buff will replace other buffs applied to the entity that have the same effect_id and their values are higher than the value of this buff |
| FullStack | This buff will stack with other buffs applied to the entity that have the same effect_id until the maximum stack value is reached |
Effect Stack Limit
Defines how many times effects can be stacked up in case that the buff features
a FullStack effect stack policy. This number limits how many buffs of the same
effect_id can be stacked up into each other in the same entity.
Expiration
Defines the rules about this buff effects expiration times.
An example Expiration value could be
#![allow(unused)] fn main() { use alacrity_lib::prelude::*; // instantiate a new Expiration value that will expire in 30 minutes let exp = Expiration::new(1800); }
Activation Time
Registers the last time that the buff was activated in the entity.
Stack Policy
Defines how this buff will stack with itself if it gets re-applied to the entity after having being activated already.
The available policies are defined in the table below
| Policy | Description |
|---|---|
| NoStack | The buff or modifier can not be stacked at all |
| RefreshDuration | Stacking this buff or modifier will refresh its duration (Expiration) |
| StackDuration | Stacking this buff or modifier will stack its duration but not its value (add time to its duration) |
| StackValue | Stacking this buff or modifier will stack its value but not its duration (this is the default behavior) |
| StackValueAndRefreshDuration | Stacking this buff or modifier will stack its value and will refresh its duration |
| StackValueAndDuration | Stacking this buff or modifier will stack both its value and its duration |
Stack Limit
Defines the maximum number of times that this buff can be stacked up in case
that the buff features a FullStack stack policy or if the ame buff is
re-applied to the same entity. If the stack_limit is set to zero (that
happens to be its default value), then this buff will stack indefinitely.
Current Stack
Keeps track of the current stack count of the buff.
Propagation Map
The propagation map helps the buff to define propagation rules that must be followed for its effects to propagate to other entities.
📝 Note
Buff propagation is a very advanced topic that requires of library users to implement their own networking layer or entity-to-entity communication if needed. They are being review in more detail in their own buff propagations section.
Version
The buff's version. It can be used to track buff versions or to update their data when a version change is detected. Each buff blueprint has to be in an specific version (0.0.1 by default).