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;
|
2020-05-28 04:50:40 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using MessagePack;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, MessagePackObject, Order(10)]
|
2020-05-28 04:50:40 +01:00
|
|
|
public class MiningToolData : BehaviorData
|
|
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(1)]
|
2020-05-28 04:50:40 +01:00
|
|
|
public PerformanceStat DamagePerSecond = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[Inspectable, Key(2)]
|
2020-05-28 04:50:40 +01:00
|
|
|
public PerformanceStat Efficiency = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[Inspectable, Key(3)]
|
2020-05-28 04:50:40 +01:00
|
|
|
public PerformanceStat Penetration = new PerformanceStat();
|
2026-06-13 04:56:50 +01:00
|
|
|
|
|
|
|
|
[Inspectable, Key(4)]
|
2020-05-28 04:50:40 +01:00
|
|
|
public PerformanceStat Range = 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 MiningTool(this, item);
|
|
|
|
|
}
|
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
2020-05-28 04:50:40 +01:00
|
|
|
{
|
2021-04-12 04:20:52 +01:00
|
|
|
return new MiningTool(this, item);
|
2020-05-28 04:50:40 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public class MiningTool : Behavior
|
2020-05-28 04:50:40 +01:00
|
|
|
{
|
|
|
|
|
public Guid AsteroidBelt;
|
|
|
|
|
public int Asteroid;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2020-05-28 04:50:40 +01:00
|
|
|
private MiningToolData _data;
|
|
|
|
|
public float Range { get; private set; }
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public MiningTool(MiningToolData data, EquippedItem item) : base(data, item)
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MiningTool(MiningToolData data, ConsumableItemEffect item) : base(data, item)
|
2020-05-28 04:50:40 +01:00
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-05-28 04:50:40 +01:00
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Range = Evaluate(_data.Range);
|
|
|
|
|
var belt = Entity.Zone.AsteroidBelts[AsteroidBelt];
|
2026-06-13 04:56:50 +01:00
|
|
|
if (AsteroidBelt != Guid.Empty &&
|
|
|
|
|
Entity.Zone.AsteroidExists(AsteroidBelt, Asteroid) &&
|
2022-07-19 18:55:17 +01:00
|
|
|
length(Entity.Position.xz - belt.Transforms[Asteroid].xy) - belt.Transforms[Asteroid].w < Range)
|
2020-05-28 04:50:40 +01:00
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Entity.Zone.MineAsteroid(
|
|
|
|
|
Entity,
|
2020-05-28 04:50:40 +01:00
|
|
|
AsteroidBelt,
|
|
|
|
|
Asteroid,
|
2021-04-18 05:13:20 +01:00
|
|
|
Evaluate(_data.DamagePerSecond) * dt,
|
|
|
|
|
Evaluate(_data.Efficiency),
|
|
|
|
|
Evaluate(_data.Penetration));
|
2020-05-28 04:50:40 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|