Initial Beta of Bashmatic
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
if not bashmatic.configs.death.event then
|
||||
if not bashmatic.death.event then
|
||||
cecho("<firebrick>BASHMATIC: You must configure the death trigger first. Please see bm help for more info.")
|
||||
else
|
||||
if bashmatic.configs.enemies.detection == "inline" then
|
||||
-- using trigger detection
|
||||
local area = nil
|
||||
if bashmatic.configs.areas.detection == "mapper" then area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) end
|
||||
if bashmatic.configs.areas.detection == "gmcp" and bashmatic.configs.areas.data ~= nil then area = bashmatic.configs.areas.data end
|
||||
inlineAddTarget(matches[2], area)
|
||||
elseif bashmatic.configs.enemies.detection == "gmcp" then
|
||||
-- using gmcp detection
|
||||
cecho("<firebrick>BASHMATIC: GMCP not implemented yet.")
|
||||
if bashmatic.enemies.group then
|
||||
-- grouping enemies by area
|
||||
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if area == nil then
|
||||
cecho("<firebrick>BASHMATIC: We tried to add that enemy but got a bad area.\nGot: " .. area .. "<reset>")
|
||||
else
|
||||
inlineAddTarget(matches[2], area)
|
||||
end
|
||||
else
|
||||
-- well this is broken
|
||||
cecho("<firebrick>BASHMATIC: Invalid enemy detection method.<reset>")
|
||||
-- not grouping by area
|
||||
inlineAddTarget(matches[2], nil)
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,20 @@
|
||||
if table.size(bashmatic.hunting.events) > 0 then
|
||||
for _, tid in ipairs(bashmatic.hunting.events) do
|
||||
killTrigger(tid)
|
||||
end
|
||||
end
|
||||
killBashingTriggers()
|
||||
toggleBashing(false)
|
||||
bmDisable()
|
||||
bashmatic.hunting.events = {}
|
||||
bashmatic.hunting.targets = {}
|
||||
cecho("<firebrick>BASHMATIC: Cleared target list.<reset>")
|
||||
|
||||
if Bashmatic.enemies.group then
|
||||
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if area == nil then
|
||||
cecho("<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if not table.contains(Bashmatic.enemies.targets, area) then
|
||||
cecho("<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
Bashmatic.enemies.targets.area = nil
|
||||
cecho("<DarkSlateBlue>Bashmatic: Cleared target list for area " .. area .. "<reset>")
|
||||
else
|
||||
Bashmatic.enemies.targets = {}
|
||||
cecho("<DarkSlateBlue>Bashmatic: Cleared target list.<reset>")
|
||||
end
|
||||
@@ -3,22 +3,12 @@ cecho("<Slategrey>---------------------------------")
|
||||
cecho("<DarkSlateBlue>See bm help for information on configuration.")
|
||||
cecho("<DarkSlateBlue>")
|
||||
cecho("<MediumPurple>\nBattle Commands:")
|
||||
cecho("<DarkSlateBlue>-- Start : " .. bashmatic.commands.start or "None")
|
||||
cecho("<DarkSlateBlue>-- Before: " .. bashmatic.commands.before or "None")
|
||||
cecho("<DarkSlateBlue>-- During: " .. bashmatic.commands.during or "None" .. "(Every " .. bashmatic.commands.duringTime .. "s)")
|
||||
cecho("<DarkSlateBlue>-- After : " .. bashmatic.commands.after or "None")
|
||||
cecho("<DarkSlateBlue>-- Start : " .. Bashmatic.commands.start or "None")
|
||||
cecho("<DarkSlateBlue>-- Before: " .. Bashmatic.commands.before or "None")
|
||||
cecho("<DarkSlateBlue>-- During: " .. Bashmatic.commands.during or "None" .. "(Every " .. Bashmatic.commands.duringTime .. "s)")
|
||||
cecho("<DarkSlateBlue>-- After : " .. Bashmatic.commands.after or "None")
|
||||
cecho("<MediumPurple>\n\nDeath Trigger:")
|
||||
cecho("<DarkSlateBlue>-- Phrase : " .. bashmatic.death.phrase or "None")
|
||||
cecho("<DarkSlateBlue>-- Activated?: " .. bashmatic.death.event or "No")
|
||||
cecho("<MediumPurple>\n\nDetection:")
|
||||
cecho("<DarkSlateBlue>-- Detecting enemies using " .. bashmatic.configs.enemies.detection)
|
||||
if bashmatic.configs.areas.detection == nil then
|
||||
cecho("<DarkSlateBlue>-- Not currently grouping enemies by areas.")
|
||||
else
|
||||
cecho("<DarkSlateBlue>-- Currently grouping enemies by areas using " .. bashmatic.configs.areas.detection)
|
||||
end
|
||||
if bashmatic.configs.enemies.detection == "gmcp" or bashmatic.configs.areas.detection == "gmcp" then
|
||||
cecho("<MediumPurple>\n\nGMCP Detection Settings:")
|
||||
if bashmatic.configs.enemies.detection == "gmcp" then cecho("<DarkSlateBlue>-- Enemy data located at " .. bashmatic.configs.enemies.location) end
|
||||
if bashmatic.configs.areas.detection == "gmcp" then cecho("<DarkSlateBlue>-- Area data located at " .. bashmatic.configs.areas.location) end
|
||||
end
|
||||
cecho("<DarkSlateBlue>-- Phrase : " .. Bashmatic.death.phrase or "None")
|
||||
cecho("<DarkSlateBlue>-- Activated?: " .. Bashmatic.death.event or "No")
|
||||
cecho("<MediumPurple>\n\nEnemies:")
|
||||
cecho("<DarkSlateBlue>-- Grouping by Areas: " .. Bashmatic.enemies.group or "No")
|
||||
@@ -2,24 +2,49 @@ local which = matches[2]:lower()
|
||||
|
||||
if which == "phrase" then
|
||||
-- death phrase
|
||||
if Bashmatic.death.event ~= nil then
|
||||
killTrigger(Bashmatic.death.event)
|
||||
end
|
||||
Bashmatic.death.phrase = matches[2]
|
||||
Bashmatic.death.event = tempTrigger(Bashmatic.death.phrase,handleMobDeath)
|
||||
cecho("<DarkSlateBlue>Bashmatic: Reset the death event trigger phrase to " .. matches[2] .. ".<reset>")
|
||||
elseif which == "start" then
|
||||
-- starting battle command
|
||||
Bashmatic.commands.start = matches[2]
|
||||
cecho("<DarkSlateBlue>Bashmatic: Set battle start command to " .. matches[2] .. " target.<reset>")
|
||||
elseif which == "before" then
|
||||
-- before battle command
|
||||
Bashmatic.commands.before = matches[2]
|
||||
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[2] .. " before battle start.<reset>")
|
||||
elseif which == "during" then
|
||||
-- during battle command
|
||||
Bashmatic.comands.during = matches[2]
|
||||
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[2] .. " during battle every " .. Bashmatic.commands.duringTime .. " seconds.<reset>")
|
||||
elseif which == "duringTime" then
|
||||
-- during battle command time frame
|
||||
Bashmatic.commands.duringTime = tonumber(mathces[2])
|
||||
cecho("<DarkSlateBlue>Bashmatic: Will send " .. Bashmatic.commands.during .. " during battle every " .. tonumber(matches[2]) .. " seconds.<reset>")
|
||||
elseif which == "after" then
|
||||
-- after battle command
|
||||
elseif which == "enemy" then
|
||||
-- enemy detection method
|
||||
elseif which == "egmcp" then
|
||||
-- enemy gmcp path
|
||||
elseif which == "area" then
|
||||
-- area detection method
|
||||
elseif which == "agmcp" then
|
||||
-- area gmcp path
|
||||
Bashmatic.commands.after = matches[2]
|
||||
cecho("<DarkSlateBlue>Bashmatic: Will send " .. matches[2] .. " after combat.<reset>")
|
||||
elseif which == "group" then
|
||||
-- group by area
|
||||
if #getRooms() == 0 then
|
||||
Bashmatic.enemies.group = false
|
||||
cecho("<firebrick>Bashmatic: No map detected. Did you make one? You need at least one room to use this feature.<reset>")
|
||||
else
|
||||
Bashmatic.enemies.group = not Bashmatic.enemies.group
|
||||
if Bashmatic.enemies.group then
|
||||
-- we've just turned on enemy grouping
|
||||
Bashmatic.enemies.targets = {}
|
||||
cecho("<DarkSlateBlue>Bashmatic: Now grouping enemies by areas. Cleared previous enemies.<reset>")
|
||||
else
|
||||
-- we've just turned off enemy grouping
|
||||
squashTargetGroups()
|
||||
cecho("<DarkSlateBlue>Bashmatic: No longer grouping enemies by areas. Squashed previous enemies into one large table.\nYou can bm clear to erase them.<reset>")
|
||||
end
|
||||
end
|
||||
else
|
||||
cecho("<firebrick>BASHMATIC: Unrecognized option " .. matches[2] .. ". See bm help for a list of options.")
|
||||
cecho("<firebrick>Bashmatic: Unrecognized option " .. matches[2] .. ". See bm help for a list of options.")
|
||||
end
|
||||
28
src/aliases/bashmatic/BM_Delete.lua
Normal file
28
src/aliases/bashmatic/BM_Delete.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local ourIndex = tonumber(matches[2])
|
||||
|
||||
if Bashmatic.enemies.group then
|
||||
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if area == nil then
|
||||
cecho("<firebrick>Bashmatic: Attempted to clear area targets but got a bad area.\nGot: " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if not table.contains(Bashmatic.enemies.targets, area) then
|
||||
cecho("<firebrick>Bashmatic: You don't have any enemies for the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
local size = table.size(Bashmatic.enemies.targets.area)
|
||||
if ourIndex > size then
|
||||
cecho("<firebrick>Bashmatic: Index out of range for this area. There are only " .. size .. " targets stored.<reset>")
|
||||
return
|
||||
end
|
||||
table.remove(Bashmatic.enemies.targets.area, ourIndex)
|
||||
cecho("<DarkSlateBlue>Bashmatic: Removed target from the area list.<reset>")
|
||||
else
|
||||
local size = table.size(Bashmatic.enemies.targets)
|
||||
if ourIndex > size then
|
||||
cecho("<firebrick>Bashmatic: Index out of range. There are only " .. size .. " targets stored.<reset>")
|
||||
return
|
||||
end
|
||||
table.remove(Bashmatic.enemies.targets, ourIndex)
|
||||
cecho("<DarkSlateBlue>Bashmatic: Removed target from the list.<reset")
|
||||
end
|
||||
@@ -4,35 +4,33 @@ Let's Bash some Mobs!
|
||||
|
||||
Basic Setup
|
||||
-----------
|
||||
Bare Minimum, you need to setup a death trigger, a starting battle command, and at least one target. Set up the death trigger by doing bm config phrase=your game's death phrase. Then setup a starting command with bm config start=kill. Then go find a target and bm add target. Then type bm and you're all set to auto bash them. Altogether again then that was.
|
||||
Bare Minimum, you need to setup a death trigger, a starting battle command, and at least one target. Set up the death trigger by doing bm config phrase=your game's death phrase or word. Then setup a starting command with bm config start=kill command. Then go find a target and bm add target. Then type bm and you're all set to auto bash them. Altogether again then that was.
|
||||
|
||||
1) bm config phrase=death phrase
|
||||
2) bm config start=kill command
|
||||
3) bm add target
|
||||
1) bmc phrase=death phrase or keyword
|
||||
2) bmc start=kill command (target added automatically)
|
||||
3) bma target
|
||||
4) bm - this will toggle the system on
|
||||
|
||||
All config options
|
||||
------------------
|
||||
Toggle all of these using bm config option=value
|
||||
|
||||
bm config phrase - sets the phrase that should trigger resolution for the death of our target.
|
||||
bm config start - sets the command used to start combat. The target name is added here.
|
||||
bm config before - commands to execute before we start combat.
|
||||
bm config during - commands to execute during combat.
|
||||
bm config duringTime - time delay between during command execution. Default 2 seconds. Wants a number.
|
||||
bm config after - commands to execute after the death trigger fires.
|
||||
bm config enemy - Set to one of inline or gmcp to determine how we grab enemy data.
|
||||
bm config egmcp - if using gmcp to grab enemy data, use this to set the gmcp path for enemy data.
|
||||
bm config area - if wanting to group by areas, set this to mapper or gmcp to set how we get area information.
|
||||
bm config agmcp - if using gmcp for areas, use this to set the gmcp path for area data.
|
||||
bmc phrase - sets the phrase that should trigger resolution for the death of our target.
|
||||
bmc start - sets the command used to start combat. The target name is added here.
|
||||
bmc before - commands to execute before we start combat.
|
||||
bmc during - commands to execute during combat.
|
||||
bmc duringTime - time delay between during command execution. Default 2 seconds. Wants a number.
|
||||
bmc after - commands to execute after the death trigger fires.
|
||||
bmc group - set to yes or no to toggle grouping enemies by mudlet mapper areas on or off
|
||||
|
||||
Aliases Available
|
||||
-----------------
|
||||
bm add <target> - add a new target to the hunt list
|
||||
bma <target> - add a new target to the hunt list
|
||||
bmc - show the current configuration
|
||||
bm config option=value - change the configuration
|
||||
bmt - List all current targets
|
||||
bmc option=value - change the configuration
|
||||
bmt - List all current targets (if grouped by areas this will be for the current area)
|
||||
bm - toggle the bashing system on and off
|
||||
bm clear - clear all targets
|
||||
bm clear - clear all targets (All Targets. For All Areas.)
|
||||
bmd # - Delete the target with the given ID from bmt
|
||||
bm help - this screen
|
||||
<reset>]])
|
||||
@@ -0,0 +1,40 @@
|
||||
if Bashmatic.enemies.group then
|
||||
-- grouped by areas
|
||||
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if area == nil then
|
||||
cecho("<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if not table.contains(Bashmatic.enemies.targets, area) then
|
||||
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
local size = table.size(Bashmatic.enemies.targets.area)
|
||||
if size == 0 then
|
||||
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if size <= 15 then
|
||||
-- fits on one page
|
||||
displayAreaTargetList(area, 1, size, nil, nil)
|
||||
else
|
||||
-- paginator
|
||||
local pages = math.floor(size/15)+1
|
||||
displayAreaTargetList(area, 1, 15, 1, pages)
|
||||
end
|
||||
else
|
||||
-- not grouped by area
|
||||
local size = table.size(Bashmatic.enemies.targets)
|
||||
if size == 0 then
|
||||
cecho("<firebrick>Bashmatic: No enemies added.<reset>")
|
||||
return
|
||||
end
|
||||
if size <= 15 then
|
||||
-- fits on one page
|
||||
displayTargetList(1, size, nil, nil)
|
||||
else
|
||||
-- paginator
|
||||
local pages = math.floor(size/15)+1
|
||||
displayTargetList(1, 15, 1, pages)
|
||||
end
|
||||
end
|
||||
54
src/aliases/bashmatic/BM_Listtargets_Pager.lua
Normal file
54
src/aliases/bashmatic/BM_Listtargets_Pager.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
if Bashmatic.enemies.group then
|
||||
-- grouped by areas
|
||||
local area = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if area == nil then
|
||||
cecho("<firebrick>Bashmatic: We got an invalid area.\nWe Got: " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if not table.contains(Bashmatic.enemies.targets, area) then
|
||||
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
local size = table.size(Bashmatic.enemies.targets.area)
|
||||
if size == 0 then
|
||||
cecho("<firebrick>Bashmatic: No enemies added from the area " .. area .. "<reset>")
|
||||
return
|
||||
end
|
||||
if size <= 15 then
|
||||
-- fits on one page
|
||||
displayAreaTargetList(area, 1, size, nil, nil)
|
||||
else
|
||||
-- paginator
|
||||
local pages = math.floor(size/15)+1
|
||||
if tonumber(matches[2]) > pages then
|
||||
cecho("<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>")
|
||||
return
|
||||
end
|
||||
local startIndex = ((tonumber(matches[2]) - 1)*15)+1
|
||||
local endIndex = startIndex + 14
|
||||
if endIndex > size then endIndex = size end
|
||||
displayAreaTargetList(area, startIndex, endIndex, tonumber(matches[2]), pages)
|
||||
end
|
||||
else
|
||||
-- not grouped by area
|
||||
local size = table.size(Bashmatic.enemies.targets)
|
||||
if size == 0 then
|
||||
cecho("<firebrick>Bashmatic: No enemies added.<reset>")
|
||||
return
|
||||
end
|
||||
if size <= 15 then
|
||||
-- fits on one page
|
||||
displayTargetList(1, size, nil, nil)
|
||||
else
|
||||
-- paginator
|
||||
local pages = math.floor(size/15)+1
|
||||
if tonumber(matches[2]) > pages then
|
||||
cecho("<firebrick>Bashmatic: There aren't that many pages. There are only " .. pages .. " pages.<reset>")
|
||||
return
|
||||
end
|
||||
local startIndex = ((tonumber(matches[2]) - 1)*15)+1
|
||||
local endIndex = startIndex + 14
|
||||
if endIndex > size then endIndex = size end
|
||||
displayTargetList(startIndex, endIndex, tonumber(matches[2]), pages)
|
||||
end
|
||||
end
|
||||
@@ -1 +1,7 @@
|
||||
bashmatic.configs.enabled = not bashmatic.configs.enabled
|
||||
Bashmatic.enabled = not Bashmatic.enabled
|
||||
|
||||
if Bashmatic.enabled and table.size(Bashmatic.hunting.events) == 0 and table.size(Bashmatic.enemies.targets) > 1 then
|
||||
-- we just turned ourself on, we have targets, and no triggers are running
|
||||
recreateTriggers()
|
||||
cecho("<DarkSlateBlue>Bashmatic: Bashmatic turned on. Let's go bash some mobs.<reset>")
|
||||
end
|
||||
@@ -3,7 +3,7 @@
|
||||
"isActive": "yes",
|
||||
"isFolder": "no",
|
||||
"name": "BM Addtarget",
|
||||
"regex": "^bm add (.*)$",
|
||||
"regex": "^bma (.*)$",
|
||||
"script": ""
|
||||
},
|
||||
{
|
||||
@@ -17,7 +17,7 @@
|
||||
"isActive": "yes",
|
||||
"isFolder": "no",
|
||||
"name": "BM Configset",
|
||||
"regex": "^bm config (.*)=(.*)$",
|
||||
"regex": "^bmc (.*)=(.*)$",
|
||||
"script": ""
|
||||
},
|
||||
{
|
||||
@@ -27,6 +27,13 @@
|
||||
"regex": "^bmt$",
|
||||
"script": ""
|
||||
},
|
||||
{
|
||||
"isActive": "yes",
|
||||
"isFolder": "no",
|
||||
"name": "BM Listtargets Pager",
|
||||
"regex": "^bmt (\\d+)$",
|
||||
"script": ""
|
||||
},
|
||||
{
|
||||
"isActive": "yes",
|
||||
"isFolder": "no",
|
||||
@@ -47,5 +54,12 @@
|
||||
"name": "BM Help",
|
||||
"regex": "^bm help$",
|
||||
"script": ""
|
||||
},
|
||||
{
|
||||
"isActive": "yes",
|
||||
"isFolder": "no",
|
||||
"name": "BM Delete",
|
||||
"regex": "^bmd (\\d+)",
|
||||
"script": ""
|
||||
}
|
||||
]
|
||||
48
src/resources/LICENSE_MDK.lua
Executable file
48
src/resources/LICENSE_MDK.lua
Executable file
@@ -0,0 +1,48 @@
|
||||
--[===[
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Damian Monogue
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
--]===]
|
||||
|
||||
-- schema validation provided by schema.lua, license below
|
||||
--[[
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Sebastian Schoener
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
]]
|
||||
1697
src/resources/ftext.lua
Executable file
1697
src/resources/ftext.lua
Executable file
File diff suppressed because it is too large
Load Diff
447
src/resources/ftext_spec.lua
Executable file
447
src/resources/ftext_spec.lua
Executable file
@@ -0,0 +1,447 @@
|
||||
local ftext = require("MDK.ftext")
|
||||
|
||||
describe("ftext:", function()
|
||||
describe("ftext.fText:", function()
|
||||
local fText = ftext.fText
|
||||
|
||||
it("Should properly center text", function()
|
||||
local expected = " some text "
|
||||
local actual = fText("some text", {width = 20})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should properly pad left aligned text", function()
|
||||
local expected = "some text "
|
||||
local actual = fText("some text", {width = 20, alignment = "left"})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should properly pad right aligned text", function()
|
||||
local expected = " some text"
|
||||
local actual = fText("some text", {width = 20, alignment = "right"})
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should wrap lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = fText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(line:len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = fText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(line:len(), 15)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("non-space spacer character:", function()
|
||||
local str = "some text"
|
||||
local options = {width = "20", alignment = "left", spacer = "="}
|
||||
it("Should work with left align", function()
|
||||
local expected = "some text =========="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with right align", function()
|
||||
local expected = "========== some text"
|
||||
options.alignment = "right"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with center align", function()
|
||||
local expected = ("==== some text =====")
|
||||
options.alignment = "center"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("nogap option:", function()
|
||||
local str = "some text"
|
||||
local options = {width = "20", alignment = "left", spacer = "=", nogap = true}
|
||||
|
||||
it("Should work with left align", function()
|
||||
local expected = "some text==========="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with right align", function()
|
||||
local expected = "===========some text"
|
||||
options.alignment = "right"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should work with center align", function()
|
||||
local expected = "=====some text======"
|
||||
options.alignment = "center"
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("cap functionality", function()
|
||||
local str = "some text"
|
||||
local options = {width = 20, spacer = "=", cap = "|"}
|
||||
|
||||
it("Should place the spacer outside the cap by default", function()
|
||||
local expected = "===| some text |===="
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should place it inside the cap if inside option is true", function()
|
||||
local expected = "|=== some text ====|"
|
||||
options.inside = true
|
||||
local actual = fText(str, options)
|
||||
options.inside = nil
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(20, actual:len())
|
||||
end)
|
||||
|
||||
it("Should mirror certain characters with their opposites", function()
|
||||
local expected = "===[ some text ]===="
|
||||
options.mirror = true
|
||||
options.cap = "["
|
||||
local actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.inside = true
|
||||
expected = "[=== some text ====]"
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.inside = nil
|
||||
options.cap = "<"
|
||||
expected = "===< some text >===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "{"
|
||||
expected = "==={ some text }===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "("
|
||||
expected = "===( some text )===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
options.cap = "|"
|
||||
expected = "===| some text |===="
|
||||
actual = fText(str, options)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.cfText", function()
|
||||
local cfText = ftext.cfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "<purple>",
|
||||
spacerColor = "<green>",
|
||||
textColor = "<red>",
|
||||
}
|
||||
it("Should handle cecho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "<purple>[<reset><green>===<reset><red> some text <reset><green>====<reset><purple>]<reset>"
|
||||
local actual = cfText(str, options)
|
||||
local actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "<green>===<reset><purple>[<reset><red> some text <reset><purple>]<reset><green>====<reset>"
|
||||
options.inside = false
|
||||
actual = cfText(str, options)
|
||||
actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap cecho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = cfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(cecho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = cfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(cecho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
describe("ftext.dfText", function()
|
||||
local dfText = ftext.dfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "<160,32,240>",
|
||||
spacerColor = "<0,255,0>",
|
||||
textColor = "<255,0,0>",
|
||||
}
|
||||
it("Should handle decho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "<160,32,240>[<r><0,255,0>===<r><255,0,0> some text <r><0,255,0>====<r><160,32,240>]<r>"
|
||||
local actual = dfText(str, options)
|
||||
local actualStripped = decho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "<0,255,0>===<r><160,32,240>[<r><255,0,0> some text <r><160,32,240>]<r><0,255,0>====<r>"
|
||||
options.inside = false
|
||||
actual = dfText(str, options)
|
||||
actualStripped = decho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap decho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = dfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(decho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = dfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(decho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.hfText", function()
|
||||
local hfText = ftext.hfText
|
||||
local str = "some text"
|
||||
local options = {
|
||||
width = 20,
|
||||
spacer = "=",
|
||||
cap = "[",
|
||||
inside = true,
|
||||
mirror = true,
|
||||
capColor = "#a020f0",
|
||||
spacerColor = "#00ff00",
|
||||
textColor = "#ff0000",
|
||||
}
|
||||
it("Should handle hecho colored text", function()
|
||||
local expectedStripped = "[=== some text ====]"
|
||||
local expected = "#a020f0[#r#00ff00===#r#ff0000 some text #r#00ff00====#r#a020f0]#r"
|
||||
local actual = hfText(str, options)
|
||||
local actualStripped = hecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
expectedStripped = "===[ some text ]===="
|
||||
expected = "#00ff00===#r#a020f0[#r#ff0000 some text #r#a020f0]#r#00ff00====#r"
|
||||
options.inside = false
|
||||
actual = hfText(str, options)
|
||||
actualStripped = hecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should wrap hecho lines to the correct length", function()
|
||||
local str = "This is a test of the emergency broadcast system. This is only a test"
|
||||
local options = {width = 10, alignment = "centered"}
|
||||
local actual = hfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(hecho2string(line):len(), 10)
|
||||
end
|
||||
options.width = 15
|
||||
actual = hfText(str, options)
|
||||
for _, line in ipairs(actual:split("\n")) do
|
||||
assert.equals(hecho2string(line):len(), 15)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.TextFormatter", function()
|
||||
local tf = ftext.TextFormatter
|
||||
local str = "some text"
|
||||
local formatter
|
||||
|
||||
before_each(function()
|
||||
formatter = tf:new({width = 20})
|
||||
end)
|
||||
|
||||
it("Should let you change width using :setWidth", function()
|
||||
formatter:setWidth(80)
|
||||
local expected =
|
||||
"<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(80, cecho2string(actual):len())
|
||||
end)
|
||||
|
||||
it("Should format for cecho by default", function()
|
||||
local expected = "<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local expectedStripped = " some text "
|
||||
local actual = formatter:format(str)
|
||||
local actualStripped = cecho2string(actual)
|
||||
assert.equals(expected, actual)
|
||||
assert.equals(expectedStripped, actualStripped)
|
||||
assert.equals(20, actualStripped:len())
|
||||
end)
|
||||
|
||||
it("Should produce the same line as cfText given the same options", function()
|
||||
local expected = ftext.cfText(str, formatter.options)
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should let you change type using :setType", function()
|
||||
formatter:setType("h")
|
||||
local expected = ftext.hfText(str, formatter.options)
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setType("d")
|
||||
expected = ftext.dfText(str, formatter.options)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setType("")
|
||||
expected = ftext.fText(str, formatter.options)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should default to word wrapping, and let you change it with :setWrap", function()
|
||||
formatter:setWidth(10)
|
||||
local expected =
|
||||
"<white><reset><white> <reset><white> some <reset><white> <reset><white><reset>\n<white><reset><white> <reset><white> text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
expected = "<white><reset><white><reset><white> some text <reset><white><reset><white><reset>"
|
||||
formatter:setWrap(false)
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the cap using :setCap", function()
|
||||
formatter:setCap('|')
|
||||
local expected = "<white>|<reset><white> <reset><white> some text <reset><white> <reset><white>|<reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the capColor using :setCapColor", function()
|
||||
formatter:setCapColor('<red>')
|
||||
local expected = "<red><reset><white> <reset><white> some text <reset><white> <reset><red><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the spacer color using :setSpacerColor", function()
|
||||
formatter:setSpacerColor("<red>")
|
||||
local expected = "<white><reset><red> <reset><white> some text <reset><red> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the text color using :setTextColor", function()
|
||||
formatter:setTextColor("<red>")
|
||||
local expected = "<white><reset><white> <reset><red> some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the spacer using :setSpacer", function()
|
||||
formatter:setSpacer("=")
|
||||
-- local expected = "<white><reset><white> <reset><white> some text <reset><white> <reset><white><reset>"
|
||||
local expected = "<white><reset><white>====<reset><white> some text <reset><white>=====<reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to set the alignment using :setAlignment", function()
|
||||
formatter:setAlignment("left")
|
||||
local expected = "<white><reset><white><reset><white>some text <reset><white> <reset><white><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
formatter:setAlignment("right")
|
||||
expected = "<white><reset><white> <reset><white> some text<reset><white><reset><white><reset>"
|
||||
actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the 'inside' option using :setInside", function()
|
||||
formatter:setInside(false)
|
||||
local expected = "<white> <reset><white><reset><white> some text <reset><white><reset><white> <reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("Should allow you to change the mirror option using :setMirror", function()
|
||||
formatter:setCap('<')
|
||||
formatter:setMirror(true)
|
||||
local expected = "<white><<reset><white> <reset><white> some text <reset><white> <reset><white>><reset>"
|
||||
local actual = formatter:format(str)
|
||||
assert.equal(expected, actual)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("ftext.TableMaker", function()
|
||||
local TableMaker = ftext.TableMaker
|
||||
local tm
|
||||
before_each(function()
|
||||
tm = TableMaker:new()
|
||||
tm:addColumn({name = "col1", width = 15, textColor = "<red>"})
|
||||
tm:addColumn({name = "col2", width = 15, textColor = "<blue>"})
|
||||
tm:addColumn({name = "col3", width = 15, textColor = "<green>"})
|
||||
tm:addRow({"some text", "more text", "other text"})
|
||||
tm:addRow({"little text", "bigger text", "text"})
|
||||
end)
|
||||
|
||||
it("Should assemble a formatted table given default options", function()
|
||||
local expected = [[<white>*************************************************<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> col1 <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> col2 <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> col3 <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>*<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> some text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> more text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> other text <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>|<reset><white>---------------<reset><white>*<reset>
|
||||
<white>*<reset><white><reset><white> <reset><red> little text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><blue> bigger text <reset><white> <reset><white><reset><white>|<reset><white><reset><white> <reset><green> text <reset><white> <reset><white><reset><white>*<reset>
|
||||
<white>*************************************************<reset>
|
||||
]]
|
||||
local actual = tm:assemble()
|
||||
assert.equals(expected, actual)
|
||||
end)
|
||||
|
||||
it("TableMaker:getCell should return the text and formatter for a specific cell", function()
|
||||
local expectedText = "more text"
|
||||
local expectedFormatter = tm.columns[2]
|
||||
local actualText, actualFormatter = tm:getCell(1, 2)
|
||||
assert.equals(expectedText, actualText)
|
||||
assert.equals(expectedFormatter, actualFormatter)
|
||||
local expectedFormatted = "<white><reset><white> <reset><blue> more text <reset><white> <reset><white><reset>"
|
||||
local actualFormatted = actualFormatter:format(actualText)
|
||||
assert.equals(expectedFormatted, actualFormatted)
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
@@ -1,207 +1,235 @@
|
||||
bashmatic = bashmatic or nil
|
||||
local ourTables = require("Bashmatic.ftext").TableMaker
|
||||
|
||||
Bashmatic = Bashmatic or {
|
||||
["commands"] = {
|
||||
start = nil,
|
||||
before = nil,
|
||||
during = nil,
|
||||
duringTime = nil,
|
||||
after = nil
|
||||
},
|
||||
["death"] = {
|
||||
phrase = nil,
|
||||
event = nil
|
||||
},
|
||||
["enemies"] = {
|
||||
group = false,
|
||||
targets = {}
|
||||
},
|
||||
["enabled"] = false,
|
||||
["bashing"] = false,
|
||||
["hunting"] = {
|
||||
events = {}
|
||||
}
|
||||
}
|
||||
|
||||
function handleInstall(_, name)
|
||||
if name:lower() == "bashmatic" then
|
||||
if bashmatic == nil then
|
||||
-- it's empty
|
||||
bashmatic = {}
|
||||
bashmatic.commands = {
|
||||
"start" = nil,
|
||||
"before" = nil,
|
||||
"during" = nil,
|
||||
"duringTime" = 2,
|
||||
"after" = nil
|
||||
}
|
||||
bashmatic.death = {
|
||||
"phrase" = nil,
|
||||
"event" = nil
|
||||
}
|
||||
bashmatic.configs = {
|
||||
"enemies" = {
|
||||
"detection" = "inline",
|
||||
"location" = nil,
|
||||
"data" = nil
|
||||
},
|
||||
"areas" = {
|
||||
"detection" = nil,
|
||||
"location" = nil,
|
||||
"data" = nil
|
||||
}
|
||||
}
|
||||
bashmatic.enabled = false
|
||||
bashmatic.bashing = false
|
||||
bashmatic.hunting = {
|
||||
"targets" = {},
|
||||
"events" = {}
|
||||
}
|
||||
else
|
||||
-- it's not empty, verify install
|
||||
local corruptions = 0
|
||||
if not table.contains(bashmatic, "commands") then
|
||||
bashmatic.commands = {
|
||||
"start" = nil,
|
||||
"before" = nil,
|
||||
"during" = nil,
|
||||
"duringTime" = 2,
|
||||
"after" = nil
|
||||
}
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair bashing commands.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if not table.contains(bashmatic, "death") then
|
||||
bashmatic.death = {
|
||||
"phrase" = nil,
|
||||
"event" = nil
|
||||
}
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair death trigger.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if not table.contains(bashmatic, "configs") then
|
||||
bashmatic.configs = {
|
||||
"enemies"{
|
||||
"detection" = "inline",
|
||||
"location" = nil,
|
||||
"data" = nil
|
||||
},
|
||||
"areas" = {
|
||||
"detection" = nil,
|
||||
"location" = nil,
|
||||
"data" = nil
|
||||
}
|
||||
}
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair configuration.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if not table.contains(bashmatic, "enabled") then
|
||||
bashmatic.enabled = false
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair status settings.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if not table.contains(bashmatic, "bashing") then
|
||||
bashmatic.bashing = false
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair status settings.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if not table.contains(bashmatic, "hunting") then
|
||||
bashmatic.hunting = {
|
||||
"targets" = {},
|
||||
"events" = {}
|
||||
}
|
||||
cecho("<firebrick>BASHMATIC: Potentially corrupt install. Tried to repair target listings.<reset>")
|
||||
corruptions += 1
|
||||
end
|
||||
|
||||
if corruptions >= 2 then
|
||||
cecho("<firebrick>BASHMATIC: Multiple corruptions fixed. You should probably uninstall and reinstall Bashmatic.<reset>")
|
||||
end
|
||||
end
|
||||
if name:lower() == "Bashmatic" then
|
||||
cecho("<MediumPurple>Bashmatic: Welcome to Bashmatic. See bm help to get started.")
|
||||
end
|
||||
end
|
||||
registerAnonymousEventHandler("sysInstallPackage", handleInstall)
|
||||
|
||||
function handleShutdown()
|
||||
|
||||
if bashmatic.configs.death.event ~= nil then killTrigger(bashmatic.configs.death.event) end
|
||||
bashmatic.configs.death.event = nil
|
||||
if Bashmatic.death.event ~= nil then killTrigger(Bashmatic.death.event) end
|
||||
killBashingTriggers()
|
||||
bmDisable()
|
||||
toggleBashing(false)
|
||||
Bashmatic.death.event = nil
|
||||
|
||||
table.save(getMudletHomeDir() .. "/bashmatic.lua", bashmatic)
|
||||
table.save(getMudletHomeDir() .. "/Bashmatic.lua", Bashmatic)
|
||||
|
||||
end
|
||||
registerAnonymousEventHandler("sysExitEvent", handleShutdown)
|
||||
|
||||
function handleLoadEvent()
|
||||
|
||||
if io.exists(getMudletHomeDir() .. "/bashmatic.lua") then
|
||||
table.load(getMudletHomeDir() .. "/bashmatic.lua", bashmatic)
|
||||
if io.exists(getMudletHomeDir() .. "/Bashmatic.lua") then
|
||||
table.load(getMudletHomeDir() .. "/Bashmatic.lua", Bashmatic)
|
||||
end
|
||||
|
||||
if bashmatic.configs.death.phrase ~= nil then
|
||||
bashmatic.configs.death.event = tempTrigger(bashmatic.configs.death.phrase,handleMobDeath)
|
||||
if Bashmatic.death.phrase ~= nil then
|
||||
Bashmatic.death.event = tempTrigger(Bashmatic.death.phrase,handleMobDeath)
|
||||
end
|
||||
|
||||
cecho("<DarkSlateBlue>BASHMATIC: Loaded settings. Let's bash some mobs.")
|
||||
cecho("<DarkSlateBlue>Bashmatic: Loaded settings. Let's bash some mobs.")
|
||||
|
||||
end
|
||||
registerAnonymousEventHandler("sysLoadEvent", handleLoadEvent)
|
||||
|
||||
function bmDisable()
|
||||
bashmatic.enabled = false
|
||||
Bashmatic.enabled = false
|
||||
end
|
||||
|
||||
function toggleBashing(status)
|
||||
bashmatic.bashing = status
|
||||
Bashmatic.bashing = status
|
||||
end
|
||||
|
||||
function handleMobDeath()
|
||||
if bashmatic.configs.commands.after then
|
||||
send(bashmatic.configs.commands.after)
|
||||
if Bashmatic.commands.after then
|
||||
send(Bashmatic.commands.after)
|
||||
end
|
||||
toggleBashing(false)
|
||||
if bashmatic.configs.enabled then
|
||||
send("look")
|
||||
if Bashmatic.enabled then
|
||||
if table.size(Bashmatic.hunting.events) > 0 then
|
||||
-- active triggers
|
||||
send("look")
|
||||
else
|
||||
-- recreate triggers and then look
|
||||
recreateTriggers()
|
||||
send("look")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function handleDuringTick()
|
||||
send(bashmatic.configs.commands.during)
|
||||
if bashmatic.configs.bashing then tempTimer(bashmatic.configs.commands.duringTime,handleDuringTick) end
|
||||
send(Bashmatic.commands.during)
|
||||
if Bashmatic.bashing then tempTimer(Bashmatic.commands.duringTime,handleDuringTick) end
|
||||
end
|
||||
|
||||
-- Functions for handling inline matching
|
||||
|
||||
function handleBashingMatches(match)
|
||||
if not bashmatic.configs.enabled then
|
||||
-- bashing is disabled, so clear the triggers
|
||||
for _, tid in ipairs(bashmatic.hunting.events) do
|
||||
killTrigger(tid)
|
||||
end
|
||||
bashmatic.hunting.events = {}
|
||||
if not Bashmatic.enabled or Bashmatic.bashing then
|
||||
-- bashing is disabled or we're currently bashing something, so clear the triggers
|
||||
killBashingTriggers()
|
||||
else
|
||||
if bashmatic.configs.bashing then
|
||||
-- we're currently bashing something, so reup the trigger and wait
|
||||
bmCreateTrigger(match)
|
||||
else
|
||||
if bashmatic.configs.commands.before then send(bashmatic.configs.commands.before) end
|
||||
send(bashmatic.configs.commands.start .. match)
|
||||
if bashmatic.configs.commands.during then tempTimer(bashmatic.configs.commands.duringTime,handleDuringTick) end
|
||||
end
|
||||
if Bashmatic.commands.before then send(Bashmatic.commands.before) end
|
||||
send(Bashmatic.commands.start .. match)
|
||||
if Bashmatic.commands.during then tempTimer(Bashmatic.commands.duringTime,handleDuringTick) end
|
||||
end
|
||||
end
|
||||
|
||||
function bmCreateTrigger(keyword)
|
||||
table.insert(bashmatic.hunting.events, tempTrigger(keyword, handleBashingMatches(keyword), 1))
|
||||
table.insert(Bashmatic.hunting.events, tempTrigger(keyword, handleBashingMatches(keyword), 1))
|
||||
end
|
||||
|
||||
-- Functions for handling GMCP matching
|
||||
|
||||
-- Functions for handling adding targets
|
||||
|
||||
function inlineAddTarget(target, area)
|
||||
if area == nil then
|
||||
cecho("<DarkSlateBlue>BASHMATIC: Added " .. matches[2] .. " to hunting targets.<reset>")
|
||||
if not table.contains(bashmatic.hunting.targets, matches[2]) then
|
||||
table.insert(bashmatic.hunting.targets, matches[2])
|
||||
cecho("<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets.<reset>")
|
||||
if not table.contains(Bashmatic.enemies.targets, target) then
|
||||
table.insert(Bashmatic.enemies.targets, target)
|
||||
end
|
||||
end
|
||||
|
||||
if area ~= nil then
|
||||
cecho("<DarkSlateBlue>BASHMATIC: Added " .. matches[2] .. " to hunting targets in " .. area .. ".<reset>")
|
||||
if table.contains(bashmatic.hunting.targets, area) then
|
||||
table.insert(bashmatic.hunting.targets.area, matches[2])
|
||||
cecho("<DarkSlateBlue>Bashmatic: Added " .. target .. " to hunting targets in " .. area .. ".<reset>")
|
||||
if table.contains(Bashmatic.enemies.targets, area) then
|
||||
table.insert(Bashmatic.enemies.targets.area, target)
|
||||
else
|
||||
bashmatic.hunting.targets.area = {}
|
||||
table.insert(bashmatic.hunting.targets.area, matches[2])
|
||||
Bashmatic.enemies.targets.area = {}
|
||||
table.insert(Bashmatic.enemies.targets.area, target)
|
||||
end
|
||||
end
|
||||
|
||||
if not bashmatic.configs.bashing then
|
||||
if bashmatic.configs.enabled then
|
||||
bmCreateTrigger(matches[2])
|
||||
if not Bashmatic.bashing and Bashmatic.enabled then
|
||||
bmCreateTrigger(target)
|
||||
end
|
||||
end
|
||||
|
||||
function recreateTriggers()
|
||||
if Bashmatic.enemies.group then
|
||||
-- Grouping enemies by areas
|
||||
local thisArea = GetRoomAreaName(GetRoomArea(GetPlayerRoom())) or nil
|
||||
if thisArea == nil then
|
||||
cecho("<firebrick>Bashmatic: We attempted to locate your area but failed.\nGot: " .. thisArea .. "<reset>")
|
||||
return
|
||||
end
|
||||
if not table.contains(Bashmatic.enemies.targets, thisArea) then
|
||||
cecho("<firebrick>Bashmatic: You haven't added any enemies for the area " .. thisArea .. "<reset>")
|
||||
return
|
||||
end
|
||||
for _, keyword in ipairs(Bashmatic.enemies.targets.thisArea) do
|
||||
bmCreateTrigger(keyword)
|
||||
end
|
||||
else
|
||||
-- Not grouping enemies by areas
|
||||
for _, keyword in ipairs(Bashmatic.enemies.targets) do
|
||||
bmCreateTrigger(keyword)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function killBashingTriggers()
|
||||
if table.size(Bashmatic.hunting.events) > 0 then
|
||||
for _, tid in ipairs(Bashmatic.hunting.events) do
|
||||
killTrigger(tid)
|
||||
end
|
||||
end
|
||||
Bashmatic.hunting.events = {}
|
||||
end
|
||||
|
||||
function displayTargetList(start, endi, page, pages)
|
||||
local thisTable = ourTables:new({
|
||||
title = "Bashmatic Target List",
|
||||
printTitle = true,
|
||||
titleColor = "<MediumPurple>",
|
||||
printHeaders = false,
|
||||
separateRows = false
|
||||
})
|
||||
thisTable:addColumn({
|
||||
name = "Index",
|
||||
width = 8,
|
||||
textColor = "<firebrick>"
|
||||
})
|
||||
thisTable:addColumn({
|
||||
name = "Target",
|
||||
width = 72,
|
||||
textColor = "<Slategrey>"
|
||||
})
|
||||
for i=start,i<=endi,1 do
|
||||
thisTable:addRow({
|
||||
i,
|
||||
Bashmatic.enemies.targets[i]
|
||||
})
|
||||
end
|
||||
cecho(thisTable:assemble())
|
||||
if page ~= nil then
|
||||
cecho("<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>")
|
||||
end
|
||||
end
|
||||
|
||||
function displayAreaTargetList(area, start, endi, page, pages)
|
||||
local thisTable = ourTables:new({
|
||||
title = "Bashmatic Target List",
|
||||
printTitle = true,
|
||||
titleColor = "<MediumPurple>",
|
||||
printHeaders = false,
|
||||
separateRows = false
|
||||
})
|
||||
thisTable:addColumn({
|
||||
name = "Index",
|
||||
width = 8,
|
||||
textColor = "<firebrick>"
|
||||
})
|
||||
thisTable:addColumn({
|
||||
name = "Target",
|
||||
width = 72,
|
||||
textColor = "<Slategrey>"
|
||||
})
|
||||
for i=start,i<=endi,1 do
|
||||
thisTable:addRow({
|
||||
i,
|
||||
Bashmatic.enemies.targets.area[i]
|
||||
})
|
||||
end
|
||||
cecho("<MediumPurple>Target Listing for area " .. area .. "<reset>")
|
||||
if page ~= nil then
|
||||
cecho("<DarkSlateBlue>Displaying " .. start .. " to " .. endi .. " (Page " .. page .. " of " .. pages .. ")<reset>")
|
||||
end
|
||||
end
|
||||
|
||||
function squashTargetGroups()
|
||||
local finalTable = {}
|
||||
for _, area in ipairs(Bashmatic.enemies.targets) do
|
||||
if table.size(Bashmatic.enemies.targets.area) > 0 then
|
||||
for _, enemy in ipairs(Bashmatic.enemies.targets.area) do
|
||||
table.insert(finalTable,enemy)
|
||||
end
|
||||
end
|
||||
end
|
||||
Bashmatic.enemies.targets = finalTable
|
||||
end
|
||||
Reference in New Issue
Block a user