From 4db58094b860e30ce004fba11d10d65701af990c Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 20 Feb 2024 13:47:58 -0300 Subject: [PATCH] chore: change offline training to core (#2276) --- .../actions/other/offline_training.lua | 31 -------- .../others/offline_training.lua | 76 ------------------- .../objects}/offline_training_book.lua | 0 .../actions/objects}/skill_trainer.lua | 0 .../others}/offline_training.lua | 3 +- 5 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 data-otservbr-global/scripts/actions/other/offline_training.lua delete mode 100644 data-otservbr-global/scripts/creaturescripts/others/offline_training.lua rename {data-otservbr-global/scripts/actions/other => data/scripts/actions/objects}/offline_training_book.lua (100%) rename {data-canary/scripts/actions/other => data/scripts/actions/objects}/skill_trainer.lua (100%) rename {data-canary/scripts/creaturescripts => data/scripts/creaturescripts/others}/offline_training.lua (97%) diff --git a/data-otservbr-global/scripts/actions/other/offline_training.lua b/data-otservbr-global/scripts/actions/other/offline_training.lua deleted file mode 100644 index d205feb6b2f..00000000000 --- a/data-otservbr-global/scripts/actions/other/offline_training.lua +++ /dev/null @@ -1,31 +0,0 @@ -local statues = { - [16198] = SKILL_SWORD, - [16199] = SKILL_AXE, - [16200] = SKILL_CLUB, - [16201] = SKILL_DISTANCE, - [16202] = SKILL_MAGLEVEL, -} - -local offlineTraining = Action() - -function offlineTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local skill = statues[item:getId()] - if not player:isPremium() then - player:sendCancelMessage(RETURNVALUE_YOUNEEDPREMIUMACCOUNT) - return true - end - - if player:isPzLocked() then - return false - end - - player:setOfflineTrainingSkill(skill) - player:remove(false) - return true -end - -for index, value in pairs(statues) do - offlineTraining:id(index) -end - -offlineTraining:register() diff --git a/data-otservbr-global/scripts/creaturescripts/others/offline_training.lua b/data-otservbr-global/scripts/creaturescripts/others/offline_training.lua deleted file mode 100644 index afe28e82134..00000000000 --- a/data-otservbr-global/scripts/creaturescripts/others/offline_training.lua +++ /dev/null @@ -1,76 +0,0 @@ -local offlineTraining = CreatureEvent("OfflineTraining") -function offlineTraining.onLogin(player) - local lastLogout = player:getLastLogout() - local offlineTime = lastLogout ~= 0 and math.min(os.time() - lastLogout, 86400 * 21) or 0 - local offlineTrainingSkill = player:getOfflineTrainingSkill() - if offlineTrainingSkill == SKILL_NONE then - player:addOfflineTrainingTime(offlineTime * 1000) - return true - end - - player:setOfflineTrainingSkill(SKILL_NONE) - - if offlineTime < 600 then - player:sendTextMessage(MESSAGE_OFFLINE_TRAINING, "You must be logged out for more than 10 minutes to start offline training.") - return true - end - - local trainingTime = math.max(0, math.min(offlineTime, math.min(43200, player:getOfflineTrainingTime() / 1000))) - player:removeOfflineTrainingTime(trainingTime * 1000) - - local remainder = offlineTime - trainingTime - if remainder > 0 then - player:addOfflineTrainingTime(remainder * 1000) - end - - if trainingTime < 60 then - return true - end - - local text = "During your absence you trained for" - local hours = math.floor(trainingTime / 3600) - if hours > 1 then - text = string.format("%s %d hours", text, hours) - elseif hours == 1 then - text = string.format("%s 1 hour", text) - end - - local minutes = math.floor((trainingTime % 3600) / 60) - if minutes ~= 0 then - if hours ~= 0 then - text = string.format("%s and", text) - end - - if minutes > 1 then - text = string.format("%s %d minutes", text, minutes) - else - text = string.format("%s 1 minute", text) - end - end - text = string.format("%s.", text) - player:sendTextMessage(MESSAGE_OFFLINE_TRAINING, text) - - local vocation = player:getVocation() - local promotion = vocation:getPromotion() - local topVocation = not promotion and vocation or promotion - - local updateSkill = false - if table.contains({ SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE }, offlineTrainingSkill) then - local modifier = topVocation:getBaseAttackSpeed() / 1000 / configManager.getFloat(configKeys.RATE_OFFLINE_TRAINING_SPEED) - updateSkill = player:addOfflineTrainingTries(offlineTrainingSkill, (trainingTime / modifier) / (offlineTrainingSkill == SKILL_DISTANCE and 4 or 2)) - elseif offlineTrainingSkill == SKILL_MAGLEVEL then - local gainTicks = (topVocation:getManaGainTicks() / 1000) * 2 - if gainTicks == 0 then - gainTicks = 1 - end - - updateSkill = player:addOfflineTrainingTries(SKILL_MAGLEVEL, trainingTime * (vocation:getManaGainAmount() / gainTicks)) - end - - if updateSkill then - player:addOfflineTrainingTries(SKILL_SHIELD, trainingTime / 4) - end - return true -end - -offlineTraining:register() diff --git a/data-otservbr-global/scripts/actions/other/offline_training_book.lua b/data/scripts/actions/objects/offline_training_book.lua similarity index 100% rename from data-otservbr-global/scripts/actions/other/offline_training_book.lua rename to data/scripts/actions/objects/offline_training_book.lua diff --git a/data-canary/scripts/actions/other/skill_trainer.lua b/data/scripts/actions/objects/skill_trainer.lua similarity index 100% rename from data-canary/scripts/actions/other/skill_trainer.lua rename to data/scripts/actions/objects/skill_trainer.lua diff --git a/data-canary/scripts/creaturescripts/offline_training.lua b/data/scripts/creaturescripts/others/offline_training.lua similarity index 97% rename from data-canary/scripts/creaturescripts/offline_training.lua rename to data/scripts/creaturescripts/others/offline_training.lua index e6ada9880d1..abfb0b94b3d 100644 --- a/data-canary/scripts/creaturescripts/offline_training.lua +++ b/data/scripts/creaturescripts/others/offline_training.lua @@ -1,4 +1,4 @@ -local offlineTraining = CreatureEvent("Offline Training") +local offlineTraining = CreatureEvent("OfflineTraining") function offlineTraining.onLogin(player) local lastLogout = player:getLastLogout() @@ -72,7 +72,6 @@ function offlineTraining.onLogin(player) if updateSkills then player:addOfflineTrainingTries(SKILL_SHIELD, trainingTime / 4) end - return true end