コード例 #1
0
        public virtual int setInventory(ItemData data, int value = 0)
        {
            int max = 0;

            max = maxInventory(data);
            if (value > max)
            {
                value = max;
            }

            int amount = this["inv[" + data.getName() + "]"].AsInt();

            if (amount != value)
            {
                this["inv[" + data.getName() + "]"] = value.AsString();
                //console.warn("Setting " + data.getName() + " to " + value);

                data.onInventory(this, value);
            }
            return(value);
        }
コード例 #2
0
        public virtual int decInventory(ItemData data, int amount = 0)
        {
            int total = this["inv[" + data.getName() + "]"].AsInt();

            if (total > 0)
            {
                if (total < amount)
                {
                    amount = total;
                }

                setInventory(data, (total - amount));
                return(amount);
            }
            return(0);
        }
コード例 #3
0
        public virtual int incInventory(ItemData datablock, int amount)
        {
            int maxamount = maxInventory(datablock);

            int total = this["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
            {
                if (total + amount > maxamount)
                {
                    amount = (maxamount - total);
                }
                setInventory(datablock, (total + amount));
                return(amount);
            }
            return(0);
        }
コード例 #4
0
        public virtual int setInventory(ItemData data, int value = 0)
        {
            int max = 0;

            max = maxInventory(data);
            if (value > max)
                value = max;

            int amount = this["inv[" + data.getName() + "]"].AsInt();

            if (amount != value)
                {
                this["inv[" + data.getName() + "]"] = value.AsString();
                //console.warn("Setting " + data.getName() + " to " + value);

                data.onInventory(this, value);
                }
            return value;
        }
コード例 #5
0
        public virtual int decInventory(ItemData data, int amount = 0)
        {
            int total = this["inv[" + data.getName() + "]"].AsInt();

            if (total > 0)
                {
                if (total < amount)
                    amount = total;

                setInventory(data, (total - amount));
                return amount;
                }
            return 0;
        }
コード例 #6
0
        public virtual int incInventory(ItemData datablock, int amount)
        {
            int maxamount = maxInventory(datablock);

            int total = this["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
                {
                if (total + amount > maxamount)
                    amount = (maxamount - total);
                setInventory(datablock, (total + amount));
                return amount;
                }
            return 0;
        }