初次提交
This commit is contained in:
45
Script/Item/BagItem.cs
Normal file
45
Script/Item/BagItem.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class BagItem
|
||||
{
|
||||
public ItemResource itemResource;
|
||||
public int amount;
|
||||
|
||||
public string ItemName
|
||||
{
|
||||
get
|
||||
{
|
||||
return itemResource?.ItemName ?? "Unknown"; // 防止空引用
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return itemResource?.Description ?? "No description"; // 防止空引用
|
||||
}
|
||||
}
|
||||
|
||||
public void AddAmount(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
GD.PrintErr("Cannot add negative amount to BagItem.");
|
||||
return;
|
||||
}
|
||||
amount += value;
|
||||
}
|
||||
|
||||
public void RemoveAmount(int value)
|
||||
{
|
||||
if (value < 0 || value > amount)
|
||||
{
|
||||
GD.PrintErr("Invalid amount to remove from BagItem.");
|
||||
return;
|
||||
}
|
||||
amount -= value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user