]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/mob/api/interaction.lua
Overhaul snowman with ElCeejo's remake of 22i's snowman model :D
[Crafter.git] / mods / mob / api / interaction.lua
index dade0f937959bf8e7cd34100371700aa6999372c..a98d8f4f8f522be16626a4d4c048a34c3f0f9f8c 100644 (file)
@@ -54,8 +54,8 @@ mobs.create_interaction_functions = function(def,mob_register)
                                
                                local velocity = vector.multiply(dir,1.1)
                                
-                               vel1 = vector.multiply(velocity, -1)
-                               vel2 = velocity
+                               local vel1 = vector.multiply(velocity, -1)
+                               local vel2 = velocity
                                self.object:add_velocity(vel1)
                                
                                if object:is_player() then
@@ -66,21 +66,22 @@ mobs.create_interaction_functions = function(def,mob_register)
                        end
                end
        end
-       
-       mob_register.fall_damage = function(self)
-               local vel = self.object:get_velocity()
-               if vel and self.oldvel then
-                  if self.oldvel.y < -7 and vel.y == 0 then
-                         local damage = math.abs(self.oldvel.y + 7)
-                         damage = math.floor(damage/1.5)
-                         self.object:punch(self.object, 2, 
-                                {
-                                 full_punch_interval=1.5,
-                                 damage_groups = {damage=damage},
-                                })
-                  end
+       if def.takes_fall_damage == nil or def.takes_fall_damage == true then
+               mob_register.fall_damage = function(self)
+                       local vel = self.object:get_velocity()
+                       if vel and self.oldvel then
+                               if self.oldvel.y < -7 and vel.y == 0 then
+                                       local damage = math.abs(self.oldvel.y + 7)
+                                       damage = math.floor(damage/1.5)
+                                       self.object:punch(self.object, 2, 
+                                               {
+                                               full_punch_interval=1.5,
+                                               damage_groups = {damage=damage},
+                                               })
+                               end
+                       end
+                       self.oldvel = vel
                end
-               self.oldvel = vel
        end
 
        --this controls what happens when the mob gets punched
@@ -106,20 +107,24 @@ mobs.create_interaction_functions = function(def,mob_register)
                end
                
                local hp = hp-hurt
-               
-               if (self.punched_timer <= 0 and hp > 1) then
+
+               if (self.punched_timer <= 0 and hp > 1) and not self.dead then
+                       self.object:set_texture_mod("^[colorize:"..self.damage_color..":130")
+                       self.hurt_color_timer = 0.25
                        if puncher ~= self.object then
-                               self.hostile = true
-                               if self.group_attack == true then
-                                       for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
-                                               if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
-                                                       object:get_luaentity().hostile = true
-                                                       object:get_luaentity().hostile_timer = 20
+                               self.punched_timer = 0.8
+                               if self.attacked_hostile then
+                                       self.hostile = true
+                                       self.hostile_timer = 20
+                                       if self.group_attack == true then
+                                               for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
+                                                       if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
+                                                               object:get_luaentity().hostile = true
+                                                               object:get_luaentity().hostile_timer = 20
+                                                       end
                                                end
                                        end
                                end
-                               self.hostile_timer = 20
-                               self.punched_timer = 0.8
                        end
                        
                        --critical effect
@@ -143,6 +148,23 @@ mobs.create_interaction_functions = function(def,mob_register)
                        self.object:add_velocity(dir)
                        self.add_sword_wear(self, puncher, time_from_last_punch, tool_capabilities, dir)
                elseif (self.punched_timer <= 0 and self.death_animation_timer == 0) then
+                       self.object:set_texture_mod("^[colorize:"..self.damage_color..":130")
+                       self.hurt_color_timer = 0.25
+                       if puncher ~= self.object then
+                               self.punched_timer = 0.8
+                               if self.attacked_hostile then
+                                       self.hostile = true
+                                       self.hostile_timer = 20
+                                       if self.group_attack == true then
+                                               for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
+                                                       if not object:is_player() and object:get_luaentity() and object:get_luaentity().mobname == self.mobname then
+                                                               object:get_luaentity().hostile = true
+                                                               object:get_luaentity().hostile_timer = 20
+                                                       end
+                                               end
+                                       end
+                               end
+                       end
                        self.death_animation_timer = 1
                        self.dead = true
                        
@@ -152,18 +174,13 @@ mobs.create_interaction_functions = function(def,mob_register)
                                minetest.sound_play("critical", {object=self.object, gain = 0.1, max_hear_distance = 10,pitch = math.random(80,100)/100})
                        end
                        minetest.sound_play(self.die_sound, {object=self.object, gain = 1.0, max_hear_distance = 10,pitch = math.random(80,100)/100})
-                       
-                       self.object:set_texture_mod("^[colorize:red:130")
-                       if self.child then
-                       self.child:set_texture_mod("^[colorize:red:130") 
-                       end
                        self.add_sword_wear(self, puncher, time_from_last_punch, tool_capabilities, dir)
                end
        end
 
        --this is what happens when a mob dies
        mob_register.on_death = function(self, killer)
