Teleport skill added for Chinthe

This commit is contained in:
2025-10-27 17:48:27 -07:00
parent 7e6dca1c29
commit 0b909e4e7e
7 changed files with 65 additions and 18 deletions

View File

@@ -114,7 +114,7 @@ public abstract partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLo
public virtual void PerformAction() public virtual void PerformAction()
{ {
EnemyModelView.PlayPrimaryAttackAnimation(); PerformAction();
} }
public virtual void ReturnToDefaultState() public virtual void ReturnToDefaultState()

View File

@@ -47,7 +47,7 @@ public abstract partial class Enemy2D : Enemy
MoveAndSlide(); MoveAndSlide();
} }
protected void EngagePlayerBehavior_TakeAction() => EnemyModelView.PlayPrimaryAttackAnimation(); protected void EngagePlayerBehavior_TakeAction() => PerformAction();
protected void EngagePlayerBehavior_AcquireTarget() => LookAt(new Vector3(_player.GlobalPosition.X, GlobalPosition.Y, _player.GlobalPosition.Z), Vector3.Up, true); protected void EngagePlayerBehavior_AcquireTarget() => LookAt(new Vector3(_player.GlobalPosition.X, GlobalPosition.Y, _player.GlobalPosition.Z), Vector3.Up, true);

View File

@@ -15,6 +15,7 @@ public abstract partial class EnemyModelView : Node3D, IEnemyModelView
private readonly string _stopWalkName = "Stop Walk"; private readonly string _stopWalkName = "Stop Walk";
private readonly string _primaryAttackName = "Primary Attack"; private readonly string _primaryAttackName = "Primary Attack";
private readonly string _secondaryAttackName = "Secondary Attack"; private readonly string _secondaryAttackName = "Secondary Attack";
private readonly string _primarySkillName = "Primary Skill";
private readonly string _activateName = "Activate"; private readonly string _activateName = "Activate";
private readonly string _activateFront = "activate"; private readonly string _activateFront = "activate";
private readonly string _activateLeft = "activate_left"; private readonly string _activateLeft = "activate_left";
@@ -32,6 +33,8 @@ public abstract partial class EnemyModelView : Node3D, IEnemyModelView
public event EventHandler ActivationFinished; public event EventHandler ActivationFinished;
public event EventHandler TeleportAnimationFinished;
[Export] [Export]
public bool CanMove { get; set; } = false; public bool CanMove { get; set; } = false;
@@ -45,7 +48,7 @@ public abstract partial class EnemyModelView : Node3D, IEnemyModelView
public virtual void PlaySecondaryAttackAnimation() => _stateMachine.Travel(_secondaryAttackName); public virtual void PlaySecondaryAttackAnimation() => _stateMachine.Travel(_secondaryAttackName);
public virtual void PlayPrimarySkillAnimation() => _stateMachine.Travel("Primary Skill"); public virtual void PlayPrimarySkillAnimation() => _stateMachine.Travel(_primarySkillName);
public virtual void PlayIdleAnimation() => _stateMachine.Travel(_idleName); public virtual void PlayIdleAnimation() => _stateMachine.Travel(_idleName);
@@ -65,6 +68,8 @@ public abstract partial class EnemyModelView : Node3D, IEnemyModelView
{ {
if (animName == _activateFront || animName == _activateLeft || animName == _activateRight || animName == _activateBack) if (animName == _activateFront || animName == _activateLeft || animName == _activateRight || animName == _activateBack)
ActivationFinished?.Invoke(this, EventArgs.Empty); ActivationFinished?.Invoke(this, EventArgs.Empty);
if (animName == "teleport")
TeleportAnimationFinished?.Invoke(this, EventArgs.Empty);
} }

View File

@@ -26,4 +26,6 @@ public interface IEnemyModelView : INode3D
public event EventHandler HitPlayer; public event EventHandler HitPlayer;
public event EventHandler ActivationFinished; public event EventHandler ActivationFinished;
public event EventHandler TeleportAnimationFinished;
} }

