Files
Cielonos/Assets/Scripts/MainGame/Narrative/CustomFunctions/CustomFunctions.cs
SoulliesOfficial 6d7ebc5825 Passion & UI
2026-06-12 17:11:39 -04:00

63 lines
2.6 KiB
C#

using System;
using Cielonos.MainGame;
using Cielonos.MainGame.Inventory;
using UnityEngine;
using Yarn.Unity;
namespace Cielonos.Narrative
{
public static partial class CustomFunctions
{
[YarnCommand("obtain_item")]
public static void ObtainItem(string itemClass)
{
PlayerInventorySaveData startInventory = InfoTransistor.GetInfo<PlayerInventorySaveData>("StartInventory");
if (startInventory == null)
{
InfoTransistor.SetInfo("StartInventory", new PlayerInventorySaveData());
startInventory = InfoTransistor.GetInfo<PlayerInventorySaveData>("StartInventory");
}
Type type = Type.GetType($"Cielonos.MainGame.Inventory.Collections.{itemClass}");
if (type == null)
{
Debug.LogError($"[YarnCommand] Cannot find item class type for name '{itemClass}'. Make sure it is in namespace Cielonos.MainGame.Inventory.Collections");
return;
}
ItemBase item = MainGameManager.Player.inventorySc.backpackSm.ObtainItem(type);
ItemSaveData itemSaveData = new ItemSaveData(itemClass);
if (item is MainWeaponBase mainWeapon)
{
MainGameManager.Player.inventorySc.equipmentSm.PrepareMainWeapon(mainWeapon);
MainGameManager.Player.inventorySc.equipmentSm.EquipMainWeapon(mainWeapon);
startInventory.mainWeapons.Add(itemSaveData);
startInventory.preparedMainWeapons.Add(itemSaveData);
startInventory.currentMainWeapon = itemSaveData;
}
else if (item is SupportEquipmentBase supportEquipment)
{
MainGameManager.Player.inventorySc.equipmentSm.EquipSupportEquipment(supportEquipment, 0);
startInventory.supportEquipments.Add(itemSaveData);
startInventory.currentSupportEquipments.Add(itemSaveData);
}
else if (item is PassiveEquipmentBase passiveEquipment)
{
startInventory.passiveEquipments.Add(itemSaveData);
}
else if (item is ConsumableBase consumable)
{
itemSaveData.stackAmount = consumable.stackAmount;
startInventory.consumables.Add(itemSaveData);
}
}
[YarnFunction("check_have_item")]
public static bool CheckHaveItem(string itemClass)
{
return MainGameManager.Player.inventorySc.backpackSm.HaveItem(itemClass);
}
}
}