init.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. lottpotion = {}
  2. dofile(minetest.get_modpath("lottpotion").."/cauldron.lua")
  3. lottpotion = {
  4. players = {},
  5. deaths = {},
  6. effects = {
  7. phys_override = function(sname, name, fname, time, sdata, flags)
  8. local def = {
  9. on_use = function(itemstack, user, pointed_thing)
  10. lottpotion.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags)
  11. itemstack:take_item()
  12. return itemstack
  13. end,
  14. lottpotion = {
  15. speed = 0,
  16. jump = 0,
  17. gravity = 0,
  18. air = 0,
  19. hp = 0,
  20. alive = 1,
  21. },
  22. }
  23. return def
  24. end,
  25. fixhp = function(sname, name, fname, time, sdata, flags)
  26. local def = {
  27. on_use = function(itemstack, user, pointed_thing)
  28. local hp_change = sdata.hp or 3
  29. if flags.inv == true then
  30. hp_change = -hp_change
  31. end
  32. local h = lottpotion.players[user:get_player_name()].hp
  33. lottpotion.players[user:get_player_name()].hp = h + hp_change
  34. minetest.after(sdata.time, function()
  35. if user ~= nil then
  36. h = lottpotion.players[user:get_player_name()].hp
  37. lottpotion.players[user:get_player_name()].hp = h - hp_change
  38. end
  39. end)
  40. itemstack:take_item()
  41. return itemstack
  42. end,
  43. }
  44. def.mobs = {
  45. on_near = def.on_use,
  46. }
  47. return def
  48. end,
  49. air = function(sname, name, fname, time, sdata, flags)
  50. local def = {
  51. on_use = function(itemstack, user, pointed_thing)
  52. local br_change = sdata.br or 3
  53. if flags.inv == true then
  54. br_change = -br_change
  55. end
  56. local b = lottpotion.players[user:get_player_name()].air
  57. lottpotion.players[user:get_player_name()].air = br_change
  58. minetest.after(sdata.time, function()
  59. if user ~= nil then
  60. b = lottpotion.players[user:get_player_name()].air
  61. lottpotion.players[user:get_player_name()].air = b - br_change
  62. end
  63. end)
  64. itemstack:take_item()
  65. return itemstack
  66. end,
  67. }
  68. return def
  69. end,
  70. },
  71. grant = function(time, playername, potion_name, type, flags)
  72. local rootdef = minetest.registered_items[potion_name]
  73. if rootdef == nil then
  74. return
  75. end
  76. if rootdef.lottpotion == nil then
  77. return
  78. end
  79. local def = {}
  80. for name, val in pairs(rootdef.lottpotion) do
  81. def[name] = val
  82. end
  83. if flags.inv==true then
  84. def.gravity = 0 - def.gravity
  85. def.speed = 0 - def.speed
  86. def.jump = 0 - def.jump
  87. end
  88. lottpotion.addPrefs(playername, def.speed, def.jump, def.gravity)
  89. lottpotion.refresh(playername)
  90. local deaths = lottpotion.deaths or 0
  91. minetest.chat_send_player(playername, "You are under the effects of the "..type.." potion.")
  92. minetest.after(time, function()
  93. local new_deaths = lottpotion.deaths or 0
  94. if new_deaths == deaths then
  95. lottpotion.addPrefs(playername, 0-def.speed, 0-def.jump, 0-def.gravity)
  96. lottpotion.refresh(playername)
  97. minetest.chat_send_player(playername, "The effects of the "..type.." potion have worn off.")
  98. end
  99. end)
  100. end,
  101. addPrefs = function(playername, speed, jump, gravity)
  102. local prefs = lottpotion.players[playername]
  103. prefs.speed = prefs.speed + speed
  104. if prefs.speed > 5 then
  105. prefs.speed = 5
  106. elseif prefs.speed < 0 then
  107. prefs.speed = 0
  108. end
  109. prefs.jump = prefs.jump + jump
  110. if prefs.jump > 2.5 then
  111. prefs.jump = 2.5
  112. elseif prefs.jump < 0 then
  113. prefs.jump = 0
  114. end
  115. prefs.gravity = prefs.gravity + gravity
  116. if prefs.gravity > 4 then
  117. prefs.gravity = 4
  118. elseif prefs.gravity < 0 then
  119. prefs.gravity = 0
  120. end
  121. end,
  122. refresh = function(playername)
  123. if minetest.get_player_by_name(playername)~=nil then
  124. local prefs = lottpotion.players[playername]
  125. minetest.get_player_by_name(playername):set_physics_override(prefs.speed, prefs.jump, prefs.gravity)
  126. end
  127. end,
  128. register_potion = function(sname, name, fname, time, def)
  129. local tps = {"power", "corruption"}
  130. for t=1, #tps do
  131. for i=1, #def.types do
  132. local sdata = def.types[i]
  133. local item_def = {
  134. description = name .. "\nStrength: " .. tps[t]:gsub("^%l", string.upper)
  135. .. " " .. sdata.type,
  136. inventory_image = "lottpotion_bottle.png^lottpotion_"..
  137. (def.texture or sname)..".png^lottpotion_"..
  138. tps[t]..sdata.type..".png",
  139. drawtype = "plantlike",
  140. paramtype = "light",
  141. walkable = false,
  142. groups = {dig_immediate=3,attached_node=1,vessel=1},
  143. sounds = default.node_sound_glass_defaults(),
  144. }
  145. item_def.tiles = {item_def.inventory_image}
  146. local flags = {
  147. inv = false,
  148. type = tps[t],
  149. }
  150. if t == 2 then
  151. flags.inv = true
  152. end
  153. for name, val in pairs(lottpotion.effects[def.effect](sname, name, fname, time, sdata, flags)) do
  154. item_def[name] = val
  155. end
  156. for name, val in pairs(sdata.set) do
  157. item_def[name] = val
  158. end
  159. for name, val in pairs(sdata.effects) do
  160. item_def.lottpotion[name] = val
  161. end
  162. minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def)
  163. --potions.register_liquid(i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use)
  164. if minetest.get_modpath("lottthrowing")~=nil then
  165. lottpotion.register_arrow(
  166. fname.."_"..tps[t]..sdata.type,
  167. i..tps[t]..sname,
  168. name.." ("..tps[t].." "..i..")",
  169. item_def.on_use,
  170. item_def.description,
  171. item_def.inventory_image
  172. )
  173. end
  174. end
  175. end
  176. end,
  177. }
  178. dofile(minetest.get_modpath("lottpotion").."/arrows.lua")
  179. local time = 0
  180. minetest.register_globalstep(function(dtime)
  181. time = time + dtime
  182. if time > 1 then
  183. time = 0
  184. for _, player in pairs(minetest.get_connected_players()) do
  185. local name = player:get_player_name()
  186. local hp_change = lottpotion.players[name].hp or 0
  187. if hp_change ~= 0 then
  188. local hp = player:get_hp()
  189. hp = hp + hp_change
  190. hp = math.min(20, hp)
  191. hp = math.max(0, hp)
  192. player:set_hp(hp)
  193. end
  194. local br_change = lottpotion.players[name].air or 0
  195. if br_change ~= 0 then
  196. local br = player:get_breath()
  197. br = br + br_change
  198. br = math.min(20, br)
  199. br = math.max(0, br)
  200. player:set_breath(br)
  201. end
  202. if lottpotion.players[name].alive ~= 1 then
  203. lottpotion.players[name].alive = 1
  204. end
  205. end
  206. end
  207. end)
  208. minetest.register_on_dieplayer(function(player)
  209. local name = player:get_player_name()
  210. lottpotion.players[name] = {
  211. speed = 1,
  212. jump = 1,
  213. gravity = 1,
  214. air = 0,
  215. hp = 0,
  216. alive = 0,
  217. }
  218. lottpotion.refresh(name)
  219. if lottpotion.deaths[name] == nil then
  220. lottpotion.deaths[name] = 1
  221. end
  222. lottpotion.deaths[name] = lottpotion.deaths[name] + 1
  223. end)
  224. lottpotion.register_potion("athelasbrew", "Athelas Brew", "lottpotion:athelasbrew", 100, {
  225. effect = "fixhp",
  226. types = {
  227. {
  228. type = 1,
  229. hp = 1,
  230. time = 20,
  231. set = {},
  232. effects = {
  233. },
  234. },
  235. {
  236. type = 2,
  237. hp = 2,
  238. time = 50,
  239. set = {},
  240. effects = {
  241. },
  242. },
  243. {
  244. type = 3,
  245. hp = 4,
  246. time = 100,
  247. set = {},
  248. effects = {
  249. },
  250. },
  251. }
  252. })
  253. lottpotion.register_potion("limpe", "Limpe", "lottpotion:limpe", 240, {
  254. effect = "air",
  255. types = {
  256. {
  257. type = 1,
  258. br = 2,
  259. hp = 10,
  260. time = 60,
  261. set = {},
  262. effects = {
  263. },
  264. },
  265. {
  266. type = 2,
  267. br = 5,
  268. time = 120,
  269. set = {},
  270. effects = {
  271. },
  272. },
  273. {
  274. type = 3,
  275. br = 10,
  276. time = 240,
  277. set = {},
  278. effects = {
  279. },
  280. },
  281. }
  282. })
  283. lottpotion.register_potion("miruvor", "Miruvor", "lottpotion:miruvor", 240, {
  284. effect = "phys_override",
  285. types = {
  286. {
  287. type = 1,
  288. set = {},
  289. time = 60,
  290. effects = {
  291. jump = 0.3,
  292. },
  293. },
  294. {
  295. type = 2,
  296. set = {},
  297. time = 120,
  298. effects = {
  299. jump = 0.6,
  300. },
  301. },
  302. {
  303. type = 3,
  304. set = {},
  305. time = 240,
  306. effects = {
  307. jump = 1.0,
  308. },
  309. },
  310. }
  311. })
  312. lottpotion.register_potion("spiderpoison", "Spider Poison", "lottpotion:spiderpoison", 20, {
  313. effect = "phys_override",
  314. types = {
  315. {
  316. type = 1,
  317. set = {},
  318. effects = {
  319. speed = -0.2,
  320. jump = -0.2,
  321. },
  322. },
  323. {
  324. type = 2,
  325. set = {},
  326. effects = {
  327. speed = -0.5,
  328. jump = -0.5,
  329. },
  330. },
  331. {
  332. type = 3,
  333. set = {},
  334. effects = {
  335. speed = -1,
  336. jump = -1,
  337. },
  338. },
  339. }
  340. })
  341. lottpotion.register_potion("orcdraught", "Orc Draught", "lottpotion:orcdraught", 100, {
  342. effect = "fixhp",
  343. types = {
  344. {
  345. type = 1,
  346. hp = -1,
  347. time = 20,
  348. set = {},
  349. effects = {
  350. },
  351. },
  352. {
  353. type = 2,
  354. hp = -1,
  355. time = 50,
  356. set = {},
  357. effects = {
  358. },
  359. },
  360. {
  361. type = 3,
  362. hp = -1,
  363. time = 100,
  364. set = {},
  365. effects = {
  366. },
  367. },
  368. }
  369. })
  370. lottpotion.register_potion("entdraught", "Ent Draught", "lottpotion:entdraught", 240, {
  371. effect = "phys_override",
  372. types = {
  373. {
  374. type = 1,
  375. set = {},
  376. effects = {
  377. speed = 1,
  378. jump = -0.2,
  379. },
  380. },
  381. {
  382. type = 2,
  383. set = {},
  384. effects = {
  385. speed = 2,
  386. jump = -0.5,
  387. },
  388. },
  389. {
  390. type = 3,
  391. set = {},
  392. effects = {
  393. speed = 3,
  394. jump = -1,
  395. },
  396. },
  397. }
  398. })
  399. minetest.register_on_joinplayer(function(player)
  400. lottpotion.players[player:get_player_name()] = {
  401. speed = 1,
  402. jump = 1,
  403. gravity = 1,
  404. air = 0,
  405. hp = 0,
  406. alive = 1,
  407. }
  408. end)
  409. minetest.register_on_leaveplayer(function(player)
  410. lottpotion.players[player:get_player_name()] = nil
  411. lottpotion.deaths[player:get_player_name()] = nil
  412. end)
  413. minetest.register_chatcommand("effect", {
  414. params = "none",
  415. description = "get effect info",
  416. func = function(name, param)
  417. minetest.chat_send_player(name, "effects:")
  418. local lottpotion_e = lottpotion.players[name]
  419. if lottpotion_e~=nil then
  420. for potion_name, val in pairs(lottpotion_e) do
  421. if potion_name ~= "alive" then
  422. minetest.chat_send_player(name, potion_name .. "=" .. val)
  423. end
  424. end
  425. end
  426. end,
  427. })
  428. minetest.register_craftitem( "lottpotion:wine", {
  429. description = "Wine",
  430. inventory_image = "lottpotion_wine.png",
  431. wield_image = "lottpotion_wine.png",
  432. on_use = minetest.item_eat(6),
  433. })
  434. minetest.register_craftitem( "lottpotion:beer", {
  435. description = "Beer",
  436. inventory_image = "lottpotion_beer.png",
  437. wield_image = "lottpotion_beer.png",
  438. on_use = minetest.item_eat(6),
  439. })
  440. minetest.register_craftitem( "lottpotion:ale", {
  441. description = "Ale",
  442. inventory_image = "lottpotion_ale.png",
  443. wield_image = "lottpotion_ale.png",
  444. on_use = minetest.item_eat(5),
  445. })
  446. minetest.register_craftitem( "lottpotion:mead", {
  447. description = "Mead",
  448. inventory_image = "lottpotion_mead.png",
  449. wield_image = "lottpotion_mead.png",
  450. on_use = minetest.item_eat(5),
  451. })
  452. minetest.register_craftitem( "lottpotion:cider", {
  453. description = "Cider",
  454. inventory_image = "lottpotion_cider.png",
  455. wield_image = "lottpotion_cider.png",
  456. on_use = minetest.item_eat(4),
  457. })
  458. function lottpotion.can_dig(pos, player)
  459. local meta = minetest.get_meta(pos)
  460. local inv = meta:get_inventory()
  461. if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("fuel") or
  462. not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
  463. minetest.chat_send_player(player:get_player_name(),
  464. "Brewer cannot be removed because it is not empty")
  465. return false
  466. else
  467. return true
  468. end
  469. end
  470. function lottpotion.swap_node(pos, name)
  471. local node = minetest.get_node(pos)
  472. if node.name ~= name then
  473. node.name = name
  474. minetest.swap_node(pos, node)
  475. end
  476. return node.name
  477. end
  478. dofile(minetest.get_modpath("lottpotion").."/potionbrewing.lua")
  479. dofile(minetest.get_modpath("lottpotion").."/brewing.lua")