1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 17:50:37 +01:00

Fixed mobs' update

This commit is contained in:
LeMagnesium 2015-05-22 19:28:57 +02:00
parent 20db3b7637
commit a7e5bacb65
2 changed files with 36 additions and 37 deletions

View File

@ -92,7 +92,7 @@ function mobs:register_mob(name, def)
self.attack.dist = dist self.attack.dist = dist
end end
end, end,
set_velocity = function(self, v) set_velocity = function(self, v)
if not v then v = 0 end if not v then v = 0 end
if def.drawtype and def.drawtype == "side" then self.rotate = 1.5 end if def.drawtype and def.drawtype == "side" then self.rotate = 1.5 end
@ -101,7 +101,7 @@ function mobs:register_mob(name, def)
local z = math.cos(yaw) * v local z = math.cos(yaw) * v
self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z}) self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z})
end, end,
get_velocity = function(self) get_velocity = function(self)
local v = self.object:getvelocity() local v = self.object:getvelocity()
return (v.x^2 + v.z^2)^(0.5) return (v.x^2 + v.z^2)^(0.5)
@ -116,11 +116,11 @@ function mobs:register_mob(name, def)
local ps = math.sqrt(pos.x^2 + pos.z^2) local ps = math.sqrt(pos.x^2 + pos.z^2)
local d = { x = vx / ds, z = vz / ds } local d = { x = vx / ds, z = vz / ds }
local p = { x = pos.x / ps, z = pos.z / ps } local p = { x = pos.x / ps, z = pos.z / ps }
local an = ( d.x * p.x ) + ( d.z * p.z ) local an = ( d.x * p.x ) + ( d.z * p.z )
a = math.deg( math.acos( an ) ) a = math.deg( math.acos( an ) )
if a > ( self.fov / 2 ) then if a > ( self.fov / 2 ) then
return false return false
else else
@ -161,7 +161,7 @@ function mobs:register_mob(name, def)
end end
end end
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
local yaw = 0 local yaw = 0
@ -229,7 +229,7 @@ function mobs:register_mob(name, def)
self.old_y = self.object:getpos().y self.old_y = self.object:getpos().y
end end
end end
-- knockback timer -- knockback timer
if self.pause_timer > 0 then if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime self.pause_timer = self.pause_timer - dtime
@ -238,7 +238,7 @@ function mobs:register_mob(name, def)
end end
return return
end end
-- attack timer -- attack timer
self.timer = self.timer + dtime self.timer = self.timer + dtime
if self.state ~= "attack" then if self.state ~= "attack" then
@ -251,7 +251,7 @@ function mobs:register_mob(name, def)
if self.sounds.random and math.random(1, 100) <= 1 then if self.sounds.random and math.random(1, 100) <= 1 then
minetest.sound_play(self.sounds.random, {object = self.object}) minetest.sound_play(self.sounds.random, {object = self.object})
end end
local do_env_damage = function(self) local do_env_damage = function(self)
local pos = self.object:getpos() local pos = self.object:getpos()
@ -272,7 +272,7 @@ function mobs:register_mob(name, def)
self.object:set_hp(self.object:get_hp()-self.water_damage) self.object:set_hp(self.object:get_hp()-self.water_damage)
effect(pos, 5, "bubble.png") effect(pos, 5, "bubble.png")
end end
if self.lava_damage and self.lava_damage ~= 0 if self.lava_damage and self.lava_damage ~= 0
and minetest.get_item_group(n.name, "lava") ~= 0 then and minetest.get_item_group(n.name, "lava") ~= 0 then
self.object:set_hp(self.object:get_hp()-self.lava_damage) self.object:set_hp(self.object:get_hp()-self.lava_damage)
@ -281,7 +281,7 @@ function mobs:register_mob(name, def)
check_for_death(self) check_for_death(self)
end end
local do_jump = function(self) local do_jump = function(self)
if self.fly then return end if self.fly then return end
@ -315,7 +315,7 @@ function mobs:register_mob(name, def)
self.jumptimer = 0 self.jumptimer = 0
end end
end end
-- environmental damage timer -- environmental damage timer
self.env_damage_timer = self.env_damage_timer + dtime self.env_damage_timer = self.env_damage_timer + dtime
if self.state == "attack" and self.env_damage_timer > 1 then if self.state == "attack" and self.env_damage_timer > 1 then
@ -324,7 +324,7 @@ function mobs:register_mob(name, def)
elseif self.state ~= "attack" then elseif self.state ~= "attack" then
do_env_damage(self) do_env_damage(self)
end end
-- find someone to attack -- find someone to attack
if self.type == "monster" and damage_enabled and self.state ~= "attack" then if self.type == "monster" and damage_enabled and self.state ~= "attack" then
@ -348,7 +348,7 @@ function mobs:register_mob(name, def)
type = obj.type type = obj.type
end end
end end
if type == "player" or type == "npc" then if type == "player" or type == "npc" then
s = self.object:getpos() s = self.object:getpos()
p = player:getpos() p = player:getpos()
@ -371,7 +371,7 @@ function mobs:register_mob(name, def)
self.do_attack(self, min_player, min_dist) self.do_attack(self, min_player, min_dist)
end end
end end
-- npc, find closest monster to attack -- npc, find closest monster to attack
local min_dist = self.view_range + 1 local min_dist = self.view_range + 1
local min_player = nil local min_player = nil
@ -534,7 +534,7 @@ function mobs:register_mob(name, def)
if self.type == "npc" then if self.type == "npc" then
local o = minetest.get_objects_inside_radius(self.object:getpos(), 3) local o = minetest.get_objects_inside_radius(self.object:getpos(), 3)
local yaw = 0 local yaw = 0
for _,o in ipairs(o) do for _,o in ipairs(o) do
if o:is_player() then if o:is_player() then
@ -550,7 +550,7 @@ function mobs:register_mob(name, def)
if lp.x > s.x then if lp.x > s.x then
yaw = yaw+math.pi yaw = yaw+math.pi
end end
else else
yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi) yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi)
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
@ -583,7 +583,7 @@ function mobs:register_mob(name, def)
local s = self.object:getpos() local s = self.object:getpos()
-- if there is water nearby, try to avoid it -- if there is water nearby, try to avoid it
local lp = minetest.find_node_near(s, 2, {"group:water"}) local lp = minetest.find_node_near(s, 2, {"group:water"})
if lp ~= nil then if lp ~= nil then
local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z} local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z}
yaw = math.atan(vec.z/vec.x) + 3*math.pi / 2 + self.rotate yaw = math.atan(vec.z/vec.x) + 3*math.pi / 2 + self.rotate
@ -610,7 +610,7 @@ function mobs:register_mob(name, def)
end end
-- exploding mobs -- exploding mobs
elseif self.state == "attack" and self.attack_type == "explode" then elseif self.state == "attack" and self.attack_type == "explode" then
if not self.attack.player or not self.attack.player:is_player() then if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand" self.state = "stand"
self:set_animation("stand") self:set_animation("stand")
@ -634,7 +634,7 @@ function mobs:register_mob(name, def)
self:set_animation("walk") self:set_animation("walk")
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x = p.x -s.x, y = p.y -s.y, z = p.z -s.z} local vec = {x = p.x -s.x, y = p.y -s.y, z = p.z -s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2 + self.rotate local yaw = math.atan(vec.z/vec.x)+math.pi/2 + self.rotate
if p.x > s.x then if p.x > s.x then
@ -735,7 +735,7 @@ end
else else
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
if p.x > s.x then if p.x > s.x then
@ -800,7 +800,7 @@ end
else else
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
if p.x > s.x then if p.x > s.x then
@ -808,7 +808,7 @@ end
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
self.set_velocity(self, 0) self.set_velocity(self, 0)
if self.shoot_interval and self.timer > self.shoot_interval and math.random(1, 100) <= 60 then if self.shoot_interval and self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
self.timer = 0 self.timer = 0
@ -959,7 +959,7 @@ end
kb = kb * ( tflp / tool_capabilities.full_punch_interval ) kb = kb * ( tflp / tool_capabilities.full_punch_interval )
r = r * ( tflp / tool_capabilities.full_punch_interval ) r = r * ( tflp / tool_capabilities.full_punch_interval )
end end
if v.y ~= 0 then ykb = 0 end if v.y ~= 0 then ykb = 0 end
self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb}) self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb})
self.pause_timer = r self.pause_timer = r
@ -995,7 +995,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
action = function(pos, node, _, active_object_count_wider) action = function(pos, node, _, active_object_count_wider)
-- do not spawn if too many active in area -- do not spawn if too many active in area
if active_object_count_wider > active_object_count if active_object_count_wider > active_object_count
or not mobs.spawning_mobs[name] or not mobs.spawning_mobs[name]
or not pos then or not pos then
return return
end end
@ -1130,14 +1130,13 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
elseif n.name == "doors:door_wood_t_1" then elseif n.name == "doors:door_wood_t_1" then
minetest.remove_node({x=np.x,y=np.y-1,z=np.z}) minetest.remove_node({x=np.x,y=np.y-1,z=np.z})
end end
if fire > 0 and (minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30) then if fire > 0 and (minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30) then
minetest.set_node(p, {name="fire:basic_flame"}) minetest.set_node(p, {name="fire:basic_flame"})
else else
minetest.remove_node(p) minetest.remove_node(p)
end end
if smoke > 0 then if smoke > 0 then
effect(p, 2, "tnt_smoke.png", 5) effect(p, 2, "tnt_smoke.png", 5)
end
end end
end end
vi = vi + 1 vi = vi + 1

