Major Player refactor
This commit is contained in:
@@ -1,53 +1,52 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ThrownItem : RigidBody3D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
|
||||
|
||||
public InventoryItemStats ThrownItemStats;
|
||||
public IInventoryItem ItemThatIsThrown;
|
||||
|
||||
[Node] public Sprite3D Sprite { get; set; } = default!;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
BodyEntered += ThrownItem_BodyEntered;
|
||||
GlobalPosition = Game.Player.GlobalPosition + new Vector3(0, 0, 0);
|
||||
Sprite.Texture = ThrownItemStats.Texture;
|
||||
AddCollisionExceptionWith((Node)Game.Player);
|
||||
GlobalPosition = Player.CurrentPosition;
|
||||
Sprite.Texture = ItemThatIsThrown.GetTexture();
|
||||
AddCollisionExceptionWith((Node)Player);
|
||||
}
|
||||
|
||||
private void ThrownItem_BodyEntered(Node body)
|
||||
{
|
||||
if (body is IEnemy enemy)
|
||||
{
|
||||
CalculateEffect(enemy);
|
||||
}
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
{
|
||||
ApplyCentralImpulse(-Game.Player.GlobalBasis.Z.Normalized() * ThrownItemStats.ThrowSpeed);
|
||||
ApplyCentralImpulse(-Player.CurrentBasis.Z.Normalized() * ItemThatIsThrown.ThrowSpeed);
|
||||
}
|
||||
|
||||
private void CalculateEffect(IEnemy enemy)
|
||||
{
|
||||
if (ThrownItemStats is ThrowableItemStats throwableItemStats)
|
||||
if (ItemThatIsThrown is ThrowableItem throwableItem)
|
||||
{
|
||||
if (throwableItemStats.ThrowableItemTags.Contains(ThrowableItemTag.LowerTargetTo1HP))
|
||||
enemy.TakeDamage(enemy.CurrentHP - 1, ElementType.None, false, true, true);
|
||||
if (throwableItem.ThrowableItemTags.Contains(ThrowableItemTag.LowerTargetTo1HP))
|
||||
enemy.TakeDamage(enemy.CurrentHP - 1, ignoreDefense: true, ignoreElementalResistance: true);
|
||||
else
|
||||
enemy.TakeDamage(throwableItemStats.ThrowDamage, throwableItemStats.ElementType);
|
||||
enemy.TakeDamage(throwableItem.ThrowDamage, throwableItem.ElementType);
|
||||
}
|
||||
else
|
||||
{
|
||||
enemy.TakeDamage(ThrownItemStats.ThrowDamage, ElementType.None);
|
||||
enemy.TakeDamage(ItemThatIsThrown.ThrowDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user