Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new method itemType:getDecayTime() #2991

Closed
wants to merge 3 commits into from
Closed

new method itemType:getDecayTime() #2991

wants to merge 3 commits into from

Conversation

Zbizu
Copy link
Contributor

@Zbizu Zbizu commented Apr 30, 2020

fixed version of #1229 (added missing & symbol)
closes #1212

test results:

15:29 > print(ItemType("dead rat"):getDecayTime())	-> 300 /dead rat
15:29 > print(ItemType(2168):getDecayTime())		-> 1200 /life ring
15:29 > print(ItemType(2169):getDecayTime())		-> 600 /time ring
15:29 > print(ItemType(407):getDecayTime())		-> 0 /black tile floor
15:30 > print(ItemType(2640):getDecayTime())		-> 14400 /active soft boots
15:42 > print(ItemType.getDecayTime())			-> nil /empty value
15:42 > print(ItemType.getDecayTime({}))		-> nil /table as argument

didn't had a single crash

if (itemType) {
uint32_t decayTime = itemType->decayTime;
if (decayTime == 0 && itemType->showDuration) {
const ItemType& equipItemType = Item::items[itemType->transformEquipTo];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wont work for items that are not transformed on equip to anything else right?

Copy link
Contributor Author

@Zbizu Zbizu Apr 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

16:08 > print(ItemType(2050):getDecayTime()) -> 0
16:08 > print(ItemType(2051):getDecayTime()) -> 600
16:09 > print(ItemType(2052):getDecayTime()) -> 0
16:09 > print(ItemType(2053):getDecayTime()) -> 300

what other flag could be used to return correct duration for just bought torch?

this is quite problematic because the transform happens in lua now and items.xml doesn't mention it anywhere

	<item id="2050" article="a" name="torch">
		<attribute key="slotType" value="ammo" />
		<attribute key="weight" value="500" />
		<attribute key="stopduration" value="1" />
	</item>
	<item id="2051" article="a" name="lit torch">
		<attribute key="slotType" value="ammo" />
		<attribute key="weight" value="500" />
		<attribute key="decayTo" value="2053" />
		<attribute key="duration" value="600" />
	</item>

edit: alright I think I found a solution, but it would be a weird override (not sure if suitable with tfs code style standards)

  1. moving decayItems table from actions/scripts/other/decayTo.lua to libs
  2. this
if not overrided then -- prevent loop disaster on reload
function ItemType:getDecayTime()
-- if original function gives 0 then search this global table and check the transformed item end
end
overrided = true
end

what do you think?

Copy link
Contributor Author

@Zbizu Zbizu May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually we can do two different functions, like

  • :getDecayTime() would work as current getDecayTime()
  • :getBaseDecayTime() would be written in lua and check lua libs as well

otherwise it's probably not the greatest idea to hardcode a variable from some random lua file

@DSpeichert DSpeichert added the feature New feature or functionality label May 2, 2020
@soul4soul
Copy link
Contributor

@Zbizu I want to make you aware of https://github.com/gesior/forgottenserver/commit/395e6955a31fda12c1a48a37fbc017e2a373fc7b by @gesior. It adds support for decay by timestamp using a new ITEM_ATTRIBUTE_DECAY_TIMESTAMP attribute and 3 new lua methods. See #2641 for all the details.

item:getDurationLeft()
item:setDurationLeft(timeInMiliseconds)
item:stopDecay()

@Zbizu Zbizu mentioned this pull request May 3, 2020
2 tasks
@Zbizu
Copy link
Contributor Author

Zbizu commented May 3, 2020

I was aware of his PR, but thought that it covers slightly different area than mine. I will watch his thread. Will reopen if his changes don't go through.

@Zbizu Zbizu closed this May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

itemType:getDuration()
4 participants