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/. */
|
|
|
|
|
|
2020-04-09 07:48:45 +01:00
|
|
|
using MessagePack;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, MessagePackObject, RuntimeInspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public class ShieldData : BehaviorData
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(1), RuntimeInspectable]
|
2020-04-09 07:48:45 +01:00
|
|
|
public PerformanceStat Efficiency = new PerformanceStat();
|
|
|
|
|
|
2026-06-13 04:56:50 +01:00
|
|
|
[Inspectable, Key(2), RuntimeInspectable]
|
2021-03-06 01:04:26 +00:00
|
|
|
public PerformanceStat EnergyUsage = 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 Shield(this, item);
|
|
|
|
|
}
|
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
2021-04-12 04:20:52 +01:00
|
|
|
return new Shield(this, item);
|
2020-04-09 07:48:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2020-04-09 10:33:16 +01:00
|
|
|
private ShieldData _data;
|
2020-04-09 07:48:45 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public Shield(ShieldData data, EquippedItem item) : base(data, item)
|
|
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
|
|
|
|
public Shield(ShieldData data, ConsumableItemEffect item) : base(data, item)
|
2020-04-09 07:48:45 +01:00
|
|
|
{
|
|
|
|
|
_data = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public override bool Execute(float dt)
|
2020-05-11 01:17:10 +01:00
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
Efficiency = Evaluate(_data.Efficiency);
|
|
|
|
|
EnergyUsage = Evaluate(_data.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;
|
2020-04-09 07:48:45 +01:00
|
|
|
}
|