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/. */
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
using MessagePack;
|
|
|
|
|
using Newtonsoft.Json;
|
2026-09-14 17:39:12 +02:00
|
|
|
using CultMath;
|
|
|
|
|
using static CultMath.math;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
|
|
|
|
public class VelocityLimitData : BehaviorData
|
|
|
|
|
{
|
|
|
|
|
[Inspectable, JsonProperty("topSpeed"), Key(1), RuntimeInspectable]
|
|
|
|
|
public PerformanceStat TopSpeed = new PerformanceStat();
|
|
|
|
|
|
|
|
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
|
|
|
{
|
|
|
|
|
return new VelocityLimit(this, item);
|
|
|
|
|
}
|
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
|
|
|
|
{
|
|
|
|
|
return new VelocityLimit(this, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
private VelocityLimitData _data;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
public VelocityLimit(VelocityLimitData data, EquippedItem item) : base(data, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
_data = data;
|
|
|
|
|
Limit = Evaluate(_data.TopSpeed);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
public VelocityLimit(VelocityLimitData data, ConsumableItemEffect item) : base(data, item)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
_data = data;
|
|
|
|
|
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
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
Limit = Evaluate(_data.TopSpeed);
|
|
|
|
|
if (length(Entity.Velocity) > Limit)
|
2026-10-07 05:39:40 +02:00
|
|
|
{
|
|
|
|
|
var clamped = normalize(Entity.Velocity) * Limit;
|
|
|
|
|
Entity.LimitClamp += Entity.Velocity - clamped;
|
|
|
|
|
Entity.Velocity = clamped;
|
|
|
|
|
}
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
}
|