More weapon events and abilities

This commit is contained in:
2026-05-06 11:05:55 +02:00
parent 1db30eafd9
commit bcc748ca6b
14 changed files with 455 additions and 190 deletions

View File

@@ -49,7 +49,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
{
StartedFlying,
StoppedFlying,
FlyingTick
FlyingTick,
StartedPlanted,
StoppedPlanted,
PlantedTick
}
#endregion
@@ -70,6 +73,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
private readonly Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new();
private readonly Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new();
private readonly Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStartedPlantedAbilities = new();
private readonly Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedPlantedAbilities = new();
private readonly Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponPlantedTickAbilities = new();
public Tag WeaponFlyingTickEventTag;
public Tag WeaponStartedFlyingEventTag;
public Tag WeaponStoppedFlyingEventTag;
@@ -78,24 +85,31 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
public Tag WeaponPlantedToHandEventTag;
public Tag WeaponPlantedToFlyingEventTag;
public Tag WeaponPlantedEventTag;
public Tag WeaponPlantedTickEventTag;
public Tag WeaponUnplantedEventTag;
public Tag WeaponInHandStatusTag;
public Tag WeaponFlyingStatusTag;
public Tag WeaponPlantedStatusTag;
public Tag WeaponFlyingAbilityTag;
public Tag WeaponPlantedAbilityTag;
private AbilityHandle? _weaponFlyingAbility;
private AbilityHandle? _weaponPlantedAbility;
#endregion
#region Inspector
[Export] public ForgeAbilityData? FlyingTickAbility { get; set; }
[ExportGroup("Throwing")]
[Export(PropertyHint.Range, "0,2,0.01,or_greater")]
public float ThrowForce { get; set; } = 1f;
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
public float StraightThrowDuration { get; set; } = 0.1f;
[ExportGroup("Tick raising abilities")]
[Export] public ForgeAbilityData? FlyingTickAbility { get; set; }
[Export] public ForgeAbilityData? PlantedTickAbility { get; set; }
#endregion
@@ -168,6 +182,9 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
private Vector3 _startMeshRotation;
private Vector3 _throwDirection;
private IForgeEntity? _plantedEntity;
private AbilityHandle? _plantedInEnemyHandle;
#endregion
@@ -208,22 +225,33 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
WeaponPlantedToHandEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToHand");
WeaponPlantedToFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToFlying");
WeaponPlantedEventTag = Tag.RequestTag(TagsManager, "events.weapon.planted");
WeaponPlantedTickEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedtick");
WeaponUnplantedEventTag = Tag.RequestTag(TagsManager, "events.weapon.unplanted");
// WeaponInHandStatusTag = Tag.RequestTag(TagsManager, "status.weapon.inHand");
// WeaponFlyingStatusTag = Tag.RequestTag(TagsManager, "status.weapon.flying");
// WeaponPlantedStatusTag = Tag.RequestTag(TagsManager, "status.weapon.planted");
// Manage weapon flying tick raising ability
WeaponFlyingAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.flying");
_weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this);
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
// Manage weapon tick raising abilities
if (FlyingTickAbility != null)
{
WeaponFlyingAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.flying");
_weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this);
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
}
if (PlantedTickAbility != null)
{
WeaponPlantedAbilityTag = Tag.RequestTag(TagsManager,"abilities.weapon.planted");
_weaponPlantedAbility = Abilities.GrantAbilityPermanently(PlantedTickAbility.GetAbilityData(), 1, LevelComparison.None, this);
Events.Subscribe(WeaponUnplantedEventTag, _ => { _weaponPlantedAbility.Cancel(); });
}
#region EventRaising
BodyEntered += OnThrownWeaponReachesGround;
InHandState.StateExited += WeaponLeft;
InHandState.StateEntered += WeaponBack;
#region EventRaising
_handToFlying.Taken += () =>
{
Events.Raise(new EventData
@@ -257,7 +285,15 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
Events.Raise(new EventData
{
EventTags = WeaponPlantedToHandEventTag.GetSingleTagContainer()!,
Source = this
Source = this,
Target = _plantedEntity
});
Events.Raise(new EventData
{
EventTags = WeaponUnplantedEventTag.GetSingleTagContainer()!,
Source = this,
Target = _plantedEntity
});
};
@@ -273,6 +309,12 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
EventTags = WeaponStartedFlyingEventTag.GetSingleTagContainer()!,
Source = this
});
Events.Raise(new EventData
{
EventTags = WeaponUnplantedEventTag.GetSingleTagContainer()!,
Source = this,
Target = _plantedEntity
});
};
_toPlanted.Taken += () =>
@@ -303,6 +345,9 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
{ WeaponEvent.StartedFlying, WeaponStartedFlyingEventTag },
{ WeaponEvent.StoppedFlying, WeaponStoppedFlyingEventTag },
{ WeaponEvent.FlyingTick, WeaponFlyingTickEventTag },
{ WeaponEvent.StartedPlanted, WeaponPlantedEventTag },
{ WeaponEvent.StoppedPlanted, WeaponUnplantedEventTag },
{ WeaponEvent.PlantedTick, WeaponPlantedTickEventTag },
};
var ability = new AbilityData(
@@ -362,6 +407,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
{ WeaponEvent.StartedFlying, _grantedWeaponStartedFlyingAbilities },
{ WeaponEvent.StoppedFlying, _grantedWeaponStoppedFlyingAbilities },
{ WeaponEvent.FlyingTick, _grantedWeaponFlyingTickAbilities },
{ WeaponEvent.StartedPlanted, _grantedWeaponStartedPlantedAbilities },
{ WeaponEvent.StoppedPlanted, _grantedWeaponStoppedPlantedAbilities },
{ WeaponEvent.PlantedTick, _grantedWeaponPlantedTickAbilities },
};
return abilitiesMap[forEvent];
@@ -409,7 +458,6 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
tween.Finished += ThrowWeaponOnCurve;
}
private IForgeEntity? _plantedEntity;
public void PlantInEnemy(Node3D enemy)
{
GetTree().GetRoot().CallDeferred(Node.MethodName.RemoveChild, this);
@@ -417,11 +465,6 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
if (enemy is IForgeEntity victim) _plantedEntity = victim;
else _plantedEntity = null;
// if (enemy is IDamageable damageable)
// {
// damageable.TakeDamage(new DamageRecord(GlobalPosition, RDamage));
// }
}
public void RethrowWeapon()
@@ -470,12 +513,10 @@ public partial class WeaponSystem : RigidBody3D, IForgeEntity
public override void _IntegrateForces(PhysicsDirectBodyState3D state)
{
base._IntegrateForces(state);
if (!Freeze && state.GetContactCount() > 0)
{
PlantLocation = state.GetContactLocalPosition(0);
PlantNormal = state.GetContactLocalNormal(0);
}
if (Freeze || state.GetContactCount() <= 0) return;
PlantLocation = state.GetContactLocalPosition(0);
PlantNormal = state.GetContactLocalNormal(0);
}
public override void _Process(double delta)

