Major Player refactor

This commit is contained in:
2025-02-07 02:29:50 -08:00
parent 0cdae88952
commit fe1a1e61ef
132 changed files with 2554 additions and 2478 deletions

View File

@@ -1,34 +1,65 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using GameJamDungeon;
using Godot;
using System;
using System.Collections.Immutable;
namespace GameJamDungeon;
[Meta(typeof(IAutoNode))]
public partial class Weapon : Node3D, IInventoryItem, IEquipableItem
{
public override void _Notification(int what) => this.Notify(what);
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
public InventoryItemStats Info => WeaponStats;
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
[Signal]
public delegate void EquippedItemEventHandler(Weapon equippedWeapon);
[Export]
public WeaponStats WeaponStats { get; set; } = new WeaponStats();
private WeaponStats _weaponStats { get; set; } = new WeaponStats();
[Node] public Sprite3D Sprite { get; set; } = default!;
[Node] public Sprite3D Sprite { get; set; } = new Sprite3D();
[Node] public Area3D Pickup { get; set; } = default!;
public Texture2D GetTexture() => _weaponStats.Texture;
public Guid ID => Guid.NewGuid();
public string ItemName => _weaponStats.Name;
public string Description => _weaponStats.Description;
public float SpawnRate => _weaponStats.SpawnRate;
public int Damage => _weaponStats.Damage;
public double ThrowDamage => _weaponStats.ThrowDamage;
public float ThrowSpeed => _weaponStats.ThrowSpeed;
public double Luck => _weaponStats.Luck;
public double AttackSpeed => _weaponStats.AttackSpeed;
public ImmutableList<WeaponTag> WeaponTags => [.. _weaponStats.WeaponTags];
public ElementType WeaponElement => _weaponStats.WeaponElement;
public double ElementalDamageBonus => _weaponStats.ElementalDamageBonus;
public void OnReady()
{
Sprite.Texture = WeaponStats.Texture;
Pickup.BodyEntered += OnEntered;
Sprite.Texture = _weaponStats.Texture;
}
public void SetItemStats(InventoryItemStats inventoryItemStats)
{
_weaponStats = (WeaponStats)inventoryItemStats;
var texture = ResourceLoader.Load(inventoryItemStats.Texture.ResourcePath) as Texture2D;
Sprite.Texture = texture;
}
public void Equip()
@@ -43,17 +74,17 @@ public partial class Weapon : Node3D, IInventoryItem, IEquipableItem
public void Throw()
{
GameRepo.PlayerData.Inventory.Remove(this);
Player.Inventory.Remove(this);
}
public void Drop()
{
GameRepo.PlayerData.Inventory.Remove(this);
Player.Inventory.Remove(this);
}
public void OnEntered(Node3D body)
{
var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this);
var isAdded = Player.Inventory.TryAdd(this);
if (isAdded)
QueueFree();
}

View File

@@ -1,6 +1,7 @@
using GameJamDungeon;
using Godot;
namespace GameJamDungeon;
[GlobalClass]
public partial class WeaponStats : InventoryItemStats
{

View File

@@ -1,7 +0,0 @@
using Godot;
using System;
public partial class Rigid : RigidBody3D
{
}