From 3ae18f0c5fc2c1ebfd3c8d37cccc5f25d6d48549 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Sun, 23 Feb 2020 16:57:24 +0200 Subject: [PATCH] introduce global rate boost talkaction --- New Text Document.txt | 2 +- data/events/scripts/player.lua | 21 +++++++- data/spells/spells.xml | 2 + .../talkactions/scripts/global_rate_boost.lua | 48 +++++++++++++++++++ data/talkactions/talkactions.xml | 9 ++-- 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 data/talkactions/scripts/global_rate_boost.lua diff --git a/New Text Document.txt b/New Text Document.txt index 1904266..5a05507 100644 --- a/New Text Document.txt +++ b/New Text Document.txt @@ -1 +1 @@ -next: 17585 \ No newline at end of file +next: 17593 \ No newline at end of file diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index b65cb56..0cf8a29 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -191,6 +191,10 @@ function Player:onGainExperience(source, exp, rawExp) end end + if getGlobalStorageValue(17589) > os.time() then + exp = exp * (1 + getGlobalStorageValue(17585) / 100) + end + return exp end @@ -204,7 +208,20 @@ function Player:onGainSkillTries(skill, tries) end if skill == SKILL_MAGLEVEL then - return tries * configManager.getNumber(configKeys.RATE_MAGIC) + tries = tries * configManager.getNumber(configKeys.RATE_MAGIC) + + if getGlobalStorageValue(17591) > os.time() then + tries = tries * (1 + getGlobalStorageValue(17587) / 100) + end + + return tries end - return tries * configManager.getNumber(configKeys.RATE_SKILL) + + tries = tries * configManager.getNumber(configKeys.RATE_SKILL) + + if getGlobalStorageValue(17590) > os.time() then + tries = tries * (1 + getGlobalStorageValue(17586) / 100) + end + + return tries end diff --git a/data/spells/spells.xml b/data/spells/spells.xml index 2a94ea2..40d8a23 100644 --- a/data/spells/spells.xml +++ b/data/spells/spells.xml @@ -207,6 +207,8 @@ + + diff --git a/data/talkactions/scripts/global_rate_boost.lua b/data/talkactions/scripts/global_rate_boost.lua new file mode 100644 index 0000000..e4a3ca6 --- /dev/null +++ b/data/talkactions/scripts/global_rate_boost.lua @@ -0,0 +1,48 @@ +local config = { + ['exp'] = {skillKey = 17585, timeKey = 17589}, + ['skill'] = {skillKey = 17586, timeKey = 17590}, + ['magic'] = {skillKey = 17587, timeKey = 17591}, + ['loot'] = {skillKey = 17588, timeKey = 17592} -- TODO +} + +function onSay(player, words, param) + if not player:getGroup():getAccess() then + return true + end + + if player:getAccountType() < ACCOUNT_TYPE_GOD then + return false + end + + local split = param:split(",") + if split[3] == nil then + player:sendCancelMessage("Insufficient parameters [(exp,skill,loot,magic),percentage,hours].") + return false + end + + local skillName = split[1] + local percentage = tonumber(split[2]) + local hours = tonumber(split[3]) + + local globalStorage = config[skillName] + if not globalStorage then + player:sendCancelMessage("Skill name value must be one of the following: exp, skill, loot, magic.") + return false + end + + if percentage <= 0 then + player:sendCancelMessage("Percentage value must be higher than 0. For example, 50% means 1.5x higher rate.") + return false + end + + if hours <= 0 then + player:sendCancelMessage("Hours value must be higher than 0.") + return false + end + + setGlobalStorageValue(globalStorage.skillKey, percentage) + setGlobalStorageValue(globalStorage.timeKey, os.time() + hours * 60 * 60) + broadcastMessage(player:getName() .. " have activated the global " .. percentage .. "% " .. skillName .. " rate boost for next " .. hours .. " " .. (hours == 1 and "hour" or "hours") .. ".", MESSAGE_STATUS_WARNING) + + return false +end diff --git a/data/talkactions/talkactions.xml b/data/talkactions/talkactions.xml index a0c7fa5..230a9a1 100644 --- a/data/talkactions/talkactions.xml +++ b/data/talkactions/talkactions.xml @@ -28,9 +28,9 @@ - - - + + + @@ -38,11 +38,12 @@ + - +