tabs to spaces

item-info
HumanoidSandvichDispenser 2023-03-19 14:13:39 -07:00
parent 488ace3149
commit 613f476cb1
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
1 changed files with 143 additions and 143 deletions

View File

@ -5,173 +5,173 @@ using SupaLidlGame.Extensions;
namespace SupaLidlGame.Items.Weapons namespace SupaLidlGame.Items.Weapons
{ {
public partial class Sword : Weapon public partial class Sword : Weapon
{ {
public bool IsAttacking { get; protected set; } public bool IsAttacking { get; protected set; }
[Export] [Export]
public Hitbox Hitbox { get; set; } public Hitbox Hitbox { get; set; }
[Export] [Export]
public AnimationPlayer AnimationPlayer { get; set; } public AnimationPlayer AnimationPlayer { get; set; }
/// <summary> /// <summary>
/// The time frame in seconds for which the weapon will deal damage. /// The time frame in seconds for which the weapon will deal damage.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The value of <c>AttackTime</c> should be less than the /// The value of <c>AttackTime</c> should be less than the
/// value of <c>UseTime</c> /// value of <c>UseTime</c>
/// </remarks> /// </remarks>
[Export] [Export]
public double AttackTime { get; set; } = 0; public double AttackTime { get; set; } = 0;
[Export] [Export]
public CpuParticles2D ParryParticles { get; set; } public CpuParticles2D ParryParticles { get; set; }
public override bool IsParryable { get; protected set; } public override bool IsParryable { get; protected set; }
public override void Equip(Character character) public override void Equip(Character character)
{ {
Visible = true; Visible = true;
base.Equip(character); base.Equip(character);
Hitbox.Faction = character.Faction; // character is null before base Hitbox.Faction = character.Faction; // character is null before base
} }
public override void Unequip(Character character) public override void Unequip(Character character)
{ {
Visible = false; Visible = false;
base.Unequip(character); base.Unequip(character);
} }
public override void Use() public override void Use()
{ {
// we can't use if we're still using the weapon // we can't use if we're still using the weapon
if (RemainingUseTime > 0) if (RemainingUseTime > 0)
{ {
return; return;
} }
// reset state of the weapon // reset state of the weapon
IsParried = false; IsParried = false;
IsParryable = true; IsParryable = true;
ParryTimeOrigin = Time.GetTicksMsec(); ParryTimeOrigin = Time.GetTicksMsec();
AnimationPlayer.Stop(); AnimationPlayer.Stop();
// play animation depending on rotation of weapon // play animation depending on rotation of weapon
string anim = "use"; string anim = "use";
if (GetNode<Node2D>("Anchor").Rotation > Mathf.DegToRad(50)) if (GetNode<Node2D>("Anchor").Rotation > Mathf.DegToRad(50))
{ {
anim = "use2"; anim = "use2";
} }
if (Character is NPC) if (Character is NPC)
{ {
// NPCs have a slower attack // NPCs have a slower attack
anim += "-npc"; anim += "-npc";
} }
AnimationPlayer.Play(anim); AnimationPlayer.Play(anim);
base.Use(); base.Use();
} }
public override void Deuse() public override void Deuse()
{ {
//AnimationPlayer.Stop(); //AnimationPlayer.Stop();
Deattack(); Deattack();
base.Deuse(); base.Deuse();
} }
public void Attack() public void Attack()
{ {
//RemainingAttackTime = AttackTime; //RemainingAttackTime = AttackTime;
IsAttacking = true; IsAttacking = true;
Hitbox.IsDisabled = false; Hitbox.IsDisabled = false;
} }
public void Deattack() public void Deattack()
{ {
IsAttacking = false; IsAttacking = false;
IsParryable = false; IsParryable = false;
Hitbox.IsDisabled = true; Hitbox.IsDisabled = true;
ProcessHits(); ProcessHits();
Hitbox.ResetIgnoreList(); Hitbox.ResetIgnoreList();
AnimationPlayer.SpeedScale = 1; AnimationPlayer.SpeedScale = 1;
} }
public override void _Ready() public override void _Ready()
{ {
Hitbox.Damage = Damage; Hitbox.Damage = Damage;
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
base._Process(delta); base._Process(delta);
} }
public void ProcessHits() public void ProcessHits()
{ {
if (IsParried) if (IsParried)
{ {
return; return;
} }
foreach (BoundingBox box in Hitbox.Hits) foreach (BoundingBox box in Hitbox.Hits)
{ {
GD.Print("processing hit"); GD.Print("processing hit");
if (box is Hurtbox hurtbox) if (box is Hurtbox hurtbox)
{ {
hurtbox.InflictDamage(Damage, Character, Knockback); hurtbox.InflictDamage(Damage, Character, Knockback);
} }
} }
} }
public void AttemptParry(Weapon otherWeapon) public void AttemptParry(Weapon otherWeapon)
{ {
if (IsParryable && otherWeapon.IsParryable) if (IsParryable && otherWeapon.IsParryable)
{ {
ParryParticles.Emitting = true; ParryParticles.Emitting = true;
if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin) if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin)
{ {
// our character was parried // our character was parried
IsParried = true; IsParried = true;
AnimationPlayer.SpeedScale = 0.25f; AnimationPlayer.SpeedScale = 0.25f;
Character.Stun(1.5f); Character.Stun(1.5f);
GetNode<AudioStreamPlayer2D>("ParrySound").PlayOnRoot(); GetNode<AudioStreamPlayer2D>("ParrySound").PlayOnRoot();
} }
} }
//this.GetAncestor<TileMap>().AddChild(instance); //this.GetAncestor<TileMap>().AddChild(instance);
} }
public override void _on_hitbox_hit(BoundingBox box) public override void _on_hitbox_hit(BoundingBox box)
{ {
if (IsParried) if (IsParried)
{ {
return; return;
} }
if (box is Hitbox hb) if (box is Hitbox hb)
{ {
Weapon w = hb.GetAncestor<Weapon>(); Weapon w = hb.GetAncestor<Weapon>();
if (w is not null) if (w is not null)
{ {
AttemptParry(w); AttemptParry(w);
} }
} }
if (box is Hurtbox hurt) if (box is Hurtbox hurt)
{ {
if (hurt.GetParent() is Character c) if (hurt.GetParent() is Character c)
{ {
var item = c.Inventory.SelectedItem; var item = c.Inventory.SelectedItem;
if (item is Weapon w) if (item is Weapon w)
{ {
AttemptParry(w); AttemptParry(w);
} }
} }
} }
} }
} }
} }