-------------------------------------------------------------------------------- -- skill.lua is part of ZS Shaiya Bot. -- -- ZS Shaiya Bot is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- ZS Shaiya Bot is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with ZS Shaiya Bot. If not, see . -- -- Copyright © 2008 Joshua Langley -------------------------------------------------------------------------------- SKILL_MESSAGE_INTERVAL = 100 --SKILL_DELAY = 2; --[[ Any Skill that's been placed in the Shortcut bar is created with this Class. Skill This is a sub-class from Shortcuts. @param name The name of the Skill. Make sure it typed exactly as it's shown or the skills won't register. @param level The level of the skill. @param shortcut_key Shortcut key of the skill. @param rest The time taken to check if the skill has been executed. ]] Skill = class(Shortcut, --function(obj, name, shortcut_key, rest, cooldown, mp, sp) function(obj, name, level, shortcut_key, rest) debug_message("skill: "..name.. " " ..level.."") print_r(g_skills) if (g_skills[name] == nil or g_skills[name][level] == nil) then error(name .. " Level " .. level .. " has not been added to \"skills.xml\". " .. "\nPlease add it, and don't forget to also post it at the MicroMacro scripts website so others may benefit. ", 0) end local l_cooldown if (g_skills[name].duration ~= nil) then --debug_message("g_skills["..name.."].duration: ".. g_skills[name].duration) l_cooldown = g_skills[name].duration else l_cooldown = g_skills[name][level].cooldown end --[[local l_rest if (g_skills[name].wait ~= nil) then l_cooldown = g_skills[name].duration else end]] Shortcut.init(obj, shortcut_key, (l_cooldown + rest)) obj.name = name obj.level = level obj.mp = g_skills[name][level].mp obj.sp = g_skills[name][level].sp obj.rest = (rest * 1000) --print("obj.rest: " .. obj.rest) end ) function Skill:available(mp, sp) --[[local dbg = sprintf("avatar.mp: %d, avatar.sp: %d, mp: %d, sp: %d, " .. "self.timer: %d, self.cooldown: %d\n", mp, sp, self.mp, self.sp, self.timer, self.cooldown) debug_message(dbg)]] local l_time_elapsed = os.difftime(os.time(), self.timer) --debug_message("l_time_elapsed: " .. l_time_elapsed) if (l_time_elapsed >= self.cooldown and mp >= self.mp and sp >= self.sp) then return true; else return false; end end -- Try and uses the skill. If the required mp/sp is not percieved as being deducted, -- then it will not reset the timer. SKILL_USED = 0 SKILL_RECHARGING = 1 SKILL_PREV_REQ = 2 SKILL_CANNOT_ATTACK = 3 SKILL_WRONG_TARGET = 4 SKILL_INSUFFICIENT_RANGE = 5 SKILL_TIMED_OUT = 6 function Skill:use() local l_avi = get_avatar() local l_gui = get_gui() local l_prev_mp = l_avi.mp local l_prev_sp = l_avi.sp local l_used = false print("skill: " .. self.name .. " pressed") keyboardPress(self.shortcut_key) yrest(SKILL_MESSAGE_INTERVAL) --print("msg: " .. gui:get_latest_text_msg()) --if(l_gui:in_latest_text_msg(GUI_TEXT_MESSAGE_SKILL_RECHARGING) ) then if(l_gui:find_in_text_msg_array(GUI_TEXT_MESSAGE_SKILL_RECHARGING)) then print("skill: recharging") self.timer = os.time() --yrest(self.rest) return SKILL_RECHARGING elseif (l_gui:in_latest_text_msg(GUI_TEXT_MESSAGE_CANNOT_ATTACK)) then print("skill: cannot attack") l_avi.status = USER_CANNOT_ATTACK return SKILL_CANNOT_ATTACK elseif(l_gui:in_latest_text_msg(GUI_TEXT_MESSAGE_WRONG_TARGET)) then print("skill: wrong target.") return SKILL_WRONG_TARGET elseif(l_gui:in_latest_text_msg(GUI_TEXT_INSUFFICIENT_RANGE)) then print("skill: insuffiecient range.") return SKILL_WRONG_TARGET end local l_skill_delay = 0 local l_prev_msg = nil local l_latest_msg = nil local l_skill_used_msg = sprintf(GUI_TEXT_MESSAGE_SKILL_USED, self.name) --print("l_skill_used_msg: " .. l_skill_used_msg) while (l_skill_delay < self.rest) do l_latest_msg = l_gui:get_latest_text_msg() if (l_prev_msg ~= l_latest_msg) then if (l_gui:find_in_text_msg_array(l_skill_used_msg)) then print("skill: used") --yrest(g_max_round_trip) self.timer = os.time() return SKILL_USED elseif (l_gui:in_latest_text_msg(GUI_TEXT_MESSAGE_PREV_SKILL_REQ)) then print("skill: previous required") yrest(g_cfg.max_round_trip) return SKILL_PREV_REQ end l_prev_msg = l_latest_msg end yrest(SKILL_MESSAGE_INTERVAL) l_skill_delay = l_skill_delay + SKILL_MESSAGE_INTERVAL end print("skill: timed out") return SKILL_TIMED_OUT end