made the initial inventory loadout into a resource to initialize the injected dependency with
This commit is contained in:
@@ -33,54 +33,32 @@ namespace Movementtests.systems;
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_sword.png")]
|
||||
public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
{
|
||||
#region Enums
|
||||
|
||||
public enum WeaponEvent
|
||||
{
|
||||
StartedFlying,
|
||||
StoppedFlying,
|
||||
FlyingTick
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Signals
|
||||
|
||||
[Signal]
|
||||
public delegate void WeaponThrownEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void WeaponRetrievedEventHandler();
|
||||
|
||||
[Export]
|
||||
public ForgeTagContainer BaseTags { get; set; }
|
||||
[Export] public ForgeAbilityData FlyingTickAbility { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage RDamage { get; set; }
|
||||
[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;
|
||||
|
||||
public EntityAttributes Attributes { get; set; } = null!;
|
||||
public EntityTags Tags { get; set; } = null!;
|
||||
public EffectsManager EffectsManager { get; set; } = null!;
|
||||
public EntityAbilities Abilities { get; set; } = null!;
|
||||
public EventManager Events { get; set; } = null!;
|
||||
public Variables SharedVariables { get; }
|
||||
|
||||
private StateChart _weaponState = null!;
|
||||
public StateChartState InHandState = null!;
|
||||
public StateChartState FlyingState = null!;
|
||||
public StateChartState PlantedState = null!;
|
||||
private Transition _handToFlying = null!;
|
||||
private Transition _flyingToHand = null!;
|
||||
private Transition _plantedToHand = null!;
|
||||
private Transition _plantedToFlying = null!;
|
||||
private Transition _toPlanted = null!;
|
||||
#endregion
|
||||
|
||||
private ShapeCast3D _dashCast3D = null!;
|
||||
public Timer WeaponFlyingTick = null!;
|
||||
|
||||
private Transform3D _startTransform;
|
||||
private Vector3 _startMeshRotation;
|
||||
#region Forge
|
||||
|
||||
private Vector3 _throwDirection;
|
||||
public Vector3 PlantLocation { get; set; }
|
||||
public Vector3 PlantNormal { get; set; }
|
||||
public Node? PlantObject { get; set; }
|
||||
|
||||
public MeshInstance3D WeaponLocationIndicator { get; set; } = null!;
|
||||
public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; } = null!;
|
||||
public MeshInstance3D WeaponMesh { get; set; } = null!;
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new ();
|
||||
|
||||
public Tag WeaponFlyingTickEventTag;
|
||||
public Tag WeaponStartedFlyingEventTag;
|
||||
@@ -99,6 +77,66 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
|
||||
private AbilityHandle? _weaponFlyingAbility;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Inspector
|
||||
|
||||
[Export]
|
||||
public ForgeTagContainer BaseTags { get; set; }
|
||||
[Export] public ForgeAbilityData FlyingTickAbility { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage RDamage { get; set; }
|
||||
[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;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Publics
|
||||
|
||||
public EntityAttributes Attributes { get; set; } = null!;
|
||||
public EntityTags Tags { get; set; } = null!;
|
||||
public EffectsManager EffectsManager { get; set; } = null!;
|
||||
public EntityAbilities Abilities { get; set; } = null!;
|
||||
public EventManager Events { get; set; } = null!;
|
||||
public Variables SharedVariables { get; }
|
||||
|
||||
public StateChartState InHandState = null!;
|
||||
public StateChartState FlyingState = null!;
|
||||
public StateChartState PlantedState = null!;
|
||||
|
||||
public Timer WeaponFlyingTick = null!;
|
||||
|
||||
public Vector3 PlantLocation { get; set; }
|
||||
public Vector3 PlantNormal { get; set; }
|
||||
public Node? PlantObject { get; set; }
|
||||
|
||||
public MeshInstance3D WeaponLocationIndicator { get; set; } = null!;
|
||||
public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; } = null!;
|
||||
public MeshInstance3D WeaponMesh { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Privates
|
||||
|
||||
private StateChart _weaponState = null!;
|
||||
private Transition _handToFlying = null!;
|
||||
private Transition _flyingToHand = null!;
|
||||
private Transition _plantedToHand = null!;
|
||||
private Transition _plantedToFlying = null!;
|
||||
private Transition _toPlanted = null!;
|
||||
|
||||
private ShapeCast3D _dashCast3D = null!;
|
||||
|
||||
private Transform3D _startTransform;
|
||||
private Vector3 _startMeshRotation;
|
||||
|
||||
private Vector3 _throwDirection;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
@@ -163,7 +201,6 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
Abilities = new(this);
|
||||
Events = new();
|
||||
|
||||
// TODO: Waiting on bug resolve
|
||||
_weaponFlyingAbility = Abilities.GrantAbilityPermanently(FlyingTickAbility.GetAbilityData(), 1, LevelComparison.None, this);
|
||||
|
||||
BodyEntered += OnThrownWeaponReachesGround;
|
||||
@@ -171,6 +208,8 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
InHandState.StateExited += WeaponLeft;
|
||||
InHandState.StateEntered += WeaponBack;
|
||||
|
||||
#region EventRaising
|
||||
|
||||
_handToFlying.Taken += () =>
|
||||
{
|
||||
Events.Raise(new EventData
|
||||
@@ -237,24 +276,14 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
});
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
|
||||
}
|
||||
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStartedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponStoppedFlyingAbilities = new ();
|
||||
private Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> _grantedWeaponFlyingTickAbilities = new ();
|
||||
|
||||
public enum WeaponEvent
|
||||
{
|
||||
StartedFlying,
|
||||
StoppedFlying,
|
||||
FlyingTick
|
||||
}
|
||||
|
||||
public void GrantNewAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
var relevantMap = GetGrantedAbilities(forEvent);
|
||||
GD.Print($"Granted {abilityBehavior} for {forEvent}");
|
||||
if (relevantMap.ContainsKey(abilityBehavior)) return;
|
||||
|
||||
var eventTagsMap = new Dictionary<WeaponEvent, Tag>
|
||||
@@ -296,6 +325,19 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
relevantMap.Remove(abilityBehavior);
|
||||
}
|
||||
|
||||
public void RemoveAllEventAbilities()
|
||||
{
|
||||
foreach (var weaponEvent in Enum.GetValues<WeaponEvent>())
|
||||
{
|
||||
var abilities = GetGrantedAbilities(weaponEvent);
|
||||
foreach (var ability in abilities.Values)
|
||||
{
|
||||
EffectsManager.RemoveEffect(ability);
|
||||
}
|
||||
abilities.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<ForgeAbilityBehavior, ActiveEffectHandle> GetGrantedAbilities(WeaponEvent forEvent)
|
||||
{
|
||||
var abilitiesMap = new Dictionary<WeaponEvent, Dictionary<ForgeAbilityBehavior, ActiveEffectHandle>>
|
||||
|
||||
Reference in New Issue
Block a user