Implementation of saving inventory items (had to resturcture texture loading)
This commit is contained in:
@@ -1,68 +1,31 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ConsumableItem : Node3D, IUsableItem
|
||||
[Meta, Id("consumable_item")]
|
||||
public partial class ConsumableItem : InventoryItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
[Export]
|
||||
private ConsumableItemStats _consumableItemStats { get; set; }
|
||||
private ConsumableItemStats _consumableItemStats { get; set; } = new ConsumableItemStats();
|
||||
|
||||
[Node] private Sprite3D Sprite { get; set; } = new Sprite3D();
|
||||
public override string ItemName => _consumableItemStats.Name;
|
||||
|
||||
[Node] private Area3D Pickup { get; set; } = default!;
|
||||
public override string Description => _consumableItemStats.Description;
|
||||
|
||||
public Guid ID => Guid.NewGuid();
|
||||
public override float SpawnRate => _consumableItemStats.SpawnRate;
|
||||
|
||||
public string ItemName => _consumableItemStats.Name;
|
||||
public override double ThrowDamage => _consumableItemStats.ThrowDamage;
|
||||
|
||||
public string Description => _consumableItemStats.Description;
|
||||
public override float ThrowSpeed => _consumableItemStats.ThrowSpeed;
|
||||
|
||||
public float SpawnRate => _consumableItemStats.SpawnRate;
|
||||
public int HealHPAmount => _consumableItemStats.HealHPAmount;
|
||||
|
||||
public Texture2D GetTexture() => _consumableItemStats.Texture;
|
||||
public int HealVTAmount => _consumableItemStats.HealVTAmount;
|
||||
|
||||
public double ThrowDamage => _consumableItemStats.ThrowDamage;
|
||||
public int RaiseHPAmount => _consumableItemStats.RaiseHPAmount;
|
||||
|
||||
public float ThrowSpeed => _consumableItemStats.ThrowSpeed;
|
||||
public int RaiseVTAmount => _consumableItemStats.RaiseVTAmount;
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (Player.Stats.CurrentHP == Player.Stats.MaximumHP && _consumableItemStats.RaiseHPAmount > 0)
|
||||
Player.RaiseHP(_consumableItemStats.RaiseHPAmount);
|
||||
if (Player.Stats.CurrentVT == Player.Stats.MaximumVT && _consumableItemStats.RaiseVTAmount > 0)
|
||||
Player.RaiseVT(_consumableItemStats.RaiseVTAmount);
|
||||
|
||||
if (_consumableItemStats.HealHPAmount > 0 && Player.Stats.CurrentHP != Player.Stats.MaximumHP)
|
||||
Player.HealHP(_consumableItemStats.HealHPAmount);
|
||||
if (_consumableItemStats.HealVTAmount > 0 && Player.Stats.CurrentVT != Player.Stats.MaximumVT)
|
||||
Player.HealVT(_consumableItemStats.HealVTAmount);
|
||||
}
|
||||
|
||||
public void SetItemStats(InventoryItemStats inventoryItemStats)
|
||||
{
|
||||
_consumableItemStats = (ConsumableItemStats)inventoryItemStats;
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
Sprite.Texture = _consumableItemStats.Texture;
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var isAdded = Player.Inventory.TryAdd(this);
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
public override InventoryItemStats ItemStats { get => _consumableItemStats; set => _consumableItemStats = (ConsumableItemStats)value; }
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ script = ExtResource("1_26bad")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
|
||||
[node name="Sprite" type="Sprite3D" parent="Pickup"]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
using Godot;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[GlobalClass]
|
||||
[Meta, Id("consumable_item_stats")]
|
||||
public partial class ConsumableItemStats : InventoryItemStats
|
||||
{
|
||||
[Export]
|
||||
[Save("consumable_item_raise_hp")]
|
||||
public int RaiseHPAmount { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
[Save("consumable_item_raise_vt")]
|
||||
public int RaiseVTAmount { get; set; } = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user