57 lines
2.4 KiB
C#
57 lines
2.4 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);
|
|
}
|
|
}
|
|
}
|
|
} |