bobber.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. -----------------------------------------------------------------------------------------------
  2. -- Fishing - Mossmanikin's version - Bobber 0.1.7
  3. -- License (code & textures): WTFPL
  4. -- Contains code from: fishing (original), mobs, throwing, volcano
  5. -- Supports: 3d_armor, animal_clownfish, animal_fish_blue_white, animal_rat, flowers_plus, mobs, seaplants
  6. -----------------------------------------------------------------------------------------------
  7. local PoLeWeaR = (65535/(30-(math.random(15, 29))))
  8. local BooTSWear = (2000*(math.random(20, 29)))
  9. -- Here's what you can catch
  10. local CaTCH = {
  11. -- MoD iTeM WeaR MeSSaGe ("You caught "..) GeTBaiTBack NRMiN CHaNCe (../120)
  12. {"fishing", "fish_raw", 0, "a Fish.", false, 1, 100},
  13. -- {"animal_clownfish", "clownfish", 0, "a Clownfish.", false, 61, 10},
  14. -- {"animal_fish_blue_white", "fish_blue_white", 0, "a Blue white fish.", false, 71, 10},
  15. {"default", "stick", 0, "a Twig.", true, 81, 2},
  16. -- {"mobs", "rat", 0, "a Rat.", false, 83, 1},
  17. -- {"animal_rat", "rat", 0, "a Rat.", false, 84, 1},
  18. -- {"", "rat", 0, "a Rat.", false, 85, 1},
  19. -- {"flowers_plus", "seaweed", 0, "some Seaweed.", true, 86, 20},
  20. -- {"seaplants", "kelpgreen", 0, "a Green Kelp.", true, 106, 10},
  21. {"farming", "string", 0, "a String.", true, 116, 2},
  22. {"fishing", "pole", PoLeWeaR, "an old Fishing Pole.", true, 118, 2},
  23. -- {"3d_armor", "boots_wood", BooTSWear, "some very old Boots.", true, 120, 1},
  24. -- {"trunks", "twig_1", 0, "a Twig.", true, 121, 2},
  25. }
  26. minetest.register_alias("flowers_plus:seaweed", "flowers:seaweed") -- exception
  27. local PLaNTS = {
  28. -- MoD* iTeM MeSSaGe ("You caught "..)
  29. {"flowers", "waterlily", "a Waterlily." },
  30. {"flowers", "waterlily_225", "a Waterlily." },
  31. {"flowers", "waterlily_45", "a Waterlily." },
  32. {"flowers", "waterlily_675", "a Waterlily." },
  33. {"flowers", "waterlily_s1", "a Waterlily." },
  34. {"flowers", "waterlily_s2", "a Waterlily." },
  35. {"flowers", "waterlily_s3", "a Waterlily." },
  36. {"flowers", "waterlily_s4", "a Waterlily." },
  37. {"flowers", "seaweed", "some Seaweed."},
  38. {"flowers", "seaweed_2", "some Seaweed."},
  39. {"flowers", "seaweed_3", "some Seaweed."},
  40. {"flowers", "seaweed_4", "some Seaweed."},
  41. {"trunks", "twig_1", "a Twig." },
  42. {"trunks", "twig_2", "a Twig." },
  43. {"trunks", "twig_3", "a Twig." },
  44. {"trunks", "twig_4", "a Twig." },
  45. {"trunks", "twig_5", "a Twig." },
  46. {"trunks", "twig_7", "a Twig." },
  47. {"trunks", "twig_8", "a Twig." },
  48. {"trunks", "twig_9", "a Twig." },
  49. {"trunks", "twig_10", "a Twig." },
  50. {"trunks", "twig_11", "a Twig." },
  51. {"trunks", "twig_12", "a Twig." },
  52. {"trunks", "twig_13", "a Twig." },
  53. }
  54. -- *as used in the node name
  55. local MoBS = { -- not in use
  56. -- iTeM MeSSaGe ("You caught "..)
  57. {"animal_clownfish:clownfish", "a Clownfish." },
  58. {"animal_fish_blue_white:fish_blue_white", "a Blue white fish."},
  59. }
  60. local say = minetest.chat_send_player
  61. minetest.register_node("fishing:bobber_box", {
  62. drawtype = "nodebox",
  63. node_box = {
  64. type = "fixed",
  65. fixed = {
  66. -- { left, bottom, front, right, top , back}
  67. {-8/16, -8/16, 0, 8/16, 8/16, 0}, -- feathers
  68. {-2/16, -8/16, -2/16, 2/16, -4/16, 2/16}, -- bobber
  69. }
  70. },
  71. tiles = {
  72. "fishing_bobber_top.png",
  73. "fishing_bobber_bottom.png",
  74. "fishing_bobber.png",
  75. "fishing_bobber.png",
  76. "fishing_bobber.png",
  77. "fishing_bobber.png^[transformFX"
  78. }, --
  79. groups = {not_in_creative_inventory=1},
  80. })
  81. local FISHING_BOBBER_ENTITY={
  82. hp_max = 605,
  83. water_damage = 1,
  84. physical = true,
  85. timer = 0,
  86. env_damage_timer = 0,
  87. visual = "wielditem",
  88. visual_size = {x=1/3, y=1/3, z=1/3},
  89. textures = {"fishing:bobber_box"},
  90. -- {left ,bottom, front, right, top , back}
  91. collisionbox = {-2/16, -4/16, -2/16, 2/16, 0/16, 2/16},
  92. view_range = 7,
  93. -- DESTROY BOBBER WHEN PUNCHING IT
  94. on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
  95. local player = puncher:get_player_name()
  96. local inv = puncher:get_inventory()
  97. if MESSAGES == true then minetest.chat_send_player(player, "You didn't catch anything.", false) end -- fish escaped
  98. if not minetest.setting_getbool("creative_mode") then
  99. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  100. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  101. if MESSAGES == true then minetest.chat_send_player(player, "The bait is still there.", false) end -- bait still there
  102. end
  103. end
  104. -- make sound and remove bobber
  105. minetest.sound_play("fishing_bobber1", {
  106. pos = self.object:getpos(),
  107. gain = 0.5,
  108. })
  109. self.object:remove()
  110. placed_bobbler[player] = nil
  111. end,
  112. -- WHEN RIGHTCLICKING THE BOBBER THE FOLLOWING HAPPENS (CLICK AT THE RIGHT TIME WHILE HOLDING A FISHING POLE)
  113. on_activate = function(self,staticdata)
  114. if staticdata then
  115. local tmp = minetest.deserialize(staticdata)
  116. if tmp and tmp.owner then
  117. self.owner = tmp.owner
  118. end
  119. end
  120. end,
  121. get_staticdata = function(self)
  122. local tmp = {
  123. owner=self.owner,
  124. }
  125. return minetest.serialize(tmp)
  126. end,
  127. -- AS SOON AS THE BOBBER IS PLACED IT WILL ACT LIKE
  128. on_step = function(self, dtime)
  129. local pos = self.object:getpos()
  130. if math.random(1, 4) == 1 then
  131. self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/2880*math.pi))
  132. end
  133. for _,player in pairs(minetest.get_connected_players()) do
  134. local s = self.object:getpos()
  135. local p = player:getpos()
  136. local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
  137. if dist > self.view_range then
  138. -- make sound and remove bobber
  139. minetest.sound_play("fishing_bobber1", {
  140. pos = self.object:getpos(),
  141. gain = 0.5,
  142. })
  143. self.object:remove()
  144. placed_bobbler[player] = nil
  145. end
  146. end
  147. if self.object:get_hp() > 310 then
  148. local find_fish = minetest.get_objects_inside_radius({x=pos.x,y=pos.y+0.5,z=pos.z}, 1)
  149. for k, obj in pairs(find_fish) do
  150. if obj:get_luaentity() ~= nil then
  151. if obj:get_luaentity().name == "animal_fish_blue_white:fish_blue_white" then
  152. if math.random(1, 30) == 1 then
  153. self.object:set_hp(310)
  154. end
  155. end
  156. end
  157. end
  158. end
  159. local do_env_damage = function(self)
  160. self.object:set_hp(self.object:get_hp()-self.water_damage)
  161. if self.object:get_hp() == 600 then
  162. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  163. elseif self.object:get_hp() == 595 then
  164. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  165. elseif self.object:get_hp() == 590 then
  166. self.object:moveto({x=pos.x,y=pos.y+0.015625,z=pos.z})
  167. elseif self.object:get_hp() == 585 then
  168. self.object:moveto({x=pos.x,y=pos.y-0.015625,z=pos.z})
  169. self.object:set_hp(self.object:get_hp()-(math.random(1, 275)))
  170. elseif self.object:get_hp() == 300 then
  171. minetest.sound_play("fishing_bobber1", {
  172. pos = self.object:getpos(),
  173. gain = 0.5,
  174. })
  175. minetest.add_particlespawner(30, 0.5, -- for how long (?) -- Particles on splash
  176. {x=pos.x,y=pos.y-0.0625,z=pos.z}, {x=pos.x,y=pos.y,z=pos.z}, -- position min, pos max
  177. {x=-2,y=-0.0625,z=-2}, {x=2,y=3,z=2}, -- velocity min, vel max
  178. {x=0,y=-9.8,z=0}, {x=0,y=-9.8,z=0},
  179. 0.3, 1.2,
  180. 0.25, 0.5, -- min size, max size
  181. false, "default_snow.png")
  182. self.object:moveto({x=pos.x,y=pos.y-0.0625,z=pos.z})
  183. elseif self.object:get_hp() == 295 then
  184. self.object:moveto({x=pos.x,y=pos.y+0.0625,z=pos.z})
  185. elseif self.object:get_hp() == 290 then
  186. self.object:moveto({x=pos.x,y=pos.y+0.0625,z=pos.z})
  187. elseif self.object:get_hp() == 285 then
  188. self.object:moveto({x=pos.x,y=pos.y-0.1,z=pos.z})
  189. elseif self.object:get_hp() < 284 then
  190. self.object:moveto({x=pos.x+(0.001*(math.random(-8, 8))),y=pos.y,z=pos.z+(0.001*(math.random(-8, 8)))})
  191. --self.object:setyaw(self.object:getyaw()+((math.random(0,360)-180)/1440*math.pi))
  192. self.object:setyaw(((math.random(0,360)-180)/1440*math.pi))
  193. elseif self.object:get_hp() == 0 then
  194. -- make sound and remove bobber
  195. minetest.sound_play("fishing_bobber1", {
  196. pos = self.object:getpos(),
  197. gain = 0.5,
  198. })
  199. self.object:remove()
  200. placed_bobbler[player] = nil
  201. end
  202. end
  203. do_env_damage(self)
  204. local objects = minetest.get_objects_inside_radius(pos, BOBBER_CHECK_RADIUS)
  205. if #objects==0 then return true end
  206. -- minetest.chat_send_all('#objects > 0 ')
  207. for i,clicker in ipairs(objects) do
  208. if clicker:is_player() then
  209. -- minetest.chat_send_all('clicker is player')
  210. local pll = clicker:get_player_name()
  211. if self.owner == pll then
  212. -- minetest.chat_send_all('self==owner')
  213. local rmb = clicker:get_player_control()['RMB']
  214. local item = clicker:get_wielded_item()
  215. local player = clicker:get_player_name()
  216. if not pused[pll] and rmb and item:get_name() == "fishing:pole" then
  217. pused[pll]=true
  218. local inv = clicker:get_inventory()
  219. local say = minetest.chat_send_player
  220. if self.object:get_hp() <= 300 then
  221. if math.random(1, 100) < FISH_CHANCE then
  222. local chance = math.random(1, 122) -- ><((((�>
  223. for i in pairs(CaTCH) do
  224. local MoD = CaTCH[i][1]
  225. local iTeM = CaTCH[i][2]
  226. local WeaR = CaTCH[i][3]
  227. local MeSSaGe = CaTCH[i][4]
  228. local GeTBaiTBack = CaTCH[i][5]
  229. local NRMiN = CaTCH[i][6]
  230. local CHaNCe = CaTCH[i][7]
  231. local NRMaX = NRMiN + CHaNCe - 1
  232. if chance <= NRMaX and chance >= NRMiN then
  233. if minetest.get_modpath(MoD) ~= nil then
  234. -- remove visible fish, if there
  235. -- add (in)visible fish to inventory
  236. if inv:room_for_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""}) then
  237. inv:add_item("main", {name=MoD..":"..iTeM, count=1, wear=WeaR, metadata=""})
  238. if MESSAGES == true then say(player, "You caught "..MeSSaGe, false) end -- caught somethin'
  239. end
  240. if not minetest.setting_getbool("creative_mode") then
  241. if GeTBaiTBack == true then
  242. if inv:room_for_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""}) then
  243. inv:add_item("main", {name="fishing:bait_worm", count=1, wear=0, metadata=""})
  244. if MESSAGES == true then say(player, "The bait is still there.", false) end -- bait still there?
  245. end
  246. end
  247. end
  248. else
  249. if inv:room_for_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""}) then
  250. inv:add_item("main", {name="fishing:fish_raw", count=1, wear=0, metadata=""})
  251. if MESSAGES == true then say(player, "You caught a Fish.", false) end -- caught Fish
  252. end
  253. end
  254. end
  255. end
  256. else --if math.random(1, 100) > FISH_CHANCE then
  257. if MESSAGES == true then say(player, "Your fish escaped.", false) end -- fish escaped
  258. end
  259. end -- 300
  260. minetest.sound_play("fishing_bobber1", {
  261. pos = self.object:getpos(),
  262. gain = 0.5,
  263. })
  264. minetest.chat_send_player(player, 'bobber\'s dead')
  265. self.object:remove()
  266. placed_bobbler[player] = nil
  267. end
  268. end
  269. end
  270. end
  271. return true
  272. end,
  273. }
  274. minetest.register_entity("fishing:bobber_entity", FISHING_BOBBER_ENTITY)