252 lines
7.3 KiB
C#
252 lines
7.3 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 class LookAround : IBehaviour
|
|
{
|
|
public enum Type
|
|
{
|
|
Direction,
|
|
Player,
|
|
Randomly
|
|
}
|
|
|
|
public new class MethodName : IBehaviour.MethodName
|
|
{
|
|
public new static readonly StringName Do = "Do";
|
|
}
|
|
|
|
public new class PropertyName : IBehaviour.PropertyName
|
|
{
|
|
public static readonly StringName type = "type";
|
|
|
|
public static readonly StringName anim = "anim";
|
|
|
|
public static readonly StringName direction = "direction";
|
|
|
|
public static readonly StringName time = "time";
|
|
|
|
public static readonly StringName variance = "variance";
|
|
|
|
public static readonly StringName cooldown = "cooldown";
|
|
}
|
|
|
|
public new class SignalName : IBehaviour.SignalName
|
|
{
|
|
}
|
|
|
|
[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;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal new static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(1)
|
|
{
|
|
new MethodInfo(MethodName.Do, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
|
|
{
|
|
if (method == MethodName.Do && args.Count == 0)
|
|
{
|
|
Do();
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
return base.InvokeGodotClassMethod(in method, args, out ret);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool HasGodotClassMethod(in godot_string_name method)
|
|
{
|
|
if (method == MethodName.Do)
|
|
{
|
|
return true;
|
|
}
|
|
return base.HasGodotClassMethod(in method);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
|
|
{
|
|
if (name == PropertyName.type)
|
|
{
|
|
type = VariantUtils.ConvertTo<Type>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.anim)
|
|
{
|
|
anim = VariantUtils.ConvertTo<Entity.Animations>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.direction)
|
|
{
|
|
direction = VariantUtils.ConvertTo<Entity.Direction>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.time)
|
|
{
|
|
time = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
variance = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cooldown)
|
|
{
|
|
cooldown = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
return base.SetGodotClassPropertyValue(in name, in value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
|
|
{
|
|
if (name == PropertyName.type)
|
|
{
|
|
value = VariantUtils.CreateFrom(in type);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.anim)
|
|
{
|
|
value = VariantUtils.CreateFrom(in anim);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.direction)
|
|
{
|
|
value = VariantUtils.CreateFrom(in direction);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.time)
|
|
{
|
|
value = VariantUtils.CreateFrom(in time);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in variance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cooldown)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cooldown);
|
|
return true;
|
|
}
|
|
return base.GetGodotClassPropertyValue(in name, out value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal new static List<PropertyInfo> GetGodotPropertyList()
|
|
{
|
|
return new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.type, PropertyHint.Enum, "Direction,Player,Randomly", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.anim, PropertyHint.Enum, "Override:-2,None:-1,Idle:0,Walk:1,Run:2,Jumped:3,ReadyJump:4,JumpIn:5,Fallen:6,BattleStart:7,Hurt:8,BattleIdle:9,Sweep:10,BattleEnd:11,AttackReady:12,SkillReady:13,SkillDo:14,ActReady:15,ActDo:16,ItemReady:17,ItemDo:18,Defend:19,KO:20,Slide:21,Sit:22,Attack:23,Back:24,HandRaise:25,Talk:26,Elec:27,Fainted:28,Sleep:29,Special:30", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.direction, PropertyHint.Enum, "South:0,North:1,East:2,West:3,Side:4,None:-1", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.time, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.variance, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cooldown, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.type, Variant.From(in type));
|
|
info.AddProperty(PropertyName.anim, Variant.From(in anim));
|
|
info.AddProperty(PropertyName.direction, Variant.From(in direction));
|
|
info.AddProperty(PropertyName.time, Variant.From(in time));
|
|
info.AddProperty(PropertyName.variance, Variant.From(in variance));
|
|
info.AddProperty(PropertyName.cooldown, Variant.From(in cooldown));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.type, out var value))
|
|
{
|
|
type = value.As<Type>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.anim, out var value2))
|
|
{
|
|
anim = value2.As<Entity.Animations>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.direction, out var value3))
|
|
{
|
|
direction = value3.As<Entity.Direction>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.time, out var value4))
|
|
{
|
|
time = value4.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.variance, out var value5))
|
|
{
|
|
variance = value5.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cooldown, out var value6))
|
|
{
|
|
cooldown = value6.As<float>();
|
|
}
|
|
}
|
|
}
|