introduce offline training scripts

This commit is contained in:
ErikasKontenis
2020-11-07 14:32:53 +02:00
parent 093ac51d31
commit 33d9dd7dcd
12 changed files with 378 additions and 5 deletions

View File

@@ -239,6 +239,7 @@
<action itemid="3031" script="misc/changegold.lua" />
<action itemid="3035" script="misc/changegold.lua" />
<action itemid="3043" script="misc/changegold.lua" />
<action fromid="2032" toid="2032" script="misc/skill_trainer.lua" />
<!-- Chests -->
<action itemid="2479" script="misc/chests.lua" />

View File

@@ -0,0 +1,23 @@
local statues = {
[2032] = SKILL_SWORD,
[18489] = SKILL_AXE,
[18490] = SKILL_CLUB,
[18491] = SKILL_DISTANCE,
[18492] = SKILL_MAGLEVEL
}
function 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()
return true
end

View File

@@ -6,7 +6,8 @@
<event type="login" name="FirstItems" script="firstitems.lua"/>
<event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
<event type="death" name="PlayerDeath" script="playerdeath.lua"/>
<event type="login" name="OfflineTraining" script="offlinetraining.lua" />
<!-- Killing In The Name Of Quest -->
<event type="kill" name="KillingInTheNameOfKills" script="killing_in_the_name_of.lua" />
</creaturescripts>

View File

@@ -0,0 +1,75 @@
function 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 == -1 then
player:addOfflineTrainingTime(offlineTime * 1000)
return true
end
player:setOfflineTrainingSkill(-1)
if offlineTime < 600 then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "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_EVENT_ADVANCE, text)
local vocation = player:getVocation()
local promotion = vocation:getPromotion()
local topVocation = not promotion and vocation or promotion
local updateSkills = false
if table.contains({SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE}, offlineTrainingSkill) then
local modifier = topVocation:getAttackSpeed() / 1000
updateSkills = player:addOfflineTrainingTries(offlineTrainingSkill, (trainingTime / modifier) / (offlineTrainingSkill == SKILL_DISTANCE and 4 or 2))
elseif offlineTrainingSkill == SKILL_MAGLEVEL then
local gainTicks = topVocation:getManaGainTicks() * 2
if gainTicks == 0 then
gainTicks = 1
end
updateSkills = player:addOfflineTrainingTries(SKILL_MAGLEVEL, trainingTime * (vocation:getManaGainAmount() / gainTicks))
end
if updateSkills then
player:addOfflineTrainingTries(SKILL_SHIELD, trainingTime / 4)
end
return true
end

View File

@@ -372,6 +372,7 @@ function setPlayerGroupId(cid, groupId) local p = Player(cid) return p ~= nil an
function doPlayerSetSex(cid, sex) local p = Player(cid) return p ~= nil and p:setSex(sex) or false end
function doPlayerSetGuildLevel(cid, level) local p = Player(cid) return p ~= nil and p:setGuildLevel(level) or false end
function doPlayerSetGuildNick(cid, nick) local p = Player(cid) return p ~= nil and p:setGuildNick(nick) or false end
function doPlayerSetOfflineTrainingSkill(cid, skillId) local p = Player(cid) return p and p:setOfflineTrainingSkill(skillId) or false end
function doShowTextDialog(cid, itemId, text) local p = Player(cid) return p ~= nil and p:showTextDialog(itemId, text) or false end
function doPlayerAddItemEx(cid, uid, ...) local p = Player(cid) return p ~= nil and p:addItemEx(Item(uid), ...) or false end
function doPlayerRemoveItem(cid, itemid, count, ...) local p = Player(cid) return p ~= nil and p:removeItem(itemid, count, ...) or false end