Skip to content

Commit

Permalink
refactor: move exercise training to core (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored Feb 22, 2024
1 parent ea5867a commit a17ae7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 77 deletions.
66 changes: 0 additions & 66 deletions data-canary/scripts/actions/other/exercise_training.lua

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
local exerciseTraining = Action()
local exhaustionTime = 10

local maxAllowedOnADummy = configManager.getNumber(configKeys.MAX_ALLOWED_ON_A_DUMMY)
local dummies = Game.getDummies()
local function isDummy(id)
local dummies = Game.getDummies()
return dummies[id] and dummies[id] > 0
end

local cooldown = 10
local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target then
return
if not target or not target:getId() then
return true
end

local playerId = player:getId()
local targetId = target:getId()

Expand Down Expand Up @@ -41,22 +41,22 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition,
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must be inside the house to use this dummy.")
return true
end

local playersOnDummy = 0
for _, playerTraining in pairs(_G.OnExerciseTraining) do
if playerTraining.dummyPos == targetPos then
playersOnDummy = playersOnDummy + 1
end

if playersOnDummy >= maxAllowedOnADummy then
if playersOnDummy >= configManager.getNumber(configKeys.MAX_ALLOWED_ON_A_DUMMY) then
player:sendTextMessage(MESSAGE_FAILURE, "That exercise dummy is busy.")
return true
end
end
end

local hasExhaustion = player:kv():get("training-exhaustion") or 0
if hasExhaustion > os.time() then
player:sendTextMessage(MESSAGE_FAILURE, "You are already training!")
if player:hasExhaustion("training-exhaustion") then
player:sendTextMessage(MESSAGE_FAILURE, "This exercise dummy can only be used after a " .. exhaustionTime .. " seconds cooldown.")
return true
end

Expand All @@ -65,7 +65,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition,
_G.OnExerciseTraining[playerId].event = addEvent(ExerciseEvent, 0, playerId, targetPos, item.itemid, targetId)
_G.OnExerciseTraining[playerId].dummyPos = targetPos
player:setTraining(true)
player:kv():set("training-exhaustion", os.time() + cooldown)
player:setExhaustion("training-exhaustion", exhaustionTime)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have started training on an exercise dummy.")
end
return true
Expand Down

0 comments on commit a17ae7b

Please sign in to comment.