Massive Item Behavior Refactoring
Item behaviors are now separated into more granular units, allowing designers to create more interesting items by combining behaviors
This commit is contained in:
parent
fc94531566
commit
8cd4ea3dc5
40 changed files with 822 additions and 445 deletions
55
Assets/Scripts/ServerShared/Behaviors/Cooldown.cs
Normal file
55
Assets/Scripts/ServerShared/Behaviors/Cooldown.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
public class CooldownData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("cooldown"), Key(1)]
|
||||
public PerformanceStat Cooldown = new PerformanceStat();
|
||||
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
{
|
||||
return new Cooldown(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-10)]
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private CooldownData _data;
|
||||
|
||||
private Entity Entity { get; }
|
||||
private Gear Item { get; }
|
||||
private GameContext Context { get; }
|
||||
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private float _cooldown; // Normalized
|
||||
|
||||
public Cooldown(GameContext context, CooldownData data, Entity entity, Gear item)
|
||||
{
|
||||
_data = data;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
Context = context;
|
||||
}
|
||||
|
||||
public bool Update(float delta)
|
||||
{
|
||||
if (_cooldown < 0)
|
||||
{
|
||||
_cooldown = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public void AlwaysUpdate(float delta)
|
||||
{
|
||||
_cooldown -= delta / Context.Evaluate(_data.Cooldown, Item, Entity);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue