Forgottenserver: Items in depot don鈥檛 decay

Created on 16 Aug 2019  路  29Comments  路  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 item that decay (crystal arrow)
  2. put into depot
  3. relog
  4. it won鈥檛 decay until you touch it

Expected behaviour


item should decay

Actual behaviour


item don鈥檛 decay

Environment

enhancement

Most helpful comment

Normal decaying items will always decay as soon as they are loaded. The cases in which they are not loaded anymore are if a player logs out while having such an item in their inventory or if a player puts them in a depot box and moves away (Depots and inboxes are only loaded when stepping on the tile and unloaded when walking away).

Timestamped items will always decay, no matter where they are or what you do. You simply cannot stop it. If they item is loaded while decaying it will disappear. If the item gets loaded after the timestamp has expired then it will not be loaded (e.g. a player logging back in after the item has expired).

All 29 comments

That's the actual design of the implemented decay system, unless there is a major re write (which I doubt will happen anywhere soon) this is not going to change.

We would have to introduce different decayTypes in order to make something like this.
So an item which should decay all the time should be marked with a timestamp, if the item passed the timestamp it should just be removed/transformed.

The way I interrupt this issue @infister isn't asking for the item to always decay. I believe he is referring to the fact that items in the depot are suppose to decay when standing on the depot tile. TibiaWiki's description of item decay is accurate. It should be possible to test on cipbia with a torch which decays fast-ish.

Expected Behavior

  1. create crystal arrow (decay should be started immediately)
  2. stand on depot square and put arrow in depot (decay continues)
  3. log off while still on depot square (decay stops)
  4. log back on directly on the depot square (decay continues) [<- the issue reported is at this step, the decay does not continue until the item is moved.]

my answer maybe was missleading.
I meant the way tfs currently has decay implemented is limited, unless we re write a majority of the item loading/unloading process we wont be able to accomplish that for now.
The problem is once the Player login the items are getting "pre" load but only once the depot is opened the items are getting "created" so we cannot let an item decay which is just pre load and not created yet.
That's why I meant we need to re write a majority of code or introduce another method (maybe a timestamp which gets saved as an item attribute in sql)

There should be added timestamp decay too (temporary gold converter)
System should rely on timestamps imho. Current timer system does not fit the newest circumstances.

I've reported something similar on 2015 #1199

my answer maybe was missleading.
I meant the way tfs currently has decay implemented is limited, unless we re write a majority of the item loading/unloading process we wont be able to accomplish that for now.
The problem is once the Player login the items are getting "pre" load but only once the depot is opened the items are getting "created" so we cannot let an item decay which is just pre load and not created yet.

Then there still may be a bug with the system implemented in TFS. Shouldn't the item continue decaying when its "re-"created when the depot is opened? OP says the item doesn't start decaying until moved.

Pull requests are always welcome!

@soul4soul
All player items are created 'on login' (including depot and inbox), but only items in player slots are being decayed. Exactly, slots items start decaying when player is added to 'game':
https://github.com/otland/forgottenserver/blob/master/src/player.cpp#L1020

You can add there call to 'decay' all player depot chests ( player->depotChests ). Decay goes recurrently thru backpacks, so you only need to call it for each depot chest in array.
Remember that people keep a lot of items in backpack and it may give some server freez on login of player with 100k items Inbox.

@soul4soul
All player items are created 'on login' (including depot and inbox), but only items in player slots are being decayed. Exactly, slots items start decaying when player is added to 'game':
https://github.com/otland/forgottenserver/blob/master/src/player.cpp#L1020

You can add there call to 'decay' all player depot chests ( player->depotChests ). Decay goes recurrently thru backpacks, so you only need to call it for each depot chest in array.
Remember that people keep a lot of items in backpack and it may give some server freez on login of player with 100k items Inbox.

Items in depot only decay when standing on depot space. The call to start decaying depot items should maybe be triggered from tiles.lua movements script.
https://github.com/otland/forgottenserver/blob/master/data/movements/scripts/tiles.lua#L29

When the player leaves the depot space items in depot stop decaying.

Based on @infister comments it sounds like there are new items that have a special type of decay in which the item is always decaying. That is a separate issues from items not decaying in the depot until they are touched.

Items in depot only decay when standing on depot space. The call to start decaying depot items should maybe be triggered from tiles.lua movements script.

@soul4soul
Is it on real tibia OR is it your idea OR is it how it works now on TFS?

If you want all items in depot to decay only when there is player in front of depot, it will kill OTS easily. Step on/off with 50k items parcel in depot, whole OTS lag.

What I'm explaining is cipbia implementation.

Cipbia depots have an item limitation of 2k for facc and 10k for pacc, those limitations help prevent these types of issues.
The mailbox is something different from the depot. I'm not sure of the behavior of items in the mailbox on cipbia. It needs to be investigated first whether items decay in the mailbox. Second would be investigating item limit on the mailbox.

