Skip to content

Commit

Permalink
Fix of glyph informs and change of glyph cooldown to use the same LTE…
Browse files Browse the repository at this point in the history
… instead of the previous quest IDs
  • Loading branch information
brightrim committed Nov 17, 2024
1 parent 0c0cdb2 commit ec939ae
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 60 deletions.
102 changes: 62 additions & 40 deletions lte/glyph_equip_inform.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,97 +15,119 @@ You should have received a copy of the GNU Affero General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
]]

-- This times an inform after you've had a glyphed item equipped long enough to let you know it is ready, effect id 403
-- Used to check if a glyph is ready and provide informs for it to more clearly communicate to the player if the glyph is usable, effect id 403

local handlingOfGlyphEquipment = require("magic.arcane.enchanting.core.handling_of_glyph_equipment")

local common = require("base.common")

local M = {}

local slots = handlingOfGlyphEquipment.slots

local function atleastOnePieceOfJewelleryOnCooldown(user, effect)
function M.addEffect(effect, user)

local retVal = false
local retVal2 = false
end

if not effect then
return retVal
end
local function checkIfCooldownsRemain(effect)

for _, slot in pairs(slots) do

local slotValueFound, slotValue = effect:findValue(tostring(slot))

if slotValueFound and slotValue == 1 then
if not handlingOfGlyphEquipment.checkIfLongEnoughTimePassedSinceEquip(user, slot) then
retVal2 = true
end
retVal = true
if slotValueFound and slotValue ~= 0 then
return true
end
end

return retVal, retVal2

end

function M.addEffect(effect, user)

return false
end

function M.callEffect(effect, user)

local informsRequested = atleastOnePieceOfJewelleryOnCooldown(user, effect)

if not informsRequested then
return false
end
effect.nextCalled = 100

local count = 0

local amulet = false

local english = "ring"
local german = "Ring"
local amuletGerman = "Amulett"
local amuletEnglish = "amulet"
local ringGerman = "Ring"
local ringEnglish = "ring"

for _, slot in pairs(slots) do

local time = common.GetCurrentTimestamp()

local slotValueFound, slotValue = effect:findValue(tostring(slot))

if slotValueFound and slotValue == 1 and handlingOfGlyphEquipment.checkIfLongEnoughTimePassedSinceEquip(user, slot) then
if slotValueFound and (time - slotValue) >= 120 and slotValue > 0 then --Enough time has passed for the cooldown to be over and it has not already informed the user

effect:addValue(tostring(slot), 0) -- Timer reset to 0 to indicate that no inform is to be given on next cycle

if user:getItemAt(slot).id ~= 0 and not common.IsNilOrEmpty(user:getItemAt(slot):getData("glyphCharges")) then --Verify item still exists

amulet = slot == Character.neck
count = count + 1

effect:addValue(tostring(slot), 0)
if not amulet then --Only check for amulet if it was not already found, to prevent it being overwritten
amulet = slot == Character.neck
end

local foundId, jewelleryId = effect:findValue(tostring(slot).."id")

if foundId then

local commonItem = world:getItemStatsFromId(jewelleryId)

if slot == Character.neck then
amuletEnglish = commonItem.English
amuletGerman = commonItem.German
else
ringEnglish = commonItem.English
ringGerman = commonItem.German
end
end
end

count = count + 1
end

end

if amulet then
english = "amulet"
german = "Amulett"
local english = ringEnglish
local german = ringGerman

local cooldownsRemain = checkIfCooldownsRemain(effect)

if count == 0 then
if cooldownsRemain then
return true
else
return false
end
end

local _, cooldownsRemaining = atleastOnePieceOfJewelleryOnCooldown(user, effect)
if amulet then
english = amuletEnglish
german = amuletGerman
end

--all german translations below are chatGPT and need proofreading

