70 lines
2.9 KiB
C#
70 lines
2.9 KiB
C#
/* 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/. */
|
|
|
|
using static CultMath.math;
|
|
|
|
public class MiningTool : Behavior
|
|
{
|
|
public string AsteroidBeltBodyKey = "";
|
|
public int Asteroid;
|
|
|
|
private readonly PerformanceStat _damagePerSecond;
|
|
private readonly PerformanceStat _efficiency;
|
|
private readonly PerformanceStat _penetration;
|
|
private readonly PerformanceStat _range;
|
|
public float Range { get; private set; }
|
|
|
|
public MiningTool(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
|
{
|
|
_damagePerSecond = definition.PerformanceStat(1, new PerformanceStat());
|
|
_efficiency = definition.PerformanceStat(2, new PerformanceStat());
|
|
_penetration = definition.PerformanceStat(3, new PerformanceStat());
|
|
_range = definition.PerformanceStat(4, new PerformanceStat());
|
|
RegisterPerformanceStat("DamagePerSecond", _damagePerSecond);
|
|
RegisterPerformanceStat("Efficiency", _efficiency);
|
|
RegisterPerformanceStat("Penetration", _penetration);
|
|
RegisterPerformanceStat(nameof(Range), _range);
|
|
}
|
|
|
|
public MiningTool(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
|
{
|
|
_damagePerSecond = definition.PerformanceStat(1, new PerformanceStat());
|
|
_efficiency = definition.PerformanceStat(2, new PerformanceStat());
|
|
_penetration = definition.PerformanceStat(3, new PerformanceStat());
|
|
_range = definition.PerformanceStat(4, new PerformanceStat());
|
|
RegisterPerformanceStat("DamagePerSecond", _damagePerSecond);
|
|
RegisterPerformanceStat("Efficiency", _efficiency);
|
|
RegisterPerformanceStat("Penetration", _penetration);
|
|
RegisterPerformanceStat(nameof(Range), _range);
|
|
}
|
|
|
|
public override bool Execute(float dt)
|
|
{
|
|
Range = Evaluate(_range);
|
|
if (!string.IsNullOrWhiteSpace(AsteroidBeltBodyKey) &&
|
|
Entity.Zone.TryGetAsteroidBelt(AsteroidBeltBodyKey, out var belt) &&
|
|
Entity.Zone.AsteroidExists(AsteroidBeltBodyKey, Asteroid) &&
|
|
Entity.Zone.TryGetCultAsteroidTransform(AsteroidBeltBodyKey, Asteroid, out var asteroidPosition, out var asteroidRadius) &&
|
|
length(Entity.CultPositionXZ - asteroidPosition) - asteroidRadius < Range)
|
|
{
|
|
Entity.Zone.MineAsteroid(
|
|
Entity,
|
|
AsteroidBeltBodyKey,
|
|
Asteroid,
|
|
Evaluate(_damagePerSecond) * dt,
|
|
Evaluate(_efficiency),
|
|
Evaluate(_penetration));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void RestoreRuntimeState(string asteroidBeltBodyKey, int asteroid, float range)
|
|
{
|
|
AsteroidBeltBodyKey = asteroidBeltBodyKey ?? "";
|
|
Asteroid = asteroid;
|
|
Range = range;
|
|
}
|
|
}
|