Major Player refactor
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ThrowableItem : Node3D, IUsableItem
|
||||
@@ -11,56 +13,75 @@ public partial class ThrowableItem : Node3D, IUsableItem
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
public InventoryItemStats Info => ThrowableItemInfo;
|
||||
|
||||
public int Count { get; }
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
public Guid ID => Guid.NewGuid();
|
||||
|
||||
public string ItemName => _throwableItemStats.Name;
|
||||
|
||||
public string Description => _throwableItemStats.Description;
|
||||
|
||||
public float SpawnRate => _throwableItemStats.SpawnRate;
|
||||
|
||||
public Texture2D GetTexture() => _throwableItemStats.Texture;
|
||||
|
||||
public double ThrowDamage => _throwableItemStats.ThrowDamage;
|
||||
|
||||
public float ThrowSpeed => _throwableItemStats.ThrowSpeed;
|
||||
|
||||
public ElementType ElementType => _throwableItemStats.ElementType;
|
||||
|
||||
public ImmutableList<ThrowableItemTag> ThrowableItemTags => [.. _throwableItemStats.ThrowableItemTags];
|
||||
|
||||
public int Count { get; }
|
||||
|
||||
public void SetItemStats(InventoryItemStats inventoryItemStats)
|
||||
{
|
||||
_throwableItemStats = (ThrowableItemStats)inventoryItemStats;
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var isAdded = Player.Inventory.TryAdd(this);
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
[Export]
|
||||
public ThrowableItemStats ThrowableItemInfo { get; set; }
|
||||
private ThrowableItemStats _throwableItemStats { get; set; }
|
||||
|
||||
[Node] public Sprite3D Sprite { get; set; } = default!;
|
||||
[Node] private Sprite3D Sprite { get; set; } = new Sprite3D();
|
||||
|
||||
[Node] public Area3D Pickup { get; set; } = default!;
|
||||
[Node] private Area3D Pickup { get; set; } = default!;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
Sprite.Texture = ThrowableItemInfo.Texture;
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
Sprite.Texture = _throwableItemStats.Texture;
|
||||
}
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (ThrowableItemInfo.HealHPAmount > 0)
|
||||
Game.HealHP(ThrowableItemInfo.HealHPAmount);
|
||||
if (ThrowableItemInfo.HealVTAmount > 0)
|
||||
Game.HealVT(ThrowableItemInfo.HealVTAmount);
|
||||
if (_throwableItemStats.HealHPAmount > 0)
|
||||
Game.HealHP(_throwableItemStats.HealHPAmount);
|
||||
if (_throwableItemStats.HealVTAmount > 0)
|
||||
Game.HealVT(_throwableItemStats.HealVTAmount);
|
||||
|
||||
if (ThrowableItemInfo.UsableItemTags.Contains(UsableItemTag.DoubleEXP))
|
||||
if (_throwableItemStats.UsableItemTags.Contains(UsableItemTag.DoubleEXP))
|
||||
Game.DoubleEXP(TimeSpan.FromSeconds(30));
|
||||
|
||||
if (ThrowableItemInfo.ThrowableItemTags.Contains(ThrowableItemTag.CanChangeAffinity))
|
||||
if (_throwableItemStats.ThrowableItemTags.Contains(ThrowableItemTag.CanChangeAffinity))
|
||||
ChangeAffinity();
|
||||
}
|
||||
|
||||
private void ChangeAffinity()
|
||||
{
|
||||
var maximumElements = Enum.GetNames(typeof(ElementType)).Length;
|
||||
ThrowableItemInfo.ElementType = ThrowableItemInfo.ElementType + 1 % maximumElements;
|
||||
_throwableItemStats.ElementType = _throwableItemStats.ElementType + 1 % maximumElements;
|
||||
|
||||
// TODO: Make this an inventory animation to cycle through elements.
|
||||
ThrowableItemInfo.Description =
|
||||
$"Inflicts {ThrowableItemInfo.ElementType} damage when thrown." +
|
||||
_throwableItemStats.Description =
|
||||
$"Inflicts {_throwableItemStats.ElementType} damage when thrown." +
|
||||
$"{System.Environment.NewLine}Use item to change Affinity.";
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
{
|
||||
var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this);
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user