if count == 1 then -- To prevent the spam of 2/3 informs if multiple glyphs are charged at once, we do this check
--One ring or one amulet finished charging
user:inform("Du spürst, dass die Glyphe im "..german.." das Aufladen abgeschlossen hat und nun, mit etwas Glück und unter den richtigen Umständen, Wirkung zeigen kann." ,"You feel the glyph in the "..english.." has finished charging and can now, with some luck and under the right circumstances, take effect.")
elseif count > 1 and not cooldownsRemaining then
user:inform("Die Glyphen in deinem Schmuck sind alle vollständig aufgeladen und werden unter den richtigen Umständen und mit etwas Glück Wirkung zeigen.", "The glyphs in your jewellery have all finished charging and will, under the right circumstances and with some luck, take effect.")
elseif count > 1 and cooldownsRemaining then
elseif count == 2 then
-- Two rings or a ring and amulet finished charging
if amulet then
user:inform("Einer deiner mit Glyphen versehenen Ringe und dein Amulett sind vollständig aufgeladen und werden unter den richtigen Umständen und mit etwas Glück Wirkung zeigen." ,"One of your glyphed rings and your glyphed amulet have finished charging and will, under the right circumstances and with some luck, take effect.")
user:inform("Dein mit einer Glyphe versehener "..ringGerman.." und dein "..amuletGerman.." sind vollständig aufgeladen und werden unter den richtigen Umständen und mit etwas Glück Wirkung zeigen." ,"Your glyphed "..ringEnglish.." and your glyphed "..amuletEnglish.." have finished charging and will, under the right circumstances and with some luck, take effect.")
else
user:inform("Beide Glyphen in deinen Ringen sind vollständig aufgeladen und werden unter den richtigen Umständen und mit etwas Glück Wirkung zeigen.", "Both of the glyphs in your rings have finished charging and will, under the right circumstances and with some luck, take effect.")
end
elseif count == 3 then
--All three finished charging at once
user:inform("Die Glyphen in deinem Schmuck sind alle vollständig aufgeladen und werden unter den richtigen Umständen und mit etwas Glück Wirkung zeigen.", "The glyphs in your jewellery have all finished charging and will, under the right circumstances and with some luck, take effect.")
end

effect.nextCalled = 100

return true

end
Expand Down
44 changes: 24 additions & 20 deletions magic/arcane/enchanting/core/handling_of_glyph_equipment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ local M = {}

M.slots = {Character.neck, Character.finger_left_hand, Character.finger_right_hand}

local quests = {}
quests[Character.neck] = 564
quests[Character.finger_left_hand] = 565
quests[Character.finger_right_hand] = 566

local function addValues(myEffect, jewellery)

myEffect:addValue(tostring(jewellery.itempos), 1)

return myEffect
end

local effectId = 403

function M.unequipJewellery(user, jewellery)
Expand All @@ -46,10 +34,12 @@ function M.unequipJewellery(user, jewellery)
local commonItem = world:getItemStatsFromId(jewellery.id)

if foundEffect then

local time = common.GetCurrentTimestamp()

local foundValue, value = myEffect:findValue(tostring(slot))

if foundValue and value == 1 then
myEffect:addValue(tostring(jewellery.itempos), 0)
if foundValue and (time - value) < 120 and value ~= 0 then --less than the required 2 min have passed
user:inform("Du hast das "..commonItem.German.." abgelegt, bevor die Glyphe darin Zeit hatte, sich vollständig aufzuladen.", "You unequipped the "..commonItem.English.." before the glyph in it had time to finish charging up.")
break
end
Expand All @@ -61,6 +51,8 @@ end

function M.saveTimeOfJewelleryEquipment(user, jewellery)

local time = common.GetCurrentTimestamp()

local hasGlyph = not common.IsNilOrEmpty(jewellery:getData("glyphCharges"))

if not hasGlyph then
Expand All @@ -73,32 +65,44 @@ function M.saveTimeOfJewelleryEquipment(user, jewellery)

if foundEffect then

addValues(myEffect, jewellery)
myEffect:addValue(tostring(jewellery.itempos), time)

myEffect:addValue(tostring(jewellery.itempos).."id", jewellery.id)

elseif not foundEffect then

myEffect = LongTimeEffect(effectId, 100)

myEffect = addValues(myEffect, jewellery)
myEffect:addValue(tostring(jewellery.itempos), time)

myEffect:addValue(tostring(jewellery.itempos).."id", jewellery.id)

user.effects:addEffect(myEffect)
end

user:inform("Als du das "..commonItem.German.." dass die Glyphe darin sich auflädt und einen Moment benötigt, bevor sie Wirkung zeigen kann.", "As you equip the "..commonItem.English.." you perceive that the glyph in it is charging up, requiring a moment before it can begin to take effect.") --chatGPT german translation that needs a proofread for accuracy

user:setQuestProgress(quests[jewellery.itempos], common.GetCurrentTimestamp())

end

function M.checkIfLongEnoughTimePassedSinceEquip(user, itempos)

local foundEffect, myEffect = user.effects:find(effectId)

if not foundEffect then -- No effect means no ongoing timer means enough time has passed by default
return true
end

local time = common.GetCurrentTimestamp()

local savedTime = user:getQuestProgress(quests[itempos])
local foundtime, savedTime = myEffect:findValue(itempos)

if not foundtime then
return true
end

local difference = time - savedTime

if difference >= 120 then
if difference >= 120 or savedTime == 0 then -- Checks if 2 minutes has passed since equipping it
return true
end

Expand Down

0 comments on commit ec939ae

Please sign in to comment.