2020-12-22 03:13:43 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
using MessagePack;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, MessagePackObject, RuntimeInspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public class VelocityLimitData : BehaviorData
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(1), RuntimeInspectable]
|
2020-04-09 10:33:16 +01:00
|
|
|
public PerformanceStat TopSpeed = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
|
|
|
{
|
|
|
|
|
return new VelocityLimit(this, item);
|
|
|
|
|
}
|
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2021-04-12 04:20:52 +01:00
|
|
|
return new VelocityLimit(this, item);
|
2020-04-09 10:33:16 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 22:35:56 +01:00
|
|
|
[Order(100)]
|
2021-04-18 05:13:20 +01:00
|
|
|
public class VelocityLimit : Behavior
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2020-05-07 03:53:54 +01:00
|
|
|
public float Limit { get; private set; }
|
2020-04-09 10:33:16 +01:00
|
|
|
|
|
|
|
|
private VelocityLimitData _data;
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public VelocityLimit(VelocityLimitData data, EquippedItem item) : base(data, item)
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
Limit = Evaluate(_data.TopSpeed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VelocityLimit(VelocityLimitData data, ConsumableItemEffect item) : base(data, item)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
|
|
|
|
_data = data;
|
2021-04-18 05:13:20 +01:00
|
|
|
Limit = Evaluate(_data.TopSpeed);
|
2020-04-09 10:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Limit = Evaluate(_data.TopSpeed);
|
|
|
|
|
if (length(Entity.Velocity) > Limit)
|
|
|
|
|
Entity.Velocity = normalize(Entity.Velocity) * Limit;
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-04-09 10:33:16 +01:00
|
|
|
}
|