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-06-21 09:37:54 +01:00
|
|
|
using static CultMath.math;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
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-06-15 17:48:36 +01:00
|
|
|
private readonly PerformanceStat _topSpeed;
|
2020-04-09 10:33:16 +01:00
|
|
|
|
2026-06-15 19:06:13 +01:00
|
|
|
public VelocityLimit(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-06-15 19:06:13 +01:00
|
|
|
_topSpeed = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat("TopSpeed", _topSpeed);
|
2026-06-15 17:48:36 +01:00
|
|
|
Limit = Evaluate(_topSpeed);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-15 19:06:13 +01:00
|
|
|
public VelocityLimit(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2026-06-15 19:06:13 +01:00
|
|
|
_topSpeed = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat("TopSpeed", _topSpeed);
|
2026-06-15 17:48:36 +01:00
|
|
|
Limit = Evaluate(_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-06-15 17:48:36 +01:00
|
|
|
Limit = Evaluate(_topSpeed);
|
2026-06-21 09:37:54 +01:00
|
|
|
var velocity = Entity.CultVelocity;
|
|
|
|
|
if (length(velocity) > Limit)
|
|
|
|
|
Entity.CultVelocity = normalize(velocity) * Limit;
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2026-06-16 09:01:05 +01:00
|
|
|
|
|
|
|
|
public void RestoreRuntimeState(float limit)
|
|
|
|
|
{
|
|
|
|
|
Limit = limit;
|
|
|
|
|
}
|
2026-06-15 17:48:36 +01:00
|
|
|
}
|