2026-08-10 14:57: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-21 01:53:06 +01:00
|
|
|
|
using System.Linq;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
|
|
[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable]
|
|
|
|
|
|
public class EnergyDrawData : BehaviorData
|
|
|
|
|
|
{
|
|
|
|
|
|
[Inspectable, JsonProperty("draw"), Key(1), RuntimeInspectable]
|
|
|
|
|
|
public PerformanceStat EnergyDraw = new PerformanceStat();
|
|
|
|
|
|
|
|
|
|
|
|
[Inspectable, JsonProperty("perSecond"), Key(2)]
|
|
|
|
|
|
public bool PerSecond;
|
|
|
|
|
|
|
|
|
|
|
|
public override Behavior CreateInstance(EquippedItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new EnergyDraw(this, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Behavior CreateInstance(ConsumableItemEffect item)
|
|
|
|
|
|
{
|
|
|
|
|
|
return new EnergyDraw(this, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
|
public class EnergyDraw : Behavior
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
private EnergyDrawData _data;
|
2020-05-21 01:53:06 +01:00
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public EnergyDraw(EnergyDrawData data, EquippedItem item) : base(data, item)
|
2021-04-18 05:13:20 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
_data = data;
|
2021-04-18 05:13:20 +01:00
|
|
|
|
}
|
2020-05-21 01:53:06 +01:00
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
|
public EnergyDraw(EnergyDrawData data, ConsumableItemEffect item) : base(data, item)
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
2026-08-10 14:57:50 +01:00
|
|
|
|
_data = data;
|
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-08-10 14:57:50 +01:00
|
|
|
|
return Entity.TryConsumeEnergy(Evaluate(_data.EnergyDraw) * (_data.PerSecond ? dt : 1));
|
2020-05-21 01:53:06 +01:00
|
|
|
|
}
|
2026-08-10 14:57:50 +01:00
|
|
|
|
}
|