-               local pos = self.object:getpos()
+               local pos = self.object:get_pos()
                --pos.y = pos.y + 0.4
                minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
                minetest.add_particlespawner({
@@ -187,22 +204,23 @@ mobs.create_interaction_functions = function(def,mob_register)
                --only throw items if registered
                if self.item_drop then
                        --detect if multiple items are going to be added
-                       if self.item_amount  and self.item_minumum then
-                               local data_item_amount = math.random(self.item_minimum, self.item_amount)
-                               for i = self.item_minimum,data_item_amount do
-                                       minetest.throw_item(pos,self.item_drop)
+                       if self.item_max then
+                               local data_item_amount = math.random(self.item_minimum, self.item_max)
+                               for i = ,data_item_amount do
+                                       minetest.throw_item(vector.new(pos.x,pos.y+0.1,pos.z),self.item_drop)
                                end
                        else
-                               minetest.throw_item(pos,self.item_drop)
+                               minetest.throw_item(vector.new(pos.x,pos.y+0.1,pos.z),self.item_drop)
                        end
                end
                        
                global_mob_amount = global_mob_amount - 1
                print("Mobs Died. Current Mobs: "..global_mob_amount)
-               if self.child and self.child:get_luaentity() then
-                       self.child:get_luaentity().parent = nil
-               end
                
+               if self.custom_on_death then
+                       self.custom_on_death(self)
+               end
+
                self.object:remove()
        end
        
@@ -228,6 +246,7 @@ mobs.create_interaction_functions = function(def,mob_register)
                --and follow!
                self.following = false
                local player_found = false
+
                for _,object in ipairs(minetest.get_objects_inside_radius(pos, self.view_distance)) do
                        if object:is_player() and player_found == false and object:get_hp() > 0 then
                                --look at player's camera
@@ -240,13 +259,11 @@ mobs.create_interaction_functions = function(def,mob_register)
                                        self.move_head(self,pos2,dtime)
                                end
                                
-                               
+                               --print(self.hostile)
                                if self.hostile == true then
-                                       
-                                       self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
                                        local distance = vector.distance(pos,pos2)
-                                       
-                                       
+                                       self.following_pos = vector.new(pos2.x,pos2.y-1.625,pos2.z)
+
                                        --punch the player
                                        if self.attack_type == "punch" then
                                                if distance < 2.5 and self.punch_timer <= 0 and object:get_hp() > 0 then
@@ -261,11 +278,14 @@ mobs.create_interaction_functions = function(def,mob_register)
                                                        end
                                                end
                                        elseif self.attack_type == "explode" then
-                                               if distance <  self.explosion_radius then
+                                               --mob will not explode if it cannot see you
+                                               if distance <  self.explosion_radius and minetest.line_of_sight(vector.new(pos.x,pos.y+self.object:get_properties().collisionbox[5],pos.z), pos2) then
                                                        
                                                        if not self.tnt_timer then
                                                                minetest.sound_play("tnt_ignite", {object = self.object, gain = 1.0,})
                                                                self.tnt_timer = self.explosion_time
+                                                               self.tnt_tick_timer  = 0.2
+                                                               self.tnt_mod_state = 1
                                                                self.object:set_texture_mod("^[colorize:white:130")
                                                        end
                                                end
@@ -276,18 +296,23 @@ mobs.create_interaction_functions = function(def,mob_register)
                                                if self.projectile_timer <= 0 then
                                                        self.projectile_timer = self.projectile_timer_cooldown
                                                        
-                                                       local obj = minetest.add_entity(pos, self.projectile_type)
+                                                       local obj = minetest.add_entity(vector.new(pos.x,pos.y+self.object:get_properties().collisionbox[5],pos.z), self.projectile_type)
                                                        if obj then
-                                                               local dir = vector.multiply(vector.direction(pos,pos2), 50)
+                                                               local dir = vector.multiply(vector.direction(pos,vector.new(pos2.x,pos2.y-3,pos2.z)), 50)
                                                                obj:set_velocity(dir)
                                                                obj:get_luaentity().timer = 2
+                                                               obj:get_luaentity().owner = self.object
                                                        end
                                                end
                                        end
-                                       --self.speed = distance * 4
-                                       --if self.speed > self.max_speed then
+                                       --smart
+                                       if self.path_data and table.getn(self.path_data) > 0 then
+                                               self.direction = vector.direction(vector.new(pos.x,0,pos.z), vector.new(self.path_data[1].x,0,self.path_data[1].z))
+                                       --dumb
+                                       else
+                                               self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
+                                       end
                                        self.speed = self.max_speed
-                                       --end
                                        self.following = true
                                end
                                --only look at one player
@@ -296,7 +321,12 @@ mobs.create_interaction_functions = function(def,mob_register)
                end
                --stare straight if not found
                if player_found == false then
-                       --self.move_head(self,nil,dtime)
+                       if self.move_head then
+                               self.move_head(self,nil,dtime)
+                       end
+                       if self.following_pos then
+                               self.following_pos = nil
+                       end
                        if self.manage_hostile_timer then
                                self.manage_hostile_timer(self,dtime)
                        end
@@ -304,4 +334,4 @@ mobs.create_interaction_functions = function(def,mob_register)
        end
        
        return(mob_register)
-end
+end
\ No newline at end of file