2026-06-13 04:56:50 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2020-12-22 03:13:43 +00:00
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
|
|
using System;
|
2026-06-21 09:37:54 +01:00
|
|
|
using static CultMath.math;
|
2020-05-21 01:53:06 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public class ResourceScanner : Behavior, IAlwaysUpdatedBehavior
|
2020-05-21 01:53:06 +01:00
|
|
|
{
|
2020-05-29 23:06:35 +01:00
|
|
|
public int Asteroid = -1;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2026-06-15 17:54:59 +01:00
|
|
|
private readonly PerformanceStat _range;
|
|
|
|
|
private readonly PerformanceStat _minimumDensity;
|
|
|
|
|
private readonly PerformanceStat _scanDuration;
|
2020-05-29 23:06:35 +01:00
|
|
|
private float _scanTime;
|
2026-06-16 15:08:00 +01:00
|
|
|
private string _scanTargetBodyKey = "";
|
2020-05-21 01:53:06 +01:00
|
|
|
|
2020-05-29 23:06:35 +01:00
|
|
|
public float Range { get; private set; }
|
|
|
|
|
public float MinimumDensity { get; private set; }
|
|
|
|
|
public float ScanDuration { get; private set; }
|
2026-06-14 16:01:36 +01:00
|
|
|
public float ScanTime => _scanTime;
|
2020-05-29 23:06:35 +01:00
|
|
|
|
2026-06-16 15:08:00 +01:00
|
|
|
public string ScanTargetBodyKey
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-16 15:08:00 +01:00
|
|
|
get => _scanTargetBodyKey;
|
2020-05-29 23:06:35 +01:00
|
|
|
set
|
|
|
|
|
{
|
2026-06-16 15:08:00 +01:00
|
|
|
value ??= "";
|
|
|
|
|
if (!string.Equals(value, _scanTargetBodyKey, StringComparison.Ordinal))
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-16 15:08:00 +01:00
|
|
|
_scanTargetBodyKey = value;
|
2020-05-29 23:06:35 +01:00
|
|
|
_scanTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-21 01:53:06 +01:00
|
|
|
|
2026-06-15 19:20:06 +01:00
|
|
|
public ResourceScanner(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-06-15 19:20:06 +01:00
|
|
|
_range = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
_minimumDensity = definition.PerformanceStat(2, new PerformanceStat());
|
|
|
|
|
_scanDuration = definition.PerformanceStat(3, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat(nameof(Range), _range);
|
|
|
|
|
RegisterPerformanceStat(nameof(MinimumDensity), _minimumDensity);
|
|
|
|
|
RegisterPerformanceStat(nameof(ScanDuration), _scanDuration);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
|
2026-06-15 19:20:06 +01:00
|
|
|
public ResourceScanner(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
2020-05-21 01:53:06 +01:00
|
|
|
{
|
2026-06-15 19:20:06 +01:00
|
|
|
_range = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
_minimumDensity = definition.PerformanceStat(2, new PerformanceStat());
|
|
|
|
|
_scanDuration = definition.PerformanceStat(3, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat(nameof(Range), _range);
|
|
|
|
|
RegisterPerformanceStat(nameof(MinimumDensity), _minimumDensity);
|
|
|
|
|
RegisterPerformanceStat(nameof(ScanDuration), _scanDuration);
|
2020-05-21 01:53:06 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-05-21 01:53:06 +01:00
|
|
|
{
|
2026-06-16 15:08:00 +01:00
|
|
|
if (Entity.Zone.TryGetAsteroidBelt(ScanTargetBodyKey, out var belt))
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
if (Entity.Zone.TryGetCultAsteroidTransform(ScanTargetBodyKey, Asteroid, out var asteroidPosition, out _) &&
|
|
|
|
|
length(Entity.CultPositionXZ - asteroidPosition) < Range)
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-14 19:05:23 +01:00
|
|
|
_scanTime += dt;
|
|
|
|
|
if (_scanTime > ScanDuration)
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-14 19:05:23 +01:00
|
|
|
// TODO: Implement Scanning!
|
|
|
|
|
_scanTime = 0;
|
2020-05-29 23:06:35 +01:00
|
|
|
}
|
2026-06-14 19:05:23 +01:00
|
|
|
return true;
|
2020-05-29 23:06:35 +01:00
|
|
|
}
|
2026-06-14 19:05:23 +01:00
|
|
|
}
|
2026-06-16 15:08:00 +01:00
|
|
|
else if (Entity.Zone.TryGetPlanet(ScanTargetBodyKey, out var planet))
|
2026-06-14 19:05:23 +01:00
|
|
|
{
|
2026-06-21 09:37:54 +01:00
|
|
|
if(length(Entity.CultPositionXZ - AetheriaMath.ToCult(Entity.Zone.GetOrbitPosition(planet.OrbitKey))) < Range)
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-14 19:05:23 +01:00
|
|
|
_scanTime += dt;
|
|
|
|
|
if (_scanTime > ScanDuration)
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-14 19:05:23 +01:00
|
|
|
_scanTime = 0;
|
2020-05-29 23:06:35 +01:00
|
|
|
}
|
2026-06-14 19:05:23 +01:00
|
|
|
return true;
|
2020-05-29 23:06:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-10 03:59:47 +00:00
|
|
|
public void Update(float delta)
|
2020-05-29 23:06:35 +01:00
|
|
|
{
|
2026-06-15 17:54:59 +01:00
|
|
|
Range = Evaluate(_range);
|
|
|
|
|
MinimumDensity = Evaluate(_minimumDensity);
|
|
|
|
|
ScanDuration = Evaluate(_scanDuration);
|
2020-05-21 01:53:06 +01:00
|
|
|
}
|
2026-06-16 09:01:05 +01:00
|
|
|
|
|
|
|
|
public void RestoreRuntimeState(
|
2026-06-16 15:08:00 +01:00
|
|
|
string scanTargetBodyKey,
|
2026-06-16 09:01:05 +01:00
|
|
|
int asteroid,
|
|
|
|
|
float scanTime,
|
|
|
|
|
float range,
|
|
|
|
|
float minimumDensity,
|
|
|
|
|
float scanDuration)
|
|
|
|
|
{
|
2026-06-16 15:08:00 +01:00
|
|
|
_scanTargetBodyKey = scanTargetBodyKey ?? "";
|
2026-06-16 09:01:05 +01:00
|
|
|
Asteroid = asteroid;
|
|
|
|
|
_scanTime = scanTime;
|
|
|
|
|
Range = range;
|
|
|
|
|
MinimumDensity = minimumDensity;
|
|
|
|
|
ScanDuration = scanDuration;
|
|
|
|
|
}
|
2026-06-13 14:07:21 +01:00
|
|
|
}
|