57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using BITFALL.Items;
|
||
|
using BITKit;
|
||
|
using NodeCanvas.Framework;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BITFALL.Quest
|
||
|
{
|
||
|
public class PostmanReceiveItem : ActionTask
|
||
|
{
|
||
|
public BBParameter<IBasicItem> item;
|
||
|
public BBParameter<bool> disposeItem;
|
||
|
protected override void OnExecute()
|
||
|
{
|
||
|
base.OnExecute();
|
||
|
QuestPostman.OnRelease += OnRelease;
|
||
|
}
|
||
|
private void OnRelease(WorldItemContainer arg1, IBasicItem arg2)
|
||
|
{
|
||
|
if (arg2 != item.value) return;
|
||
|
if (disposeItem.value)
|
||
|
{
|
||
|
arg1.Remove(arg2);
|
||
|
}
|
||
|
EndAction();
|
||
|
}
|
||
|
protected override void OnStop()
|
||
|
{
|
||
|
base.OnStop();
|
||
|
QuestPostman.OnRelease -= OnRelease;
|
||
|
}
|
||
|
}
|
||
|
public class QuestPostman : MonoBehaviour
|
||
|
{
|
||
|
public static event Action<WorldItemContainer, IBasicItem> OnRelease;
|
||
|
[SerializeField] private WorldItemContainer container;
|
||
|
private readonly List<IBasicItem> addedItems=new();
|
||
|
private void Start()
|
||
|
{
|
||
|
container.OnRelease += _OnRelease;
|
||
|
container.OnAdd += addedItems.Add;
|
||
|
container.OnRemove +=x=> addedItems.Remove(x);
|
||
|
}
|
||
|
private void _OnRelease(bool obj)
|
||
|
{
|
||
|
if (!obj) return;
|
||
|
foreach (var x in addedItems.ToArray())
|
||
|
{
|
||
|
OnRelease?.Invoke(container,x);
|
||
|
}
|
||
|
addedItems.Clear();
|
||
|
}
|
||
|
}
|
||
|
}
|