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-13 22:35:56 +01:00
|
|
|
|
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20)]
|
2020-05-12 01:42:13 +01:00
|
|
|
|
public class TriggerData : BehaviorData
|
|
|
|
|
|
{
|
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 Trigger(context, this, entity, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class Trigger : IBehavior
|
|
|
|
|
|
{
|
|
|
|
|
|
private TriggerData _data;
|
|
|
|
|
|
|
2021-01-06 14:56:39 +00:00
|
|
|
|
public Entity Entity { get; }
|
|
|
|
|
|
public EquippedItem Item { get; }
|
|
|
|
|
|
public ItemManager Context { get; }
|
2020-05-12 01:42:13 +01:00
|
|
|
|
|
|
|
|
|
|
public BehaviorData Data => _data;
|
|
|
|
|
|
|
|
|
|
|
|
public bool _pulled;
|
|
|
|
|
|
|
|
|
|
|
|
public void Pull()
|
|
|
|
|
|
{
|
|
|
|
|
|
_pulled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
|
public Trigger(ItemManager context, TriggerData data, Entity entity, EquippedItem item)
|
2020-05-12 01:42:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
_data = data;
|
|
|
|
|
|
Entity = entity;
|
|
|
|
|
|
Item = item;
|
|
|
|
|
|
Context = context;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-10 03:59:47 +00:00
|
|
|
|
public bool Execute(float delta)
|
2020-05-12 01:42:13 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (_pulled)
|
|
|
|
|
|
{
|
|
|
|
|
|
_pulled = false;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|