View File

@@ -1,6 +1,8 @@
using Chickensoft.AutoInject; using Chickensoft.AutoInject;
using Chickensoft.Introspection; using Chickensoft.Introspection;
using Godot; using Godot;
using System;
using System.Collections.Generic;
using Zennysoft.Game.Ma; using Zennysoft.Game.Ma;
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
@@ -8,8 +10,14 @@ public partial class Chinthe : Enemy2D, IHaveEngagePlayerBehavior, IHaveFollowBe
{ {
public override void _Notification(int what) => this.Notify(what); public override void _Notification(int what) => this.Notify(what);
[Export] private float PrimaryAttackChance { get; set; } = 0.7f;
[Export] private float PrimarySkillChance { get; set; } = 0.1f;
[Node] public NavigationAgent3D NavigationAgent { get; set; } [Node] public NavigationAgent3D NavigationAgent { get; set; }
[Node] public FollowBehavior FollowBehavior { get; set; } = default!; [Node] public FollowBehavior FollowBehavior { get; set; } = default!;
[Node] public EngagePlayerBehavior EngagePlayerBehavior { get; set; } = default!; [Node] public EngagePlayerBehavior EngagePlayerBehavior { get; set; } = default!;
[Node] public Area3D PlayerDetector { get; set; } = default!; [Node] public Area3D PlayerDetector { get; set; } = default!;
@@ -17,10 +25,19 @@ public partial class Chinthe : Enemy2D, IHaveEngagePlayerBehavior, IHaveFollowBe
public void OnReady() public void OnReady()
{ {
EnemyModelView.ActivationFinished += EnemyModelView_ActivationFinished; EnemyModelView.ActivationFinished += EnemyModelView_ActivationFinished;
EnemyModelView.TeleportAnimationFinished += Teleport;
SetPhysicsProcess(true); SetPhysicsProcess(true);
} }
private void EnemyModelView_ActivationFinished(object sender, System.EventArgs e) public override void PerformAction()
{
var rng = new RandomNumberGenerator();
var options = new List<Action>() { EnemyModelView.PlayPrimaryAttackAnimation, EnemyModelView.PlayPrimarySkillAnimation };
var selection = rng.RandWeighted([PrimaryAttackChance, PrimarySkillChance]);
options[(int)selection].Invoke();
}
private void EnemyModelView_ActivationFinished(object sender, EventArgs e)
{ {
FollowBehavior.Init(NavigationAgent); FollowBehavior.Init(NavigationAgent);
FollowBehavior.OnVelocityComputed += OnChintheVelocityComputed; FollowBehavior.OnVelocityComputed += OnChintheVelocityComputed;
@@ -43,6 +60,13 @@ public partial class Chinthe : Enemy2D, IHaveEngagePlayerBehavior, IHaveFollowBe
EnemyModelView.PlayIdleAnimation(); EnemyModelView.PlayIdleAnimation();
} }
private void Teleport(object sender, EventArgs e)
{
var targetPosition = _player.GlobalBasis.Z;
var currentDirection = GlobalBasis.Z;
GlobalPosition = GlobalPosition + new Vector3(0, 0, 5 * targetPosition.Z);
}
public void OnChintheVelocityComputed(Vector3 safeVelocity) public void OnChintheVelocityComputed(Vector3 safeVelocity)
{ {
Velocity = safeVelocity; Velocity = safeVelocity;

View File

@@ -35,6 +35,7 @@ axis_lock_angular_x = true
axis_lock_angular_z = true axis_lock_angular_z = true
motion_mode = 1 motion_mode = 1
script = ExtResource("1_120m2") script = ExtResource("1_120m2")
PrimaryAttackChance = 0.9
[node name="CollisionShape" type="CollisionShape3D" parent="."] [node name="CollisionShape" type="CollisionShape3D" parent="."]
unique_name_in_owner = true unique_name_in_owner = true

View File

@@ -1,7 +1,8 @@
[gd_scene load_steps=502 format=3 uid="uid://byd7cwxq1be6f"] [gd_scene load_steps=505 format=3 uid="uid://byd7cwxq1be6f"]
[ext_resource type="Script" uid="uid://cvr1qimxpignl" path="res://src/enemy/EnemyModelView2D.cs" id="1_6dej3"] [ext_resource type="Script" uid="uid://cvr1qimxpignl" path="res://src/enemy/EnemyModelView2D.cs" id="1_6dej3"]
[ext_resource type="Texture2D" uid="uid://dnd6d5cx7x7i8" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0400.png" id="2_3sdh3"] [ext_resource type="Texture2D" uid="uid://dnd6d5cx7x7i8" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0400.png" id="2_3sdh3"]
[ext_resource type="Script" uid="uid://ctshiyffvt4y5" path="res://src/system/AttackDataResource.cs" id="2_keq07"]
[ext_resource type="Texture2D" uid="uid://c0unwba144tls" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0402.png" id="3_dbwem"] [ext_resource type="Texture2D" uid="uid://c0unwba144tls" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0402.png" id="3_dbwem"]
[ext_resource type="Texture2D" uid="uid://ca1im2so1vkym" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0404.png" id="4_y7pe6"] [ext_resource type="Texture2D" uid="uid://ca1im2so1vkym" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0404.png" id="4_y7pe6"]
[ext_resource type="Texture2D" uid="uid://cgnm3v0t63aiw" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0406.png" id="5_xu4hf"] [ext_resource type="Texture2D" uid="uid://cgnm3v0t63aiw" path="res://src/enemy/enemy_types/07. chinthe/animations/CHINTHE - RERENDER/BACK/0406.png" id="5_xu4hf"]
@@ -397,6 +398,12 @@
[ext_resource type="AnimationNodeStateMachine" uid="uid://cy2ngl55c0rws" path="res://src/enemy/animation_state_machines/WalkingStateMachine.tres" id="395_jbhro"] [ext_resource type="AnimationNodeStateMachine" uid="uid://cy2ngl55c0rws" path="res://src/enemy/animation_state_machines/WalkingStateMachine.tres" id="395_jbhro"]
[ext_resource type="Texture2D" uid="uid://c7pf2dib2ilhs" path="res://src/vfx/Enemy/CHINTHE_BLAST.png" id="395_ymova"] [ext_resource type="Texture2D" uid="uid://c7pf2dib2ilhs" path="res://src/vfx/Enemy/CHINTHE_BLAST.png" id="395_ymova"]
[sub_resource type="Resource" id="Resource_w4c47"]
script = ExtResource("2_keq07")
Damage = 10
ElementType = 0
metadata/_custom_type_script = "uid://ctshiyffvt4y5"
[sub_resource type="ViewportTexture" id="ViewportTexture_h1kaf"] [sub_resource type="ViewportTexture" id="ViewportTexture_h1kaf"]
viewport_path = NodePath("Sprite3D/SubViewportContainer/SubViewport") viewport_path = NodePath("Sprite3D/SubViewportContainer/SubViewport")
@@ -3154,7 +3161,7 @@ _data = {
&"teleport in": SubResource("Animation_3sdh3") &"teleport in": SubResource("Animation_3sdh3")
} }
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_op3hf"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_sgkk0"]
animation = &"teleport" animation = &"teleport"
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_jbhro"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_jbhro"]
@@ -3248,6 +3255,9 @@ states/stop_walk_front/node = SubResource("AnimationNodeAnimation_5lbxl")
states/stop_walk_front/position = Vector2(516, 72) states/stop_walk_front/position = Vector2(516, 72)
transitions = ["Start", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_yu6fp"), "stop_walk_front", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_djlpo"), "stop_left_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_t2war"), "stop_walk_front", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_b16jm"), "stop_back_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_d1ogr"), "stop_walk_front", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_7dl50"), "stop_right_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_y2ova"), "stop_back_walk", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_8vs7h"), "stop_right_walk", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_rgja2"), "stop_back_walk", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_syao6"), "stop_left_walk", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_3iqav"), "stop_left_walk", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_ii52r"), "stop_right_walk", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_v8fg0"), "stop_right_walk", "End", SubResource("AnimationNodeStateMachineTransition_r44fx"), "stop_walk_front", "End", SubResource("AnimationNodeStateMachineTransition_dhuhq"), "stop_back_walk", "End", SubResource("AnimationNodeStateMachineTransition_y4bdd"), "stop_left_walk", "End", SubResource("AnimationNodeStateMachineTransition_syb4h")] transitions = ["Start", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_yu6fp"), "stop_walk_front", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_djlpo"), "stop_left_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_t2war"), "stop_walk_front", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_b16jm"), "stop_back_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_d1ogr"), "stop_walk_front", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_7dl50"), "stop_right_walk", "stop_walk_front", SubResource("AnimationNodeStateMachineTransition_y2ova"), "stop_back_walk", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_8vs7h"), "stop_right_walk", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_rgja2"), "stop_back_walk", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_syao6"), "stop_left_walk", "stop_back_walk", SubResource("AnimationNodeStateMachineTransition_3iqav"), "stop_left_walk", "stop_right_walk", SubResource("AnimationNodeStateMachineTransition_ii52r"), "stop_right_walk", "stop_left_walk", SubResource("AnimationNodeStateMachineTransition_v8fg0"), "stop_right_walk", "End", SubResource("AnimationNodeStateMachineTransition_r44fx"), "stop_walk_front", "End", SubResource("AnimationNodeStateMachineTransition_dhuhq"), "stop_back_walk", "End", SubResource("AnimationNodeStateMachineTransition_y4bdd"), "stop_left_walk", "End", SubResource("AnimationNodeStateMachineTransition_syb4h")]
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_li182"]
animation = &"teleport in"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_umemc"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_umemc"]
advance_mode = 2 advance_mode = 2
@@ -3257,12 +3267,6 @@ advance_mode = 2
switch_mode = 2 switch_mode = 2
advance_mode = 2 advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_gr3tp"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ixs6i"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_jbhro"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_jbhro"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_keq07"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_keq07"]
@@ -3273,8 +3277,6 @@ advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_li182"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_li182"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_sgkk0"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_8u7he"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_8u7he"]
reset = false reset = false
switch_mode = 1 switch_mode = 1
@@ -3283,6 +3285,16 @@ switch_mode = 1
switch_mode = 2 switch_mode = 2
advance_mode = 2 advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_manul"]
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_auprl"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_i5vf2"]
switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_nvqie"] [sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_nvqie"]
states/Activate/node = ExtResource("243_5jjkq") states/Activate/node = ExtResource("243_5jjkq")
states/Activate/position = Vector2(583, 100) states/Activate/position = Vector2(583, 100)
@@ -3290,17 +3302,19 @@ states/Idle/node = ExtResource("244_2oumr")
states/Idle/position = Vector2(348, 285) states/Idle/position = Vector2(348, 285)
"states/Primary Attack/node" = ExtResource("394_ldtka") "states/Primary Attack/node" = ExtResource("394_ldtka")
"states/Primary Attack/position" = Vector2(623.437, 285) "states/Primary Attack/position" = Vector2(623.437, 285)
"states/Secondary Attack/node" = SubResource("AnimationNodeAnimation_op3hf") "states/Primary Skill/node" = SubResource("AnimationNodeAnimation_sgkk0")
"states/Secondary Attack/position" = Vector2(583, 404) "states/Primary Skill/position" = Vector2(82.437, 193.144)
states/Start/position = Vector2(199, 100) states/Start/position = Vector2(199, 100)
"states/Stop Walk/node" = SubResource("AnimationNodeStateMachine_8u7he") "states/Stop Walk/node" = SubResource("AnimationNodeStateMachine_8u7he")
"states/Stop Walk/position" = Vector2(132.437, 323.65) "states/Stop Walk/position" = Vector2(132.437, 323.65)
"states/Teleport In/node" = SubResource("AnimationNodeAnimation_li182")
"states/Teleport In/position" = Vector2(-67.563, 254.144)
"states/Unactivated Idle/node" = ExtResource("245_gr3tp") "states/Unactivated Idle/node" = ExtResource("245_gr3tp")
"states/Unactivated Idle/position" = Vector2(357, 100) "states/Unactivated Idle/position" = Vector2(357, 100)
states/Walking/node = ExtResource("395_jbhro") states/Walking/node = ExtResource("395_jbhro")
states/Walking/position = Vector2(348, 398.498) states/Walking/position = Vector2(348, 398.498)
transitions = ["Start", "Unactivated Idle", SubResource("AnimationNodeStateMachineTransition_umemc"), "Unactivated Idle", "Activate", SubResource("AnimationNodeStateMachineTransition_t3xhd"), "Activate", "Idle", SubResource("AnimationNodeStateMachineTransition_5jjkq"), "Idle", "Secondary Attack", SubResource("AnimationNodeStateMachineTransition_gr3tp"), "Secondary Attack", "Idle", SubResource("AnimationNodeStateMachineTransition_ixs6i"), "Idle", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_jbhro"), "Primary Attack", "Idle", SubResource("AnimationNodeStateMachineTransition_keq07"), "Idle", "Walking", SubResource("AnimationNodeStateMachineTransition_w4c47"), "Walking", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_li182"), "Walking", "Secondary Attack", SubResource("AnimationNodeStateMachineTransition_sgkk0"), "Walking", "Stop Walk", SubResource("AnimationNodeStateMachineTransition_8u7he"), "Stop Walk", "Idle", SubResource("AnimationNodeStateMachineTransition_8e7of")] transitions = ["Start", "Unactivated Idle", SubResource("AnimationNodeStateMachineTransition_umemc"), "Unactivated Idle", "Activate", SubResource("AnimationNodeStateMachineTransition_t3xhd"), "Activate", "Idle", SubResource("AnimationNodeStateMachineTransition_5jjkq"), "Idle", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_jbhro"), "Primary Attack", "Idle", SubResource("AnimationNodeStateMachineTransition_keq07"), "Idle", "Walking", SubResource("AnimationNodeStateMachineTransition_w4c47"), "Walking", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_li182"), "Walking", "Stop Walk", SubResource("AnimationNodeStateMachineTransition_8u7he"), "Stop Walk", "Idle", SubResource("AnimationNodeStateMachineTransition_8e7of"), "Idle", "Primary Skill", SubResource("AnimationNodeStateMachineTransition_manul"), "Primary Skill", "Teleport In", SubResource("AnimationNodeStateMachineTransition_auprl"), "Teleport In", "Idle", SubResource("AnimationNodeStateMachineTransition_i5vf2")]
graph_offset = Vector2(-196.563, 209.65) graph_offset = Vector2(-196.563, 38.1444)
[sub_resource type="AtlasTexture" id="AtlasTexture_tawq7"] [sub_resource type="AtlasTexture" id="AtlasTexture_tawq7"]
atlas = ExtResource("395_ymova") atlas = ExtResource("395_ymova")
@@ -3563,6 +3577,7 @@ rings = 8
[node name="EnemyModelView" type="Node3D"] [node name="EnemyModelView" type="Node3D"]
script = ExtResource("1_6dej3") script = ExtResource("1_6dej3")
AttackData = SubResource("Resource_w4c47")
[node name="Sprite3D" type="Sprite3D" parent="."] [node name="Sprite3D" type="Sprite3D" parent="."]
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 0, 0) transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 0, 0)