View File

@ -1,9 +1,9 @@
-- Npc by TenPlus1 -- Npc by TenPlus1
mobs.npc_drops = { "farming:meat", "farming:donut", "farming:bread", "default:apple", "default:sapling", "default:junglesapling", mobs.npc_drops = { "farming:meat", "farming:donut", "farming:bread", "default:apple", "default:sapling", "default:junglesapling",
"shields:shield_enhanced_wood", "3d_armor:chestplate_cactus", "3d_armor:boots_bronze", "shields:shield_enhanced_wood", "3d_armor:chestplate_cactus", "3d_armor:boots_bronze",
"default:sword_steel", "default:sword_gold", "default:pick_steel", "default:shovel_steel", "default:sword_steel", "default:sword_gold", "default:pick_steel", "default:shovel_steel",
"default:bronze_ingot", "bucket:bucket_water" } "default:bronze_ingot", "bucket:bucket_water" }
mobs.npc_max_hp = 20 mobs.npc_max_hp = 20
@ -94,6 +94,7 @@ mobs:register_mob("mobs:npc", {
self.diamond_count = (self.diamond_count or 0) + 1 self.diamond_count = (self.diamond_count or 0) + 1
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
item:take_item() item:take_item()
end
-- pick up npc -- pick up npc
elseif item:get_name() == "mobs:magic_lasso" elseif item:get_name() == "mobs:magic_lasso"
and clicker:is_player() and clicker:is_player()
@ -120,7 +121,6 @@ mobs:register_mob("mobs:npc", {
-- if owner switch between follow and stand -- if owner switch between follow and stand
if self.owner and self.owner == clicker:get_player_name() then if self.owner and self.owner == clicker:get_player_name() then
self.damages = 4 self.damages = 4
else
if self.order == "follow" then if self.order == "follow" then
self.order = "stand" self.order = "stand"
else else