Beispiel #1
0
    /**
     * Adds an item to current user
     *
     * @param int id item id
     * @param int amount item quantity
     *
     * @return bool
     */
    public bool addItem(int id, int amount = 1)
    {
        bool          success;
        CharacterItem characterItem = Service.getOne <CharacterItem>("FROM inventory WHERE item == ?", id);

        if (characterItem != null)
        {
            characterItem.quantity += amount;
            characterItem.save();
            success = true;
        }
        else
        {
            CharacterItem item = new CharacterItem {
                item     = id,
                quantity = amount
            };
            success = item.create();
        }
        // reload inventory
        if (success)
        {
            try {
                QuestManager.Instance.sendAction(id, Task.ActorType.Item, Task.ActionType.GetItem, amount);
                Inventory.Instance.reload();
            } catch (Exception) { }
        }

        return(success);
    }
Beispiel #2
0
    /**
     * Use this item
     *
     */
    public void use()
    {
        switch (type)
        {
        case Item.ItemType.Consumable:
            switch (subType)
            {
            case Item.ItemSubType.Health:
                Player.Instance.health += health;
                characterItem.quantity--;
                break;
            }
            break;

        default:
            return;
        }
        characterItem.save();
    }