SupaLidlGame/Items/Weapons/Sword.cs

87 lines
2.1 KiB
C#
Raw Normal View History

2022-11-18 13:53:51 -08:00
using Godot;
using SupaLidlGame.BoundingBoxes;
2022-11-13 19:52:09 -08:00
using SupaLidlGame.Characters;
namespace SupaLidlGame.Items.Weapons
{
public partial class Sword : Weapon
{
2022-11-19 21:21:12 -08:00
public double RemainingAttackTime { get; protected set; } = 0;
public bool IsAttacking => RemainingAttackTime > 0;
2022-11-18 13:53:51 -08:00
[Export]
public Hitbox Hitbox { get; set; }
2022-11-13 19:52:09 -08:00
2022-11-19 21:21:12 -08:00
[Export]
public AnimationPlayer AnimationPlayer { get; set; }
/// <summary>
/// The time frame in seconds for which the weapon will deal damage.
/// </summary>
/// <remarks>
/// The value of <c>AttackTime</c> should be less than the
/// value of <c>UseTime</c>
/// </remarks>
[Export]
public double AttackTime { get; set; } = 0;
2022-11-13 19:52:09 -08:00
public override void Equip(Character character)
{
2022-11-19 21:21:12 -08:00
Visible = true;
2022-11-13 19:52:09 -08:00
base.Equip(character);
2022-11-19 21:21:12 -08:00
Hitbox.Faction = character.Faction; // character is null before base
}
public override void Unequip(Character character)
{
Visible = false;
base.Unequip(character);
2022-11-13 19:52:09 -08:00
}
public override void Use()
{
2022-11-19 21:21:12 -08:00
if (RemainingUseTime > 0)
{
return;
}
RemainingAttackTime = AttackTime;
AnimationPlayer.Play("use");
Hitbox.IsDisabled = false;
base.Use();
2022-11-18 13:53:51 -08:00
}
public override void Deuse()
{
2022-11-19 21:21:12 -08:00
AnimationPlayer.Stop();
Deattack();
base.Deuse();
}
protected void Deattack()
{
Hitbox.IsDisabled = true;
Hitbox.ResetIgnoreList();
}
public override void _Ready()
{
Hitbox.Damage = Damage;
}
public override void _Process(double delta)
{
if (RemainingAttackTime > 0)
{
if ((RemainingAttackTime -= delta) <= 0)
{
Deattack();
}
}
base._Process(delta);
2022-11-13 19:52:09 -08:00
}
}
}