71 lines
1.8 KiB
C#
71 lines
1.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITFALL.Industry;
|
|
using BITFALL.Items;
|
|
using BITKit;
|
|
using NodeCanvas.Framework;
|
|
using UnityEngine;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace BITFALL.Quest
|
|
{
|
|
public class CreateItemToContainer : ActionTask<Transform>
|
|
{
|
|
[DictionaryReferenceConfig(nameof(allow_quest_item))]
|
|
public const string allow_quest_item = nameof(allow_quest_item);
|
|
|
|
|
|
public BBParameter<Vector3> size;
|
|
public BBParameter<ScriptableItem> itemTemplate;
|
|
public BBParameter<IBasicItem> item;
|
|
protected override void OnExecute()
|
|
{
|
|
base.OnExecute();
|
|
|
|
|
|
var containers = WorldItemContainer.Query(agent.position, size.value);
|
|
|
|
containers = containers.Where(x => x.TryGetComponent<ITag>(out var tag) && tag.GetTags().Contains(allow_quest_item)).ToArray();
|
|
|
|
var newItem = itemTemplate.value.Clone().As<IBasicItem>();
|
|
|
|
if (containers.Length is 0)
|
|
{
|
|
newItem = Object.Instantiate(itemTemplate.value.GetPrefab(), agent.position,Quaternion.identity);
|
|
|
|
BIT4Log.Log<CreateItemToContainer>($"未找到容器,已创建物品于场景,物品名称:{newItem.Name}");
|
|
}
|
|
else
|
|
{
|
|
newItem.GetOrCreateProperty<IsQuestItem>();
|
|
|
|
var container =containers.Random();
|
|
|
|
container.AddInternal(newItem);
|
|
BIT4Log.Log<CreateItemToContainer>($"已创建:{newItem.Name}于容器:{container.Name}");
|
|
}
|
|
|
|
newItem.GetOrCreateProperty<IsQuestItem>();
|
|
|
|
// newItem.TryRemoveProperty<IDataStorage>();
|
|
//
|
|
// var data= newItem.GetOrAddProperty<IDataStorage>(()=>new GameDataStorage()
|
|
// {
|
|
// ReadOnly = true,
|
|
// Data = Guid.NewGuid().ToString(),
|
|
// Encrypted = true
|
|
// });
|
|
//
|
|
// key.value = data.Data;
|
|
|
|
item.SetValue(newItem);
|
|
|
|
EndAction();
|
|
}
|
|
}
|
|
|
|
}
|
|
|