From f5b8e6c04a7aa547e96d686bf7bafe35041a0324 Mon Sep 17 00:00:00 2001 From: Matt Wagner Date: Wed, 29 Sep 2021 11:24:07 -0700 Subject: [PATCH] Adding autoresearch --- src/aliases/autoresearch/aliases.json | 7 + src/scripts/autoresearch/autoresearch.lua | 69 ++++++++++ src/scripts/autoresearch/scripts.json | 5 + .../autoresearch.grabSkills.skillLine.lua | 19 +++ .../autoresearch/autoresearch.practiceEnd.lua | 14 ++ src/triggers/autoresearch/triggers.json | 130 ++++++++++++++++++ 6 files changed, 244 insertions(+) create mode 100644 src/aliases/autoresearch/aliases.json create mode 100644 src/scripts/autoresearch/autoresearch.lua create mode 100644 src/scripts/autoresearch/scripts.json create mode 100644 src/triggers/autoresearch/autoresearch.grabSkills.skillLine.lua create mode 100644 src/triggers/autoresearch/autoresearch.practiceEnd.lua create mode 100644 src/triggers/autoresearch/triggers.json diff --git a/src/aliases/autoresearch/aliases.json b/src/aliases/autoresearch/aliases.json new file mode 100644 index 0000000..9571f8b --- /dev/null +++ b/src/aliases/autoresearch/aliases.json @@ -0,0 +1,7 @@ +[ + { + "name": "autoresearch", + "regex": "^autoresearch( ?.*)$", + "script": "lotj.autoResearch.command(matches[2])" + } +] \ No newline at end of file diff --git a/src/scripts/autoresearch/autoresearch.lua b/src/scripts/autoresearch/autoresearch.lua new file mode 100644 index 0000000..f7520f8 --- /dev/null +++ b/src/scripts/autoresearch/autoresearch.lua @@ -0,0 +1,69 @@ +lotj = lotj or {} +lotj.autoResearch = lotj.autoResearch or {} + +function lotj.autoResearch.log(text, precedingNewline) + if precedingNewline then + echo("\n") + end + cecho("[LOTJ AutoResearch] "..text.."\n") +end + +function lotj.autoResearch.command(args) + argList = splitargs(args) + + if #argList == 1 and argList[1] == "start" then + lotj.autoResearch.enabled = true + lotj.autoResearch.researchList = {} + lotj.autoResearch.log("Research list cleared.") + + enableTrigger("autoresearch.grabSkills") + lotj.autoResearch.log("Retrieving research list...") + send("practice", false) + + elseif #argList == 1 and argList[1] == "next" then + if #(lotj.autoResearch.researchList or {}) == 0 then + lotj.autoResearch.log("Research list empty.") + lotj.autoResearch.enabled = false + return + end + + table.remove(lotj.autoResearch.researchList, 1) + expandAlias("autoresearch continue", false) + + elseif #argList == 1 and argList[1] == "continue" then + if #(lotj.autoResearch.researchList or {}) == 0 then + lotj.autoResearch.log("Research list empty.") + lotj.autoResearch.enabled = false + return + end + + local current = lotj.autoResearch.initialCount - #lotj.autoResearch.researchList + 1 + lotj.autoResearch.log(current.."/"..lotj.autoResearch.initialCount..": Researching "..lotj.autoResearch.researchList[1].."...") + send("research "..lotj.autoResearch.researchList[1], false) + + elseif #argList == 1 and argList[1] == "stop" then + lotj.autoResearch.enabled = false + lotj.autoResearch.researchList = {} + lotj.autoResearch.log("Research list cleared.") + + else + lotj.autoResearch.log("AutoResearch Command List\n") + cecho([[ +autoresearch start + +Get the practice list and automatically begin researching anything eligible for it. Must be in a library. + +autoresearch continue + +Resume researching the first skill in the current autoresearch list. + +autoresearch next + +Skip to the next skill in the autoresearch list and begin researching it. + +autoresearch stop + +Clear the autoresearch list and disable triggers for continuing automatically. +]]) + end +end \ No newline at end of file diff --git a/src/scripts/autoresearch/scripts.json b/src/scripts/autoresearch/scripts.json new file mode 100644 index 0000000..a428c22 --- /dev/null +++ b/src/scripts/autoresearch/scripts.json @@ -0,0 +1,5 @@ +[ + { + "name": "autoresearch" + } +] diff --git a/src/triggers/autoresearch/autoresearch.grabSkills.skillLine.lua b/src/triggers/autoresearch/autoresearch.grabSkills.skillLine.lua new file mode 100644 index 0000000..2258ea2 --- /dev/null +++ b/src/triggers/autoresearch/autoresearch.grabSkills.skillLine.lua @@ -0,0 +1,19 @@ +for str in matches[1]:gmatch("[^%%]+%s*") do + str = str:gsub('^%s*(.-)%s*$', '%1') -- Trim whitespace + local skill, pct = str:match("(.*)%s+([0-9]+)") + if skill then + skill = skill:gsub('^%s*(.-)%s*$', '%1') -- Trim whitespace + pct = tonumber(pct) + + if pct < 90 then + if skill == "research" then + -- Always do research first if it's in the list + table.insert(lotj.autoResearch.researchList, 1, skill) + else + table.insert(lotj.autoResearch.researchList, skill) + end + end + end +end + +setTriggerStayOpen("autoresearch.grabSkills", 1) \ No newline at end of file diff --git a/src/triggers/autoresearch/autoresearch.practiceEnd.lua b/src/triggers/autoresearch/autoresearch.practiceEnd.lua new file mode 100644 index 0000000..1a68cea --- /dev/null +++ b/src/triggers/autoresearch/autoresearch.practiceEnd.lua @@ -0,0 +1,14 @@ +if lotj.autoResearch.startOnPracticeEnd then + lotj.autoResearch.startOnPracticeEnd = false + echo("\n") + lotj.autoResearch.initialCount = #(lotj.autoResearch.researchList or {}) + if lotj.autoResearch.initialCount == 0 then + lotj.autoResearch.enabled = false + lotj.autoResearch.log("Nothing to research.") + return + end + lotj.autoResearch.log("Don't forget to 'bot start' if you won't be monitoring your screen as this runs.") + expandAlias("autoresearch continue", false) +else + lotj.autoResearch.log("Type 'autoresearch start' to start researching all skills below 90%.", true) +end \ No newline at end of file diff --git a/src/triggers/autoresearch/triggers.json b/src/triggers/autoresearch/triggers.json new file mode 100644 index 0000000..2dc72ae --- /dev/null +++ b/src/triggers/autoresearch/triggers.json @@ -0,0 +1,130 @@ +[ + { + "name": "autoresearch.grabSkills", + "isActive": "no", + "fireLength": 1, + "patterns": [ + { + "pattern": "^-+Skills -+$", + "type": "regex" + } + ], + "children": [ + { + "name": "autoresearch.grabSkills.skillLine", + "patterns": [ + { + "pattern": "^\\s*[^%]+ +[0-9]+%.*$", + "type": "regex" + } + ] + }, + { + "name": "autoresearch.grabSkills.weaponsLine", + "patterns": [ + { + "pattern": "^-+Weapons-+$", + "type": "regex" + } + ], + "script": "setTriggerStayOpen(\"autoresearch.grabSkills\", 1)" + }, + { + "name": "autoresearch.grabSkills.featsLine", + "patterns": [ + { + "pattern": "^-+ Feats -+$", + "type": "regex" + } + ], + "script": "lotj.autoResearch.startOnPracticeEnd = true; disableTrigger(\"autoresearch.grabSkills\")" + } + ] + }, + { + "name": "autoresearch.next", + "patterns": [ + { + "pattern": "^You search and search but can't find that information.$", + "type": "regex" + }, + { + "pattern": "^You can't learn about that in books. Go find a teacher.$", + "type": "regex" + }, + { + "pattern": "^You can't learn any more about that from books!$", + "type": "regex" + }, + { + "pattern": "^You can't learn smuggling skills from a book!$", + "type": "regex" + }, + { + "pattern": "^You aren't going to learn that from a book. Go find a Wookiee!$", + "type": "regex" + }, + { + "pattern": "^You can't learn bounty hunting skills from a book!$", + "type": "regex" + }, + { + "pattern": "^Go learn it the hard way, sissy.$", + "type": "regex" + }, + { + "pattern": "^You're not going to learn force spells from a book. Trust me.$", + "type": "regex" + }, + { + "pattern": "^You cannot learn more about that from books.$", + "type": "regex" + } + ], + "script": "if lotj.autoResearch.enabled then echo(\"\\n\"); expandAlias(\"autoresearch next\", false) end" + }, + { + "name": "autoresearch.continue", + "patterns": [ + { + "pattern": "^You finish your studies and feel much more skilled.$", + "type": "regex" + }, + { + "pattern": "^You study for hours on end, but fail to gather any knowledge.$", + "type": "regex" + } + ], + "script": "if lotj.autoResearch.enabled then echo(\"\\n\"); expandAlias(\"autoresearch continue\", false) end" + }, + { + "name": "autoresearch.interrupted", + "patterns": [ + { + "pattern": "^You are interrupted and fail to finish your studies...$", + "type": "regex" + } + ], + "script": "if lotj.autoResearch.enabled then lotj.autoResearch.log(\"Type 'autoresearch continue' to pick up where you left off.\", true) end" + }, + { + "name": "autoresearch.practiceEnd", + "patterns": [ + { + "pattern": "^To see a shorter practice list, type PRACTICE .$", + "type": "regex" + } + ] + } +] + + + + + + + + + + +