Forgottenserver: Item charge conflicting.

Created on 21 Oct 2019  路  4Comments  路  Source: otland/forgottenserver

Before creating an issue, please ensure:

  • [x] This is a bug in the software that resides in this repository, and not a
    support matter (use https://otland.net/forums/support.16/ for support)
  • [x] This issue is reproducible without changes to the code in this repository

Steps to reproduce (include any configuration/script required to reproduce)

  1. Create an item with charge attribute.
    Example:
    Screenshot_17

  2. See the description, it'll show only 1 charge.
    Screenshot_16

Expected behaviour

Show all charges declared in items.xml.

Environment

I made a test in Item::getDescription(const ItemType& it, int32_t lookDistance, const Item* item /*= nullptr*/, int32_t subType /*= -1*/, bool addArticle /*= true*/) too see why it's returning 1, because when we set the charge by item:setAttribute(ITEM_ATTRIBUTE_CHARGES), it works fine (you can test it now using enchating.lua in data/actions).
Screenshot_11

Most helpful comment

I think it's not a problem, because when the item have charges, count is = charge. See this example:

/i might ring, 94

02:04 You see a might ring (protection physical +20%, energy +20%, earth +20%, fire +20%, ice +20%, holy +20%, death +20%) that has 94 charges left.

in constructor of the file item.cpp you can find this code:

    } else if (it.charges != 0) {
        if (count != 0) {
            setCharges(count);
        } else {
            setCharges(it.charges);
        }
    }

EDIT:
I created a function to use as you suggested, please test and tell me what you think.

function Player.addChargeItem(self, itemid, count)
    local type = ItemType(itemid)
    if type:getCharges() == 0 then
        return nil
    end

    local items = {}
    for i = 1, math.max(1, count or 0) do
        local item = self:addItem(itemid, type:getCharges())
        table.insert(items, item)
    end

    return #items == 1 and items[1] or items
end

Example

-- add 1 might ring with 20 charges
player:addChargeItem('might ring')

-- add 3 might rings with 20 charges
player:addChargeItem('might ring', 3)

All 4 comments

How did you create the item? You may have created it like /i bonfire amulet, 1, which would yield only 1 charge. Try putting it in a monster's loot list and see if it drops with the proper amount of charges.

How did you create the item? You may have created it like /i bonfire amulet, 1, which would yield only 1 charge. Try putting it in a monster's loot list and see if it drops with the proper amount of charges.

Hey, I tested with monster's loot and it's working fine, thank you. But I think it's very strange, because if we use in some script functions like player:addItem() or Game.createItem(), the charges in items.xml doesn't have any functionality here? Ok... we can use ItemType(id):getCharges() to get these values, but... like I said, I think it's very strange. I'll keep this issue open until someone can explain a little more about this functionality. Again, thank you.

I think it's not a problem, because when the item have charges, count is = charge. See this example:

/i might ring, 94

02:04 You see a might ring (protection physical +20%, energy +20%, earth +20%, fire +20%, ice +20%, holy +20%, death +20%) that has 94 charges left.

in constructor of the file item.cpp you can find this code:

    } else if (it.charges != 0) {
        if (count != 0) {
            setCharges(count);
        } else {
            setCharges(it.charges);
        }
    }

EDIT:
I created a function to use as you suggested, please test and tell me what you think.

function Player.addChargeItem(self, itemid, count)
    local type = ItemType(itemid)
    if type:getCharges() == 0 then
        return nil
    end

    local items = {}
    for i = 1, math.max(1, count or 0) do
        local item = self:addItem(itemid, type:getCharges())
        table.insert(items, item)
    end

    return #items == 1 and items[1] or items
end

Example

-- add 1 might ring with 20 charges
player:addChargeItem('might ring')

-- add 3 might rings with 20 charges
player:addChargeItem('might ring', 3)

I forgot to check the constructor, thank you. Yeah, maybe I create a custom function to use addItem with charges in multiple quantity. Ty, guys, closing issue.

Was this page helpful?
0 / 5 - 0 ratings