From 67540796645c6ebb8a5085c5dda74ae27b534d91 Mon Sep 17 00:00:00 2001 From: Aliquis <61360121+4liquis@users.noreply.github.com> Date: Fri, 9 Dec 2022 17:00:54 -0500 Subject: [PATCH 1/3] Cancel Addon Rewritten to better reflect Windower 5 code standards and guidelines. --- addons/cancel/cancel.lua | 63 ++++++++++++++++++++++++++++++++++++++ addons/cancel/manifest.xml | 11 +++++++ 2 files changed, 74 insertions(+) create mode 100644 addons/cancel/cancel.lua create mode 100644 addons/cancel/manifest.xml diff --git a/addons/cancel/cancel.lua b/addons/cancel/cancel.lua new file mode 100644 index 00000000..d4508e5b --- /dev/null +++ b/addons/cancel/cancel.lua @@ -0,0 +1,63 @@ +local command = require('core.command') +local packet = require('packet') +local resources = require('resources') +local status_effects = require('status_effects') +local string = require('string.ext') + +local resource_buffs = resources.buffs +local string_match = string.match +local string_normalize = string.normalize + +local cancel = function(...) + local cancel_args = {...} + + for _, arg in ipairs(cancel_args) do + local arg_norm = string_normalize(arg) + + for _, status in ipairs(status_effects.array) do + if status.duration == 0 then + break + end + + local id = status.id + local res = resource_buffs[id] + + if string_match(string_normalize(res.en), arg_norm) or string_match(string_normalize(res.enl), arg_norm) then + packet.outgoing[0x0F1]:inject({buff = id}) + break + end + end + end +end + +command.arg.register('buff', '') +command.new('cancel'):register(cancel, '{buff}*') + +--[[ +Copyright © 2022, Aliquis https://github.com/4liquis +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of the "Cancel" nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT +SHALL ALIQUIS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +]] diff --git a/addons/cancel/manifest.xml b/addons/cancel/manifest.xml new file mode 100644 index 00000000..4e9ebc31 --- /dev/null +++ b/addons/cancel/manifest.xml @@ -0,0 +1,11 @@ + + cancel + 1.0.0.0 + addon + + packet + resources + status_effects + string + + From 3cb6596896f6b8235c0453f117e4b99997acc5ff Mon Sep 17 00:00:00 2001 From: Aliquis <61360121+4liquis@users.noreply.github.com> Date: Fri, 9 Dec 2022 19:02:49 -0500 Subject: [PATCH 2/3] minor update --- addons/cancel/cancel.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/cancel/cancel.lua b/addons/cancel/cancel.lua index d4508e5b..b478e24a 100644 --- a/addons/cancel/cancel.lua +++ b/addons/cancel/cancel.lua @@ -4,7 +4,7 @@ local resources = require('resources') local status_effects = require('status_effects') local string = require('string.ext') -local resource_buffs = resources.buffs +local buffs_resource = resources.buffs local string_match = string.match local string_normalize = string.normalize @@ -19,11 +19,11 @@ local cancel = function(...) break end - local id = status.id - local res = resource_buffs[id] + local status_id = status.id + local enl_norm = string_normalize(buffs_resource[status_id].enl) - if string_match(string_normalize(res.en), arg_norm) or string_match(string_normalize(res.enl), arg_norm) then - packet.outgoing[0x0F1]:inject({buff = id}) + if string_match(enl_norm, arg_norm) then + packet.outgoing[0x0F1]:inject({buff = status_id}) break end end From e7d92656c9a65f1fb35419efbbcf069da6e4d92f Mon Sep 17 00:00:00 2001 From: Aliquis <61360121+4liquis@users.noreply.github.com> Date: Fri, 9 Dec 2022 20:05:18 -0500 Subject: [PATCH 3/3] touch up --- addons/cancel/cancel.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/cancel/cancel.lua b/addons/cancel/cancel.lua index b478e24a..c8dd435e 100644 --- a/addons/cancel/cancel.lua +++ b/addons/cancel/cancel.lua @@ -4,14 +4,12 @@ local resources = require('resources') local status_effects = require('status_effects') local string = require('string.ext') -local buffs_resource = resources.buffs +local buffs = resources.buffs local string_match = string.match local string_normalize = string.normalize local cancel = function(...) - local cancel_args = {...} - - for _, arg in ipairs(cancel_args) do + for _, arg in ipairs({...}) do local arg_norm = string_normalize(arg) for _, status in ipairs(status_effects.array) do @@ -19,11 +17,10 @@ local cancel = function(...) break end - local status_id = status.id - local enl_norm = string_normalize(buffs_resource[status_id].enl) + local id = status.id - if string_match(enl_norm, arg_norm) then - packet.outgoing[0x0F1]:inject({buff = status_id}) + if string_match(string_normalize(buffs[id].enl), arg_norm) then + packet.outgoing[0x0F1]:inject({buff = id}) break end end