A bit of an anecdote. Back in the day we would farm pharaoh items (such as the crystal arrow mentioned in this issue) and store them in the depot of a second character so we would have them available anytime we wanted one.

@soul4soul
Do you have some character on RL Tibia to check it?
Can you investigate, if items decay in Inbox?
Can you investigate, if always-decay items decay in Inbox?

TFS also has limit of items in depot and with that limit (2-10k), it would not be a problem to start/stop decay items, when player step on/off depot tile.

About always-decay feature. It could work on TFS, but not in case when items are in Inbox. Inbox has no limit and decay/stop decay on items in it would lag OTS.

@soul4soul
Do you have some character on RL Tibia to check it?
Can you investigate, if items decay in Inbox?
Can you investigate, if always-decay items decay in Inbox?

TFS also has limit of items in depot and with that limit (2-10k), it would not be a problem to start/stop decay items, when player step on/off depot tile.

About always-decay feature. It could work on TFS, but not in case when items are in Inbox. Inbox has no limit and decay/stop decay on items in it would lag OTS.

or you can implement timestamp based decay, for example temporary gold converter decays no matter player is logged in or not

@infister
I will try to do some benchmarks in free time.
To test, if there is a big difference, if we change current decay (decreasing duration of 1/4 of items every 1/4 of second) to timestamp based (for ALL items, also these with few seconds decay).
I will try with map ordered by timestamp.

EDIT:
If we want to rewrite decay code, we need to name decay types and define expected behavior.
My current idea:

  • duration decreases when item is active (equiped: life ring etc.), name: DECAY_ACTIVE
  • duration decreases when player is online (IDK this kind of item, decreases in BP, depot etc.), name: DECAY_ONLINE
  • duration decreases always (also when player is offline, timestamp based), name: DECAY_ALWAYS

Question to RL Tibia players:

Can you show examples of items that decay like described above?
If you could test it or at least post names of items.

I'll try some experiments with the mailbox and see how they effect decaying items.

Examples of what you are calling DECAY_ONLINE items include most light fixtures such as torches, oil lamps, and candles, all pharaoh items such as crystal arrow, blue note, and burning heart (there are 7? in total). The decay traits of these items are

  • The item decays when the player is online and the item is in the players equipment or backpack
  • The item decays when in the players depot box and the player is standing on the depot tile
  • The item decays when in a house even if the player is offline
  • The item decays when in a container in a house even if the player if offline
  • The item decays when on the ground
  • The item decays when in a container on the ground
  • It is currently unknown to myself how these items behave when in a players mailbox

I believe the item Enigmatic Voodoo Skull is an example of an item that is DECAY_ALWAYS. After 20 hours no matter where* the item is, it will change back to a Mysterious Voodoo Skull. I don't know how these items behave when inside a mailbox.

As far as I know, burning hearts will decay even if your offline (in official tibia). It just has a long cooldown (24 hours?)

These are some I found, but most corpses are DECAY_ALWAYS? You could for instance store rat corpses in depot.

2348: ancient rune
duration: 86400

2349: blue note
duration: 86400

2350: sword hilt
duration: 86400

2351: cobrafang dagger
duration: 86400

2352: crystal arrow
duration: 86400

2353: burning heart
duration: 86400

2354: ornamented ankh
duration: 86400

2433: enchanted staff
duration: 60

2815: dead rat
duration: 30

6092: very noble-looking watch
duration: 259200

8208: ice cream cone
duration: 120

Okay first test underway. I bought a torch and killed 3 rats and logged out.

  1. The first torch and rat I kept on my character
  2. The second torch and rat I put in the depot
  3. The third torch and rat I mailed to myself.

A torch takes 20 minutes to decay and all corpses take 5 minutes now. I'll use this point as a point of reference in elapsed time for when I log back in.

I believe TFS already handles it now but some items become non decaying when loaded from a map. This is often seen with corpses, a common place to see this in cipbia is POH.

I'm working on timestamp based decay now.

enum ItemDecayType_t : uint8_t {
    DECAY_TYPE_NORMAL = 0, // life ring, torch etc.
    DECAY_TYPE_TIMESTAMP = 1, // items that decay when player is offline
};

In first version of code items decay will be handled like normal items with 'duration', but they will have extra attribute 'decay_timestamp' (int64_t with disappear timestamp) and other IFs will be checked.

// gesior at work

First version (beta) of decaying items when player is offline.
Example item with timestamp based decay:

    <item id="2376" article="a" name="sword">
        <attribute key="weight" value="3500" />
        <attribute key="defense" value="12" />
        <attribute key="attack" value="14" />
        <attribute key="weaponType" value="sword" />
        <attribute key="extradef" value="1" />

        <attribute key="duration" value="20" />
        <attribute key="decayTo" value="2377" />
        <attribute key="decayType" value="timestamp" />
        <attribute key="showduration" value="1" />

    </item>

