@@ -26,10 +26,17 @@ extends AttributeBuff
2626
2727@export var damage: float = 1.0
2828
29- func _ready(_damage: float):
30- attribute_name = HealthAttribute.ATTRIBUTE_NAME
31- damage = _damage
32- operation = AttributeOperation.sub(damage)
29+
30+ func _init(damage: float):
31+ self.damage = damage
32+
33+
34+ func _apply(context: AttributeBuffContext) -> void:
35+ var changeset = context.new_changeset()
36+
37+ changeset.operate(context.get_attribute(HealthAttribute.ATTRIBUTE_NAME), AttributeOperation.subtract(damage))
38+
39+ context.commit(changeset)
3340```
3441
3542Apply the buff to the ` HealthAttribute ` attribute like this:
@@ -39,24 +46,3 @@ attribute_container.apply_buff(DamageBuff.new(10.0))
3946```
4047
4148That's all folks!
42-
43- ## Example 2, the complex way
44-
45- In certain games, you have multiple damage types, multiple resistances,
46- and multiple damage sources.
47-
48- The logic (to handle the most complex cases) could sound awkward:
49- - you have to create, for each damage type you need, a damage attribute
50- - you have to assign these attributes to any attribute set you need (player, mobs, etc.).
51- - you must not deal with damage directly to the health, instead you have to increase the damage attributes
52- - once an attribute changed, the [ ` AttributeContainer ` ] ( ../classes/AttributeContainer.md ) emits a ` attribute_changed ` signal.
53- - if the attribute changed is a damage attribute, you should apply a new attribute buff
54- which is going to take care of calculating the proper damage, operating on health attribute and resetting the damage attribute(s) to 0.0.
55-
56- ## Example 2.1, a complex but less complex way
57-
58- As the example above, but instead of handling damage as attributes, you
59- can export the damage type(s) and value(s) as a resource.
60- Once the buff
61- is applied, take those into consideration to determine how the buff can damage the health attribute.
62-
0 commit comments