Refactor Enemy

This commit is contained in:
2025-02-06 01:58:36 -08:00
parent badc6d2375
commit 4e6c545e81
38 changed files with 581 additions and 589 deletions

View File

@@ -3,7 +3,6 @@ using Chickensoft.Introspection;
using GameJamDungeon;
using Godot;
using System;
using System.ComponentModel;
[Meta(typeof(IAutoNode))]
public partial class ThrowableItem : Node3D, IUsableItem
@@ -27,23 +26,10 @@ 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()
@@ -62,13 +48,12 @@ public partial class ThrowableItem : Node3D, IUsableItem
private void ChangeAffinity()
{
ThrowableItemInfo.ThrowableItemTags.Remove(_affinityTypes[_affinityIndex]);
_affinityIndex = (_affinityIndex + 1) % (_affinityTypes.Length);
ThrowableItemInfo.ThrowableItemTags.Add(_affinityTypes[_affinityIndex]);
var maximumElements = Enum.GetNames(typeof(ElementType)).Length;
ThrowableItemInfo.ElementType = ThrowableItemInfo.ElementType + 1 % maximumElements;
// TODO: Make this an inventory animation to cycle through elements.
ThrowableItemInfo.Description =
$"{GetDescription(_affinityTypes[_affinityIndex])} when thrown." +
$"Inflicts {ThrowableItemInfo.ElementType} damage when thrown." +
$"{System.Environment.NewLine}Use item to change Affinity.";
}
@@ -78,19 +63,4 @@ 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();
}
}