50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using GameJamDungeon;
|
|
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class Accessory : Node3D, IInventoryItem, IEquipable
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
|
|
|
public InventoryItemStats Info => AccessoryInfo;
|
|
|
|
[Export]
|
|
public AccessoryStats AccessoryInfo { get; set; } = new AccessoryStats();
|
|
|
|
[Node] public Sprite3D Sprite { get; set; } = default!;
|
|
|
|
[Node] public Area3D Pickup { get; set; } = default!;
|
|
|
|
public Guid ID => Guid.NewGuid();
|
|
|
|
public void OnReady()
|
|
{
|
|
Sprite.Texture = AccessoryInfo.Texture;
|
|
Pickup.BodyEntered += OnEntered;
|
|
}
|
|
|
|
public void Throw()
|
|
{
|
|
GameRepo.PlayerData.Inventory.Remove(this);
|
|
}
|
|
|
|
public void Drop()
|
|
{
|
|
GameRepo.PlayerData.Inventory.Remove(this);
|
|
}
|
|
|
|
public void OnEntered(Node3D body)
|
|
{
|
|
var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this);
|
|
if (isAdded)
|
|
QueueFree();
|
|
}
|
|
}
|