diff --git a/data/libs/systems/exercise_training.lua b/data/libs/systems/exercise_training.lua deleted file mode 100644 index ab4282b3cbb..00000000000 --- a/data/libs/systems/exercise_training.lua +++ /dev/null @@ -1,125 +0,0 @@ -ExerciseWeaponsTable = { - -- MELE - [28540] = { skill = SKILL_SWORD }, - [28552] = { skill = SKILL_SWORD }, - [35279] = { skill = SKILL_SWORD }, - [35285] = { skill = SKILL_SWORD }, - [28553] = { skill = SKILL_AXE }, - [28541] = { skill = SKILL_AXE }, - [35280] = { skill = SKILL_AXE }, - [35286] = { skill = SKILL_AXE }, - [28554] = { skill = SKILL_CLUB }, - [28542] = { skill = SKILL_CLUB }, - [35281] = { skill = SKILL_CLUB }, - [35287] = { skill = SKILL_CLUB }, - [44064] = { skill = SKILL_SHIELD }, - [44065] = { skill = SKILL_SHIELD }, - [44066] = { skill = SKILL_SHIELD }, - [44067] = { skill = SKILL_SHIELD }, - -- ROD - [28544] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, - [28556] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, - [35283] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, - [35289] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, - -- RANGE - [28543] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, - [28555] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, - [35282] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, - [35288] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, - -- WAND - [28545] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, - [28557] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, - [35284] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, - [35290] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, -} - -local dummies = Game.getDummies() - -function LeaveTraining(playerId) - if _G.OnExerciseTraining[playerId] then - stopEvent(_G.OnExerciseTraining[playerId].event) - _G.OnExerciseTraining[playerId] = nil - end - - local player = Player(playerId) - if player then - player:setTraining(false) - end - return -end - -function ExerciseEvent(playerId, tilePosition, weaponId, dummyId) - local player = Player(playerId) - if not player then - return LeaveTraining(playerId) - end - - if player:isTraining() == 0 then - player:sendTextMessage(MESSAGE_FAILURE, "You have stopped training.") - return LeaveTraining(playerId) - end - - if not Tile(tilePosition):getItemById(dummyId) then - player:sendTextMessage(MESSAGE_FAILURE, "Someone has moved the dummy, the training has stopped.") - LeaveTraining(playerId) - return false - end - - local playerPosition = player:getPosition() - if not playerPosition:isProtectionZoneTile() then - player:sendTextMessage(MESSAGE_FAILURE, "You are no longer in a protection zone, the training has stopped.") - LeaveTraining(playerId) - return false - end - - if player:getItemCount(weaponId) <= 0 then - player:sendTextMessage(MESSAGE_FAILURE, "You need the training weapon in the backpack, the training has stopped.") - LeaveTraining(playerId) - return false - end - - local weapon = player:getItemById(weaponId, true) - if not weapon:isItem() or not weapon:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then - player:sendTextMessage(MESSAGE_FAILURE, "The selected item is not a training weapon, the training has stopped.") - LeaveTraining(playerId) - return false - end - - local weaponCharges = weapon:getAttribute(ITEM_ATTRIBUTE_CHARGES) - if not weaponCharges or weaponCharges <= 0 then - weapon:remove(1) -- ?? - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has disappeared.") - LeaveTraining(playerId) - return false - end - - local isMagic = ExerciseWeaponsTable[weaponId].skill == SKILL_MAGLEVEL - if not dummies[dummyId] then - return false - end - local rate = dummies[dummyId] / 100 - - if isMagic then - player:addManaSpent(500 * rate) - else - player:addSkillTries(ExerciseWeaponsTable[weaponId].skill, 7 * rate) - end - - weapon:setAttribute(ITEM_ATTRIBUTE_CHARGES, (weaponCharges - 1)) - tilePosition:sendMagicEffect(CONST_ME_HITAREA) - - if ExerciseWeaponsTable[weaponId].effect then - playerPosition:sendDistanceEffect(tilePosition, ExerciseWeaponsTable[weaponId].effect) - end - - if weapon:getAttribute(ITEM_ATTRIBUTE_CHARGES) <= 0 then - weapon:remove(1) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has disappeared.") - LeaveTraining(playerId) - return false - end - - local vocation = player:getVocation() - _G.OnExerciseTraining[playerId].event = addEvent(ExerciseEvent, vocation:getBaseAttackSpeed() / configManager.getFloat(configKeys.RATE_EXERCISE_TRAINING_SPEED), playerId, tilePosition, weaponId, dummyId) - return true -end diff --git a/data/libs/systems/load.lua b/data/libs/systems/load.lua index bea41404dd9..5c7073ad64e 100644 --- a/data/libs/systems/load.lua +++ b/data/libs/systems/load.lua @@ -3,7 +3,6 @@ dofile(CORE_DIRECTORY .. "/libs/systems/concoctions.lua") dofile(CORE_DIRECTORY .. "/libs/systems/daily_reward.lua") dofile(CORE_DIRECTORY .. "/libs/systems/encounters.lua") dofile(CORE_DIRECTORY .. "/libs/systems/exaltation_forge.lua") -dofile(CORE_DIRECTORY .. "/libs/systems/exercise_training.lua") dofile(CORE_DIRECTORY .. "/libs/systems/familiar.lua") dofile(CORE_DIRECTORY .. "/libs/systems/features.lua") dofile(CORE_DIRECTORY .. "/libs/systems/hazard.lua") diff --git a/data/scripts/actions/items/exercise_training_weapons.lua b/data/scripts/actions/items/exercise_training_weapons.lua index c8e7240902f..4a72f19e5c8 100644 --- a/data/scripts/actions/items/exercise_training_weapons.lua +++ b/data/scripts/actions/items/exercise_training_weapons.lua @@ -1,7 +1,132 @@ local exhaustionTime = 10 +local exerciseWeaponsTable = { + -- MELE + [28540] = { skill = SKILL_SWORD }, + [28552] = { skill = SKILL_SWORD }, + [35279] = { skill = SKILL_SWORD }, + [35285] = { skill = SKILL_SWORD }, + [28553] = { skill = SKILL_AXE }, + [28541] = { skill = SKILL_AXE }, + [35280] = { skill = SKILL_AXE }, + [35286] = { skill = SKILL_AXE }, + [28554] = { skill = SKILL_CLUB }, + [28542] = { skill = SKILL_CLUB }, + [35281] = { skill = SKILL_CLUB }, + [35287] = { skill = SKILL_CLUB }, + [44064] = { skill = SKILL_SHIELD }, + [44065] = { skill = SKILL_SHIELD }, + [44066] = { skill = SKILL_SHIELD }, + [44067] = { skill = SKILL_SHIELD }, + -- ROD + [28544] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, + [28556] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, + [35283] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, + [35289] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_SMALLICE, allowFarUse = true }, + -- RANGE + [28543] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, + [28555] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, + [35282] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, + [35288] = { skill = SKILL_DISTANCE, effect = CONST_ANI_SIMPLEARROW, allowFarUse = true }, + -- WAND + [28545] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, + [28557] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, + [35284] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, + [35290] = { skill = SKILL_MAGLEVEL, effect = CONST_ANI_FIRE, allowFarUse = true }, +} + +local dummies = Game.getDummies() + +local function leaveExerciseTraining(playerId) + if _G.OnExerciseTraining[playerId] then + stopEvent(_G.OnExerciseTraining[playerId].event) + _G.OnExerciseTraining[playerId] = nil + end + + local player = Player(playerId) + if player then + player:setTraining(false) + end + return +end + +local function exerciseTrainingEvent(playerId, tilePosition, weaponId, dummyId) + local player = Player(playerId) + if not player then + return leaveExerciseTraining(playerId) + end + + if player:isTraining() == 0 then + player:sendTextMessage(MESSAGE_FAILURE, "You have stopped training.") + return leaveExerciseTraining(playerId) + end + + if not Tile(tilePosition):getItemById(dummyId) then + player:sendTextMessage(MESSAGE_FAILURE, "Someone has moved the dummy, the training has stopped.") + leaveExerciseTraining(playerId) + return false + end + + local playerPosition = player:getPosition() + if not playerPosition:isProtectionZoneTile() then + player:sendTextMessage(MESSAGE_FAILURE, "You are no longer in a protection zone, the training has stopped.") + leaveExerciseTraining(playerId) + return false + end + + if player:getItemCount(weaponId) <= 0 then + player:sendTextMessage(MESSAGE_FAILURE, "You need the training weapon in the backpack, the training has stopped.") + leaveExerciseTraining(playerId) + return false + end + + local weapon = player:getItemById(weaponId, true) + if not weapon:isItem() or not weapon:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then + player:sendTextMessage(MESSAGE_FAILURE, "The selected item is not a training weapon, the training has stopped.") + leaveExerciseTraining(playerId) + return false + end + + local weaponCharges = weapon:getAttribute(ITEM_ATTRIBUTE_CHARGES) + if not weaponCharges or weaponCharges <= 0 then + weapon:remove(1) -- ?? + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has disappeared.") + leaveExerciseTraining(playerId) + return false + end + + if not dummies[dummyId] then + return false + end + + local rate = dummies[dummyId] / 100 + local isMagic = exerciseWeaponsTable[weaponId].skill == SKILL_MAGLEVEL + if isMagic then + player:addManaSpent(500 * rate) + else + player:addSkillTries(exerciseWeaponsTable[weaponId].skill, 7 * rate) + end + + weapon:setAttribute(ITEM_ATTRIBUTE_CHARGES, (weaponCharges - 1)) + tilePosition:sendMagicEffect(CONST_ME_HITAREA) + + if exerciseWeaponsTable[weaponId].effect then + playerPosition:sendDistanceEffect(tilePosition, exerciseWeaponsTable[weaponId].effect) + end + + if weapon:getAttribute(ITEM_ATTRIBUTE_CHARGES) <= 0 then + weapon:remove(1) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your training weapon has disappeared.") + leaveExerciseTraining(playerId) + return false + end + + local vocation = player:getVocation() + _G.OnExerciseTraining[playerId].event = addEvent(exerciseTrainingEvent, vocation:getBaseAttackSpeed() / configManager.getFloat(configKeys.RATE_EXERCISE_TRAINING_SPEED), playerId, tilePosition, weaponId, dummyId) + return true +end + local function isDummy(id) - local dummies = Game.getDummies() return dummies[id] and dummies[id] > 0 end @@ -22,7 +147,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, end local playerPos = player:getPosition() - if not ExerciseWeaponsTable[item.itemid].allowFarUse and (playerPos:getDistance(target:getPosition()) > 1) then + if not exerciseWeaponsTable[item.itemid].allowFarUse and (playerPos:getDistance(target:getPosition()) > 1) then player:sendTextMessage(MESSAGE_FAILURE, "Get closer to the dummy.") return true end @@ -62,7 +187,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, _G.OnExerciseTraining[playerId] = {} if not _G.OnExerciseTraining[playerId].event then - _G.OnExerciseTraining[playerId].event = addEvent(ExerciseEvent, 0, playerId, targetPos, item.itemid, targetId) + _G.OnExerciseTraining[playerId].event = addEvent(exerciseTrainingEvent, 0, playerId, targetPos, item.itemid, targetId) _G.OnExerciseTraining[playerId].dummyPos = targetPos player:setTraining(true) player:setExhaustion("training-exhaustion", exhaustionTime) @@ -73,7 +198,7 @@ function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, return false end -for weaponId, weapon in pairs(ExerciseWeaponsTable) do +for weaponId, weapon in pairs(exerciseWeaponsTable) do exerciseTraining:id(weaponId) if weapon.allowFarUse then exerciseTraining:allowFarUse(true)