read_weapon_config.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. local S=minerdream.intllib
  2. local has_value = basic_functions.has_value
  3. local tier_cols={
  4. col_num={"name"},}
  5. local tier_definition = basic_functions.import_csv(minerdream.path.."/tiers.txt",tier_cols)
  6. local tool_cols={
  7. col_num={"bow_wield_scale","tier","bow_velocity","bow_acceleration","arrow_damage"},
  8. groups_num={"is_bowarrow"},
  9. -- as_numeric=1,
  10. }
  11. local tool_definition = basic_functions.import_csv(minerdream.path.."/arrows.txt",tool_cols)
  12. --print(dump2(tool_definition))
  13. local minerdream_arrow = {
  14. physical = false,
  15. timer = 0,
  16. visual = "wielditem",
  17. visual_size = {x=0.5, y=0.5,},
  18. textures = {'minerdream:shotarrow'},
  19. lastpos= {},
  20. collisionbox = {0, 0, 0, 0, 0, 0},
  21. }
  22. for i,tdef in pairs(tool_definition) do
  23. if (i ~= "default") then
  24. if tdef.groups.is_bowarrow then
  25. -- register bow
  26. minetest.register_tool("minerdream:bow_"..i, {
  27. description = "".. core.colorize("#BFFFFF", S(i:gsub("^%l", string.upper)).." bow\n")..core.colorize("#A0A0A0", "projectile speed: "..tdef.bow_velocity.."\n")..core.colorize("#A0A0A0", "projectile gravity: "..tdef.bow_acceleration.."\n")..core.colorize("#A0A0A0", "ranged damage: "..tdef.arrow_damage.."\n")..core.colorize("#A0A0A0", "ammo: arrows"),
  28. inventory_image = "minerdream_bow_"..i..".png",
  29. wield_scale = {x=tdef.bow_wield_scale,y=tdef.bow_wield_scale,z=tdef.bow_wield_scale},
  30. on_use = function(itemstack, user, pointed_thing)
  31. local inv = user:get_inventory()
  32. if not inv:contains_item("main", "minerdream:arrow 1") then
  33. minetest.sound_play("", {object=user})
  34. return itemstack
  35. end
  36. if not minetest.setting_getbool("creative_mode") then
  37. inv:remove_item("main", "minerdream:arrow")
  38. end
  39. local pos = user:getpos()
  40. local dir = user:get_look_dir()
  41. local yaw = user:get_look_yaw()
  42. if pos and dir and yaw then
  43. pos.y = pos.y + 1.6
  44. local obj = minetest.add_entity(pos, "minerdream:copperarrow")
  45. if obj then
  46. minetest.sound_play("", {object=obj})
  47. obj:setvelocity({x=dir.x * tdef.bow_velocity, y=dir.y * tdef.bow_velocity, z=dir.z * tdef.bow_velocity})
  48. obj:setacceleration({x=dir.x * tdef.bow_acceleration, y=tdef.bow_acceleration, z=dir.z * tdef.bow_acceleration})
  49. obj:setyaw(yaw + math.pi)
  50. local ent = obj:get_luaentity()
  51. if ent then
  52. ent.player = ent.player or user
  53. end
  54. end
  55. end
  56. return itemstack
  57. end,
  58. })
  59. -- end register bow
  60. local tarrow=table.copy(minerdream_arrow)
  61. tarrow.on_step = function(self, dtime)
  62. self.timer = self.timer + dtime
  63. local pos = self.object:getpos()
  64. local node = minetest.get_node(pos)
  65. if self.timer > (3.5/tdef.bow_velocity) then
  66. local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
  67. for k, obj in pairs(objs) do
  68. if obj:get_luaentity() ~= nil then
  69. if obj:get_luaentity().name ~= "minerdream:"..i.."arrow" and obj:get_luaentity().name ~= "__builtin:item" then
  70. obj:punch(self.object, 1.0, {
  71. full_punch_interval = 1.0,
  72. damage_groups= {fleshy = tdef.arrow_damage},
  73. }, nil)
  74. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  75. self.object:remove()
  76. end
  77. else
  78. obj:punch(self.object, 1.0, {
  79. full_punch_interval = 1.0,
  80. damage_groups= {fleshy = tdef.arrow_damage},
  81. }, nil)
  82. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  83. self.object:remove()
  84. end
  85. end
  86. end
  87. if self.lastpos.x ~= nil then
  88. if minetest.registered_nodes[node.name].walkable then
  89. if not minetest.setting_getbool("creative_mode") then
  90. minetest.add_item(self.lastpos, "minerdream:arrow")
  91. end
  92. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  93. self.object:remove()
  94. end
  95. end
  96. self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
  97. end
  98. minetest.register_entity("minerdream:"..i.."arrow", tarrow )
  99. else
  100. minetest.register_craftitem("minerdream:"..i:gsub(" ","_"), {
  101. description = "".. core.colorize("#BFFFFF", i.."\n")..core.colorize("#A0A0A0", "throwable speed: "..tdef.bow_velocity.."\n")..core.colorize("#A0A0A0", "throwable gravity: "..tdef.bow_acceleration.."\n")..core.colorize("#A0A0A0", "throwing damage: "..tdef.arrow_damage),
  102. range = 0,
  103. stack_max= 500,
  104. inventory_image = "minerdream_"..i:gsub(" ","_")..".png",
  105. on_use = function(itemstack, user, pointed_thing)
  106. if not minetest.setting_getbool("creative_mode") then itemstack:take_item()
  107. end
  108. if pointed_thing.type ~= "nothing" then
  109. local pointed = minetest.get_pointed_thing_position(pointed_thing)
  110. if vector.distance(user:getpos(), pointed) < tdef.distance then
  111. return itemstack
  112. end
  113. end
  114. local pos = user:getpos()
  115. local dir = user:get_look_dir()
  116. local yaw = user:get_look_yaw()
  117. if pos and dir then
  118. pos.y = pos.y + 1.5
  119. local obj = minetest.add_entity(pos, "minerdream:shuriken")
  120. if obj then
  121. obj:setvelocity({x=dir.x * tdef.bow_velocity, y=dir.y * tdef.bow_velocity, z=dir.z * tdef.bow_velocity})
  122. obj:setacceleration({x=dir.x * tdef.bow_acceleration, y=tdef.bow_acceleration, z=dir.z * tdef.bow_acceleration})
  123. obj:setyaw(yaw + math.pi)
  124. local ent = obj:get_luaentity()
  125. if ent then
  126. ent.player = ent.player or user
  127. end
  128. end
  129. end
  130. return itemstack
  131. end,
  132. })
  133. local tthrow=table.copy(minerdream_arrow)
  134. tthrow.visual="cube"
  135. tthrow.visual_size={x=0.5,y=0.0,}
  136. tthrow.textures = {'minerdream_'..i:gsub(" ","_")..'.png','minerdream_'..i:gsub(" ","_")..'.png','minerdream_'..i:gsub(" ","_")..'.png','minerdream_'..i:gsub(" ","_")..'.png','minerdream_'..i:gsub(" ","_")..'.png','minerdream_'..i:gsub(" ","_")..'.png'}
  137. tthrow.on_step = function(self, dtime)
  138. self.timer = self.timer + dtime
  139. local pos = self.object:getpos()
  140. local node = minetest.get_node(pos)
  141. if self.timer > (3.5/tdef.bow_velocity) then
  142. local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
  143. for k, obj in pairs(objs) do
  144. if obj:get_luaentity() ~= nil then
  145. if obj:get_luaentity().name ~= "minerdream:"..i:gsub(" ","_") and obj:get_luaentity().name ~= "__builtin:item" then
  146. obj:punch(self.object, 1.0, {
  147. full_punch_interval = 1.0,
  148. damage_groups= {fleshy = tdef.arrow_damage},
  149. }, nil)
  150. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  151. self.object:remove()
  152. end
  153. else
  154. obj:punch(self.object, 1.0, {
  155. full_punch_interval = 1.0,
  156. damage_groups= {fleshy = tdef.arrow_damage},
  157. }, nil)
  158. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  159. self.object:remove()
  160. end
  161. end
  162. end
  163. if self.lastpos.x ~= nil then
  164. if minetest.registered_nodes[node.name].walkable then
  165. if not minetest.setting_getbool("creative_mode") then
  166. minetest.add_item(self.lastpos, "minerdream:"..i:gsub(" ","_"))
  167. end
  168. minetest.sound_play("default_dig_cracky", {pos = self.lastpos, gain = 0.8})
  169. self.object:remove()
  170. end
  171. end
  172. self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
  173. end
  174. minetest.register_entity("minerdream:"..i:gsub(" ","_"), tthrow)
  175. end
  176. end
  177. end
  178. minetest.register_craftitem("minerdream:arrow", {
  179. description = "".. core.colorize("#FFFFFF", "arrow\n")..core.colorize("#A0A0A0", "ammunition for bows"),
  180. stack_max= 1000,
  181. inventory_image = "minerdream_arrow_inv.png",
  182. })
  183. minetest.register_craftitem("minerdream:shotarrow", {
  184. inventory_image = "minerdream_arrow.png",
  185. })