parrying projectiles
This commit is contained in:
@@ -1,36 +1,44 @@
|
||||
using Gamesmiths.Forge.Abilities;
|
||||
using Gamesmiths.Forge.Core;
|
||||
using Gamesmiths.Forge.Effects;
|
||||
using Gamesmiths.Forge.Godot.Resources;
|
||||
using Gamesmiths.Forge.Godot.Resources.Abilities;
|
||||
using Godot;
|
||||
using Movementtests.interfaces;
|
||||
using Movementtests.tools;
|
||||
|
||||
namespace Movementtests.forge.abilities;
|
||||
|
||||
public record OnProjectileSpawned(Vector3 Direction, float SpeedMultiplier, Vector3? SpawnOffset = null, uint? CollisionOverride = null);
|
||||
|
||||
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior
|
||||
public class SpawnProjectileBehavior(PackedScene projectileScene) : IAbilityBehavior<OnProjectileSpawned>
|
||||
{
|
||||
public void OnStarted(AbilityBehaviorContext context)
|
||||
public void OnStarted(AbilityBehaviorContext context, OnProjectileSpawned data)
|
||||
{
|
||||
if (context.Target is not Node3D target || context.Source is not Node3D source)
|
||||
if (context.Source is not Node3D source || projectileScene.Instantiate() is not Projectile projectile)
|
||||
{
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceLocation = source.GlobalPosition;
|
||||
|
||||
if (projectileScene.Instantiate() is not Projectile projectile)
|
||||
{
|
||||
context.InstanceHandle.End();
|
||||
return;
|
||||
}
|
||||
|
||||
source.GetTree().GetCurrentScene().AddChild(projectile);
|
||||
|
||||
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : sourceLocation;
|
||||
projectile.GlobalPosition = startPos + Vector3.Up;
|
||||
source.GetTree().GetCurrentScene().AddChild(projectile);
|
||||
|
||||
// Computing projectile properties
|
||||
var offset = data.SpawnOffset ?? Vector3.Zero;
|
||||
var startPos = source is ITargetable targetable ? targetable.GetTargetGlobalPosition() : source.GlobalPosition;
|
||||
var target = context.Target as Node3D;
|
||||
var magnitude = context.Magnitude != 0 ? context.Magnitude : 1;
|
||||
var impulse = data.Direction * data.SpeedMultiplier * magnitude;
|
||||
var collisionOverride = data.CollisionOverride ?? projectile.CollisionMask;
|
||||
|
||||
GD.Print(impulse);
|
||||
|
||||
// Setting up projectile
|
||||
projectile.GlobalPosition = startPos + offset;
|
||||
projectile.Target = target;
|
||||
projectile.ImpulseDirection = impulse;
|
||||
projectile.CollisionMask = collisionOverride;
|
||||
|
||||
if (projectile is ISpawnable spawnable) spawnable.Init();
|
||||
|
||||
context.AbilityHandle.CommitAbility();
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_l686n")
|
||||
RegisteredTags = Array[String](["character.player", "character.enemy", "status.stunned", "status.burning", "status.frozen", "abilities.weapon.land", "abilities.weapon.flying", "abilities.weapon.left", "events.combat.damage", "events.combat.hit", "events.weapon.flyingTick", "events.weapon.startedFlying", "events.weapon.stoppedFlying", "events.weapon.handToFlying", "events.weapon.flyingToHand", "events.weapon.plantedToHand", "events.weapon.plantedToFlying", "events.weapon.planted", "cooldown.empoweredAction", "cooldown.empoweredSwordThrow", "cues.resources.mana", "events.player.empowered_action_used", "cues.resources.mana.inhibited", "cues.resources.health", "cooldown.enemy.hit", "events.combat.death", "cooldown.hit", "events.player.hit", "cues.enemy.health", "immunity.damage", "status", "traits.damageable", "traits.knockbackable", "events.combat.knockback_dealt", "events.combat.knockback_received", "events.weapon.plantedtick", "events.weapon.unplanted", "abilities.weapon.planted", "events.enemy.try_hit", "events.enemy.launch_projectile", "objects.projectile", "objects.weapon", "events.enemy.request_projectile"])
|
||||
RegisteredTags = Array[String](["character.player", "character.enemy", "status.stunned", "status.burning", "status.frozen", "abilities.weapon.land", "abilities.weapon.flying", "abilities.weapon.left", "events.combat.damage", "events.combat.hit", "events.weapon.flyingTick", "events.weapon.startedFlying", "events.weapon.stoppedFlying", "events.weapon.handToFlying", "events.weapon.flyingToHand", "events.weapon.plantedToHand", "events.weapon.plantedToFlying", "events.weapon.planted", "cooldown.empoweredAction", "cooldown.empoweredSwordThrow", "cues.resources.mana", "events.player.empowered_action_used", "cues.resources.mana.inhibited", "cues.resources.health", "cooldown.enemy.hit", "events.combat.death", "cooldown.hit", "events.player.hit", "cues.enemy.health", "immunity.damage", "status", "traits.damageable", "traits.knockbackable", "events.combat.knockback_dealt", "events.combat.knockback_received", "events.weapon.plantedtick", "events.weapon.unplanted", "abilities.weapon.planted", "events.enemy.try_hit", "events.enemy.launch_projectile", "objects.projectile", "objects.weapon", "events.enemy.request_projectile", "events.player.parry"])
|
||||
|
||||
23
forge/resources/ability_datas/lauche_projectile.tres
Normal file
23
forge/resources/ability_datas/lauche_projectile.tres
Normal file
@@ -0,0 +1,23 @@
|
||||
[gd_resource type="Resource" script_class="ForgeAbilityData" format=3 uid="uid://ckfbi6lu255ep"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://g0u88alm6hcb" path="res://assets/ui/IconGodotNode/node/icon_bullet.png" id="1_hixal"]
|
||||
[ext_resource type="PackedScene" uid="uid://bhp6qunnwhncf" path="res://scenes/projectile/Projectile.tscn" id="2_ljwqp"]
|
||||
[ext_resource type="Script" uid="uid://dxtjifb8hv8k4" path="res://forge/abilities/ForgeSpawnProjectileBehavior.cs" id="3_urund"]
|
||||
[ext_resource type="Resource" uid="uid://bkr1xfokymvp4" path="res://forge/resources/tag_containers/on_enemy_lauch_project.tres" id="4_5yymv"]
|
||||
[ext_resource type="Script" uid="uid://dhxfbxh54pyxp" path="res://addons/forge/resources/abilities/ForgeAbilityData.cs" id="5_xbj7n"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_idpl5"]
|
||||
script = ExtResource("3_urund")
|
||||
Projectile = ExtResource("2_ljwqp")
|
||||
Name = "Spawn projectile"
|
||||
Icon = ExtResource("1_hixal")
|
||||
metadata/_custom_type_script = "uid://dxtjifb8hv8k4"
|
||||
|
||||
[resource]
|
||||
script = ExtResource("5_xbj7n")
|
||||
Name = "Launch projectile"
|
||||
CooldownEffects = []
|
||||
AbilityBehavior = SubResource("Resource_idpl5")
|
||||
TriggerSource = 1
|
||||
TriggerTag = ExtResource("4_5yymv")
|
||||
metadata/_custom_type_script = "uid://dhxfbxh54pyxp"
|
||||
Reference in New Issue
Block a user