Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.01 KB | None | 0 0
  1. Agatha = {
  2. lastprompt = "",
  3. currentprompt = "",
  4. Markov = {
  5. dictionary = {},
  6. replyrate = 50,
  7. SYSTEM_VERBS = {
  8. target = "target",
  9. attack = "target",
  10. kill = "target",
  11. get = "get",
  12. take = "get",
  13. grab = "get",
  14. },
  15. UNWANTED_WORDS = { "a", "an", "the", "that", "those", "few", "of", "in", "out", "my" },
  16. },
  17. Mapping = {
  18. map_capture = false,
  19. },
  20. Gradients = {
  21. left = "|c111111-|c222222-|c333333-|c444444-|c555555-|c666666-|c777777-|c888888-|c999999-|caaaaaa-",
  22. right = "|caaaaaa-|c999999-|c888888-|c777777-|c666666-|c555555-|c444444-|c333333-|c222222-|c111111-",
  23. },
  24. Afflictions = {
  25. last_applied = "",
  26. herb_queue = {},
  27. salve_queue = {},
  28. tincture_queue = {},
  29. pipe_queue = {},
  30. last_eaten = "",
  31. last_applied_to = "",
  32. slice_queue = {},
  33. poultice_queue = {},
  34. skill_queue = {},
  35. aff_dict = {},
  36. },
  37. Cure_dict = {
  38. Concoctions = {
  39. Herbs = {
  40. ash = true,
  41. goldenseal = true,
  42. kelp = true,
  43. lobelia = true,
  44. ginseng = true,
  45. bellwort = true,
  46. bloodroot = true,
  47. moss = true,
  48. },
  49. Salves = {
  50. epidermal = true,
  51. mending = true,
  52. caloric = true,
  53. restoration = true,
  54. },
  55. Smoked = {
  56. elm = true,
  57. valerian = true,
  58. },
  59. Elixirs = {
  60. immunity = true,
  61. },
  62. },
  63. Reanimation = {
  64. Slices = {
  65. bladder = true,
  66. liver = true,
  67. eyeball = true,
  68. testis = true,
  69. ovary = true,
  70. castorite = true,
  71. lung = true,
  72. kidney = true,
  73. },
  74. Poultices = {
  75. oculi = true,
  76. orbis = true,
  77. fumeae = true,
  78. jecis = true,
  79. },
  80. Tinctures = {
  81. demulcent = true,
  82. antispasmadic = true,
  83. },
  84. },
  85. Skills = {},
  86. Bodyparts = {
  87. torso = true,
  88. head = true,
  89. ["right leg"] = true,
  90. ["left leg"] = true,
  91. ["right arm"] = true,
  92. ["left arm"] = true,
  93. skin = true,
  94. },
  95. },
  96. Status = {
  97. States = {
  98. blackout = false,
  99. stun = false,
  100. asleep = false,
  101. writhe = false,
  102. },
  103. Balances = {
  104. moss_bal = true,
  105. try_moss = false,
  106. elix_bal = true,
  107. try_elix = false,
  108. herb_bal = true,
  109. try_herb = false,
  110. salve_bal = true,
  111. try_salve = false,
  112. poultice_bal = true,
  113. try_poultice = false,
  114. slice_bal = true,
  115. try_slice = false,
  116. pipe_bal = true,
  117. try_pipe = false,
  118. tincture_bal = true,
  119. try_tincture = false,
  120. balance = true,
  121. equilibrium = true,
  122. try_stand = false,
  123. try_attack = false,
  124. left_arm_bal = false,
  125. right_arm_bal = false,
  126. try_outc_moss = false,
  127. try_outc_lobelia = false,
  128. try_outc_ash = false,
  129. try_outc_bellwort = false,
  130. try_outc_goldenseal = false,
  131. try_outc_kelp = false,
  132. try_outc_bloodroot = false,
  133. try_outc_ginseng = false,
  134. focus_bal = false,
  135. try_focus = false,
  136. },
  137. Vitals = {
  138. p_health = 0,
  139. p_mana = 0,
  140. p_endu = 0,
  141. p_will = 0,
  142. c_xp = 0,
  143. l_xp = 0,
  144. p_xp = 0,
  145. },
  146. },
  147. Data = {
  148. },
  149. Sipper = {
  150. primary = "health",
  151. secondary = "mana",
  152. health_sip = 50,
  153. mana_sip = 50,
  154. health_eat = 70,
  155. mana_eat = 70,
  156. living = {
  157. sip_cmd = "sip",
  158. health = "health",
  159. mana = "mana",
  160. moss = "moss",
  161. },
  162. undead = {
  163. sip_cmd = "stick",
  164. health = "analeptic",
  165. mana = "stimulant",
  166. moss = "kidney slice",
  167. },
  168. },
  169. Settings = {
  170. auto_sip = false,
  171. auto_outc = false,
  172. auto_slice = false,
  173. auto_sip = true,
  174. auto_smoke = true,
  175. auto_bash = true,
  176. auto_salve = true,
  177. auto_stand = false,
  178. auto_poultice = false,
  179. auto_tincture = false,
  180. auto_herb = true,
  181. auto_target_feed = true,
  182. },
  183. }
  184.  
  185. Agatha.Stacks = {}
  186. stack = {}
  187.  
  188. function Load(silent)
  189.  
  190. if not silent then Agatha:Announce("Loading settings.") end
  191. table.load( "system_settings.txt", Agatha )
  192. table.load( "autobasher_settings.txt", Bismuth )
  193. table.load( "skaiabot_settings.txt", Skaiabot )
  194. if not silent then Agatha:Announce("Settings loaded.") end
  195. end
  196.  
  197. function Save(silent)
  198. if not silent then Agatha:Announce("Saving settings.") end
  199. table.save( "system_settings.txt", Agatha )
  200. table.save( "autobasher_settings.txt", Bismuth )
  201. table.save( "skaiabot_settings.txt", Skaiabot )
  202. if not silent then Agatha:Announce("Settings saved.") end
  203. end
  204.  
  205. function Agatha:Error(str)
  206. cecho("<red>\[[AGATHA:] \"Error: " .. str .. "\"]\n")
  207. end
  208.  
  209.  
  210. function Agatha:StripHexCodes(str)
  211. local stripped = rex.gsub(str,"|c([0-9a-fA-F]{6})","")
  212. stripped = string.gsub(stripped,"|","")
  213. return stripped
  214. end
  215.  
  216. function Agatha:Wrap(str,ind)
  217.  
  218. local temp_str = str
  219. local lines = {}
  220.  
  221. while string.len(temp_str)>0 do
  222. i = ind
  223. if string.sub(temp_str,i,i) == "" then
  224. i = 0
  225. table.insert(lines,temp_str)
  226. temp_str = ""
  227. end
  228. while i > 0 do
  229. if string.sub(temp_str,i,i) == " " or string.sub(temp_str,i,i) == "\!" or string.sub(temp_str,i,i) == "\?" or string.sub(temp_str,i,i) == "\"" then
  230. table.insert(lines, string.sub(temp_str,1,i))
  231. temp_str = string.sub(temp_str,i+1)
  232. i = 0
  233. else
  234. i = i-1
  235. end
  236. end
  237. end
  238.  
  239. if string.sub(lines[#lines],string.len(lines[#lines]),string.len(lines[#lines])) ~= "\." and
  240. string.sub(lines[#lines],string.len(lines[#lines]),string.len(lines[#lines])) ~= "\!" and
  241. string.sub(lines[#lines],string.len(lines[#lines]),string.len(lines[#lines])) ~= "\?" then
  242. lines[#lines]=lines[#lines].."\."
  243. end
  244.  
  245. return lines
  246. end
  247.  
  248. function Agatha:Announce(str)
  249. local text = {}
  250. if str then
  251. if Agatha:StripHexCodes(str):len() > 75 then text = Agatha:Wrap(str,75) else text[1] = str end
  252. else
  253. return false
  254. end
  255. if not text[1] then text[1] = "No text to be displayed." end
  256.  
  257. for _,v in pairs(text) do
  258. temp = Agatha:StripHexCodes(v)
  259. pad = math.floor((75-string.len(temp)))
  260. hecho("\n"..self.Gradients.left..string.rep("-",pad).."[ "..v.." |c999999]"..self.Gradients.right)
  261. end
  262. end
  263.  
  264. function Agatha:UpdateVitals(...)
  265.  
  266. if not gmcp then
  267. Agatha:Error("GMPC is not enabled. Please enable it under Settings and restart Mudlet.")
  268. return false
  269. end
  270.  
  271. local args = {...}
  272.  
  273. if args[1] then
  274. if args[1]:find("p") then Agatha.Status.States.prone = true else Agatha.Status.States.prone = false end
  275. end
  276.  
  277.  
  278. if gmcp.Char.Vitals.balance == "1" then self.Status.Balances.balance = true else self.Status.Balances.balance = false end
  279. if gmcp.Char.Vitals.equilibrium == "1" then self.Status.Balances.equilibrium = true else self.Status.Balances.equilibrium = false end
  280. if gmcp.Char.Vitals.left_arm == "1" then self.Status.Balances.left_arm_bal = true else self.Status.Balances.left_arm_bal = false end
  281. if gmcp.Char.Vitals.right_arm == "1" then self.Status.Balances.right_arm_bal = true else self.Status.Balances.right_arm_bal = false end
  282.  
  283. self.Status.Vitals = {
  284. p_health = (gmcp.Char.Vitals.hp/gmcp.Char.Vitals.maxhp)*100,
  285. p_mana = (gmcp.Char.Vitals.mp/gmcp.Char.Vitals.maxmp)*100,
  286. p_endu = (gmcp.Char.Vitals.ep/gmcp.Char.Vitals.maxep)*100,
  287. p_will = (gmcp.Char.Vitals.wp/gmcp.Char.Vitals.maxwp)*100,
  288. l_xp = self.Status.Vitals.c_xp,
  289. c_xp = gmcp.Char.Vitals.xp,
  290. p_xp = (gmcp.Char.Vitals.xp/gmcp.Char.Vitals.maxxp)*100,
  291. t_xp = gmcp.Char.Vitals.maxxp
  292. }
  293. end
  294.  
  295. function Agatha:AutoSipper()
  296.  
  297. local sip_cmd = ""
  298.  
  299. if self.Settings.auto_sip then
  300. if not self.Status.Balances.try_elix and self.Status.Balances.elix_bal then
  301. if self.Status.Vitals["p_" .. self.Sipper.primary] < self.Sipper[ self.Sipper.primary .. "_sip"] then
  302. sip_cmd = self.Sipper[gmcp.Char.Vitals.status].sip_cmd .. " " .. self.Sipper[gmcp.Char.Vitals.status][self.Sipper.primary]
  303. elseif self.Status.Vitals["p_" .. self.Sipper.secondary] < self.Sipper[self.Sipper.secondary .. "_sip"] then
  304. sip_cmd = self.Sipper[gmcp.Char.Vitals.status].sip_cmd .. " " .. self.Sipper[gmcp.Char.Vitals.status][self.Sipper.secondary]
  305. end
  306. end
  307.  
  308. if sip_cmd ~= "" then
  309. send(sip_cmd)
  310. self.Status.Balances.try_elix = true
  311. end
  312.  
  313. if not self.Status.Balances.try_moss and self.Status.Balances.moss_bal then
  314. if self.Status.Vitals.p_health <= self.Sipper.health_eat or self.Status.Vitals.p_mana <= self.Sipper.mana_eat then
  315. send("outc "..self.Sipper[gmcp.Char.Vitals.status].moss)
  316. send("eat "..self.Sipper[gmcp.Char.Vitals.status].moss)
  317. self.Status.Balances.try_moss = true
  318. end
  319. end
  320. end
  321. end
  322.  
  323.  
  324.  
  325.  
  326. function Agatha:AutoBash()
  327. if Agatha.Settings.auto_bash and Bismuth.Attack.cmd and Bismuth.Targets[1] and not Agatha.Status.Balances.try_attack then
  328.  
  329. local attack_now = false
  330. Agatha.Status.Balances.try_attack = true
  331.  
  332. if Bismuth.Attack.needs_equ and Agatha.Status.Balances.equilibrium then
  333. attack_now = true
  334. elseif Bismuth.Attack.needs_bal and Agatha.Status.Balances.balance then
  335. attack_now = true
  336. elseif Bismuth.Attack.needs_armbal and (Agatha.Status.Balances.left_arm_bal or Agatha.Status.Balances.right_arm_bal) then
  337. attack_now = true
  338. end
  339.  
  340. if attack_now then
  341. local atk_output = string.gsub(Bismuth.Attack.cmd, "@TAR", Bismuth.Targets[1])
  342. atk_output = string.gsub(atk_output , "\|", "\;")
  343. send(atk_output)
  344. end
  345. end
  346. end
  347.  
  348. function Agatha:ParseSkills()
  349.  
  350. skills = {}
  351.  
  352. for i,v in pairs(gmcp.Char.Skills.Groups) do
  353. skills[i] = yajl.to_value(gmcp.Char.Skills.Groups[i])
  354. end
  355.  
  356. end
  357.  
  358. function Agatha:CreateInterface()
  359. local mapx = 1300
  360. local mapy = 600
  361.  
  362. createMiniConsole("minimap",1000,800,350,285)
  363. setBackgroundColor("minimap",0,0,0,0);
  364. setMiniConsoleFontSize("minimap", 10)
  365. setWindowWrap("minimap", 90);
  366. setTextFormat("minimap",55,0,0,0,0,255,0,0,0);
  367. moveWindow("minimap", mapx, mapy)
  368. resizeWindow("minimap", 350, 285)
  369.  
  370. end
  371.  
  372. function Agatha:StudyString(str)
  373.  
  374. -- This function takes a string, removes punctuation, shrinks spaces, and
  375. -- breaks the string into a table of individual words, which are then added
  376. -- to Agatha's dictionary.
  377. input = string.lower(str)
  378. input = string.gsub(input, "[\.,!?]", "")
  379. input = string.gsub(input, " ", " ")
  380. input = string.split(input, " ")
  381.  
  382. -- We iterate through the table and use the remember_word function
  383. -- to add each entry to the dictionary, using the preceding word as
  384. -- the parent.
  385. for k,v in pairs(input) do
  386. if k ~= #input then
  387. Agatha:RememberWord(input[k+1],input[k])
  388. end
  389. end
  390.  
  391. Save(true)
  392.  
  393. -- if a random number between 0 and 100 exeeds the replyrate chance, we generate a reply from Agatha.
  394. if math.random(100) <= self.Markov.replyrate then Agatha:GenerateString(input[math.random(#input)], math.random(20)) end
  395.  
  396. end
  397.  
  398. function Agatha:ShowDictionary()
  399. -- displays the contents of the dictionary. This can get pretty huge - several hundred lines or so.
  400. Agatha:Announce("The dictionary currently contains:")
  401. for k,v in pairs(self.Markov.dictionary) do
  402. echo("\n" .. k .. ":\n [")
  403. for i,j in pairs(v) do
  404. echo(j .. ", ")
  405. end
  406. echo("]")
  407. end
  408. end
  409.  
  410. function Agatha:RememberWord(word, parent)
  411.  
  412. -- this function takes a word and a parent and adds them to the dictionary.
  413.  
  414. -- if the dictionary doesn't have an entry for 'parent', we create it.
  415. if self.Markov.dictionary[parent] == nil then
  416. self.Markov.dictionary[parent] = {}
  417. end
  418.  
  419. -- we search the dictionary entry to see if 'word' is already present.
  420. -- if it isn't, we add it.
  421. newword_found = 0
  422. for _,y in pairs(self.Markov.dictionary[parent]) do
  423. if word == y
  424. then newword_found = 1
  425. break
  426. end
  427. end
  428. if newword_found == 0 then table.insert(self.Markov.dictionary[parent],word) end
  429. end
  430.  
  431. function Agatha:GenerateString(seed, len)
  432.  
  433. -- this function takes a seed word and a string length, and generates a semi-random
  434. -- string of 'len' words based on the seed.
  435.  
  436. i = 0
  437. mark_output = seed
  438.  
  439. while i <= len and self.Markov.dictionary[seed] ~= nil do
  440. j = math.random(#self.Markov.dictionary[seed])
  441. seed = self.Markov.dictionary[seed][j]
  442. mark_output = mark_output .. " " .. seed
  443. i = i+1
  444. end
  445.  
  446. -- we add some punctuation to give Agatha a bit of life.
  447. i = math.random(20)
  448. if i < 10 then mark_output = mark_output .. "."
  449. elseif i >= 10 and i < 15 then mark_output = mark_output .. "!"
  450. elseif i >=15 and i <= 20 then mark_output = mark_output .. "?"
  451. end
  452.  
  453. -- capitalize individual letters 'I' and output the string.
  454. mark_output = string.gsub(mark_output, " i ", " I ")
  455. hecho("|cffffffAGATHA |ccccccctells you, \"|cffffff"..string.upper(mark_output:sub(1,1))..mark_output:sub(2).."|ccccccc\"")
  456. end
  457.  
  458. function Agatha:ParseString(str)
  459.  
  460. -- this function is not finished or really used for anything.
  461. -- it parses a string sent to Agatha and attempts to derive a
  462. -- useable Aetolia command from it - ie. 'Agatha, get that pack'
  463. -- would be reduced to 'get pack'.
  464.  
  465. -- Agatha learns from anything said to her via atell, commands included.
  466. Agatha:StudyString(str)
  467.  
  468. temp_str = " " .. str .. " "
  469. temp_str = string.gsub(temp_str, "[\.\,\!\?]", "")
  470.  
  471. for _,v in pairs(self.Markov.UNWANTED_WORDS) do
  472. temp_str = string.gsub(temp_str, " " .. v .. " ", " ")
  473. end
  474.  
  475. words = {}
  476. verbs = {}
  477. nouns = {}
  478.  
  479. for s in string.gmatch(temp_str, "%w+") do
  480. words[#words+1] = s
  481. end
  482.  
  483. -- for all the entries in the 'words' table, we compare them to our list of acceptable verbs
  484. -- and our table of possible targets in the room and our inventory (room and inventory contents
  485. -- are tracked via triggers)
  486. -- for k,v in ipairs(words) do
  487. -- for i, j in pairs(self.Markov.SYSTEM_VERBS) do
  488. -- if v == i then
  489. -- verbs[#verbs+1] = j
  490. -- end
  491. -- end
  492.  
  493. -- for i, j in pairs(environment.room_contents) do
  494. -- if string.find(j.longname, v) ~= nil then
  495. -- nouns[#nouns+1] = j.shortname
  496. -- end
  497. -- end
  498. -- end
  499. end
  500.  
  501. function stack:new()
  502. local obj = {}
  503. setmetatable(obj, self)
  504. self.__index = self
  505. return obj
  506. end
  507.  
  508. function stack:add(str)
  509. self[#self+1] = str
  510. Agatha:Announce("|cffffffAdded to queue: "..self[#self])
  511. end
  512.  
  513. function stack:pop(str)
  514. if self[1] then
  515. local temp = self[1]
  516. table.remove(self,1)
  517. return temp
  518. else
  519. return false
  520. end
  521. end
  522.  
  523. function stackInit()
  524. Agatha.Stacks = {}
  525. for k,v in pairs({"bal","equ","sync"}) do
  526. Agatha.Stacks[v] = stack:new()
  527. end
  528. end
  529.  
  530. Load()
  531. Agatha:CreateInterface()
  532. stackInit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement