2026-06-05 04:21:00 -04:00
using System ;
using Cielonos.MainGame ;
using Cielonos.MainGame.Inventory ;
2026-06-02 12:55:39 -04:00
using UnityEngine ;
2026-06-05 04:21:00 -04:00
using Yarn.Unity ;
2026-06-02 12:55:39 -04:00
namespace Cielonos.Narrative
{
public static partial class CustomFunctions
{
2026-06-05 04:21:00 -04:00
[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 ) ;
}
}
2026-06-02 12:55:39 -04:00
}
}