Damage dealing through meta attribute and custom exec
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
|
||||
[sub_resource type="Resource" id="Resource_mpigw"]
|
||||
script = ExtResource("2_u8yay")
|
||||
ContainerTags = Array[String](["character.player"])
|
||||
ContainerTags = Array[String](["character.player", "traits.damageable"])
|
||||
metadata/_custom_type_script = "uid://cw525n4mjqgw0"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_5gbhg"]
|
||||
@@ -72,7 +72,7 @@ metadata/_custom_type_script = "uid://dpakv7agvir6y"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_2rkt1"]
|
||||
script = ExtResource("11_u8yay")
|
||||
Tag = "status.invincible"
|
||||
Tag = "immunity.damage"
|
||||
metadata/_custom_type_script = "uid://dpakv7agvir6y"
|
||||
|
||||
[sub_resource type="Resource" id="Resource_cb2lu"]
|
||||
@@ -224,6 +224,15 @@ InitialAttributeValues = Dictionary[String, ExtResource("11_2rkt1")]({
|
||||
})
|
||||
metadata/_custom_type_script = "uid://cxihb42t2mfqi"
|
||||
|
||||
[node name="CharaAttributeSet" type="Node" parent="." unique_id=2058864775]
|
||||
script = ExtResource("10_pw5r7")
|
||||
AttributeSetClass = "CharacterAttributeSet"
|
||||
InitialAttributeValues = Dictionary[String, ExtResource("11_2rkt1")]({
|
||||
"Health": Object(RefCounted,"script":ExtResource("11_2rkt1"),"Default":100,"Min":0,"Max":100)
|
||||
|
||||
})
|
||||
metadata/_custom_type_script = "uid://cxihb42t2mfqi"
|
||||
|
||||
[node name="MetaAttributeSet" type="Node" parent="." unique_id=1777903944]
|
||||
script = ExtResource("10_pw5r7")
|
||||
AttributeSetClass = "MetaAttributeSet"
|
||||
|
||||
@@ -26,6 +26,7 @@ using Movementtests.systems;
|
||||
using Movementtests.player_controller.Scripts;
|
||||
using Movementtests.managers;
|
||||
using Movementtests.tools;
|
||||
using Movementtests.tools.calculators;
|
||||
using RustyOptions;
|
||||
using Node = Godot.Node;
|
||||
|
||||
@@ -457,7 +458,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
|
||||
// General use stuff
|
||||
Attributes = new EntityAttributes([.. ForgeUtils.CollectAttributeList(this)]);
|
||||
HealthAttribute = Attributes["PlayerAttributeSet.Health"];
|
||||
HealthAttribute = Attributes["CharacterAttributeSet.Health"];
|
||||
ManaAttribute = Attributes["PlayerAttributeSet.Mana"];
|
||||
|
||||
Tags = new(BaseTags.GetTagContainer());
|
||||
@@ -666,6 +667,8 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
#endregion
|
||||
|
||||
// Forge events
|
||||
HealthAttribute.OnValueChanged += OnHealthChanged;
|
||||
|
||||
var weaponLeftToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStartedFlyingEventTag, OnWeaponLeft);
|
||||
var weaponLandedToken = WeaponSystem.Events.Subscribe(WeaponSystem.WeaponStoppedFlyingEventTag, OnWeaponLanded);
|
||||
}
|
||||
@@ -725,7 +728,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
});
|
||||
}
|
||||
|
||||
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived);
|
||||
Events.Subscribe<DamageDone>(Tag.RequestTag(TagsManager, "events.combat.damage"), OnDamageReceived);
|
||||
Events.Subscribe(Tag.RequestTag(TagsManager, "events.combat.death"), OnDeath);
|
||||
#endregion
|
||||
|
||||
@@ -2642,9 +2645,19 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
}
|
||||
|
||||
// Forge Damage handling
|
||||
public void OnDamageReceived(EventData data)
|
||||
private void OnHealthChanged(EntityAttribute healthAttribute, int i)
|
||||
{
|
||||
if (healthAttribute.CurrentValue > HealthAttribute.Min) return;
|
||||
|
||||
var tagsManager = TagsManager;
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = Tag.RequestTag(tagsManager, "events.combat.death").GetSingleTagContainer()!,
|
||||
});
|
||||
}
|
||||
|
||||
public void OnDamageReceived(EventData<DamageDone> data)
|
||||
{
|
||||
var newHealth = HealthAttribute.CurrentValue + data.EventMagnitude;
|
||||
CuesManager.ExecuteCue(
|
||||
Tag.RequestTag(TagsManager, "cues.resources.health"),
|
||||
this,
|
||||
@@ -2657,16 +2670,6 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
{"test", "hello"}
|
||||
})
|
||||
);
|
||||
|
||||
if (newHealth > HealthAttribute.Min) return;
|
||||
|
||||
var tagsManager = TagsManager;
|
||||
Events.Raise(new EventData
|
||||
{
|
||||
EventTags = Tag.RequestTag(tagsManager, "events.combat.death").GetSingleTagContainer()!,
|
||||
Source = data.Source,
|
||||
Target = data.Target
|
||||
});
|
||||
}
|
||||
|
||||
public void OnExecute(IForgeEntity? target, CueParameters? parameters)
|
||||
@@ -2674,7 +2677,7 @@ public partial class PlayerController : CharacterBody3D, IForgeEntity, ICueHandl
|
||||
if (target == null || !parameters.HasValue) return;
|
||||
|
||||
float magnitude = parameters.Value.Magnitude;
|
||||
if (magnitude >= 0) return;
|
||||
if (magnitude <= 0) return;
|
||||
|
||||
HeadSystem.OnGetHit();
|
||||
_audioStream.SwitchToClipByName("damage_taken");
|
||||
|
||||
Reference in New Issue
Block a user