Refactor more stuff (Audio mostly)
This commit is contained in:
7
Zennysoft.Game.Ma/src/audio/BGMPlayer.cs
Normal file
7
Zennysoft.Game.Ma/src/audio/BGMPlayer.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using Zennysoft.Game.Implementation;
|
||||
|
||||
namespace Zennsoft.Game.Ma;
|
||||
|
||||
public partial class BGMPlayer : DimmableAudioStreamPlayer
|
||||
{
|
||||
}
|
||||
1
Zennysoft.Game.Ma/src/audio/BGMPlayer.cs.uid
Normal file
1
Zennysoft.Game.Ma/src/audio/BGMPlayer.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://d2usinntpmcry
|
||||
@@ -1,58 +0,0 @@
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Godot;
|
||||
|
||||
public interface IDimmableAudioStreamPlayer : IAudioStreamPlayer
|
||||
{
|
||||
/// <summary>Fade this dimmable audio stream track in.</summary>
|
||||
public void FadeIn();
|
||||
/// <summary>Fade this dimmable audio stream track out.</summary>
|
||||
public void FadeOut();
|
||||
}
|
||||
|
||||
public partial class DimmableAudioStreamPlayer :
|
||||
AudioStreamPlayer, IDimmableAudioStreamPlayer
|
||||
{
|
||||
#region Constants
|
||||
// -60 to -80 is considered inaudible for decibels.
|
||||
public const float VOLUME_DB_INAUDIBLE = -80f;
|
||||
public const double FADE_DURATION = 3d; // seconds
|
||||
#endregion Constants
|
||||
|
||||
public ITween? FadeTween { get; set; }
|
||||
|
||||
public float InitialVolumeDb;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
InitialVolumeDb = VolumeDb;
|
||||
VolumeDb = VOLUME_DB_INAUDIBLE;
|
||||
}
|
||||
|
||||
public void FadeIn()
|
||||
{
|
||||
SetupFade(InitialVolumeDb, Tween.EaseType.Out);
|
||||
Play();
|
||||
}
|
||||
|
||||
public void FadeOut()
|
||||
{
|
||||
SetupFade(VOLUME_DB_INAUDIBLE, Tween.EaseType.In);
|
||||
FadeTween!.TweenCallback(Callable.From(Stop));
|
||||
}
|
||||
|
||||
public void SetupFade(float volumeDb, Tween.EaseType ease)
|
||||
{
|
||||
FadeTween?.Kill();
|
||||
|
||||
FadeTween = GodotInterfaces.Adapt<ITween>(CreateTween());
|
||||
|
||||
FadeTween.TweenProperty(
|
||||
this,
|
||||
"volume_db",
|
||||
volumeDb,
|
||||
FADE_DURATION
|
||||
).SetTrans(Tween.TransitionType.Circ).SetEase(ease);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -55,85 +56,85 @@ public partial class InGameAudio : Node
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
InGameAudioLogic = new InGameAudioLogic();
|
||||
InGameAudioLogic = new InGameAudioLogic();
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
InGameAudioLogic.Set(AppRepo);
|
||||
InGameAudioLogic.Set(GameEventDepot);
|
||||
InGameAudioLogic.Set(Player);
|
||||
InGameAudioLogic.Set(GameRepo);
|
||||
InGameAudioLogic.Set(AppRepo);
|
||||
InGameAudioLogic.Set(GameEventDepot);
|
||||
InGameAudioLogic.Set(Player);
|
||||
InGameAudioLogic.Set(GameRepo);
|
||||
|
||||
InGameAudioBinding = InGameAudioLogic.Bind();
|
||||
InGameAudioBinding = InGameAudioLogic.Bind();
|
||||
|
||||
InGameAudioBinding
|
||||
.Handle((in InGameAudioLogic.Output.PlayOverworldMusic _) => StartOverworldMusic())
|
||||
.Handle((in InGameAudioLogic.Output.PlayDungeonThemeAMusic _) => StartDungeonThemeA())
|
||||
.Handle((in InGameAudioLogic.Output.PlayMenuScrollSound _) => PlayMenuScrollSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayEquipSound _) => PlayEquipSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayMenuBackSound _) => PlayMenuBackSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayInventorySortedSound _) => PlayInventorySortedSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayHealingItemSound _) => PlayHealingItemSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayTeleportSound _) => PlayTeleportSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackSound _) => { PlayerAttackSFX.Stop(); PlayerAttackSFX.Play(); })
|
||||
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackWallSound _) => { PlayerAttackWallSFX.Stop(); PlayerAttackWallSFX.Play(); });
|
||||
InGameAudioBinding
|
||||
.Handle((in InGameAudioLogic.Output.PlayOverworldMusic _) => StartOverworldMusic())
|
||||
.Handle((in InGameAudioLogic.Output.PlayDungeonThemeAMusic _) => StartDungeonThemeA())
|
||||
.Handle((in InGameAudioLogic.Output.PlayMenuScrollSound _) => PlayMenuScrollSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayEquipSound _) => PlayEquipSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayMenuBackSound _) => PlayMenuBackSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayInventorySortedSound _) => PlayInventorySortedSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayHealingItemSound _) => PlayHealingItemSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayTeleportSound _) => PlayTeleportSound())
|
||||
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackSound _) => { PlayerAttackSFX.Stop(); PlayerAttackSFX.Play(); })
|
||||
.Handle((in InGameAudioLogic.Output.PlayPlayerAttackWallSound _) => { PlayerAttackWallSFX.Stop(); PlayerAttackWallSFX.Play(); });
|
||||
|
||||
InGameAudioLogic.Start();
|
||||
InGameAudioLogic.Start();
|
||||
}
|
||||
|
||||
public void OnExitTree()
|
||||
{
|
||||
InGameAudioLogic.Stop();
|
||||
InGameAudioBinding.Dispose();
|
||||
InGameAudioLogic.Stop();
|
||||
InGameAudioBinding.Dispose();
|
||||
}
|
||||
|
||||
private void StartOverworldMusic()
|
||||
{
|
||||
OverworldBgm.Stop();
|
||||
OverworldBgm.FadeIn();
|
||||
OverworldBgm.Stop();
|
||||
OverworldBgm.FadeIn();
|
||||
}
|
||||
|
||||
private void StartDungeonThemeA()
|
||||
{
|
||||
OverworldBgm.FadeOut();
|
||||
DungeonThemeABgm.Stop();
|
||||
DungeonThemeABgm.FadeIn();
|
||||
OverworldBgm.FadeOut();
|
||||
DungeonThemeABgm.Stop();
|
||||
DungeonThemeABgm.FadeIn();
|
||||
}
|
||||
|
||||
private void PlayMenuScrollSound()
|
||||
{
|
||||
MenuScrollSFX.Stop();
|
||||
MenuScrollSFX.Play();
|
||||
MenuScrollSFX.Stop();
|
||||
MenuScrollSFX.Play();
|
||||
}
|
||||
|
||||
private void PlayEquipSound()
|
||||
{
|
||||
EquipSFX.Stop();
|
||||
EquipSFX.Play();
|
||||
EquipSFX.Stop();
|
||||
EquipSFX.Play();
|
||||
}
|
||||
|
||||
private void PlayMenuBackSound()
|
||||
{
|
||||
MenuBackSFX.Stop();
|
||||
MenuBackSFX.Play();
|
||||
MenuBackSFX.Stop();
|
||||
MenuBackSFX.Play();
|
||||
}
|
||||
|
||||
private void PlayInventorySortedSound()
|
||||
{
|
||||
InventorySortedSFX.Stop();
|
||||
InventorySortedSFX.Play();
|
||||
InventorySortedSFX.Stop();
|
||||
InventorySortedSFX.Play();
|
||||
}
|
||||
|
||||
private void PlayHealingItemSound()
|
||||
{
|
||||
HealingItemSFX.Stop();
|
||||
HealingItemSFX.Play();
|
||||
HealingItemSFX.Stop();
|
||||
HealingItemSFX.Play();
|
||||
}
|
||||
|
||||
private void PlayTeleportSound()
|
||||
{
|
||||
TeleportSFX.Stop();
|
||||
TeleportSFX.Play();
|
||||
TeleportSFX.Stop();
|
||||
TeleportSFX.Play();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://2mnouyn1jcqs" path="res://src/audio/InGameAudio.cs" id="1_gpmcr"]
|
||||
[ext_resource type="AudioStream" uid="uid://dfu0fksb6slhx" path="res://src/audio/music/droney.mp3" id="2_8hfyr"]
|
||||
[ext_resource type="Script" uid="uid://br4e8xfwd73if" path="res://src/audio/DimmableAudioStreamPlayer.cs" id="2_857rw"]
|
||||
[ext_resource type="AudioStream" uid="uid://d2jrktp06xsba" path="res://src/audio/music/crossing-the-gate.mp3" id="3_wbmd6"]
|
||||
[ext_resource type="Script" path="res://src/audio/BGMPlayer.cs" id="3_wtvpb"]
|
||||
[ext_resource type="AudioStream" uid="uid://dn2e2hqujlia1" path="res://src/audio/music/tar-winds.mp3" id="4_surnl"]
|
||||
[ext_resource type="AudioStream" uid="uid://t3g04u722f2k" path="res://src/audio/music/useless immune system-1.mp3" id="6_agr3r"]
|
||||
[ext_resource type="AudioStream" uid="uid://cn8cugshq3o8k" path="res://src/audio/sfx/PlayerHitWallSFX.wav" id="7_8vh2f"]
|
||||
@@ -19,84 +19,88 @@
|
||||
process_mode = 3
|
||||
script = ExtResource("1_gpmcr")
|
||||
|
||||
[node name="MenuBgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="BGM" type="Node" parent="."]
|
||||
|
||||
[node name="MenuBgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("2_8hfyr")
|
||||
parameters/looping = true
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="OverworldBgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="OverworldBgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("3_wbmd6")
|
||||
volume_db = -15.0
|
||||
parameters/looping = true
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="DungeonThemeABgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="DungeonThemeABgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("4_surnl")
|
||||
volume_db = -15.0
|
||||
parameters/looping = true
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="DungeonThemeBBgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="DungeonThemeBBgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("6_agr3r")
|
||||
volume_db = -15.0
|
||||
parameters/looping = true
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="DungeonThemeCBgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="DungeonThemeCBgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
volume_db = -15.0
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="Title_Bgm" type="AudioStreamPlayer" parent="."]
|
||||
[node name="Title_Bgm" type="AudioStreamPlayer" parent="BGM"]
|
||||
unique_name_in_owner = true
|
||||
volume_db = -15.0
|
||||
script = ExtResource("2_857rw")
|
||||
script = ExtResource("3_wtvpb")
|
||||
|
||||
[node name="PlayerAttackSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="SFX" type="Node" parent="."]
|
||||
|
||||
[node name="PlayerAttackSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("7_wtvpb")
|
||||
volume_db = -5.0
|
||||
|
||||
[node name="PlayerAttackWallSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="PlayerAttackWallSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("7_8vh2f")
|
||||
volume_db = -5.0
|
||||
|
||||
[node name="MenuScrollSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="MenuScrollSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("7_777nl")
|
||||
volume_db = -10.0
|
||||
|
||||
[node name="MenuBackSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="MenuBackSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("8_1xcgo")
|
||||
volume_db = -10.0
|
||||
|
||||
[node name="EquipSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="EquipSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("8_kwybb")
|
||||
volume_db = -10.0
|
||||
|
||||
[node name="HealSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="HealSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("10_3lcw5")
|
||||
volume_db = -10.0
|
||||
|
||||
[node name="TeleportSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="TeleportSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("11_offhc")
|
||||
volume_db = -18.0
|
||||
|
||||
[node name="InventorySortedSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="InventorySortedSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("12_wprjr")
|
||||
volume_db = -15.0
|
||||
|
||||
[node name="HealingItemSFX" type="AudioStreamPlayer" parent="."]
|
||||
[node name="HealingItemSFX" type="AudioStreamPlayer" parent="SFX"]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("10_3lcw5")
|
||||
volume_db = -15.0
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public partial class InGameAudioLogic
|
||||
{
|
||||
public static class Output
|
||||
{
|
||||
#region BGM
|
||||
public readonly record struct PlayOverworldMusic;
|
||||
|
||||
public readonly record struct PlayDungeonThemeAMusic;
|
||||
#endregion
|
||||
|
||||
#region SFX
|
||||
public readonly record struct PlayPlayerAttackSound;
|
||||
|
||||
public readonly record struct PlayPlayerAttackWallSound;
|
||||
|
||||
public readonly record struct PlayMenuScrollSound;
|
||||
|
||||
public readonly record struct PlayEquipSound;
|
||||
|
||||
public readonly record struct PlayInventorySortedSound;
|
||||
|
||||
public readonly record struct PlayMenuBackSound;
|
||||
|
||||
public readonly record struct PlayHealingItemSound;
|
||||
|
||||
public readonly record struct PlayTeleportSound;
|
||||
#endregion
|
||||
|
||||
public readonly record struct PlayGameMusic;
|
||||
|
||||
public readonly record struct StopGameMusic;
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://bfnbplmd35454
|
||||
@@ -1,12 +0,0 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public partial class InGameAudioLogic
|
||||
{
|
||||
[Meta]
|
||||
public partial record State : StateLogic<State>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://c8cfpu81338hk
|
||||
@@ -1,13 +0,0 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
public interface IInGameAudioLogic : ILogicBlock<InGameAudioLogic.State>;
|
||||
|
||||
[Meta]
|
||||
[LogicBlock(typeof(State))]
|
||||
public partial class InGameAudioLogic :
|
||||
LogicBlock<InGameAudioLogic.State>, IInGameAudioLogic
|
||||
{
|
||||
public override Transition GetInitialState() => To<Enabled>();
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://on5thilbaogw
|
||||
@@ -1,11 +0,0 @@
|
||||
using Chickensoft.Introspection;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public partial class InGameAudioLogic
|
||||
{
|
||||
[Meta]
|
||||
public partial record Disabled : State
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://c02hwxip7xksf
|
||||
@@ -1,74 +0,0 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public partial class InGameAudioLogic
|
||||
{
|
||||
[Meta]
|
||||
public partial record Enabled : State
|
||||
{
|
||||
public Enabled()
|
||||
{
|
||||
OnAttach(() =>
|
||||
{
|
||||
var player = Get<IPlayer>();
|
||||
OnOverworldEntered();
|
||||
var gameEventDepot = Get<IGameEventDepot>();
|
||||
var gameRepo = Get<IGameRepo>();
|
||||
gameEventDepot.OverworldEntered += OnOverworldEntered;
|
||||
gameEventDepot.DungeonAThemeAreaEntered += OnDungeonAThemeEntered;
|
||||
gameEventDepot.MenuScrolled += OnMenuScrolled;
|
||||
gameEventDepot.MenuBackedOut += OnMenuBackedOut;
|
||||
player.EquippedWeapon.Changed += OnEquippedItem;
|
||||
player.EquippedArmor.Changed += OnEquippedItem;
|
||||
player.EquippedAccessory.Changed += OnEquippedItem;
|
||||
gameEventDepot.InventorySorted += OnInventorySorted;
|
||||
gameEventDepot.HealingItemConsumed += OnHealingItemConsumed;
|
||||
gameEventDepot.RestorativePickedUp += OnRestorativePickedUp;
|
||||
gameEventDepot.TeleportEntered += OnTeleportEntered;
|
||||
gameRepo.PlayerAttack += OnPlayerAttack;
|
||||
gameRepo.PlayerAttackedWall += OnPlayerAttackWall;
|
||||
});
|
||||
OnDetach(() =>
|
||||
{
|
||||
var gameEventDepot = Get<IGameEventDepot>();
|
||||
var player = Get<IPlayer>();
|
||||
var gameRepo = Get<IGameRepo>();
|
||||
gameEventDepot.OverworldEntered -= OnOverworldEntered;
|
||||
gameEventDepot.DungeonAThemeAreaEntered -= OnDungeonAThemeEntered;
|
||||
gameEventDepot.MenuScrolled -= OnMenuScrolled;
|
||||
gameEventDepot.MenuBackedOut -= OnMenuBackedOut;
|
||||
player.EquippedWeapon.Changed -= OnEquippedItem;
|
||||
player.EquippedArmor.Changed -= OnEquippedItem;
|
||||
player.EquippedAccessory.Changed -= OnEquippedItem;
|
||||
gameEventDepot.InventorySorted -= OnInventorySorted;
|
||||
gameEventDepot.TeleportEntered -= OnTeleportEntered;
|
||||
gameRepo.PlayerAttack -= OnPlayerAttack;
|
||||
gameRepo.PlayerAttackedWall -= OnPlayerAttackWall;
|
||||
});
|
||||
}
|
||||
|
||||
private void OnPlayerAttack() => Output(new Output.PlayPlayerAttackSound());
|
||||
|
||||
private void OnPlayerAttackWall() => Output(new Output.PlayPlayerAttackWallSound());
|
||||
|
||||
private void OnRestorativePickedUp(Restorative restorative) => Output(new Output.PlayHealingItemSound());
|
||||
|
||||
private void OnMenuBackedOut() => Output(new Output.PlayMenuBackSound());
|
||||
|
||||
private void OnHealingItemConsumed(ConsumableItemStats stats) => Output(new Output.PlayHealingItemSound());
|
||||
|
||||
private void OnInventorySorted() => Output(new Output.PlayInventorySortedSound());
|
||||
|
||||
private void OnEquippedItem(EquipableItem equipableItem) => Output(new Output.PlayEquipSound());
|
||||
|
||||
private void OnOverworldEntered() => Output(new Output.PlayOverworldMusic());
|
||||
|
||||
private void OnDungeonAThemeEntered() => Output(new Output.PlayDungeonThemeAMusic());
|
||||
|
||||
private void OnMenuScrolled() => Output(new Output.PlayMenuScrollSound());
|
||||
|
||||
private void OnTeleportEntered() => Output(new Output.PlayTeleportSound());
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://ddvs2b5hjchag
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
_enemyModelView.PlayHitAnimation();
|
||||
_enemyLogic.Input(new EnemyLogic.Input.Alerted());
|
||||
|
||||
if (_player.EquippedWeapon.Value.WeaponTag == WeaponTag.SelfDamage)
|
||||
if (((Weapon)_player.EquippedWeapon.Value).WeaponTag == WeaponTag.SelfDamage)
|
||||
_player.Stats.SetCurrentHP(_player.Stats.CurrentHP.Value - 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -53,8 +53,6 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
[Node] private IPauseMenu PauseMenu { get; set; } = default!;
|
||||
|
||||
[Node] private InGameAudio InGameAudio { get; set; } = default!;
|
||||
|
||||
[Node] private Timer DoubleEXPTimer { get; set; } = default!;
|
||||
|
||||
[Node] private IPlayer Player { get; set; } = default!;
|
||||
@@ -218,7 +216,7 @@ public partial class Game : Node3D, IGame
|
||||
|
||||
DoubleEXPTimer.Timeout += DoubleEXPTimer_Timeout;
|
||||
|
||||
_effectService = new EffectService(this, Player);
|
||||
_effectService = new EffectService(this, Player, Map);
|
||||
}
|
||||
|
||||
public void LoadExistingGame()
|
||||
@@ -401,8 +399,8 @@ public partial class Game : Node3D, IGame
|
||||
GameLogic.Input(new GameLogic.Input.SaveGame());
|
||||
}
|
||||
|
||||
private void GameEventDepot_RestorativePickedUp(Restorative obj)
|
||||
=> Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + obj.VTRestoreAmount);
|
||||
private void GameEventDepot_RestorativePickedUp(IHealthPack obj)
|
||||
=> Player.Stats.SetCurrentVT(Player.Stats.CurrentVT.Value + (int)obj.RestoreAmount);
|
||||
|
||||
private void SetPauseMode(bool isPaused)
|
||||
{
|
||||
|
||||
@@ -1,43 +1,8 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IGameEventDepot : IDisposable
|
||||
{
|
||||
event Action? OverworldEntered;
|
||||
public void OnOverworldEntered();
|
||||
|
||||
event Action? DungeonAThemeAreaEntered;
|
||||
public void OnDungeonAThemeAreaEntered();
|
||||
|
||||
event Action? DungeonBThemeAreaEntered;
|
||||
public void OnDungeonBThemeAreaEntered();
|
||||
|
||||
event Action? DungeonCThemeAreaEntered;
|
||||
public void OnDungeonCThemeAreaEntered();
|
||||
|
||||
event Action? TeleportEntered;
|
||||
public void OnTeleportEntered();
|
||||
|
||||
event Action? MenuScrolled;
|
||||
public void OnMenuScrolled();
|
||||
|
||||
event Action? MenuBackedOut;
|
||||
public void OnMenuBackedOut();
|
||||
|
||||
event Action? InventorySorted;
|
||||
public void OnInventorySorted();
|
||||
|
||||
event Action<ConsumableItemStats>? HealingItemConsumed;
|
||||
public void OnHealingItemConsumed(ConsumableItemStats item);
|
||||
|
||||
event Action<Vector3, EnemyStatResource>? EnemyDefeated;
|
||||
public void OnEnemyDefeated(Vector3 position, EnemyStatResource enemyStatResource);
|
||||
|
||||
event Action<Restorative>? RestorativePickedUp;
|
||||
public void OnRestorativePickedUp(Restorative restorative);
|
||||
}
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
public class GameEventDepot : IGameEventDepot
|
||||
{
|
||||
@@ -52,10 +17,8 @@ public class GameEventDepot : IGameEventDepot
|
||||
public event Action? MenuScrolled;
|
||||
public event Action? MenuBackedOut;
|
||||
public event Action? InventorySorted;
|
||||
public event Action<ConsumableItemStats>? HealingItemConsumed;
|
||||
public event Action<Restorative>? RestorativePickedUp;
|
||||
|
||||
public event Action<Vector3, EnemyStatResource>? EnemyDefeated;
|
||||
public event Action<InventoryItem>? HealingItemConsumed;
|
||||
public event Action<IHealthPack>? RestorativePickedUp;
|
||||
|
||||
public void OnOverworldEntered() => OverworldEntered?.Invoke();
|
||||
public void OnDungeonAThemeAreaEntered() => DungeonAThemeAreaEntered?.Invoke();
|
||||
@@ -68,10 +31,8 @@ public class GameEventDepot : IGameEventDepot
|
||||
public void OnMenuBackedOut() => MenuBackedOut?.Invoke();
|
||||
|
||||
public void OnInventorySorted() => InventorySorted?.Invoke();
|
||||
public void OnHealingItemConsumed(ConsumableItemStats item) => HealingItemConsumed?.Invoke(item);
|
||||
public void OnRestorativePickedUp(Restorative restorative) => RestorativePickedUp?.Invoke(restorative);
|
||||
|
||||
public void OnEnemyDefeated(Vector3 position, EnemyStatResource enemyStatResource) => EnemyDefeated?.Invoke(position, enemyStatResource);
|
||||
public void OnHealingItemConsumed(InventoryItem item) => HealingItemConsumed?.Invoke(item);
|
||||
public void OnRestorativePickedUp(IHealthPack restorative) => RestorativePickedUp?.Invoke(restorative);
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
@@ -89,9 +89,8 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
Player.Stats.CurrentExp.Sync += CurrentExp_Sync;
|
||||
Player.Stats.ExpToNextLevel.Sync += ExpToNextLevel_Sync;
|
||||
Player.Stats.CurrentLevel.Sync += CurrentLevel_Sync;
|
||||
Player.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Player.Stats.BonusAttack.Changed += BonusAttack_Sync;
|
||||
Player.Stats.BonusDefense.Changed += BonusDefense_Sync;
|
||||
|
||||
SetProcessInput(false);
|
||||
}
|
||||
@@ -107,22 +106,16 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
SetProcessInput(true);
|
||||
}
|
||||
|
||||
private void EquippedAccessory_Sync(Accessory obj)
|
||||
private void BonusAttack_Sync(int bonus)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{Player.Stats.BonusAttack.Value:+0;-#;\\.\\.\\.}";
|
||||
ATKBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{Player.Stats.BonusDefense.Value:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
|
||||
private void EquippedArmor_Sync(Armor obj)
|
||||
private void BonusDefense_Sync(int bonus)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{Player.Stats.BonusAttack.Value:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{Player.Stats.BonusDefense.Value:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Sync(Weapon obj)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{Player.Stats.BonusAttack.Value:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{Player.Stats.BonusDefense.Value:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
|
||||
private void CurrentLevel_Sync(int obj) => CurrentLevelLabel.Text = $"Level {obj:D2}";
|
||||
|
||||
@@ -41,77 +41,47 @@ public partial class ItemSlot : HBoxContainer, IItemSlot
|
||||
public void OnReady()
|
||||
{
|
||||
ItemName.Text = Item.ItemName;
|
||||
//EquipBonus.Text = "...";
|
||||
ItemTexture.Texture = Item.GetTexture();
|
||||
Player.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
Player.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
Player.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Player.EquippedWeapon.Sync += EquipableItem_Sync;
|
||||
Player.EquippedArmor.Sync += EquipableItem_Sync;
|
||||
Player.EquippedAccessory.Sync += EquipableItem_Sync;
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Sync(Weapon obj)
|
||||
private void EquipableItem_Sync(EquipableItem obj)
|
||||
{
|
||||
if (Item is Weapon weapon && weapon == obj)
|
||||
if (Item is EquipableItem equipableItem && equipableItem == obj)
|
||||
{
|
||||
//EquipBonus.Text = $"{obj.WeaponStats.Damage:+0;-#;\\.\\.\\.}";
|
||||
SetEquippedSelectedItemStyle();
|
||||
}
|
||||
if (Item is Weapon unequippedItem && unequippedItem != obj)
|
||||
if (Item is EquipableItem unequippedItem && unequippedItem != obj)
|
||||
{
|
||||
//EquipBonus.Text = $"...";
|
||||
SetItemStyle();
|
||||
}
|
||||
}
|
||||
|
||||
private void EquippedArmor_Sync(Armor obj)
|
||||
{
|
||||
if (Item is Armor armor && armor == obj)
|
||||
{
|
||||
//EquipBonus.Text = $"{obj.ArmorStats.Defense:+0;-#;\\.\\.\\.}";
|
||||
SetEquippedSelectedItemStyle();
|
||||
}
|
||||
if (Item is Armor unequippedItem && unequippedItem != obj)
|
||||
{
|
||||
//EquipBonus.Text = $"...";
|
||||
SetItemStyle();
|
||||
}
|
||||
}
|
||||
|
||||
private void EquippedAccessory_Sync(Accessory obj)
|
||||
{
|
||||
if (Item is Accessory accessory && accessory == obj)
|
||||
SetEquippedSelectedItemStyle();
|
||||
if (Item is Accessory unequippedItem && unequippedItem != obj)
|
||||
SetItemStyle();
|
||||
}
|
||||
|
||||
public void SetItemStyle()
|
||||
{
|
||||
ItemName.LabelSettings = ItemFont;
|
||||
//EquipBonus.LabelSettings = ItemFont;
|
||||
}
|
||||
public void SetSelectedItemStyle()
|
||||
{
|
||||
if (Item is EquipableItem equipableItem && equipableItem.IsEquipped)
|
||||
{
|
||||
ItemName.LabelSettings = SelectedEquippedItemFont;
|
||||
//EquipBonus.LabelSettings = EquippedItemFont;
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemName.LabelSettings = SelectedItemFont;
|
||||
//EquipBonus.LabelSettings = SelectedItemFont;
|
||||
}
|
||||
}
|
||||
public void SetEquippedItemStyle()
|
||||
{
|
||||
ItemName.LabelSettings = EquippedItemFont;
|
||||
//EquipBonus.LabelSettings = EquippedItemFont;
|
||||
}
|
||||
|
||||
public void SetEquippedSelectedItemStyle()
|
||||
{
|
||||
ItemName.LabelSettings = SelectedEquippedItemFont;
|
||||
//EquipBonus.LabelSettings = EquippedItemFont;
|
||||
}
|
||||
|
||||
public InventoryItem Item { get; set; } = default!;
|
||||
|
||||
@@ -9,18 +9,20 @@ public class EffectService
|
||||
{
|
||||
private readonly IGame _game;
|
||||
private readonly IPlayer _player;
|
||||
private readonly IMap _map;
|
||||
|
||||
public EffectService(IGame game, IPlayer player)
|
||||
public EffectService(IGame game, IPlayer player, IMap map)
|
||||
{
|
||||
_game = game;
|
||||
_player = player;
|
||||
_map = map;
|
||||
}
|
||||
|
||||
public void TeleportEnemiesToCurrentRoom()
|
||||
{
|
||||
var currentFloor = _game.CurrentFloor;
|
||||
var rooms = currentFloor.Rooms;
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
|
||||
if (currentRoom is not MonsterRoom)
|
||||
return;
|
||||
@@ -44,7 +46,7 @@ public class EffectService
|
||||
|
||||
public void KillHalfEnemiesInRoom()
|
||||
{
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
if (currentRoom is not MonsterRoom)
|
||||
return;
|
||||
|
||||
@@ -57,7 +59,7 @@ public class EffectService
|
||||
|
||||
public void TurnAllEnemiesInRoomIntoHealingItem()
|
||||
{
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
var currentEnemies = currentRoom.EnemiesInRoom;
|
||||
foreach (var enemy in currentEnemies)
|
||||
{
|
||||
@@ -83,7 +85,7 @@ public class EffectService
|
||||
|
||||
public void HealAllEnemiesAndPlayerInRoomToFull()
|
||||
{
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
var currentEnemies = currentRoom.EnemiesInRoom;
|
||||
foreach (var enemy in currentEnemies)
|
||||
enemy.SetCurrentHP(enemy.GetMaximumHP());
|
||||
@@ -92,7 +94,7 @@ public class EffectService
|
||||
|
||||
public void AbsorbHPFromAllEnemiesInRoom()
|
||||
{
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
var currentEnemies = currentRoom.EnemiesInRoom;
|
||||
var hpToAbsorb = 0.0;
|
||||
foreach (var enemy in currentEnemies)
|
||||
@@ -103,7 +105,7 @@ public class EffectService
|
||||
|
||||
public void DealElementalDamageToAllEnemiesInRoom(ElementType elementType)
|
||||
{
|
||||
var currentRoom = _player.GetCurrentRoom();
|
||||
var currentRoom = _map.GetPlayersCurrentRoom();
|
||||
var currentEnemies = currentRoom.EnemiesInRoom;
|
||||
foreach (var enemy in currentEnemies)
|
||||
enemy.TakeDamage(20, elementType);
|
||||
@@ -133,7 +135,7 @@ public class EffectService
|
||||
if (_player.EquippedWeapon.Value.ItemName == string.Empty)
|
||||
return;
|
||||
|
||||
var currentWeapon = _player.EquippedWeapon.Value;
|
||||
var currentWeapon = (Weapon)_player.EquippedWeapon.Value;
|
||||
currentWeapon.IncreaseWeaponAttack(1);
|
||||
}
|
||||
|
||||
@@ -142,7 +144,7 @@ public class EffectService
|
||||
if (_player.EquippedArmor.Value.ItemName == string.Empty)
|
||||
return;
|
||||
|
||||
var currentArmor = _player.EquippedArmor.Value;
|
||||
var currentArmor = (Armor)_player.EquippedArmor.Value;
|
||||
currentArmor.IncreaseArmorDefense(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta, Id("equipable_item")]
|
||||
public abstract partial class EquipableItem : InventoryItem
|
||||
{
|
||||
public abstract ItemTag ItemTag { get; }
|
||||
|
||||
[Save("equipable_item_is_equipped")]
|
||||
public bool IsEquipped { get; set; }
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Restorative : Node3D
|
||||
public partial class Restorative : Node3D, IHealthPack
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
@@ -13,7 +15,7 @@ public partial class Restorative : Node3D
|
||||
|
||||
[Node] public Area3D Pickup { get; set; } = default!;
|
||||
|
||||
public int VTRestoreAmount => 4;
|
||||
public double RestoreAmount => 4;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
|
||||
@@ -11,15 +11,17 @@ namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IMap : INode3D, IProvide<ISaveChunk<MapData>>
|
||||
{
|
||||
public void LoadMap();
|
||||
void LoadMap();
|
||||
|
||||
public List<string> FloorScenes { get; }
|
||||
List<string> FloorScenes { get; }
|
||||
|
||||
public IDungeonFloor CurrentFloor { get; }
|
||||
IDungeonFloor CurrentFloor { get; }
|
||||
|
||||
public void SpawnNextFloor();
|
||||
void SpawnNextFloor();
|
||||
|
||||
public Transform3D GetPlayerSpawnPosition();
|
||||
Transform3D GetPlayerSpawnPosition();
|
||||
|
||||
IDungeonRoom GetPlayersCurrentRoom();
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +97,13 @@ public partial class Map : Node3D, IMap
|
||||
Game.NextFloorLoaded();
|
||||
}
|
||||
|
||||
public IDungeonRoom GetPlayersCurrentRoom()
|
||||
{
|
||||
var rooms = CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
}
|
||||
|
||||
public Transform3D GetPlayerSpawnPosition() => CurrentFloor.GetPlayerSpawnPoint();
|
||||
|
||||
private void LoadFloor()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System.Collections.Immutable;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Abstractions;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerData>>
|
||||
{
|
||||
public void Attack();
|
||||
|
||||
public void PlayerPause();
|
||||
|
||||
public void TakeDamage(double damage, ElementType elementType = ElementType.None, bool isCriticalHit = false);
|
||||
|
||||
public void Knockback(float impulse);
|
||||
|
||||
public void GainExp(double expGained);
|
||||
|
||||
public void LevelUp();
|
||||
|
||||
public void Move(float delta);
|
||||
|
||||
public void TeleportPlayer(Transform3D newTransform);
|
||||
|
||||
public IDungeonRoom GetCurrentRoom();
|
||||
|
||||
public void HealHP(int amount);
|
||||
|
||||
public void RaiseHP(int amount);
|
||||
|
||||
public void HealVT(int amount);
|
||||
|
||||
public void RaiseVT(int amount);
|
||||
|
||||
public void ModifyBonusAttack(int amount);
|
||||
|
||||
public void ModifyBonusDefense(int amount);
|
||||
|
||||
public void ModifyMaximumHP(int amount);
|
||||
|
||||
public void ModifyMaximumVT(int amount);
|
||||
|
||||
public void ModifyBonusLuck(double amount);
|
||||
|
||||
public IInventory Inventory { get; }
|
||||
|
||||
public PlayerStatController Stats { get; }
|
||||
|
||||
public Vector3 CurrentPosition { get; }
|
||||
|
||||
public Basis CurrentBasis { get; }
|
||||
|
||||
public IAutoProp<Weapon> EquippedWeapon { get; }
|
||||
|
||||
public IAutoProp<Armor> EquippedArmor { get; }
|
||||
|
||||
public IAutoProp<Accessory> EquippedAccessory { get; }
|
||||
|
||||
public void Equip(EquipableItem equipable);
|
||||
|
||||
public void Unequip(EquipableItem equipable);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
@@ -13,7 +13,7 @@ using Zennysoft.Ma.Adapter;
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class Player : CharacterBody3D, IPlayer
|
||||
public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<PlayerData>>
|
||||
{
|
||||
#region Dependency Injection
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
@@ -36,14 +36,14 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
|
||||
public IInventory Inventory { get; private set; } = default!;
|
||||
|
||||
public IAutoProp<Weapon> EquippedWeapon => _equippedWeapon;
|
||||
private AutoProp<Weapon> _equippedWeapon { get; set; } = new AutoProp<Weapon>(new Weapon());
|
||||
public IAutoProp<EquipableItem> EquippedWeapon => _equippedWeapon;
|
||||
private AutoProp<EquipableItem> _equippedWeapon { get; set; } = new AutoProp<EquipableItem>(new Weapon());
|
||||
|
||||
public IAutoProp<Armor> EquippedArmor => _equippedArmor;
|
||||
private AutoProp<Armor> _equippedArmor { get; set; } = new AutoProp<Armor>(new Armor());
|
||||
public IAutoProp<EquipableItem> EquippedArmor => _equippedArmor;
|
||||
private AutoProp<EquipableItem> _equippedArmor { get; set; } = new AutoProp<EquipableItem>(new Armor());
|
||||
|
||||
public IAutoProp<Accessory> EquippedAccessory => _equippedAccessory;
|
||||
private AutoProp<Accessory> _equippedAccessory { get; set; } = new AutoProp<Accessory>(new Accessory());
|
||||
public IAutoProp<EquipableItem> EquippedAccessory => _equippedAccessory;
|
||||
private AutoProp<EquipableItem> _equippedAccessory { get; set; } = new AutoProp<EquipableItem>(new Accessory());
|
||||
|
||||
private PlayerLogic.Settings Settings { get; set; } = default!;
|
||||
|
||||
@@ -106,513 +106,506 @@ public partial class Player : CharacterBody3D, IPlayer
|
||||
#region Initialization
|
||||
public void Initialize()
|
||||
{
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
_expToNextLevel = new Dictionary<int, int>
|
||||
{
|
||||
{ 2, 12 },
|
||||
{ 3, 39 },
|
||||
{ 4, 87 },
|
||||
{ 5, 162 },
|
||||
{ 6, 270 },
|
||||
{ 7, 417 },
|
||||
{ 8, 609 }
|
||||
};
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
_expToNextLevel = new Dictionary<int, int>
|
||||
{
|
||||
{ 2, 12 },
|
||||
{ 3, 39 },
|
||||
{ 4, 87 },
|
||||
{ 5, 162 },
|
||||
{ 6, 270 },
|
||||
{ 7, 417 },
|
||||
{ 8, 609 }
|
||||
};
|
||||
}
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
var container = new SimpleInjector.Container();
|
||||
container.Register<IPlayerLogic, PlayerLogic>(Lifestyle.Singleton);
|
||||
container.Verify();
|
||||
var container = new SimpleInjector.Container();
|
||||
container.Register<IPlayerLogic, PlayerLogic>(Lifestyle.Singleton);
|
||||
container.Verify();
|
||||
|
||||
Settings = new PlayerLogic.Settings() { RotationSpeed = PlayerStatResource.RotationSpeed, MoveSpeed = PlayerStatResource.MoveSpeed, Acceleration = PlayerStatResource.Acceleration };
|
||||
Stats = new PlayerStatController();
|
||||
Stats.Init(
|
||||
new PlayerStats
|
||||
{
|
||||
CurrentHP = PlayerStatResource.CurrentHP,
|
||||
MaximumHP = PlayerStatResource.MaximumHP,
|
||||
CurrentVT = PlayerStatResource.CurrentVT,
|
||||
MaximumVT = PlayerStatResource.MaximumVT,
|
||||
CurrentAttack = PlayerStatResource.CurrentAttack,
|
||||
BonusAttack = PlayerStatResource.BonusAttack,
|
||||
MaxAttack = PlayerStatResource.MaxAttack,
|
||||
CurrentDefense = PlayerStatResource.CurrentDefense,
|
||||
BonusDefense = PlayerStatResource.BonusDefense,
|
||||
MaxDefense = PlayerStatResource.MaxDefense,
|
||||
CurrentExp = PlayerStatResource.CurrentExp,
|
||||
CurrentLevel = PlayerStatResource.CurrentLevel,
|
||||
ExpToNextLevel = PlayerStatResource.ExpToNextLevel,
|
||||
Luck = PlayerStatResource.Luck
|
||||
});
|
||||
Settings = new PlayerLogic.Settings() { RotationSpeed = PlayerStatResource.RotationSpeed, MoveSpeed = PlayerStatResource.MoveSpeed, Acceleration = PlayerStatResource.Acceleration };
|
||||
Stats = new PlayerStatController();
|
||||
Stats.Init(
|
||||
new PlayerStats
|
||||
{
|
||||
CurrentHP = PlayerStatResource.CurrentHP,
|
||||
MaximumHP = PlayerStatResource.MaximumHP,
|
||||
CurrentVT = PlayerStatResource.CurrentVT,
|
||||
MaximumVT = PlayerStatResource.MaximumVT,
|
||||
CurrentAttack = PlayerStatResource.CurrentAttack,
|
||||
BonusAttack = PlayerStatResource.BonusAttack,
|
||||
MaxAttack = PlayerStatResource.MaxAttack,
|
||||
CurrentDefense = PlayerStatResource.CurrentDefense,
|
||||
BonusDefense = PlayerStatResource.BonusDefense,
|
||||
MaxDefense = PlayerStatResource.MaxDefense,
|
||||
CurrentExp = PlayerStatResource.CurrentExp,
|
||||
CurrentLevel = PlayerStatResource.CurrentLevel,
|
||||
ExpToNextLevel = PlayerStatResource.ExpToNextLevel,
|
||||
Luck = PlayerStatResource.Luck
|
||||
});
|
||||
|
||||
Inventory = new Inventory();
|
||||
Inventory = new Inventory();
|
||||
|
||||
PlayerLogic = container.GetInstance<IPlayerLogic>();
|
||||
PlayerLogic.Set(this as IPlayer);
|
||||
PlayerLogic.Set(Settings);
|
||||
PlayerLogic.Set(Stats);
|
||||
PlayerLogic.Set(_gameRepo);
|
||||
PlayerLogic = container.GetInstance<IPlayerLogic>();
|
||||
PlayerLogic.Set(this as IPlayer);
|
||||
PlayerLogic.Set(Settings);
|
||||
PlayerLogic.Set(Stats);
|
||||
PlayerLogic.Set(_gameRepo);
|
||||
|
||||
var defaultWeapon = new Weapon();
|
||||
defaultWeapon.Stats = _defaultWeapon;
|
||||
var defaultArmor = new Armor();
|
||||
defaultArmor.Stats = _defaultArmor;
|
||||
Inventory.TryAdd(defaultWeapon);
|
||||
Inventory.TryAdd(defaultArmor);
|
||||
var defaultWeapon = new Weapon();
|
||||
defaultWeapon.Stats = _defaultWeapon;
|
||||
var defaultArmor = new Armor();
|
||||
defaultArmor.Stats = _defaultArmor;
|
||||
Inventory.TryAdd(defaultWeapon);
|
||||
Inventory.TryAdd(defaultArmor);
|
||||
|
||||
EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Stats.CurrentHP.Sync += CurrentHP_Sync;
|
||||
Stats.CurrentExp.Sync += CurrentEXP_Sync;
|
||||
EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
Stats.CurrentHP.Sync += CurrentHP_Sync;
|
||||
Stats.CurrentExp.Sync += CurrentEXP_Sync;
|
||||
|
||||
Equip(defaultWeapon);
|
||||
Equip(defaultArmor);
|
||||
Equip(defaultWeapon);
|
||||
Equip(defaultArmor);
|
||||
|
||||
HealthTimer.WaitTime = _healthTimerWaitTime;
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
CollisionDetector.AreaEntered += CollisionDetector_AreaEntered;
|
||||
HealthTimer.WaitTime = _healthTimerWaitTime;
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||
CollisionDetector.AreaEntered += CollisionDetector_AreaEntered;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
PlayerChunk = new SaveChunk<PlayerData>(
|
||||
onSave: (chunk) => new PlayerData()
|
||||
{
|
||||
PlayerStats = new PlayerStats()
|
||||
{
|
||||
CurrentHP = Stats.CurrentHP.Value,
|
||||
MaximumHP = Stats.MaximumHP.Value,
|
||||
CurrentVT = Stats.CurrentVT.Value,
|
||||
MaximumVT = Stats.MaximumVT.Value,
|
||||
CurrentAttack = Stats.CurrentAttack.Value,
|
||||
BonusAttack = Stats.BonusAttack.Value,
|
||||
MaxAttack = Stats.MaxAttack.Value,
|
||||
CurrentDefense = Stats.CurrentDefense.Value,
|
||||
BonusDefense = Stats.BonusDefense.Value,
|
||||
MaxDefense = Stats.MaxDefense.Value,
|
||||
CurrentExp = Stats.CurrentExp.Value,
|
||||
CurrentLevel = Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Stats.ExpToNextLevel.Value,
|
||||
Luck = Stats.Luck.Value
|
||||
},
|
||||
Inventory = Inventory
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
Stats.Init(data.PlayerStats);
|
||||
Inventory = data.Inventory;
|
||||
}
|
||||
);
|
||||
PlayerChunk = new SaveChunk<PlayerData>(
|
||||
onSave: (chunk) => new PlayerData()
|
||||
{
|
||||
PlayerStats = new PlayerStats()
|
||||
{
|
||||
CurrentHP = Stats.CurrentHP.Value,
|
||||
MaximumHP = Stats.MaximumHP.Value,
|
||||
CurrentVT = Stats.CurrentVT.Value,
|
||||
MaximumVT = Stats.MaximumVT.Value,
|
||||
CurrentAttack = Stats.CurrentAttack.Value,
|
||||
BonusAttack = Stats.BonusAttack.Value,
|
||||
MaxAttack = Stats.MaxAttack.Value,
|
||||
CurrentDefense = Stats.CurrentDefense.Value,
|
||||
BonusDefense = Stats.BonusDefense.Value,
|
||||
MaxDefense = Stats.MaxDefense.Value,
|
||||
CurrentExp = Stats.CurrentExp.Value,
|
||||
CurrentLevel = Stats.CurrentLevel.Value,
|
||||
ExpToNextLevel = Stats.ExpToNextLevel.Value,
|
||||
Luck = Stats.Luck.Value
|
||||
},
|
||||
Inventory = Inventory
|
||||
},
|
||||
onLoad: (chunk, data) =>
|
||||
{
|
||||
Stats.Init(data.PlayerStats);
|
||||
Inventory = data.Inventory;
|
||||
}
|
||||
);
|
||||
|
||||
PlayerBinding = PlayerLogic.Bind();
|
||||
PlayerBinding = PlayerLogic.Bind();
|
||||
|
||||
PlayerBinding
|
||||
.Handle((in PlayerLogic.Output.Animations.Attack output) =>
|
||||
{
|
||||
if (PlayerIsHittingGeometry())
|
||||
{
|
||||
AnimationPlayer.Play("hit_wall");
|
||||
_gameRepo.OnPlayerAttackedWall();
|
||||
}
|
||||
else
|
||||
{
|
||||
var attackSpeed = EquippedWeapon.Value.AttackSpeed;
|
||||
AnimationPlayer.SetSpeedScale((float)attackSpeed);
|
||||
AnimationPlayer.Play("attack");
|
||||
_gameRepo.OnPlayerAttack();
|
||||
}
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||
{
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.Move output) =>
|
||||
{
|
||||
Move(output.delta);
|
||||
});
|
||||
PlayerBinding
|
||||
.Handle((in PlayerLogic.Output.Animations.Attack output) =>
|
||||
{
|
||||
if (PlayerIsHittingGeometry())
|
||||
{
|
||||
AnimationPlayer.Play("hit_wall");
|
||||
_gameRepo.OnPlayerAttackedWall();
|
||||
}
|
||||
else
|
||||
{
|
||||
var attackSpeed = ((Weapon)EquippedWeapon.Value).AttackSpeed;
|
||||
AnimationPlayer.SetSpeedScale((float)attackSpeed);
|
||||
AnimationPlayer.Play("attack");
|
||||
_gameRepo.OnPlayerAttack();
|
||||
}
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||
{
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.Move output) =>
|
||||
{
|
||||
Move(output.delta);
|
||||
});
|
||||
|
||||
GameChunk.AddChunk(PlayerChunk);
|
||||
GameChunk.AddChunk(PlayerChunk);
|
||||
|
||||
PlayerLogic.Start();
|
||||
this.Provide();
|
||||
PlayerLogic.Start();
|
||||
this.Provide();
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
SetPhysicsProcess(true);
|
||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void Attack()
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Attack());
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Attack());
|
||||
}
|
||||
|
||||
public void PlayerPause()
|
||||
{
|
||||
Game.TogglePause();
|
||||
}
|
||||
|
||||
public IDungeonRoom GetCurrentRoom()
|
||||
{
|
||||
var rooms = Game.CurrentFloor.Rooms;
|
||||
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
|
||||
return playersRoom;
|
||||
Game.TogglePause();
|
||||
}
|
||||
|
||||
public void RaiseHP(int amountToRaise)
|
||||
{
|
||||
Stats.SetMaximumHP(Stats.MaximumHP.Value + amountToRaise);
|
||||
Stats.SetCurrentHP(Stats.MaximumHP.Value);
|
||||
_gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXHP Up.");
|
||||
Stats.SetMaximumHP(Stats.MaximumHP.Value + amountToRaise);
|
||||
Stats.SetCurrentHP(Stats.MaximumHP.Value);
|
||||
_gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXHP Up.");
|
||||
}
|
||||
|
||||
public void HealHP(int amountToRestore)
|
||||
{
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
_gameRepo.AnnounceMessageInInventory($"{raiseString}HP Restored.");
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
_gameRepo.AnnounceMessageInInventory($"{raiseString}HP Restored.");
|
||||
}
|
||||
|
||||
public void RaiseVT(int amountToRaise)
|
||||
{
|
||||
if (Stats.CurrentVT == Stats.MaximumVT)
|
||||
{
|
||||
Stats.SetMaximumVT(Stats.MaximumVT.Value + amountToRaise);
|
||||
Stats.SetCurrentVT(Stats.MaximumVT.Value);
|
||||
_gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXVT Up.");
|
||||
}
|
||||
if (Stats.CurrentVT == Stats.MaximumVT)
|
||||
{
|
||||
Stats.SetMaximumVT(Stats.MaximumVT.Value + amountToRaise);
|
||||
Stats.SetCurrentVT(Stats.MaximumVT.Value);
|
||||
_gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXVT Up.");
|
||||
}
|
||||
}
|
||||
|
||||
public void HealVT(int amountToRestore)
|
||||
{
|
||||
Stats.SetCurrentVT(Stats.CurrentVT.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
_gameRepo.AnnounceMessageInInventory($"{raiseString}VT Restored.");
|
||||
Stats.SetCurrentVT(Stats.CurrentVT.Value + amountToRestore);
|
||||
var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}";
|
||||
_gameRepo.AnnounceMessageInInventory($"{raiseString}VT Restored.");
|
||||
}
|
||||
|
||||
public void ModifyBonusAttack(int amount)
|
||||
{
|
||||
Stats.SetBonusAttack(Stats.BonusAttack.Value + amount);
|
||||
Stats.SetBonusAttack(Stats.BonusAttack.Value + amount);
|
||||
}
|
||||
|
||||
public void ModifyBonusDefense(int amount)
|
||||
{
|
||||
Stats.SetBonusDefense(Stats.BonusDefense.Value + amount);
|
||||
Stats.SetBonusDefense(Stats.BonusDefense.Value + amount);
|
||||
}
|
||||
|
||||
public void ModifyMaximumHP(int amount)
|
||||
{
|
||||
Stats.SetMaximumHP(Stats.MaximumHP.Value + amount);
|
||||
Stats.SetMaximumHP(Stats.MaximumHP.Value + amount);
|
||||
}
|
||||
|
||||
public void ModifyMaximumVT(int amount)
|
||||
{
|
||||
Stats.SetMaximumVT(Stats.MaximumVT.Value + amount);
|
||||
Stats.SetMaximumVT(Stats.MaximumVT.Value + amount);
|
||||
}
|
||||
|
||||
public void ModifyBonusLuck(double amount)
|
||||
{
|
||||
Stats.SetLuck(Stats.Luck.Value + amount);
|
||||
Stats.SetLuck(Stats.Luck.Value + amount);
|
||||
}
|
||||
|
||||
public void Move(float delta)
|
||||
{
|
||||
var rawInput = GlobalInputVector;
|
||||
var strafeLeftInput = LeftStrafeInputVector;
|
||||
var strafeRightInput = RightStrafeInputVector;
|
||||
var rawInput = GlobalInputVector;
|
||||
var strafeLeftInput = LeftStrafeInputVector;
|
||||
var strafeRightInput = RightStrafeInputVector;
|
||||
|
||||
var transform = Transform;
|
||||
transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis;
|
||||
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized();
|
||||
var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration;
|
||||
_knockbackStrength = _knockbackStrength * 0.9f;
|
||||
Transform = Transform with { Basis = transform.Basis };
|
||||
Velocity = velocity + (_knockbackDirection * _knockbackStrength);
|
||||
MoveAndSlide();
|
||||
var transform = Transform;
|
||||
transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis;
|
||||
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized();
|
||||
var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration;
|
||||
_knockbackStrength = _knockbackStrength * 0.9f;
|
||||
Transform = Transform with { Basis = transform.Basis };
|
||||
Velocity = velocity + (_knockbackDirection * _knockbackStrength);
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void TeleportPlayer(Transform3D newTransform)
|
||||
{
|
||||
Transform = newTransform;
|
||||
Transform = newTransform;
|
||||
}
|
||||
|
||||
public void TakeDamage(double damage, ElementType elementType, bool isCriticalHit = false)
|
||||
{
|
||||
if (Stats.CurrentHP.Value > 0)
|
||||
{
|
||||
damage = CalculateDefenseResistance(damage);
|
||||
if (isCriticalHit)
|
||||
damage *= 2;
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value - (int)damage);
|
||||
}
|
||||
if (Stats.CurrentHP.Value > 0)
|
||||
{
|
||||
damage = CalculateDefenseResistance(damage);
|
||||
if (isCriticalHit)
|
||||
damage *= 2;
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value - (int)damage);
|
||||
}
|
||||
}
|
||||
|
||||
public void Knockback(float impulse)
|
||||
{
|
||||
_knockbackStrength = impulse;
|
||||
_knockbackDirection = GlobalBasis.Z.Normalized();
|
||||
_knockbackStrength = impulse;
|
||||
_knockbackDirection = GlobalBasis.Z.Normalized();
|
||||
}
|
||||
|
||||
public void GainExp(double expGained)
|
||||
{
|
||||
Stats.SetCurrentExp(Stats.CurrentExp.Value + expGained);
|
||||
Stats.SetCurrentExp(Stats.CurrentExp.Value + expGained);
|
||||
}
|
||||
|
||||
public void LevelUp()
|
||||
{
|
||||
var nextLevel = Stats.CurrentLevel.Value + 1;
|
||||
var expToNextLevel = _expToNextLevel[nextLevel];
|
||||
var newCurrentExp = Mathf.Max(Stats.CurrentExp.Value - Stats.ExpToNextLevel.Value, 0);
|
||||
Stats.SetCurrentLevel(nextLevel);
|
||||
Stats.SetExpToNextLevel(expToNextLevel);
|
||||
Stats.SetCurrentExp(newCurrentExp);
|
||||
var nextLevel = Stats.CurrentLevel.Value + 1;
|
||||
var expToNextLevel = _expToNextLevel[nextLevel];
|
||||
var newCurrentExp = Mathf.Max(Stats.CurrentExp.Value - Stats.ExpToNextLevel.Value, 0);
|
||||
Stats.SetCurrentLevel(nextLevel);
|
||||
Stats.SetExpToNextLevel(expToNextLevel);
|
||||
Stats.SetCurrentExp(newCurrentExp);
|
||||
}
|
||||
|
||||
public void Die() => PlayerLogic.Input(new PlayerLogic.Input.Die());
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed(GameInputs.Pause))
|
||||
PlayerPause();
|
||||
if (@event.IsActionPressed(GameInputs.Pause))
|
||||
PlayerPause();
|
||||
|
||||
if (@event.IsActionPressed(GameInputs.Attack))
|
||||
Attack();
|
||||
if (@event.IsActionPressed(GameInputs.Attack))
|
||||
Attack();
|
||||
}
|
||||
|
||||
public void OnPhysicsProcess(double delta)
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform));
|
||||
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform));
|
||||
}
|
||||
|
||||
public void Equip(EquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
Unequip(_equippedWeapon.Value);
|
||||
weapon.IsEquipped = true;
|
||||
_equippedWeapon.OnNext(weapon);
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
Unequip(_equippedArmor.Value);
|
||||
armor.IsEquipped = true;
|
||||
_equippedArmor.OnNext(armor);
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
Unequip(_equippedAccessory.Value);
|
||||
accessory.IsEquipped = true;
|
||||
_equippedAccessory.OnNext(accessory);
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
Unequip(_equippedWeapon.Value);
|
||||
weapon.IsEquipped = true;
|
||||
_equippedWeapon.OnNext(weapon);
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
Unequip(_equippedArmor.Value);
|
||||
armor.IsEquipped = true;
|
||||
_equippedArmor.OnNext(armor);
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
Unequip(_equippedAccessory.Value);
|
||||
accessory.IsEquipped = true;
|
||||
_equippedAccessory.OnNext(accessory);
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
}
|
||||
|
||||
public void Unequip(EquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
weapon.IsEquipped = false;
|
||||
ModifyBonusAttack(-weapon.Damage);
|
||||
_equippedWeapon.OnNext(new Weapon());
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
armor.IsEquipped = false;
|
||||
ModifyBonusDefense(-armor.Defense);
|
||||
_equippedArmor.OnNext(new Armor());
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
accessory.IsEquipped = false;
|
||||
ModifyMaximumHP(-accessory.MaxHPUp);
|
||||
ModifyMaximumVT(-accessory.MaxVTUp);
|
||||
ModifyBonusAttack(-accessory.ATKUp);
|
||||
ModifyBonusDefense(-accessory.DEFUp);
|
||||
ModifyBonusLuck(-accessory.LuckUp);
|
||||
_equippedAccessory.OnNext(new Accessory());
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
weapon.IsEquipped = false;
|
||||
ModifyBonusAttack(-weapon.Damage);
|
||||
_equippedWeapon.OnNext(new Weapon());
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
armor.IsEquipped = false;
|
||||
ModifyBonusDefense(-armor.Defense);
|
||||
_equippedArmor.OnNext(new Armor());
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
accessory.IsEquipped = false;
|
||||
ModifyMaximumHP(-accessory.MaxHPUp);
|
||||
ModifyMaximumVT(-accessory.MaxVTUp);
|
||||
ModifyBonusAttack(-accessory.ATKUp);
|
||||
ModifyBonusDefense(-accessory.DEFUp);
|
||||
ModifyBonusLuck(-accessory.LuckUp);
|
||||
_equippedAccessory.OnNext(new Accessory());
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
|
||||
if (equipable.ItemTag == ItemTag.BreaksOnChange)
|
||||
Inventory.Remove(equipable);
|
||||
if (equipable.ItemTag == ItemTag.BreaksOnChange)
|
||||
Inventory.Remove(equipable);
|
||||
}
|
||||
|
||||
private static Vector3 GlobalInputVector
|
||||
{
|
||||
get
|
||||
{
|
||||
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
||||
var input = new Vector3
|
||||
{
|
||||
X = rawInput.X,
|
||||
Z = rawInput.Y
|
||||
};
|
||||
return input with { Y = 0f };
|
||||
}
|
||||
get
|
||||
{
|
||||
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
||||
var input = new Vector3
|
||||
{
|
||||
X = rawInput.X,
|
||||
Z = rawInput.Y
|
||||
};
|
||||
return input with { Y = 0f };
|
||||
}
|
||||
}
|
||||
|
||||
private static float LeftStrafeInputVector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.GetActionStrength(GameInputs.StrafeLeft);
|
||||
}
|
||||
get
|
||||
{
|
||||
return Input.GetActionStrength(GameInputs.StrafeLeft);
|
||||
}
|
||||
}
|
||||
|
||||
private static float RightStrafeInputVector
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.GetActionStrength(GameInputs.StrafeRight);
|
||||
}
|
||||
get
|
||||
{
|
||||
return Input.GetActionStrength(GameInputs.StrafeRight);
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowItem()
|
||||
{
|
||||
var itemScene = GD.Load<PackedScene>("res://src/items/throwable/ThrowableItem.tscn");
|
||||
var throwItem = itemScene.Instantiate<ThrowableItem>();
|
||||
GetTree().Root.AddChildEx(throwItem);
|
||||
throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0);
|
||||
throwItem.GlobalRotation = GlobalRotation;
|
||||
var itemScene = GD.Load<PackedScene>("res://src/items/throwable/ThrowableItem.tscn");
|
||||
var throwItem = itemScene.Instantiate<ThrowableItem>();
|
||||
GetTree().Root.AddChildEx(throwItem);
|
||||
throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0);
|
||||
throwItem.GlobalRotation = GlobalRotation;
|
||||
}
|
||||
|
||||
private void OnAnimationFinished(StringName animation)
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
|
||||
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
|
||||
}
|
||||
|
||||
private void OnExitTree()
|
||||
{
|
||||
PlayerLogic.Stop();
|
||||
PlayerBinding.Dispose();
|
||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||
PlayerLogic.Stop();
|
||||
PlayerBinding.Dispose();
|
||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (Stats.CurrentHP.Value <= 0)
|
||||
return;
|
||||
if (Stats.CurrentHP.Value <= 0)
|
||||
return;
|
||||
|
||||
if (Stats.CurrentVT.Value > 0)
|
||||
{
|
||||
if (EquippedAccessory.Value.AccessoryTag == AccessoryTag.HalfVTConsumption)
|
||||
{
|
||||
reduceOnTick = !reduceOnTick;
|
||||
}
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value + 1);
|
||||
if (reduceOnTick)
|
||||
Stats.SetCurrentVT(Stats.CurrentVT.Value - 1);
|
||||
}
|
||||
else
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value - 1);
|
||||
if (Stats.CurrentVT.Value > 0)
|
||||
{
|
||||
if (((Accessory)EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption)
|
||||
{
|
||||
reduceOnTick = !reduceOnTick;
|
||||
}
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value + 1);
|
||||
if (reduceOnTick)
|
||||
Stats.SetCurrentVT(Stats.CurrentVT.Value - 1);
|
||||
}
|
||||
else
|
||||
Stats.SetCurrentHP(Stats.CurrentHP.Value - 1);
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Sync(Weapon obj)
|
||||
private void EquippedWeapon_Sync(EquipableItem obj)
|
||||
{
|
||||
ModifyBonusAttack(obj.Damage);
|
||||
ModifyBonusAttack(((Weapon)obj).Damage);
|
||||
}
|
||||
|
||||
private void EquippedArmor_Sync(Armor obj)
|
||||
private void EquippedArmor_Sync(EquipableItem obj)
|
||||
{
|
||||
ModifyBonusDefense(obj.Defense);
|
||||
ModifyBonusDefense(((Armor)obj).Defense);
|
||||
}
|
||||
|
||||
private void EquippedAccessory_Sync(Accessory accessory)
|
||||
private void EquippedAccessory_Sync(EquipableItem accessory)
|
||||
{
|
||||
ModifyMaximumHP(accessory.MaxHPUp);
|
||||
ModifyMaximumVT(accessory.MaxVTUp);
|
||||
ModifyBonusAttack(accessory.ATKUp);
|
||||
ModifyBonusDefense(accessory.DEFUp);
|
||||
ModifyBonusLuck(accessory.LuckUp);
|
||||
ModifyMaximumHP(((Accessory)accessory).MaxHPUp);
|
||||
ModifyMaximumVT(((Accessory)accessory).MaxVTUp);
|
||||
ModifyBonusAttack(((Accessory)accessory).ATKUp);
|
||||
ModifyBonusDefense(((Accessory)accessory).DEFUp);
|
||||
ModifyBonusLuck(((Accessory)accessory).LuckUp);
|
||||
}
|
||||
|
||||
private void CurrentHP_Sync(int newHealth)
|
||||
{
|
||||
if (newHealth <= 0)
|
||||
Die();
|
||||
if (newHealth <= 0)
|
||||
Die();
|
||||
}
|
||||
|
||||
private void CurrentEXP_Sync(double newExp)
|
||||
{
|
||||
if (Stats.CurrentExp.Value >= Stats.ExpToNextLevel.Value)
|
||||
LevelUp();
|
||||
if (Stats.CurrentExp.Value >= Stats.ExpToNextLevel.Value)
|
||||
LevelUp();
|
||||
}
|
||||
|
||||
private double CalculateDefenseResistance(double incomingDamage)
|
||||
{
|
||||
return Mathf.Max(incomingDamage - Stats.CurrentDefense.Value - Stats.BonusDefense.Value, 0.0);
|
||||
return Mathf.Max(incomingDamage - Stats.CurrentDefense.Value - Stats.BonusDefense.Value, 0.0);
|
||||
}
|
||||
|
||||
private void Hitbox_AreaEntered(Area3D area)
|
||||
{
|
||||
var target = area.GetOwner();
|
||||
if (target is IEnemy enemy)
|
||||
HitEnemy(enemy);
|
||||
var target = area.GetOwner();
|
||||
if (target is IEnemy enemy)
|
||||
HitEnemy(enemy);
|
||||
}
|
||||
|
||||
private void HitEnemy(IEnemy enemy)
|
||||
{
|
||||
var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value;
|
||||
var ignoreElementalResistance = EquippedWeapon.Value.WeaponTag == WeaponTag.IgnoreAffinity;
|
||||
var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value);
|
||||
var element = EquippedWeapon.Value.WeaponElement;
|
||||
var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value;
|
||||
var ignoreElementalResistance = ((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.IgnoreAffinity;
|
||||
var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value);
|
||||
var element = ((Weapon)EquippedWeapon.Value).WeaponElement;
|
||||
|
||||
enemy.TakeDamage(
|
||||
attackValue * EquippedWeapon.Value.ElementalDamageBonus,
|
||||
element,
|
||||
isCriticalHit,
|
||||
false,
|
||||
ignoreElementalResistance);
|
||||
enemy.TakeDamage(
|
||||
attackValue * ((Weapon)EquippedWeapon.Value).ElementalDamageBonus,
|
||||
element,
|
||||
isCriticalHit,
|
||||
false,
|
||||
ignoreElementalResistance);
|
||||
|
||||
if (EquippedWeapon.Value.WeaponTag == WeaponTag.Knockback)
|
||||
enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
||||
if (((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback)
|
||||
enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
||||
}
|
||||
|
||||
private void CollisionDetector_AreaEntered(Area3D area)
|
||||
{
|
||||
if (area.GetParent() is InventoryItem inventoryItem)
|
||||
{
|
||||
var isAdded = Inventory.TryAdd(inventoryItem);
|
||||
if (isAdded)
|
||||
{
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up.");
|
||||
inventoryItem.QueueFree();
|
||||
}
|
||||
else
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}.");
|
||||
}
|
||||
if (area.GetParent() is DroppedItem droppedItem)
|
||||
{
|
||||
var isAdded = Inventory.TryAdd(droppedItem.Item);
|
||||
if (isAdded)
|
||||
{
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up.");
|
||||
droppedItem.QueueFree();
|
||||
}
|
||||
else
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}.");
|
||||
}
|
||||
if (area.GetParent() is InventoryItem inventoryItem)
|
||||
{
|
||||
var isAdded = Inventory.TryAdd(inventoryItem);
|
||||
if (isAdded)
|
||||
{
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up.");
|
||||
inventoryItem.QueueFree();
|
||||
}
|
||||
else
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}.");
|
||||
}
|
||||
if (area.GetParent() is DroppedItem droppedItem)
|
||||
{
|
||||
var isAdded = Inventory.TryAdd(droppedItem.Item);
|
||||
if (isAdded)
|
||||
{
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up.");
|
||||
droppedItem.QueueFree();
|
||||
}
|
||||
else
|
||||
_gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool PlayerIsHittingGeometry()
|
||||
{
|
||||
var collisions = WallCheck.GetCollidingBodies();
|
||||
return collisions.Count > 0;
|
||||
var collisions = WallCheck.GetCollidingBodies();
|
||||
return collisions.Count > 0;
|
||||
}
|
||||
|
||||
private void WallCheck_BodyEntered(Node body)
|
||||
{
|
||||
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
|
||||
GD.Print("Hit wall");
|
||||
AnimationPlayer.Stop();
|
||||
PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished());
|
||||
GD.Print("Hit wall");
|
||||
AnimationPlayer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
namespace Zennysoft.Game.Ma;
|
||||
namespace Zennysoft.Game.Abstractions;
|
||||
|
||||
public interface IKillable
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user