Refactor Enemy
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[sub_resource type="Resource" id="Resource_b0s4k"]
|
||||
script = ExtResource("2_8h2lx")
|
||||
ThrowableItemTags = Array[int]([])
|
||||
ElementType = 0
|
||||
UsableItemTags = Array[int]([])
|
||||
Name = ""
|
||||
Description = ""
|
||||
|
||||
@@ -8,6 +8,9 @@ public partial class ThrowableItemStats : InventoryItemStats
|
||||
[Export]
|
||||
public Godot.Collections.Array<ThrowableItemTag> ThrowableItemTags { get; set; } = new Godot.Collections.Array<ThrowableItemTag>();
|
||||
|
||||
[Export]
|
||||
public ElementType ElementType { get; set; } = ElementType.None;
|
||||
|
||||
[Export]
|
||||
public Godot.Collections.Array<UsableItemTag> UsableItemTags { get; set; } = new Godot.Collections.Array<UsableItemTag>();
|
||||
}
|
||||
|
||||
@@ -2,18 +2,6 @@
|
||||
|
||||
public enum ThrowableItemTag
|
||||
{
|
||||
[Description("Inflicts basic damage")]
|
||||
InflictBaseDamage,
|
||||
[Description("Inflicts Telluric damage")]
|
||||
InflictTelluricDamage,
|
||||
[Description("Inflicts Aeolic damage")]
|
||||
InflictAeolicDamage,
|
||||
[Description("Inflicts Hydric damage")]
|
||||
InflictHydricDamage,
|
||||
[Description("Inflicts Igneous damage")]
|
||||
InflictIgneousDamage,
|
||||
[Description("Inflicts Ferrum damage")]
|
||||
InflictFerrumDamage,
|
||||
LowerTargetTo1HP,
|
||||
CanChangeAffinity
|
||||
}
|
||||
|
||||
@@ -38,14 +38,16 @@ public partial class ThrownItem : RigidBody3D
|
||||
|
||||
private void CalculateEffect(IEnemy enemy)
|
||||
{
|
||||
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(ThrownItemStats.ThrowDamage));
|
||||
|
||||
if (ThrownItemStats is ThrowableItemStats throwableItemStats)
|
||||
{
|
||||
if (throwableItemStats.ThrowableItemTags.Contains(ThrowableItemTag.LowerTargetTo1HP))
|
||||
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(enemy.CurrentHP.Value - 1));
|
||||
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(DamageCalculator.CalculateThrownItemDamage(throwableItemStats.ThrowDamage, enemy.EnemyStatResource, throwableItemStats)));
|
||||
|
||||
enemy.TakeDamage(enemy.CurrentHP - 1, ElementType.None, false, true, true);
|
||||
else
|
||||
enemy.TakeDamage(throwableItemStats.ThrowDamage, throwableItemStats.ElementType);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy.TakeDamage(ThrownItemStats.ThrowDamage, ElementType.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,19 +14,10 @@ public partial class WeaponStats : InventoryItemStats
|
||||
public double AttackSpeed { get; set; } = 1;
|
||||
|
||||
[Export]
|
||||
public double TelluricDamageBonus { get; set; } = 0;
|
||||
public ElementType WeaponElement { get; set; } = ElementType.None;
|
||||
|
||||
[Export]
|
||||
public double AeolicDamageBonus { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public double BaseHydricDamageBonus { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public double IgneousDamageBonus { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public double FerrumDamageBonus { get; set; } = 0;
|
||||
public double ElementalDamageBonus { get; set; } = 1.0;
|
||||
|
||||
[Export]
|
||||
public Godot.Collections.Array<WeaponTag> WeaponTags { get; set; } = new Godot.Collections.Array<WeaponTag>();
|
||||
|
||||
Reference in New Issue
Block a user