Refactor more stuff (Audio mostly)

This commit is contained in:
2025-03-10 20:52:39 -07:00
parent 23049b3231
commit a1c26ed7fb
45 changed files with 861 additions and 846 deletions

View File

@@ -0,0 +1,13 @@
namespace Zennysoft.Game.Abstractions;
public interface IDimmableAudioStreamPlayer
{
/// <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 void Play(float fromPosition = 0);
public void Stop();
}

View File

@@ -0,0 +1,6 @@
namespace Zennysoft.Game.Abstractions;
public interface IKillable
{
public void Die();
}

View File

@@ -0,0 +1,6 @@
namespace Zennysoft.Game.Abstractions;
public interface IHealthPack
{
public double RestoreAmount { get; }
}

View File

@@ -1,18 +1,10 @@
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Game.Implementation;
using Chickensoft.GodotNodeInterfaces;
using Godot;
using Zennysoft.Game.Abstractions;
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
public partial class DimmableAudioStreamPlayer : AudioStreamPlayer, IDimmableAudioStreamPlayer
{
#region Constants
// -60 to -80 is considered inaudible for decibels.

View File

@@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Chickensoft.GodotNodeInterfaces" Version="2.4.0" />
<PackageReference Include="Chickensoft.Introspection" Version="2.2.0" />
<PackageReference Include="Chickensoft.Introspection.Generator" Version="2.2.0" />
<PackageReference Include="Chickensoft.Serialization.Godot" Version="0.7.6" />

View File

@@ -1,4 +1,4 @@
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{

View File

@@ -1,7 +1,7 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{

View File

@@ -1,7 +1,7 @@
using Chickensoft.Introspection;
using Chickensoft.LogicBlocks;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public interface IInGameAudioLogic : ILogicBlock<InGameAudioLogic.State>;
[Meta]

View File

@@ -1,6 +1,6 @@
using Chickensoft.Introspection;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{

View File

@@ -1,7 +1,7 @@
using Chickensoft.Introspection;
using Zennysoft.Ma.Adapter;
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public partial class InGameAudioLogic
{
@@ -53,15 +53,15 @@ public partial class InGameAudioLogic
private void OnPlayerAttackWall() => Output(new Output.PlayPlayerAttackWallSound());
private void OnRestorativePickedUp(Restorative restorative) => Output(new Output.PlayHealingItemSound());
private void OnRestorativePickedUp(IHealthPack restorative) => Output(new Output.PlayHealingItemSound());
private void OnMenuBackedOut() => Output(new Output.PlayMenuBackSound());
private void OnHealingItemConsumed(ConsumableItemStats stats) => Output(new Output.PlayHealingItemSound());
private void OnHealingItemConsumed(InventoryItem stats) => Output(new Output.PlayHealingItemSound());
private void OnInventorySorted() => Output(new Output.PlayInventorySortedSound());
private void OnEquippedItem(EquipableItem equipableItem) => Output(new Output.PlayEquipSound());
private void OnEquippedItem(InventoryItem equipableItem) => Output(new Output.PlayEquipSound());
private void OnOverworldEntered() => Output(new Output.PlayOverworldMusic());

View File

@@ -0,0 +1,36 @@
using Zennysoft.Game.Abstractions;
namespace Zennysoft.Ma.Adapter;
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<InventoryItem>? HealingItemConsumed;
public void OnHealingItemConsumed(InventoryItem item);
event Action<IHealthPack>? RestorativePickedUp;
public void OnRestorativePickedUp(IHealthPack restorative);
}

View File

@@ -1,8 +1,7 @@
using Chickensoft.Introspection;
using Chickensoft.Serialization;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
[Meta, Id("equipable_item")]
public abstract partial class EquipableItem : InventoryItem

View File

@@ -12,7 +12,8 @@ public class Module
container.RegisterSingleton<IFileSystem, FileSystem>();
container.RegisterSingleton<ISaveFileManager<GameData>, SaveFileManager<GameData>>();
container.RegisterSingleton<IMaSaveFileManager<GameData>, MaSaveFileManager<GameData>>();
container.Register<IGameRepo, GameRepo>(Lifestyle.Singleton);
container.Register<IGameLogic, GameLogic>(Lifestyle.Singleton);
container.RegisterSingleton<IGameRepo, GameRepo>();
container.RegisterSingleton<IGameLogic, GameLogic>();
container.RegisterSingleton<IDimmableAudioStreamPlayer, DimmableAudioStreamPlayer>();
}
}

View File

@@ -1,13 +1,10 @@
using Chickensoft.AutoInject;
using Chickensoft.Collections;
using Chickensoft.SaveFileBuilder;
using Chickensoft.Collections;
using Godot;
using Zennysoft.Game.Abstractions;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Ma.Adapter;
public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerData>>
public interface IPlayer : IKillable
{
public void Attack();
@@ -25,8 +22,6 @@ public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerData>>
public void TeleportPlayer(Transform3D newTransform);
public IDungeonRoom GetCurrentRoom();
public void HealHP(int amount);
public void RaiseHP(int amount);
@@ -53,11 +48,11 @@ public interface IPlayer : IKillable, IProvide<ISaveChunk<PlayerData>>
public Basis CurrentBasis { get; }
public IAutoProp<Weapon> EquippedWeapon { get; }
public IAutoProp<EquipableItem> EquippedWeapon { get; }
public IAutoProp<Armor> EquippedArmor { get; }
public IAutoProp<EquipableItem> EquippedArmor { get; }
public IAutoProp<Accessory> EquippedAccessory { get; }
public IAutoProp<EquipableItem> EquippedAccessory { get; }
public void Equip(EquipableItem equipable);

View File

@@ -0,0 +1,118 @@
namespace Zennysoft.Ma.Adapter;
using Chickensoft.Collections;
using Godot;
using Zennysoft.Game.Ma;
public class PlayerStatController
{
public void Init(PlayerStats playerStats)
{
_currentHP.OnNext(playerStats.CurrentHP);
_maximumHP.OnNext(playerStats.MaximumHP);
_currentVT.OnNext(playerStats.CurrentVT);
_maximumVT.OnNext(playerStats.MaximumVT);
_currentExp.OnNext(playerStats.CurrentExp);
_currentLevel.OnNext(playerStats.CurrentLevel);
_currentAttack.OnNext(playerStats.CurrentAttack);
_bonusAttack.OnNext(playerStats.BonusAttack);
_maxAttack.OnNext(playerStats.MaxAttack);
_currentDefense.OnNext(playerStats.CurrentDefense);
_bonusDefense.OnNext(playerStats.BonusDefense);
_maxDefense.OnNext(playerStats.MaxDefense);
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
_luck.OnNext(playerStats.Luck);
}
public IAutoProp<int> CurrentHP => _currentHP;
public IAutoProp<int> MaximumHP => _maximumHP;
public IAutoProp<int> CurrentVT => _currentVT;
public IAutoProp<int> MaximumVT => _maximumVT;
public IAutoProp<int> CurrentAttack => _currentAttack;
public IAutoProp<int> MaxAttack => _maxAttack;
public IAutoProp<int> BonusAttack => _bonusAttack;
public IAutoProp<int> CurrentDefense => _currentDefense;
public IAutoProp<int> MaxDefense => _maxDefense;
public IAutoProp<int> BonusDefense => _bonusDefense;
public IAutoProp<double> CurrentExp => _currentExp;
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
public IAutoProp<int> CurrentLevel => _currentLevel;
public IAutoProp<double> Luck => _luck;
public void SetCurrentHP(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
_currentHP.OnNext(clampedValue);
}
public void SetMaximumHP(int newValue)
{
_maximumHP.OnNext(newValue);
}
public void SetCurrentVT(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
_currentVT.OnNext(clampedValue);
}
public void SetMaximumVT(int newValue)
{
_maximumVT.OnNext(newValue);
}
public void SetCurrentExp(double newValue)
{
_currentExp.OnNext(newValue);
}
public void SetCurrentLevel(int newValue)
{
_currentLevel.OnNext(newValue);
}
public void SetCurrentAttack(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
_currentAttack.OnNext(clampedValue);
}
public void SetBonusAttack(int newValue)
{
_bonusAttack.OnNext(newValue);
}
public void SetMaxAttack(int newValue)
{
_maxAttack.OnNext(newValue);
}
public void SetCurrentDefense(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
_currentDefense.OnNext(clampedValue);
}
public void SetBonusDefense(int newValue)
{
_bonusDefense.OnNext(newValue);
}
public void SetMaxDefense(int newValue)
{
_maxDefense.OnNext(newValue);
}
public void SetExpToNextLevel(int newValue)
{
_expToNextLevel.OnNext(newValue);
}
public void SetLuck(double newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
_luck.OnNext(clampedValue);
}
private readonly AutoProp<int> _currentHP = new(-1);
private readonly AutoProp<int> _maximumHP = new(-1);
private readonly AutoProp<int> _currentVT = new(-1);
private readonly AutoProp<int> _maximumVT = new(-1);
private readonly AutoProp<double> _currentExp = new(-1);
private readonly AutoProp<int> _currentLevel = new(-1);
private readonly AutoProp<int> _currentAttack = new(-1);
private readonly AutoProp<int> _bonusAttack = new(-1);
private readonly AutoProp<int> _maxAttack = new(-1);
private readonly AutoProp<int> _currentDefense = new(-1);
private readonly AutoProp<int> _bonusDefense = new(-1);
private readonly AutoProp<int> _maxDefense = new(-1);
private readonly AutoProp<int> _expToNextLevel = new(-1);
private readonly AutoProp<double> _luck = new(-1);
}

View File

@@ -37,116 +37,3 @@ public partial record PlayerStats
[Save("luck")]
public double Luck { get; init; }
}
public class PlayerStatController
{
public void Init(PlayerStats playerStats)
{
_currentHP.OnNext(playerStats.CurrentHP);
_maximumHP.OnNext(playerStats.MaximumHP);
_currentVT.OnNext(playerStats.CurrentVT);
_maximumVT.OnNext(playerStats.MaximumVT);
_currentExp.OnNext(playerStats.CurrentExp);
_currentLevel.OnNext(playerStats.CurrentLevel);
_currentAttack.OnNext(playerStats.CurrentAttack);
_bonusAttack.OnNext(playerStats.BonusAttack);
_maxAttack.OnNext(playerStats.MaxAttack);
_currentDefense.OnNext(playerStats.CurrentDefense);
_bonusDefense.OnNext(playerStats.BonusDefense);
_maxDefense.OnNext(playerStats.MaxDefense);
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
_luck.OnNext(playerStats.Luck);
}
public IAutoProp<int> CurrentHP => _currentHP;
public IAutoProp<int> MaximumHP => _maximumHP;
public IAutoProp<int> CurrentVT => _currentVT;
public IAutoProp<int> MaximumVT => _maximumVT;
public IAutoProp<int> CurrentAttack => _currentAttack;
public IAutoProp<int> MaxAttack => _maxAttack;
public IAutoProp<int> BonusAttack => _bonusAttack;
public IAutoProp<int> CurrentDefense => _currentDefense;
public IAutoProp<int> MaxDefense => _maxDefense;
public IAutoProp<int> BonusDefense => _bonusDefense;
public IAutoProp<double> CurrentExp => _currentExp;
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
public IAutoProp<int> CurrentLevel => _currentLevel;
public IAutoProp<double> Luck => _luck;
public void SetCurrentHP(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
_currentHP.OnNext(clampedValue);
}
public void SetMaximumHP(int newValue)
{
_maximumHP.OnNext(newValue);
}
public void SetCurrentVT(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
_currentVT.OnNext(clampedValue);
}
public void SetMaximumVT(int newValue)
{
_maximumVT.OnNext(newValue);
}
public void SetCurrentExp(double newValue)
{
_currentExp.OnNext(newValue);
}
public void SetCurrentLevel(int newValue)
{
_currentLevel.OnNext(newValue);
}
public void SetCurrentAttack(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
_currentAttack.OnNext(clampedValue);
}
public void SetBonusAttack(int newValue)
{
_bonusAttack.OnNext(newValue);
}
public void SetMaxAttack(int newValue)
{
_maxAttack.OnNext(newValue);
}
public void SetCurrentDefense(int newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
_currentDefense.OnNext(clampedValue);
}
public void SetBonusDefense(int newValue)
{
_bonusDefense.OnNext(newValue);
}
public void SetMaxDefense(int newValue)
{
_maxDefense.OnNext(newValue);
}
public void SetExpToNextLevel(int newValue)
{
_expToNextLevel.OnNext(newValue);
}
public void SetLuck(double newValue)
{
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
_luck.OnNext(clampedValue);
}
private readonly AutoProp<int> _currentHP = new(-1);
private readonly AutoProp<int> _maximumHP = new(-1);
private readonly AutoProp<int> _currentVT = new(-1);
private readonly AutoProp<int> _maximumVT = new(-1);
private readonly AutoProp<double> _currentExp = new(-1);
private readonly AutoProp<int> _currentLevel = new(-1);
private readonly AutoProp<int> _currentAttack = new(-1);
private readonly AutoProp<int> _bonusAttack = new(-1);
private readonly AutoProp<int> _maxAttack = new(-1);
private readonly AutoProp<int> _currentDefense = new(-1);
private readonly AutoProp<int> _bonusDefense = new(-1);
private readonly AutoProp<int> _maxDefense = new(-1);
private readonly AutoProp<int> _expToNextLevel = new(-1);
private readonly AutoProp<double> _luck = new(-1);
}

View File

@@ -0,0 +1,7 @@
using Zennysoft.Game.Implementation;
namespace Zennsoft.Game.Ma;
public partial class BGMPlayer : DimmableAudioStreamPlayer
{
}

View File

@@ -0,0 +1 @@
uid://d2usinntpmcry

View File

@@ -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;

View File

@@ -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

View File

@@ -1,5 +1,6 @@
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -1,5 +1,6 @@
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -1,4 +1,5 @@
using Chickensoft.Introspection;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -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);
}
}

