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)