View File

@@ -1,9 +1,11 @@
[gd_scene format=3 uid="uid://ckm3d6k08a72u"]
[ext_resource type="Script" uid="uid://iii3wfto4t5b" path="res://scenes/player_controller/components/weapon/WeaponSystem.cs" id="1_csqwk"]
[ext_resource type="Resource" uid="uid://dgjsi1my7nlnk" path="res://forge/resources/ability_datas/player_hit.tres" id="2_2wsgo"]
[ext_resource type="Script" uid="uid://cw525n4mjqgw0" path="res://addons/forge/resources/ForgeTagContainer.cs" id="2_l1xlx"]
[ext_resource type="Script" uid="uid://cxihb42t2mfqi" path="res://addons/forge/nodes/ForgeAttributeSet.cs" id="3_3xjpi"]
[ext_resource type="Script" uid="uid://couw105c3bde4" path="res://addons/godot_state_charts/state_chart.gd" id="3_5owyf"]
[ext_resource type="Resource" uid="uid://0oo3na61ot1o" path="res://forge/resources/ability_datas/weapon_planted_tick_ability.tres" id="3_7bruw"]
[ext_resource type="ArrayMesh" uid="uid://cho5fixitrbds" path="res://assets/meshes/swords/resources/sword23.tres" id="3_svc06"]
[ext_resource type="Resource" uid="uid://btnnpqann3ktp" path="res://forge/resources/ability_datas/weapon_flying_tick_ability.tres" id="4_7bruw"]
[ext_resource type="Script" uid="uid://ccovd5i0wr3kk" path="res://addons/forge/editor/attributes/AttributeValues.cs" id="4_q6xv7"]
@@ -11,6 +13,15 @@
[ext_resource type="Script" uid="uid://rpcbb54q4atx" path="res://forge/ForgeEntityNode.cs" id="5_7bruw"]
[ext_resource type="Script" uid="uid://cytafq8i1y8qm" path="res://addons/godot_state_charts/atomic_state.gd" id="5_m0v1h"]
[ext_resource type="Script" uid="uid://cf1nsco3w0mf6" path="res://addons/godot_state_charts/transition.gd" id="6_jpdh0"]
[ext_resource type="Script" uid="uid://dps0oef50noil" path="res://addons/forge/nodes/ForgeEffect.cs" id="9_vs841"]
[ext_resource type="Resource" uid="uid://bn1getr10b4dx" path="res://forge/resources/effect_datas/simple_player_hit.tres" id="10_fyov3"]
[ext_resource type="Script" uid="uid://1hgogislo1l6" path="res://addons/forge/resources/magnitudes/ForgeScalableInt.cs" id="10_rgbou"]
[ext_resource type="Script" uid="uid://b83hf13nj37k3" path="res://addons/forge/resources/ForgeEffectData.cs" id="11_fyov3"]
[ext_resource type="Script" uid="uid://n6efm5o4uxvr" path="res://forge/abilities/ForgeSimpleHitBehavior.cs" id="12_2o32x"]
[ext_resource type="Script" uid="uid://dpakv7agvir6y" path="res://addons/forge/resources/ForgeTag.cs" id="12_fyov3"]
[ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="13_i0iid"]
[ext_resource type="Script" uid="uid://72kj3n4lm1em" path="res://addons/forge/resources/components/ForgeGrantAbilityConfig.cs" id="14_i0jsb"]
[ext_resource type="Script" uid="uid://b3wo2uge4ddnj" path="res://addons/forge/resources/components/GrantAbility.cs" id="15_a8u16"]
[sub_resource type="Resource" id="Resource_7bruw"]
script = ExtResource("2_l1xlx")
@@ -23,6 +34,62 @@ Default = 1
Min = 1
Max = 100
[sub_resource type="Resource" id="Resource_weq0w"]
script = ExtResource("12_2o32x")
DamageEffect = ExtResource("10_fyov3")
Name = "On planted simple hit"
Description = "Causes hit on enemy planted"
metadata/_custom_type_script = "uid://n6efm5o4uxvr"
[sub_resource type="Resource" id="Resource_2o32x"]
script = ExtResource("12_fyov3")
Tag = "events.weapon.planted"
metadata/_custom_type_script = "uid://dpakv7agvir6y"
[sub_resource type="Resource" id="Resource_bua0c"]
script = ExtResource("13_i0iid")
Name = "On Planted in Enemy"
InstancingPolicy = 1
CooldownEffects = []
AbilityBehavior = SubResource("Resource_weq0w")
TriggerSource = 1
TriggerTag = SubResource("Resource_2o32x")
metadata/_custom_type_script = "uid://dhxfbxh54pyxp"
[sub_resource type="Resource" id="Resource_xhc8e"]
script = ExtResource("10_rgbou")
BaseValue = 1
[sub_resource type="Resource" id="Resource_hnni7"]
script = ExtResource("14_i0jsb")
AbilityData = SubResource("Resource_bua0c")
AbilityLevel = SubResource("Resource_xhc8e")
metadata/_custom_type_script = "uid://72kj3n4lm1em"
[sub_resource type="Resource" id="Resource_rr8s3"]
script = ExtResource("15_a8u16")
GrantAbilityConfigs = [SubResource("Resource_hnni7")]
metadata/_custom_type_script = "uid://b3wo2uge4ddnj"
[sub_resource type="Resource" id="Resource_8jrha"]
script = ExtResource("10_rgbou")
BaseValue = 1
[sub_resource type="Resource" id="Resource_l026a"]
script = ExtResource("10_rgbou")
BaseValue = 1
[sub_resource type="Resource" id="Resource_x33lk"]
script = ExtResource("11_fyov3")
Name = "Grant abilities"
Modifiers = []
Components = Array[Object]([SubResource("Resource_rr8s3")])
Executions = []
StackLimit = SubResource("Resource_l026a")
InitialStack = SubResource("Resource_8jrha")
Cues = []
metadata/_custom_type_script = "uid://b83hf13nj37k3"
[sub_resource type="CylinderShape3D" id="CylinderShape3D_avini"]
height = 1.0
radius = 0.1
@@ -58,7 +125,9 @@ continuous_cd = true
contact_monitor = true
max_contacts_reported = 1
script = ExtResource("1_csqwk")
OnPlantedInEnemy = ExtResource("2_2wsgo")
FlyingTickAbility = ExtResource("4_7bruw")
PlantedTickAbility = ExtResource("3_7bruw")
[node name="ForgeEntityNode" type="Node3D" parent="." unique_id=1798885192]
script = ExtResource("5_7bruw")
@@ -73,6 +142,11 @@ InitialAttributeValues = Dictionary[String, ExtResource("4_q6xv7")]({
})
metadata/_custom_type_script = "uid://cxihb42t2mfqi"
[node name="GrantAbilities" type="Node" parent="ForgeEntityNode" unique_id=180593118]
script = ExtResource("9_vs841")
EffectData = SubResource("Resource_x33lk")
metadata/_custom_type_script = "uid://dps0oef50noil"
[node name="WeaponFlyingTick" type="Timer" parent="." unique_id=656309486]
wait_time = 0.2