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/. */
|
|
|
|
|
|
2021-04-29 00:21:33 +01:00
|
|
|
public class Shield : Behavior, IProgressBehavior
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2021-03-06 01:04:26 +00:00
|
|
|
public float Efficiency { get; private set; }
|
|
|
|
|
public float EnergyUsage { get; private set; }
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2026-06-15 17:54:59 +01:00
|
|
|
private readonly PerformanceStat _efficiency;
|
|
|
|
|
private readonly PerformanceStat _energyUsage;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2026-06-15 19:20:06 +01:00
|
|
|
public Shield(RuntimeBehaviorDefinition definition, EquippedItem item) : base(definition, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-06-15 19:20:06 +01:00
|
|
|
_efficiency = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
_energyUsage = definition.PerformanceStat(2, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat(nameof(Efficiency), _efficiency);
|
|
|
|
|
RegisterPerformanceStat(nameof(EnergyUsage), _energyUsage);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
2026-06-15 19:20:06 +01:00
|
|
|
|
|
|
|
|
public Shield(RuntimeBehaviorDefinition definition, ConsumableItemEffect item) : base(definition, item)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2026-06-15 19:20:06 +01:00
|
|
|
_efficiency = definition.PerformanceStat(1, new PerformanceStat());
|
|
|
|
|
_energyUsage = definition.PerformanceStat(2, new PerformanceStat());
|
|
|
|
|
RegisterPerformanceStat(nameof(Efficiency), _efficiency);
|
|
|
|
|
RegisterPerformanceStat(nameof(EnergyUsage), _energyUsage);
|
2020-04-09 07:48:45 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-05-11 01:17:10 +01:00
|
|
|
{
|
2026-06-15 17:54:59 +01:00
|
|
|
Efficiency = Evaluate(_efficiency);
|
|
|
|
|
EnergyUsage = Evaluate(_energyUsage);
|
2020-05-11 01:17:10 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2021-03-06 01:04:26 +00:00
|
|
|
|
|
|
|
|
public bool CanTakeHit(DamageType type, float damage)
|
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
return Entity.CanConsumeEnergy(damage * EnergyUsage);
|
2021-03-06 01:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void TakeHit(DamageType type, float damage)
|
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Entity.TryConsumeEnergy(damage * EnergyUsage);
|
|
|
|
|
AddHeat(damage / Efficiency);
|
2021-03-06 01:04:26 +00:00
|
|
|
}
|
2021-04-29 00:21:33 +01:00
|
|
|
|
|
|
|
|
public virtual float Progress => Item.ThermalPerformance;
|
2026-06-16 09:01:05 +01:00
|
|
|
|
|
|
|
|
public void RestoreRuntimeState(float efficiency, float energyUsage)
|
|
|
|
|
{
|
|
|
|
|
Efficiency = efficiency;
|
|
|
|
|
EnergyUsage = energyUsage;
|
|
|
|
|
}
|
2026-06-15 17:54:59 +01:00
|
|
|
}
|