2025-05-13 19:22:01 +08:00

70 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[GlobalClass]
[ScriptPath("res://Scripts/Actions/LookAround.cs")]
public partial class LookAround : IBehaviour
{
public enum Type
{
Direction,
Player,
Randomly
}
[Export(PropertyHint.None, "")]
private Type type;
[Export(PropertyHint.None, "")]
public Entity.Animations anim = Entity.Animations.None;
[Export(PropertyHint.None, "")]
private Entity.Direction direction;
[Export(PropertyHint.None, "")]
private float time = 180f;
[Export(PropertyHint.None, "")]
private float variance = 30f;
private float cooldown;
public override void Do()
{
if (anim != Entity.Animations.None)
{
base.parent.currentAnim = anim;
}
switch (type)
{
case Type.Randomly:
if (cooldown > 0f)
{
cooldown -= Main.deltaTime;
break;
}
base.parent.direction = (Entity.Direction)Main.RandomRange(0, 3);
cooldown = time + Main.RandomRange(0f - variance, variance);
break;
case Type.Player:
base.parent.LookAt(Player.instance.GlobalPosition);
break;
case Type.Direction:
{
Entity.Direction direction = base.parent.direction;
base.parent.direction = this.direction;
if (this.direction != direction)
{
base.parent.UpdateAnim(force: true);
}
break;
}
}
base.parent.current = null;
}
}