made weapon into a dependant and used new forgeneitty node as a node3d
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Attributes;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Cues;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Effects.Calculator;
|
||||
using Gamesmiths.Forge.Effects.Components;
|
||||
@@ -26,9 +29,20 @@ using Node = Godot.Node;
|
||||
namespace Movementtests.systems;
|
||||
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_sword.png")]
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_sword.png"), Meta(typeof(IAutoNode))]
|
||||
public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
#region Dependencies
|
||||
|
||||
[Dependency]
|
||||
public TagsManager TagsManager => this.DependOn<TagsManager>();
|
||||
[Dependency]
|
||||
public CuesManager CuesManager => this.DependOn<CuesManager>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enums
|
||||
|
||||
public enum WeaponEvent
|
||||
@@ -76,10 +90,7 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
#endregion
|
||||
|
||||
#region Inspector
|
||||
|
||||
[Export]
|
||||
public ForgeTagContainer BaseTags { get; set; }
|
||||
[Export] public ForgeAbilityData FlyingTickAbility { get; set; }
|
||||
[Export] public ForgeAbilityData? FlyingTickAbility { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage RDamage { get; set; }
|
||||
@@ -88,32 +99,60 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
[Export(PropertyHint.Range, "0,0.2,0.01,or_greater")]
|
||||
public float StraightThrowDuration { get; set; } = 0.1f;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IForgeEntity
|
||||
|
||||
// Perfectly forward the IForgeEntity interface to the ForgeEntity component
|
||||
public EntityAttributes Attributes
|
||||
{
|
||||
get => ForgeEntity.Attributes;
|
||||
set => ForgeEntity.Attributes = value;
|
||||
}
|
||||
public EntityTags Tags
|
||||
{
|
||||
get => ForgeEntity.Tags;
|
||||
set => ForgeEntity.Tags = value;
|
||||
}
|
||||
public EffectsManager EffectsManager
|
||||
{
|
||||
get => ForgeEntity.EffectsManager;
|
||||
set => ForgeEntity.EffectsManager = value;
|
||||
}
|
||||
public EntityAbilities Abilities
|
||||
{
|
||||
get => ForgeEntity.Abilities;
|
||||
set => ForgeEntity.Abilities = value;
|
||||
}
|
||||
public EventManager Events
|
||||
{
|
||||
get => ForgeEntity.Events;
|
||||
set => ForgeEntity.Events = value;
|
||||
}
|
||||
|
||||
public Variables SharedVariables
|
||||
{
|
||||
get => ForgeEntity.SharedVariables;
|
||||
set => ForgeEntity.SharedVariables = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Publics
|
||||
|
||||
public required EntityAttributes Attributes { get; set; }
|
||||
public required EntityTags Tags { get; set; }
|
||||
public required EffectsManager EffectsManager { get; set; }
|
||||
public required EntityAbilities Abilities { get; set; }
|
||||
public required EventManager Events { get; set; }
|
||||
public required Variables SharedVariables { get; set; }
|
||||
|
||||
|
||||
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!;
|
||||
|
||||
|
||||
[Node("ForgeEntityNode")] public required ForgeEntityNode ForgeEntity { get; set;}
|
||||
[Node("Weapon")] public required MeshInstance3D WeaponMesh { get; set; }
|
||||
[Node("WeaponLocationIndicator")] public required MeshInstance3D WeaponLocationIndicator { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Privates
|
||||
@@ -133,9 +172,11 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
private Vector3 _throwDirection;
|
||||
|
||||
#endregion
|
||||
|
||||
public void Init()
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
#region StateManagement
|
||||
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
InHandState = StateChartState.Of(GetNode("StateChart/Root/InHand"));
|
||||
FlyingState = StateChartState.Of(GetNode("StateChart/Root/Flying"));
|
||||
@@ -145,49 +186,41 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
_plantedToHand = Transition.Of(GetNode("StateChart/Root/Planted/ToHand"));
|
||||
_plantedToFlying = Transition.Of(GetNode("StateChart/Root/Planted/ToFlying"));
|
||||
_toPlanted = Transition.Of(GetNode("StateChart/Root/ToPlanted"));
|
||||
|
||||
WeaponLocationIndicator = GetNode<MeshInstance3D>("WeaponLocationIndicator");
|
||||
WeaponLocationIndicator.Visible = false;
|
||||
WeaponLocationIndicatorMaterial = (WeaponLocationIndicator.GetActiveMaterial(0) as StandardMaterial3D)!;
|
||||
|
||||
WeaponFlyingTick = GetNode<Timer>("WeaponFlyingTick");
|
||||
|
||||
WeaponMesh = GetNode<MeshInstance3D>("Weapon");
|
||||
#endregion
|
||||
|
||||
// Initial setup
|
||||
_startMeshRotation = WeaponMesh.Rotation;
|
||||
|
||||
_startTransform = Transform;
|
||||
Freeze = true;
|
||||
Visible = false;
|
||||
|
||||
WeaponLocationIndicator.Visible = false;
|
||||
WeaponLocationIndicatorMaterial = (WeaponLocationIndicator.GetActiveMaterial(0) as StandardMaterial3D)!;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
// Forge
|
||||
var tagsManager = ForgeManagers.Instance.TagsManager;
|
||||
var cuesManager = ForgeManagers.Instance.CuesManager;
|
||||
WeaponFlyingTickEventTag = Tag.RequestTag(TagsManager, "events.weapon.flyingTick");
|
||||
WeaponStartedFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.startedFlying");
|
||||
WeaponStoppedFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.stoppedFlying");
|
||||
WeaponHandToFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.handToFlying");
|
||||
WeaponFlyingToHandEventTag = Tag.RequestTag(TagsManager, "events.weapon.flyingToHand");
|
||||
WeaponPlantedToHandEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToHand");
|
||||
WeaponPlantedToFlyingEventTag = Tag.RequestTag(TagsManager, "events.weapon.plantedToFlying");
|
||||
WeaponPlantedEventTag = Tag.RequestTag(TagsManager, "events.weapon.planted");
|
||||
|
||||
WeaponFlyingTickEventTag = Tag.RequestTag(tagsManager, "events.weapon.flyingTick");
|
||||
WeaponStartedFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.startedFlying");
|
||||
WeaponStoppedFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.stoppedFlying");
|
||||
WeaponHandToFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.handToFlying");
|
||||
WeaponFlyingToHandEventTag = Tag.RequestTag(tagsManager, "events.weapon.flyingToHand");
|
||||
WeaponPlantedToHandEventTag = Tag.RequestTag(tagsManager, "events.weapon.plantedToHand");
|
||||
WeaponPlantedToFlyingEventTag = Tag.RequestTag(tagsManager, "events.weapon.plantedToFlying");
|
||||
WeaponPlantedEventTag = Tag.RequestTag(tagsManager, "events.weapon.planted");
|
||||
|
||||
// WeaponInHandStatusTag = Tag.RequestTag(tagsManager, "status.weapon.inHand");
|
||||
// WeaponFlyingStatusTag = Tag.RequestTag(tagsManager, "status.weapon.flying");
|
||||
// WeaponPlantedStatusTag = Tag.RequestTag(tagsManager, "status.weapon.planted");
|
||||
|
||||
WeaponFlyingAbilityTag = Tag.RequestTag(tagsManager,"abilities.weapon.flying");
|
||||
|
||||
Attributes = new EntityAttributes([.. ForgeUtils.CollectAttributeList(this)]);
|
||||
Tags = new(BaseTags.GetTagContainer());
|
||||
EffectsManager = new EffectsManager(this, cuesManager);
|
||||
Abilities = new(this);
|
||||
Events = new();
|
||||
// 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(); });
|
||||
|
||||
BodyEntered += OnThrownWeaponReachesGround;
|
||||
|
||||
InHandState.StateExited += WeaponLeft;
|
||||
InHandState.StateEntered += WeaponBack;
|
||||
|
||||
@@ -260,10 +293,8 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
Events.Subscribe(WeaponStoppedFlyingEventTag, _ => { _weaponFlyingAbility.Cancel(); });
|
||||
}
|
||||
|
||||
|
||||
public void GrantNewAbilityForEvent(WeaponEvent forEvent, ForgeAbilityBehavior abilityBehavior)
|
||||
{
|
||||
var relevantMap = GetGrantedAbilities(forEvent);
|
||||
|
||||
Reference in New Issue
Block a user