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-12 01:42:13 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using MessagePack;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
2020-05-31 03:10:11 +01:00
|
|
|
|
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable]
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public class VisibilityData : BehaviorData
|
|
|
|
|
|
{
|
2020-05-31 03:10:11 +01:00
|
|
|
|
[InspectableField, JsonProperty("visibility"), Key(1), RuntimeInspectable]
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public PerformanceStat Visibility = new PerformanceStat();
|
|
|
|
|
|
|
|
|
|
|
|
[InspectableField, JsonProperty("visibilityDecay"), Key(2)]
|
|
|
|
|
|
public PerformanceStat VisibilityDecay = new PerformanceStat();
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
2020-05-12 01:42:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
return new Visibility(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class Visibility : IBehavior, IAlwaysUpdatedBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
private VisibilityData _data;
|
|
|
|
|
|
|
|
|
|
|
|
private Entity Entity { get; }
|
2020-12-10 23:20:38 +00:00
|
|
|
|
private EquippedItem Item { get; }
|
|
|
|
|
|
private ItemManager Context { get; }
|
2020-05-12 01:42:13 +01:00
|
|
|
|
|
|
|
|
|
|
public BehaviorData Data => _data;
|
|
|
|
|
|
|
|
|
|
|
|
private float _cooldown; // Normalized
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public Visibility(ItemManager context, VisibilityData data, Entity entity, EquippedItem item)
|
2020-05-12 01:42:13 +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-12 01:42:13 +01:00
|
|
|
|
{
|
2020-12-10 23:20:38 +00:00
|
|
|
|
Entity.VisibilitySources[this] = Context.Evaluate(_data.Visibility, Item.EquippableItem, Entity);
|
2020-05-12 01:42:13 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-10 03:59:47 +00:00
|
|
|
|
public void Update(float delta)
|
2020-05-12 01:42:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
// TODO: Time independent decay?
|
2021-01-05 02:56:17 +00:00
|
|
|
|
if(Entity.VisibilitySources.ContainsKey(this))
|
|
|
|
|
|
{
|
|
|
|
|
|
Entity.VisibilitySources[this] *= Context.Evaluate(_data.VisibilityDecay, Item.EquippableItem, Entity);
|
|
|
|
|
|
}
|
2020-05-12 01:42:13 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|