EC: Missing check for luck cool down timers
Inspired by the work of @ForeverFun
The following code changes to the EC will show a buff icons or for when your luck has improved and a debuff icon when your luck has ended.
Create dds files using the images from above and put them in your "icons\my icons" folder
Add the following to the icons\icons.xml file
Add the following lines to the structure BuffDebuff.Good in the file source\BuffDebuffWindow.lua
with this
The following code changes to the EC will show a buff icons or for when your luck has improved and a debuff icon when your luck has ended.
Create dds files using the images from above and put them in your "icons\my icons" folder
Add the following to the icons\icons.xml file
<!-- Custom --> <Icon id="979551" texture="Icons/My Icons/LuckBuff.dds" name="Luck buff" /> <Icon id="979552" texture="Icons/My Icons/LuckDebuff.dds" name="Luck Debuff" /> <Icon id="979534" texture="Icons/My Icons/StillFeelLuckyBuff.dds" name="Still feel lucky buff" />
the green icon goes into the LuckBuff.dds files
the blue icon goes into the StillFeelLuckyBuff.dds file
the red icon goes into the LuckDebuff.dds file
Add the following code at the top of the function TextParsing.TimersNbuff in the files source\TextParsing.luathe blue icon goes into the StillFeelLuckyBuff.dds file
the red icon goes into the LuckDebuff.dds file
--start of added code if ( SystemData.TextID == 1079551 ) then -- * Your luck just improved * WindowData.BuffDebuffSystem.CurrentBuffId = 979551 -- use custom luck buff icon. WindowData.BuffDebuff.NameWStringVector = GetStringFromTid(1079534) WindowData.BuffDebuff.NameVectorSize = 0 WindowData.BuffDebuff.ToolTipVectorSize = 0 WindowData.BuffDebuff.IsBeingRemoved = false BuffDebuff.Timers[979551] = 3600 -- 1 hour. BuffDebuff.ShouldCreateNewBuff() local luckStartTime = Interface.Clock.Timestamp Interface.SaveNumber( "luckStartTime" , luckStartTime ) --save the time stamp so can calculate how much time is left before can use luck again return end if ( SystemData.TextID == 1079552 -- * Your luck just ended * or SystemData.TextID == 1079550 -- * You can improve your fortunes again in about hours * or SystemData.TextID == 1079548 -- * You can improve your fortunes again in about minutes * or SystemData.TextID == 1079547 -- * Your fortunes are about to improve * ) then local currentTimeStamp = Interface.Clock.Timestamp local nextPossibleLuckStartTime = Interface.LoadNumber("luckStartTime", currentTimeStamp) + 86400 local secsToWait = nextPossibleLuckStartTime - currentTimeStamp if(secsToWait <= 0 or secsToWait > 86400) then return --do not show debuff icon if odd things happened end WindowData.BuffDebuffSystem.CurrentBuffId = 979552 -- use custom luck debuff icon. WindowData.BuffDebuff.NameWStringVector = L"You need to wait before you can improve your fortunes again" WindowData.BuffDebuff.NameVectorSize = 0 WindowData.BuffDebuff.ToolTipVectorSize = 0 WindowData.BuffDebuff.IsBeingRemoved = false BuffDebuff.Timers[979552] = secsToWait BuffDebuff.ShouldCreateNewBuff() if(BuffDebuff.BuffData[979534] ~= nil) then BuffDebuff.HandleBuffRemoved(979534) --remove the custom unknown luck buff end return end if ( SystemData.TextID == 1079534 ) then -- * You're still feeling lucky * local luckBuffTimer = BuffDebuff.Timers[979551] if (BuffDebuff.BuffData[979551] == nil) then -- show a different luck buff icon if the normal luck buff is not shown WindowData.BuffDebuffSystem.CurrentBuffId = 979534 -- use custom unknown luck buff icon. WindowData.BuffDebuff.NameWStringVector = GetStringFromTid(1079534) WindowData.BuffDebuff.NameVectorSize = 0 WindowData.BuffDebuff.ToolTipVectorSize = 0 WindowData.BuffDebuff.IsBeingRemoved = false WindowData.BuffDebuff.HasTimer = false BuffDebuff.ShouldCreateNewBuff() end return end --end of added code
Add the following lines to the structure BuffDebuff.Good in the file source\BuffDebuffWindow.lua
--Begin Custom [979551] = true; -- Luck Buff [979534] = true; -- Unknown Luck Buff
Add the following code to the function BuffDebuff.Initialize in source\BuffDebuffWindow.lua after the call to UOBuildTableFromCSV
In the function BuffDebuff.UpdateTimer in source\BuffDebuffWindow.lua replace this code --add custom buff / debuff icons if (WindowData.BuffDataCSV ~= nil) then local luckBuff = { ["ID"] = 979551, ["ServerId"] = 979551, ["IconId"] = 979551, ["Define"] = 0 } table.insert(WindowData.BuffDataCSV, luckBuff) local unknownLuckBuff = { ["ID"] = 979534, ["ServerId"] = 979534, ["IconId"] = 979534, ["Define"] = 0 } table.insert(WindowData.BuffDataCSV, unknownLuckBuff) local luckDebuff = { ["ID"] = 979552, ["ServerId"] = 979552, ["IconId"] = 979552, ["Define"] = 0 } table.insert(WindowData.BuffDataCSV, luckDebuff) end --end of added code
if ( BuffDebuff.Timers[buffId] ~= nil and BuffDebuff.Timers[buffId] > 0 ) then local min = math.floor(BuffDebuff.Timers[buffId]/60) if min > 0 then timer = StringToWString(tostring(min) .. "m")
if ( BuffDebuff.Timers[buffId] ~= nil and BuffDebuff.Timers[buffId] > 0 ) then local min = math.floor(BuffDebuff.Timers[buffId]/60) -- start of added code if min > 60 then local prefix = "" if ((min / 60) - math.floor(min / 60) > 0) then prefix = ">" end local h = math.floor(min / 60) timer = StringToWString(prefix .. tostring(h) .. "h") elseif min > 0 then local prefix = "" if (BuffDebuff.Timers[buffId] - (min * 60) > 0) then prefix = ">" end timer = StringToWString(prefix .. tostring(min) .. "m") -- end of added code
In the function BuffDebuff.MouseOver in the file source\BuffDebuffWindow.lua after the line
local nameString = L""add the following code
--start of added code if(data.NameWStringVector ~= nil and type(data.NameWStringVector) == "wstring") then nameString = data.NameWStringVector end --end of added code
Comments
https://github.com/TimStotelmeyer/Ultima-Online
Also, I don't know what's scarier, all that code, or that I understood almost all of it on the first read through. *Shudders* That would have been impossible for me a couple years ago.
As soon as I have some time, I'll be adding it to my own mod. I want to be sure I can understand each line and how the different chunks interact first though. I may be messaging you in a couple months!
Thank you for posting it.