local massive = {}

function main_check(obj, amount, local_direction, who, bone_index)
   local section = obj:section()
   local id = obj:id()
   if section=="m_dog_e" or section=="dog_weak" or section=="dog_normal" or section=="dog_strong" then
      if bone_index==29
      or bone_index==30
      or bone_index==31 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"bloodsucker") then
      if bone_index==14
      or bone_index==17
      or bone_index==18
      or bone_index==19
      or bone_index==21
      or bone_index==22
      or bone_index==23
      or bone_index==25
      or bone_index==26
      or bone_index==27
      or bone_index==29
      or bone_index==30
      or bone_index==31 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"pseudodog") or string.find(section,"psy_dog")then
      if bone_index==32
      or bone_index==33 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"flesh") then
      if bone_index==13 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"burer") then
      if bone_index==18
      or bone_index==19
      or bone_index==20
      or bone_index==22
      or bone_index==24
      or bone_index==26
      or bone_index==31
      or bone_index==32
      or bone_index==33
      or bone_index==35
      or bone_index==37
      or bone_index==39 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"snork") then
      if bone_index==1
      or bone_index==2
      or bone_index==3
      or bone_index==4
      or bone_index==6
      or bone_index==7
      or bone_index==8
      or bone_index==9 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"zombie") then
      if bone_index==19
      or bone_index==20
      or bone_index==21
      or bone_index==23
      or bone_index==25
      or bone_index==27
      or bone_index==31
      or bone_index==32
      or bone_index==33
      or bone_index==35
      or bone_index==37
      or bone_index==39 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
   if string.find(section,"boar") then
      if bone_index==3
      or bone_index==4
      or bone_index==8
      or bone_index==9
      or bone_index==34
      or bone_index==35
      or bone_index==39
      or bone_index==40 then
         if massive[id]==nil then
            massive[id] = 1
            return
         end
         massive[id] = massive[id] + 1
      end
   end
end

local table_mobs = {
                    {"bloodsucker",
                    "pseudodog",
                    "psy_dog",
                    "flesh",
                    "burer",         --2
                    "snork",         --2
                    "zombie",        --2
                    "boar"           --4
                    },

                    {"mutant_krovosos_jaw",
                    "mutant_psevdodog_tail",
                    "mutant_psevdodog_tail",
                    "mutant_flesh_eye",
                    "mutant_burer_hand",
                    "mutant_snork_leg",
                    "mutant_zombie_hand",
                    "mutant_boar_leg"
                    }
                    }

function spawn_parts(obj,number)
   local section = obj:section()
   if (section=="m_dog_e" or section=="dog_weak" or section=="dog_normal" or section=="dog_strong") then
      if obj and number==nil then
         amk.spawn_item_in_inv("mutant_dog_tail",obj)
      end
      return
   end
   for a = 1,8 do
      if string.find(section,table_mobs[1][a]) then
         if obj then
            if number==nil then
               amk.spawn_item_in_inv(table_mobs[2][a],obj)
            end
            if a>4 then
               if number==nil or (number and number<3) then
                  amk.spawn_item_in_inv(table_mobs[2][a],obj)
               end
            end

            if a>7 then
               if number==nil or (number and number<5) then
                  amk.spawn_item_in_inv(table_mobs[2][a],obj)
               end
            end
         end
      end
      a = a+1
   end
end

function death_spawn(obj)
   local section = obj:section()
   local id = obj:id()
   local number = massive[id]
   spawn_parts(obj,number)
end