------------------------ Функции -"much" ------------------------

local items_count=0 
local itemin=nil
local reloc_params={} 
local stalk
 
function item_much(itm,need_namber) 
	local actor=db.actor 
	items_count=0 
	itemin=itm 
	actor:iterate_inventory(cheking_item,actor) 
     if items_count>=need_namber then 
      return true 
     else 
      return false 
     end 
end
     
function cheking_item(actor,item) 
local items=item:section() 
     if items==itemin then 
      items_count=items_count+1 
     end 
end
 
function create_items(npc,section,number) 
    for i=1,number do 
		alife():create(section,     
        npc:position(), 
        npc:level_vertex_id(),      
        npc:game_vertex_id(), 
        npc:id()) 
    end     
end 


function out_item_much(itm_section,need_number) 
    reloc_params.itm_section=itm_section 
    reloc_params.itm_cnt=need_number 
    reloc_params.itm_cnt_found=0 
    db.actor:iterate_inventory(checkout_items_count,db.actor) 
    reloc_params.itm_cnt_found=0 
		if reloc_params.itm_cnt_found<=reloc_params.itm_cnt then 
		db.actor:iterate_inventory(out_items_count,db.actor) 
		end 
     news_manager.relocate_item(db.actor, "out", itm_section) 
     reloc_params={} 
end
 
function checkout_items_count(actor,item) 
    if item.section and item:section()==reloc_params.itm_section then 
     reloc_params.itm_cnt_found = reloc_params.itm_cnt_found + 1 
    end 
end
 
function out_items_count(actor,item) 
    if item.section and item:section()==reloc_params.itm_section and reloc_params.itm_cnt_found<reloc_params.itm_cnt then 
    amk.remove_item_from_inventory(item, actor) 
    reloc_params.itm_cnt_found = reloc_params.itm_cnt_found + 1 
    end 
end


function relocate_n_items_section(victim, section, type, n)
	local kol = 0
    if db.actor and victim then
          if type == "in" then
        for i=1,n do
			alife():create(section,     
			db.actor:position(),
			db.actor:level_vertex_id(),     
			db.actor:game_vertex_id(),
			db.actor:id())
        end
    elseif type == "out" then
      db.actor:iterate_inventory(function (dummy,item)
        if item:section()==section and n>0 then 
          db.actor:transfer_item(item, victim)
          n=n-1
		  kol = kol+1
        end
		end, nil)
          end
          news_manager.relocate_item(db.actor, type, section, kol)
     end
end

 