46 lines
1.5 KiB
C#
46 lines
1.5 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public partial class ShootShortbow : PegAction
|
|
{
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
_category = "attack";
|
|
_priority = 1;
|
|
_cost = 2;
|
|
_range = 2;
|
|
_usesMax = 1;
|
|
_usesRemaining = _usesMax;
|
|
}
|
|
|
|
public override Tween CreateAnimation(Peg PEG)
|
|
{
|
|
Vector2 target = PEG._pegController._playArea._map.GetCellPositionFromAddress(Target(PEG));
|
|
Tween subtween = CreateTween();
|
|
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
|
subtween.TweenProperty(_image, "rotation", PEG.GetAngleTo(target), 0.0f);
|
|
subtween.TweenProperty(_image, "global_position", target, 0.5f);
|
|
subtween.TweenCallback(Callable.From(() =>
|
|
{
|
|
PEG._pegController._playerController.ChangeHealth(-1, this);
|
|
Position = Vector2.Zero;
|
|
Visible = false;
|
|
}));
|
|
return subtween;
|
|
}
|
|
|
|
public override Vector2I Target(Peg PEG)
|
|
{
|
|
List<Vector2I> closest = [.. PEG.GetVisibleCells().Where(c => (int)PEG._pegController._playArea._map.GetCellTileData(c).GetCustomData("disposition") == -PEG._disposition).OrderBy(c => (c - PEG._address).Length())];
|
|
if (closest.Count == 0)
|
|
{
|
|
return -Vector2I.One;
|
|
}
|
|
return closest[0]; // return PEG._pegController._playerController._towers.OrderBy(t => (t.GlobalPosition - GlobalPosition).Length()).ToList()[0].GlobalPosition;
|
|
}
|
|
|
|
}
|