View File

@@ -1,4 +1,5 @@
using Godot;
using Zennysoft.Game.Abstractions;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -1,6 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -1,4 +1,5 @@
using Chickensoft.Introspection;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -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)
{

View File

@@ -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()
{

View File

@@ -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}";

View File

@@ -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!;

View File

@@ -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);
}

View File

@@ -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()
{

View File

@@ -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()

View File

@@ -1,6 +1,7 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -2,6 +2,7 @@
using Chickensoft.Introspection;
using Godot;
using System.Collections.Immutable;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;

View File

@@ -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!;
@@ -219,7 +219,7 @@ public partial class Player : CharacterBody3D, IPlayer
}
else
{
var attackSpeed = EquippedWeapon.Value.AttackSpeed;
var attackSpeed = ((Weapon)EquippedWeapon.Value).AttackSpeed;
AnimationPlayer.SetSpeedScale((float)attackSpeed);
AnimationPlayer.Play("attack");
_gameRepo.OnPlayerAttack();
@@ -256,13 +256,6 @@ public partial class Player : CharacterBody3D, IPlayer
Game.TogglePause();
}
public IDungeonRoom GetCurrentRoom()
{
var rooms = Game.CurrentFloor.Rooms;
var playersRoom = rooms.SingleOrDefault(x => x.IsPlayerInRoom);
return playersRoom;
}
public void RaiseHP(int amountToRaise)
{
Stats.SetMaximumHP(Stats.MaximumHP.Value + amountToRaise);
@@ -504,7 +497,7 @@ public partial class Player : CharacterBody3D, IPlayer
if (Stats.CurrentVT.Value > 0)
{
if (EquippedAccessory.Value.AccessoryTag == AccessoryTag.HalfVTConsumption)
if (((Accessory)EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption)
{
reduceOnTick = !reduceOnTick;
}
@@ -516,23 +509,23 @@ public partial class Player : CharacterBody3D, IPlayer
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)
@@ -562,18 +555,18 @@ public partial class Player : CharacterBody3D, IPlayer
private void HitEnemy(IEnemy enemy)
{
var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value;
var ignoreElementalResistance = EquippedWeapon.Value.WeaponTag == WeaponTag.IgnoreAffinity;
var ignoreElementalResistance = ((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.IgnoreAffinity;
var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value);
var element = EquippedWeapon.Value.WeaponElement;
var element = ((Weapon)EquippedWeapon.Value).WeaponElement;
enemy.TakeDamage(
attackValue * EquippedWeapon.Value.ElementalDamageBonus,
attackValue * ((Weapon)EquippedWeapon.Value).ElementalDamageBonus,
element,
isCriticalHit,
false,
ignoreElementalResistance);
if (EquippedWeapon.Value.WeaponTag == WeaponTag.Knockback)
if (((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback)
enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized());
}

File diff suppressed because one or more lines are too long

View File

@@ -1,4 +1,4 @@
namespace Zennysoft.Game.Ma;
namespace Zennysoft.Game.Abstractions;
public interface IKillable
{

View File

@@ -2,6 +2,7 @@ using Chickensoft.AutoInject;
using Chickensoft.GodotNodeInterfaces;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;