Setup the base for abilities and events
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using Gamesmiths.Forge.Attributes;
|
||||
|
||||
namespace Movementtests.scenes.player_controller.components.weapon;
|
||||
|
||||
public class WeaponAttributeSet : AttributeSet
|
||||
{
|
||||
public EntityAttribute Level { get; }
|
||||
|
||||
public WeaponAttributeSet()
|
||||
{
|
||||
Level = InitializeAttribute(nameof(Level), 1, 1, 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://mvc3bv0p021
|
||||
@@ -1,13 +1,21 @@
|
||||
using System;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Events;
|
||||
using Gamesmiths.Forge.Tags;
|
||||
using Godot;
|
||||
using GodotStateCharts;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.scenes.player_controller.components.weapon;
|
||||
using Movementtests.systems.damage;
|
||||
using Movementtests.tools;
|
||||
|
||||
namespace Movementtests.systems;
|
||||
|
||||
public record struct WeaponLandPayload(int Damage, bool IsCritical);
|
||||
|
||||
[GlobalClass, Icon("res://assets/ui/IconGodotNode/node_3D/icon_sword.png")]
|
||||
public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
public partial class WeaponSystem : RigidBody3D, IDamageDealer, IForgeEntity
|
||||
{
|
||||
[Signal]
|
||||
public delegate void WeaponThrownEventHandler();
|
||||
@@ -22,6 +30,12 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
[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!;
|
||||
|
||||
private StateChart _weaponState = null!;
|
||||
public StateChartState InHandState = null!;
|
||||
public StateChartState FlyingState = null!;
|
||||
@@ -40,6 +54,8 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
public StandardMaterial3D WeaponLocationIndicatorMaterial { get; set; } = null!;
|
||||
public MeshInstance3D WeaponMesh { get; set; } = null!;
|
||||
|
||||
public Tag WeaponLandTag;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_weaponState = StateChart.Of(GetNode("StateChart"));
|
||||
@@ -57,6 +73,22 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
_startTransform = Transform;
|
||||
Freeze = true;
|
||||
Visible = false;
|
||||
|
||||
var tagsManager = ForgeManager.GetTagsManager(this);
|
||||
var cuesManager = ForgeManager.GetCuesManager(this);
|
||||
var baseTags = new TagContainer(
|
||||
tagsManager,
|
||||
[
|
||||
Tag.RequestTag(tagsManager, "weapon")
|
||||
]);
|
||||
|
||||
Attributes = new EntityAttributes(new WeaponAttributeSet());
|
||||
Tags = new EntityTags(baseTags);
|
||||
EffectsManager = new EffectsManager(this, cuesManager);
|
||||
Abilities = new(this);
|
||||
Events = new();
|
||||
|
||||
WeaponLandTag = Tag.RequestTag(tagsManager, "events.weapon.land");
|
||||
|
||||
BodyEntered += OnThrownWeaponReachesGround;
|
||||
|
||||
@@ -109,11 +141,26 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
tween.Finished += ThrowWeaponOnCurve;
|
||||
}
|
||||
|
||||
public void RaiseWeaponLandEvent(IForgeEntity? victim = null)
|
||||
{
|
||||
Events.Raise(new EventData<WeaponLandPayload>
|
||||
{
|
||||
EventTags = WeaponLandTag.GetSingleTagContainer(),
|
||||
Source = this,
|
||||
Target = victim,
|
||||
EventMagnitude = 25f,
|
||||
Payload = new WeaponLandPayload(Damage: 25, IsCritical: true)
|
||||
});
|
||||
}
|
||||
|
||||
public void PlantInEnemy(Node3D enemy)
|
||||
{
|
||||
GetTree().GetRoot().CallDeferred(Node.MethodName.RemoveChild, this);
|
||||
enemy.CallDeferred(Node.MethodName.AddChild, this);
|
||||
|
||||
if (enemy is IForgeEntity victim) RaiseWeaponLandEvent(victim);
|
||||
else RaiseWeaponLandEvent();
|
||||
|
||||
if (enemy is IDamageable damageable)
|
||||
{
|
||||
damageable.TakeDamage(new DamageRecord(GlobalPosition, RDamage));
|
||||
@@ -145,6 +192,8 @@ public partial class WeaponSystem : RigidBody3D, IDamageDealer
|
||||
{
|
||||
PlantInEnemy(node);
|
||||
}
|
||||
else RaiseWeaponLandEvent();
|
||||
|
||||
CallDeferred(Node3D.MethodName.SetGlobalPosition, PlantLocation);
|
||||
CallDeferred(Node3D.MethodName.LookAt, GlobalTransform.Origin + PlantNormal, Vector3.Up, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user