2020-05-11 01:17:10 +01:00
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
|
|
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
|
|
|
|
|
public class HitscanData : WeaponData
|
|
|
|
|
|
{
|
2020-05-21 01:53:06 +01:00
|
|
|
|
[InspectableField, JsonProperty("perSecond"), Key(6)]
|
|
|
|
|
|
public bool PerSecond;
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-05-11 01:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
return new Hitscan(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public class Hitscan : IBehavior
|
2020-05-11 01:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
private bool _firing;
|
|
|
|
|
|
private float _cooldown; // normalized
|
|
|
|
|
|
private HitscanData _data;
|
|
|
|
|
|
private Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
|
private EquippedItem Item { get; }
|
|
|
|
|
|
private ItemManager Context { get; }
|
2020-05-11 01:17:10 +01:00
|
|
|
|
private float _firingVisibility;
|
|
|
|
|
|
|
|
|
|
|
|
public BehaviorData Data => _data;
|
2020-05-28 04:50:40 +01:00
|
|
|
|
public float Range { get; private set; }
|
2020-05-11 01:17:10 +01:00
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public Hitscan(ItemManager context, HitscanData c, Entity entity, EquippedItem item)
|
2020-05-11 01:17:10 +01:00
|
|
|
|
{
|
|
|
|
|
|
Context = context;
|
|
|
|
|
|
_data = c;
|
|
|
|
|
|
Entity = entity;
|
|
|
|
|
|
Item = item;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool Update(float delta)
|
|
|
|
|
|
{
|
2020-05-21 01:53:06 +01:00
|
|
|
|
// TODO: Implement hitscan weapons!
|
2020-12-10 23:20:38 +00:00
|
|
|
|
Range = Context.Evaluate(_data.Range, Item.EquippableItem, Entity);
|
2020-05-11 01:17:10 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|