Sword (2376) will decay after 20 seconds to Two-handed Sword (2377). It will decay even, when player will be offline (with item in any slot/backpack).

Items without decayType set to timestamp:

        <attribute key="decayType" value="timestamp" />

has it set to normal (current TFS decay).

Items in depot still not decaying.

@soul4soul @infister @Znote

Waiting for RL Tibia decay test results

I do have some results

  1. Items (rat and lit torch) on the character DON'T decay at all when offline
  2. Items (rat and lit torch) in depot and mailbox DON'T decay when offline
  3. Items (rat and lit torch) in dept AND mailbox decay when standing on the depot tile (for this test I stood on the depot the entire time)
  4. Items (rat and lit torch) in dept AND mailbox DON'T when online and NOT on the depot tile

I need to check stepping on the depot tile and then stepping off to see if the items start/stop decaying.

Both the rat and lit torch are items that fall into that "DECAY_ONLINE" category. Which we need a better working name then "DECAY_ONLINE". At this time it seems more like "DECAY_WHEN_RECREATED".

I changed names to DECAY_NORMAL and DECAY_TIMESTAMP.
Maybe even better would be:
DECAY_INGAME
DECAY_ALWAYS

Huhh, did some testing on rl tibia.

  1. Killed 2 rats.
  2. Placed one inside depot
  3. Kept one in my backpack
  4. logged out, waited a minute and logged in
  5. Waited until rat in my backpack decayed to a skeleton.

Results:
Backpack rat decayed to a skeleton, and shortly after dissapeared entirely.
Went to look into the depot, and look and behold. A freshly slain rat.
So items, especially after a relog does not seem to decay in depot in rl tibia.

  1. After looking at the rat in depot, it started to decay again. So after opening the depot after the login, the decay continued.

After more testing I can confirm that items in the depot/mailbox only decay when standing on the depot tile. So far the original set of rules for DECAY_INGAME still holds with the addition of items in the mailbox decaying when standing on the depot tile. I'd like to experiment with having more then 1 page of items in the mailbox to see if that makes a difference.

  • The item decays when the player is online and the item is in the players equipment or backpack
  • The item decays when in the players depot box (locker) and the player is standing on the depot tile
  • The item decays when in a house even if the player is offline
  • The item decays when in a container in a house even if the player if offline
  • The item decays when on the ground
  • The item decays when in a container on the ground
  • The item decays when in the players depot box (mailbox) and the player is standing on the depot tile

Normal decaying items will always decay as soon as they are loaded. The cases in which they are not loaded anymore are if a player logs out while having such an item in their inventory or if a player puts them in a depot box and moves away (Depots and inboxes are only loaded when stepping on the tile and unloaded when walking away).

Timestamped items will always decay, no matter where they are or what you do. You simply cannot stop it. If they item is loaded while decaying it will disappear. If the item gets loaded after the timestamp has expired then it will not be loaded (e.g. a player logging back in after the item has expired).

Depots and inboxes are only loaded when stepping on the tile and unloaded when walking away

I did benchmark 'startDecay' with big backpack (like Inbox). My 4.8GHz CPU process around 7.000.000 items per second.
It should be acceptable to start/stop decay when player walks on depot tile.

I just finished test code of new decay algorithm (timestamp based).
https://github.com/gesior/forgottenserver/commit/395e6955a31fda12c1a48a37fbc017e2a373fc7b
I don't have time to benchmark it and check if it's safe/not crashing in some case.
Only tested few items: fire field, life ring, 'arrow' (decaying even when player is offline)

I found out that new algorithm does not care about item attributes ITEM_ATTRIBUTE_DURATION and ITEM_ATTRIBUTE_DECAY_TIMESTAMP.
They cannot be modified when item is decaying. I made changes in Lua to block access to these attributes and added new functions:

item:getDurationLeft()
item:setDurationLeft(timeInMiliseconds)

There is also new function to stop decaying:

item:stopDecay()

Also added code that stop decaying when item is removed (ex. player logouts, drop on water).

@infister
After last commit it's possible to start/stop decaying depot and all items inside from LUA!

Tested start/stop on:
Life ring (decays when equipped)
Dead rat (decays when player is online [in BP])
Fire field (decays on ground)
'arrow' (decays always, timestamp based)

While we're at it, it is not possible to get decay from torches that didn't start decaying yet unless we do it through lua somehow (due to transform script nature).

See this: https://github.com/otland/forgottenserver/pull/2991#discussion_r418039531

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marksamman picture marksamman  路  3Comments

GoularPink picture GoularPink  路  3Comments

souzajunior picture souzajunior  路  4Comments

irenicus30 picture irenicus30  路  5Comments

GoularPink picture GoularPink  路  4Comments