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/. */
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-05-21 01:53:06 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
2021-03-04 03:58:46 +00:00
|
|
|
|
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable]
|
2020-05-21 01:53:06 +01:00
|
|
|
|
public class EnergyDrawData : BehaviorData
|
|
|
|
|
|
{
|
2020-05-31 03:10:11 +01:00
|
|
|
|
[InspectableField, JsonProperty("draw"), Key(1), RuntimeInspectable]
|
2021-01-14 23:47:08 +00:00
|
|
|
|
public PerformanceStat EnergyDraw = new PerformanceStat();
|
2020-05-21 01:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
[InspectableField, JsonProperty("perSecond"), Key(2)]
|
|
|
|
|
|
public bool PerSecond;
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
return new EnergyDraw(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-27 22:18:22 +00:00
|
|
|
|
public class EnergyDraw : IBehavior
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
private EnergyDrawData _data;
|
|
|
|
|
|
|
|
|
|
|
|
private Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
|
private EquippedItem Item { get; }
|
|
|
|
|
|
private ItemManager Context { get; }
|
2020-05-21 01:53:06 +01:00
|
|
|
|
|
|
|
|
|
|
public BehaviorData Data => _data;
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public EnergyDraw(ItemManager context, EnergyDrawData data, Entity entity, EquippedItem item)
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
|
|
|
|
|
_data = data;
|
|
|
|
|
|
Entity = entity;
|
|
|
|
|
|
Item = item;
|
|
|
|
|
|
Context = context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-10 03:59:47 +00:00
|
|
|
|
public bool Execute(float delta)
|
2020-05-21 01:53:06 +01:00
|
|
|
|
{
|
2021-03-07 01:10:31 +00:00
|
|
|
|
return Entity.TryConsumeEnergy(Item.Evaluate(_data.EnergyDraw) * (_data.PerSecond ? delta : 1));
|
2020-05-21 01:53:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|