Change affinity
This commit is contained in:
@@ -3,16 +3,17 @@ using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ThrowableItem : Node3D, IUsableItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
public InventoryItemStats Info => ThrowableItemInfo;
|
||||
|
||||
public int Count { get; }
|
||||
@@ -26,10 +27,23 @@ public partial class ThrowableItem : Node3D, IUsableItem
|
||||
|
||||
[Node] public Area3D Pickup { get; set; } = default!;
|
||||
|
||||
private ThrowableItemTag[] _affinityTypes;
|
||||
|
||||
private int _affinityIndex = 0;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
Sprite.Texture = ThrowableItemInfo.Texture;
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
_affinityTypes =
|
||||
[
|
||||
ThrowableItemTag.InflictBaseDamage,
|
||||
ThrowableItemTag.InflictHydricDamage,
|
||||
ThrowableItemTag.InflictIgneousDamage,
|
||||
ThrowableItemTag.InflictTelluricDamage,
|
||||
ThrowableItemTag.InflictAeolicDamage,
|
||||
ThrowableItemTag.InflictFerrumDamage
|
||||
];
|
||||
}
|
||||
|
||||
public void Use()
|
||||
@@ -38,6 +52,24 @@ public partial class ThrowableItem : Node3D, IUsableItem
|
||||
Game.HealHP(ThrowableItemInfo.HealHPAmount);
|
||||
if (ThrowableItemInfo.HealVTAmount > 0)
|
||||
Game.HealVT(ThrowableItemInfo.HealVTAmount);
|
||||
|
||||
if (ThrowableItemInfo.UsableItemTags.Contains(UsableItemTag.DoubleEXP))
|
||||
Game.DoubleEXP(TimeSpan.FromSeconds(30));
|
||||
|
||||
if (ThrowableItemInfo.ThrowableItemTags.Contains(ThrowableItemTag.CanChangeAffinity))
|
||||
ChangeAffinity();
|
||||
}
|
||||
|
||||
private void ChangeAffinity()
|
||||
{
|
||||
ThrowableItemInfo.ThrowableItemTags.Remove(_affinityTypes[_affinityIndex]);
|
||||
_affinityIndex = (_affinityIndex + 1) % (_affinityTypes.Length);
|
||||
ThrowableItemInfo.ThrowableItemTags.Add(_affinityTypes[_affinityIndex]);
|
||||
|
||||
// TODO: Make this an inventory animation to cycle through elements.
|
||||
ThrowableItemInfo.Description =
|
||||
$"{GetDescription(_affinityTypes[_affinityIndex])} when thrown." +
|
||||
$"{System.Environment.NewLine}Use item to change Affinity.";
|
||||
}
|
||||
|
||||
public void OnEntered(Node3D body)
|
||||
@@ -46,4 +78,19 @@ public partial class ThrowableItem : Node3D, IUsableItem
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private static string GetDescription(ThrowableItemTag enumValue)
|
||||
{
|
||||
var field = enumValue.GetType().GetField(enumValue.ToString());
|
||||
if (field == null)
|
||||
return enumValue.ToString();
|
||||
|
||||
var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
|
||||
{
|
||||
return attribute.Description;
|
||||
}
|
||||
|
||||
return enumValue.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user