Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.92 KB | None | 0 0
  1. -- Introduction to Lua with Mufibot
  2. --
  3. -- Developer mode
  4. --
  5. -- __Dofus/app/config-custom.xml__
  6. -- ```xml
  7. -- <LangFile>
  8. -- <!-- Developer mode -->
  9. -- <entry key="dev.mode">true</entry>
  10. -- <!-- Controler (display FPS, MEM usage and shorcuts to Console, Event and Lua consoles) -->
  11. -- <entry key="dev.auto.display.controler">true</entry>
  12. -- <!-- Event Console -->
  13. -- <entry key="dev.auto.display.eventUtil">false</entry>
  14. -- <!-- Lua Console -->
  15. -- <entry key="dev.auto.display.luaUtil">false</entry>
  16. -- <!-- Console -->
  17. -- <entry key="boo">true</entry>
  18. -- </LangFile>
  19. -- ```
  20. --
  21. -- Console mode
  22. -- /uiinspector
  23. -- UI inspector provides information about the targeted entity such as a player, NPC, a monster, an interactive object (door, zaap, garbage, etc.).
  24. -- Useful to get IDs.
  25. --
  26. -- 1. Mufibot presentation
  27. -- 2. Lua presentation
  28. -- 3. Functional programming
  29. -- 4. Functional primitives
  30. -- 5. Dopples
  31.  
  32. -- Move ├────────────────────────────────────────────────────────────────────────
  33.  
  34. function move()
  35. return { { map = '-1,13', custom = main } }
  36. end
  37.  
  38. -- Main ├────────────────────────────────────────────────────────────────────────
  39.  
  40. function main()
  41.  
  42. if not onMap('-1,13') then
  43. return
  44. end
  45.  
  46. local npc_dopple = function(id, start)
  47. npc.npc(id, 1)
  48. if start then -- ugly
  49. npc_reply(-1)(-2)(-1)
  50. else
  51. npc_reply(-1)(-2)(-1)
  52. end
  53. -- Start fight
  54. leaveDialog()
  55. end
  56.  
  57. local function door(cell)
  58. use(cell, -1)
  59. return door
  60. end
  61.  
  62. local change_map = Function:chain(changeMap)
  63. local npc_reply = Function:chain(npc.reply)
  64.  
  65. -- Sadida
  66. go({-1,9}, (function(map)
  67. local special_map = {
  68. ['-1,11'] = (function() changeMap('right') end),
  69. ['0,11'] = (function() moveToCell(0) end) }
  70. local fn = special_map[currentMap()]
  71. if fn then fn() end
  72. end))
  73. door(342)(274)
  74. npc_dopple(442, 'start')
  75. change_map(408)(397)
  76. change_map(408)(397)
  77.  
  78. -- Cra
  79. go({0,9})({0,3})
  80. door(401)(311)
  81. npc_dopple(439)
  82. change_map(472)(({451,465})[1])
  83.  
  84. -- Iop
  85. go({1,3})
  86. door(356)
  87. change_map(({415,429})[1])
  88. npc_dopple(434)
  89. door(269)
  90. change_map(({410,425})[1])
  91.  
  92. -- Rogue
  93. go({3,3})
  94. door(191)
  95. npc.npc(1422, 1)
  96. npc_reply(-1)
  97. door(159)(338)(311)(323)
  98. npc_dopple(1414)
  99. door(({495,509})[1])
  100. change_map(347)
  101. door(({439,453})[1])(({329,343})[1])
  102. npc.npc(1422, 1)
  103. npc_reply(-2)
  104. door(241)
  105.  
  106. -- Xelor
  107. go({3,1})
  108. door(373)(346)
  109. npc_dopple(437)
  110. change_map(410)(({397,411})[1])
  111.  
  112. -- Eliotrope
  113. go({4,0})
  114. door(274)
  115. change_map('right')('left')
  116. npc_dopple(2834)
  117. change_map('right')('south')
  118. use(498, 213)
  119.  
  120. -- Eniripsa
  121. go({7,1})
  122. door(412)(290)(426)(346)
  123. -- npc_dopple(435)
  124. door(({348,362})[1])(({337,350})[1])(({319,333})[1])
  125. change_map('down')
  126.  
  127. -- Osamodas
  128. go({8,2})
  129. door(261)(242)
  130. -- npc_dopple(436)
  131. door(458)(424)
  132.  
  133. -- Féca
  134. go({12,5})
  135. door(400)(290)
  136. -- npc_dopple(433)
  137. door(451)(424)
  138.  
  139. -- Foggernaut
  140. go({9,1})
  141. door(217)(344)(398)(499)
  142. -- npc_dopple(1594)
  143. door(311)(494)(({452,466})[1])
  144. use(438, 213)
  145.  
  146. -- Pandawa
  147. go({4,-2})
  148. door(381)(317)
  149. -- npc_dopple(672)
  150. door(452)(452)
  151.  
  152. -- Huppermage
  153. go({-4,-2})
  154. door(272)(up)
  155. change_map('right')('up')
  156. door(474)
  157. -- npc_dopple(3053)
  158. change_map('left|down')('down')('left')('left|down')
  159. door(177)
  160.  
  161. -- Sram
  162. go({-4,0})
  163. door(({317,384})[1])(275)
  164. -- npc_dopple(441)
  165. door(416)(({388,442})[1])
  166.  
  167. -- Enutrof
  168. go({-1,-4})
  169. door(415)(311)
  170. -- npc_dopple(440)
  171. door(325)(({456,469})[1])
  172.  
  173. -- Ecaflip
  174. go({1,-5})
  175. door(314)(245)(305)
  176. -- npc_dopple(438)
  177. door(233)(214)(({382,397})[1])
  178.  
  179. -- Masqueraider
  180. go({1,-8})
  181. door(144)(107)(184)(184)(287)(290)
  182. -- npc_dopple(1425)
  183. door(284)(511)(402)(393)(394)(347)
  184.  
  185. -- Sacrier
  186. go({0,-8})({0,-7})({-2,-7})
  187. door(194)(394)
  188. go({-2,-8})
  189. door(286)(285)(243)
  190. -- npc_dopple(443)
  191.  
  192. end
  193.  
  194. -- Utility ├─────────────────────────────────────────────────────────────────────
  195.  
  196. function go(destination, fn)
  197.  
  198. local destination_str = Function:join(destination, ',')
  199.  
  200. local current_map = Function:map(Function:split(currentMap(), ','), tonumber)
  201.  
  202. local x_current, y_current = unpack(current_map)
  203. local x_destination, y_destination = unpack(destination)
  204.  
  205. local direction = function(start, stop) return (start == stop) and 0 or (start < stop) and 1 or -1 end
  206.  
  207. local x_direction = { [-1] = 'left', [0] = nil, [1] = 'right' }
  208. local y_direction = { [-1] = 'top', [0] = nil, [1] = 'bottom' }
  209.  
  210. local map = { map = current_map,
  211. direction = Function:join(Function:compact({ x_direction[direction(x_current, x_destination)],
  212. y_direction[direction(y_current, y_destination)] }), '|') }
  213.  
  214. local saved_current_map_str = currentMap()
  215.  
  216. if fn then fn(map) end
  217.  
  218. if (currentMap() == saved_current_map_str) then
  219. changeMap(map.direction)
  220. end
  221.  
  222. return (currentMap() == destination_str) and go or go(destination, fn)
  223. end
  224.  
  225. -- Library ├─────────────────────────────────────────────────────────────────────
  226.  
  227. -- todo split
  228.  
  229. Function = {
  230. map = function(self, objects, fn)
  231. local collection = {}
  232. for key, object in pairs(objects) do
  233. collection[key] = fn(object)
  234. end
  235. return collection
  236. end,
  237.  
  238. curry = function(self, fn, nargs)
  239. nargs = nargs or debug.getinfo(fn, 'u').nparamsend
  240. local helper = function(args, n)
  241. return n < 1 and fn(unpack(args)) or (function(...) return helper(self:concat(args, {...}), n - #{...}) end)
  242. end
  243. return helper({}, nargs)
  244. end,
  245.  
  246. infinite = (1/0),
  247.  
  248. flatten = function(self, _table, level)
  249. level = level or self.infinite
  250. return self:inject((function(memo, value)
  251. return (level < 1) or (type(value) ~= 'table') and self:push(memo, value) or self:concat(memo, self:flatten(value))
  252. end), {}, _table)
  253. end,
  254.  
  255. insert = function(self, index, _table, object)
  256. local smart_index = (function(index, length) return (index > 0) and index or ((length + 2) + index) end)
  257. local res = self:copy(_table)
  258. local index = smart_index(index, #res)
  259. local entry = res[index]
  260. res[index] = object
  261. return not entry and res or self:insert((index + 1), res, entry)
  262. end,
  263.  
  264. push = function(self, _table, object)
  265. return self:insert(-1, _table, object)
  266. end,
  267.  
  268. reverse = function(self, _table)
  269. local reversed = {}
  270. for key, value in pairs(_table) do
  271. reversed[#_table + 1 - key] = value
  272. end
  273. return reversed
  274. end,
  275.  
  276. join = function(self, _table, separator)
  277. return self:inject((function(memo, value) return memo .. (separator or '') .. value end), self:head(_table), self:tail(_table))
  278. end,
  279.  
  280. split = function(self, str, sep)
  281. res = {}
  282. pattern = string.format("([^%s]+)", sep)
  283. str:gsub(pattern, (function(match) res[#res + 1] = match end))
  284. return res
  285. end,
  286.  
  287. head = function(self, _table)
  288. return _table[1]
  289. end,
  290.  
  291. tail = function(self, _table)
  292. return { select(2, unpack(_table)) }
  293. end,
  294.  
  295. merge = function(self, a, b, fn)
  296. local a_copy, b_copy = self:copy(a), self:copy(b)
  297. local merged = a_copy
  298. for key, value in pairs(b_copy) do
  299. merged[key] = (merged[key] == nil) and value or (fn == nil) and value or fn(key, a_copy[key], b_copy[key])
  300. end
  301. return merged
  302. end,
  303.  
  304. copy = function(self, object)
  305. if type(object) ~= 'table' then
  306. return object
  307. end
  308. local res = {}
  309. for key, value in pairs(object) do
  310. res[self:copy(key)] = self:copy(value)
  311. end
  312. return res
  313. end,
  314.  
  315. inject = function(self, fn, initial, _table)
  316. local memo = self:copy(initial)
  317. for key, value in pairs(_table) do
  318. memo = fn(memo, value)
  319. end
  320. return memo
  321. end,
  322.  
  323. range = function(self, start, stop, step)
  324. local step = (step ~= nil) and step or (start < stop) and 1 or -1
  325. local res = {}
  326. for value = start, stop, step do
  327. res[#res + 1] = value
  328. end
  329. return res
  330. end,
  331.  
  332. concat = function(self, head, ...)
  333. local head = self:copy(head)
  334. for key, tail in pairs({...}) do
  335. for key, value in pairs(tail) do
  336. head[#head + 1] = value
  337. end
  338. end
  339. return head
  340. end,
  341.  
  342. filter = function(self, _table, fn)
  343. local filtered = {}
  344. for key, value in pairs(self:copy(_table)) do
  345. if fn(value) then
  346. filtered[#filtered + 1] = value
  347. end
  348. end
  349. return filtered
  350. end,
  351.  
  352. select = function(self, _table, fn)
  353. return self:head(self:filter(_table, fn))
  354. end,
  355.  
  356. compact = function(self, _table)
  357. return self:filter(_table, (function(value) return (value ~= nil) end))
  358. end,
  359.  
  360. tap = function(self, object, fn)
  361. return fn(object)
  362. end,
  363.  
  364. chain = function(self, fn)
  365. local function helper(...)
  366. fn(...)
  367. return helper
  368. end
  369. return helper
  370. end,
  371. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement