2022-11-13 19:52:09 -08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Godot;
|
|
|
|
using SupaLidlGame.Characters;
|
2022-11-19 21:21:12 -08:00
|
|
|
using SupaLidlGame.Utils;
|
2022-11-13 19:52:09 -08:00
|
|
|
|
|
|
|
namespace SupaLidlGame.BoundingBoxes
|
|
|
|
{
|
2022-11-19 21:21:12 -08:00
|
|
|
public partial class Hitbox : Area2D, IFaction
|
2022-11-13 19:52:09 -08:00
|
|
|
{
|
|
|
|
private HashSet<Hurtbox> _ignoreList = new HashSet<Hurtbox>();
|
|
|
|
|
|
|
|
[Export]
|
2022-11-19 21:21:12 -08:00
|
|
|
public float Damage { get; set; }
|
2022-11-13 19:52:09 -08:00
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
/// <summary>
|
|
|
|
/// Getter/setter for the CollisionShape2D's Disabled property.
|
|
|
|
/// </summary>
|
2022-11-13 19:52:09 -08:00
|
|
|
[Export]
|
2022-11-19 21:21:12 -08:00
|
|
|
public bool IsDisabled
|
|
|
|
{
|
|
|
|
get => _collisionShape.Disabled;
|
|
|
|
set => _collisionShape.Disabled = value;
|
|
|
|
}
|
2022-11-13 19:52:09 -08:00
|
|
|
|
|
|
|
[Export]
|
|
|
|
public float Knockback { get; set; }
|
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
[Export]
|
|
|
|
public ushort Faction { get; set; }
|
|
|
|
|
2022-11-13 19:52:09 -08:00
|
|
|
public Character Inflictor { get; set; }
|
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
private CollisionShape2D _collisionShape;
|
|
|
|
|
|
|
|
public override void _Ready()
|
2022-11-13 19:52:09 -08:00
|
|
|
{
|
2022-11-19 21:21:12 -08:00
|
|
|
_collisionShape = GetNode<CollisionShape2D>("CollisionShape2D");
|
|
|
|
}
|
2022-11-13 19:52:09 -08:00
|
|
|
|
2022-11-19 21:21:12 -08:00
|
|
|
public void _on_area_entered(Area2D area)
|
|
|
|
{
|
2022-11-13 19:52:09 -08:00
|
|
|
if (area is Hurtbox hurtbox)
|
|
|
|
{
|
2022-11-19 21:21:12 -08:00
|
|
|
// we don't want to hurt teammates
|
|
|
|
if (Faction != hurtbox.Faction)
|
2022-11-13 19:52:09 -08:00
|
|
|
{
|
2022-11-19 21:21:12 -08:00
|
|
|
if (!_ignoreList.Contains(hurtbox))
|
|
|
|
{
|
|
|
|
_ignoreList.Add(hurtbox);
|
|
|
|
hurtbox.InflictDamage(Damage, Inflictor, Knockback);
|
|
|
|
}
|
2022-11-13 19:52:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetIgnoreList() => _ignoreList.Clear();
|
|
|
|
}
|
|
|
|
}
|