-- ********************************************************
--         Подземка Агропрома
-- ********************************************************

function gunslinger_flash(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "gunslinger_flash", "in")
end



-- ********************************************************

function actor_relocate_magnum(gg,npc)	
	dialogs.relocate_item_section(npc,"wpn_eagle_ioga","out")
end

--**********************************************************

function bar_actor_has_money(actor, npc)
	return actor:money() >= 15000
end

function bar_actor_has_money_no(actor, npc)
	return actor:money() < 15000
end

function bar_actor_relocate_money(actor, npc)
	dialogs.relocate_money(npc, 15000, "out")
end

function bar_actor_derelocate_money(npc, actor)
	dialogs.relocate_money(actor, 15000, "in")
end

function relocate_to_actor_buck(npc,gg)	
	dialogs.relocate_item_section(gg,"ammo_12x70_buck","in",5)
end

function start_timer_optika()
    amk.g_start_timer("optika",1,0,0)
end

function tainik_mitjay()
	if db.actor:object("af_cristall") and
		db.actor:object("af_fuzz_kolobok") and
		db.actor:object("af_electra_moonlight") and
		db.actor:object("af_ameba_slime") and
		db.actor:object("af_ameba_mica") and
		db.actor:object("af_6") and
		db.actor:object("af_11") and
		db.actor:object("af_gold_fish") and
		db.actor:object("af_rusty_kristall") and
		db.actor:object("af_cristall_flower") then
		return true
	end
	return false
end

function relocate_item_tainik_mitjay(npc,gg)
	dialogs.relocate_item_section(gg,"af_cristall","out")
	dialogs.relocate_item_section(gg,"af_fuzz_kolobok","out")
	dialogs.relocate_item_section(gg,"af_electra_moonlight","out")
	dialogs.relocate_item_section(gg,"af_ameba_slime","out")
	dialogs.relocate_item_section(gg,"af_ameba_mica","out")
	dialogs.relocate_item_section(gg,"af_6","out")
	dialogs.relocate_item_section(gg,"af_11","out")
	dialogs.relocate_item_section(gg,"af_gold_fish","out")
	dialogs.relocate_item_section(gg,"af_rusty_kristall","out")
	dialogs.relocate_item_section(gg,"af_cristall_flower","out")
end

function relocate_to_actor_nagrada(npc,gg)	
	dialogs.relocate_item_section(gg,"wpn_bizon_kol","in")
end

function relocate_to_actor_optika(npc,gg)	
	dialogs.relocate_item_section(gg,"wpn_addon_scope_elcan","in")
end


function relocate_to_actor(npc,gg)	
	dialogs.relocate_item_section(gg,"instr_sidor","in")
end

function start_timer_sms_varjag()
    amk.g_start_timer("sms_varjag",0,0,20)
end

function sms_varjag(first_speaker,second_speaker) 
	news_manager.send_tip(db.actor, "%c[255,255,128,128]Варяг:\n%c[default] Привет, Кайдан! Надо встретиться! Я буду ждать тебя возле южного блокпоста Бара.", nil, nil, 30000) 
end

function start_timer_varjag_offline()
    amk.g_start_timer("varjag_offline",0,0,10)
end

function varjag_offline()
	local npc = alife():story_object(1709)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end
	
function start_timer_varjag_esc_offline()
    amk.g_start_timer("varjag_esc_offline",0,0,5)
end

function varjag_esc_offline()
	local npc = alife():story_object(1810)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end
	
function start_timer_varjag_gar_offline()
    amk.g_start_timer("varjag_gar_offline",0,0,5)
end

function varjag_gar_offline()
	local npc = alife():story_object(1811)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end	
	
function start_timer_varjag_bar_offline()
    amk.g_start_timer("varjag_bar_offline",0,0,3)
end

function varjag_bar_offline()
	local npc = alife():story_object(1812)
		if npc then
			alife():set_switch_offline (npc.id, true)
			alife():set_switch_online (npc.id, false)
			alife():set_interactive (npc.id, false)
		end
	end

function spawn_mutants_bar_1()
    amk.spawn_item("pseudodog_weak",vector():set(333.291,2.145,-144.274), 73987, 1284, 5)
end

---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------

function give_money_for_howto_join_killers(actor, npc)    
    dialogs.relocate_money(npc, 10000, "out")
end

function has_money_for_howto_join_killers(actor, npc)
    return actor:money() >= 10000
end

function ready_to_ask_killers(actor, npc)
    return not has_alife_info("bar_kill_professor_start")
end

function ready_to_join_killers(actor, npc)
    return has_alife_info("bar_arena_fight_4_done")
end

function not_ready_to_join_killers(actor, npc)
    return not ready_to_join_killers(actor, npc)
end

function give_kill_professor_reward(first_speaker, second_speaker)
    dialogs.relocate_money(second_speaker, 50000, "in")
end

function attach_killers_community(actor, npc)
    if db.actor then
       db.actor:set_character_community ("killer", 0, 0)
    end
end

--Взнос Долгу для прохода на территорию
function has_dolg_deposite(actor, npc)
	return actor:money() >= 1000
end

function give_dolg_deposite(actor, npc)	
	dialogs.relocate_money(npc, 1000, "out")
end

--Бармен в комнате
function give_agroprom_documents(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "quest_case_02", "out")
end

function give_agroprom_reward(first_speaker, second_speaker)
	dialogs.relocate_money(second_speaker, 5000, "in")
end

function give_extra_task(actor, npc)
	if barman_darklab_documents_given(actor,npc) or
	   barman_x16_given(actor,npc) or
	   has_alife_info("bar_deactivate_radar_start")
	then
		return true
	end
	return false
end
function dont_give_extra_task(actor, npc)
	return not give_extra_task(actor, npc)
end

function barman_dont_has_room_job(actor,npc)
	return not barman_has_room_job(actor,npc)
end
function barman_has_room_job(actor,npc)	
	if barman_need_darklab_documents(actor,npc)
	then
		return true
	end
	return false
end

function barman_need_complete_job(actor,npc)
	if barman_darklab_documents_given(actor,npc) and 
	   have_darklab_documents(actor,npc)
	then
		return true
	end
	return false
end

function barman_dont_has_job(actor,npc)
	return not barman_has_job(actor,npc)
end

function barman_has_job(actor,npc)
	if has_alife_info("bar_darklab_document_done") and
	   barman_need_kill_veterans(actor,npc) and has_alife_info("bar_rescue_research_start")
	then
		return true
	end
	return false
end



-- ********************************************************
--			БАРМЕН В КОМНАТЕ
-- ********************************************************
-- Документы с дарклаба
function barman_need_darklab_documents(actor,npc)
	if not has_alife_info("bar_darklab_document_start")
	then
		return true
	end
	return false
end

function barman_darklab_documents_given(actor,npc)
	if has_alife_info("bar_darklab_document_start") and
	   not has_alife_info("bar_darklab_document_done") 
	then
		return true
	end
	return false
end

function have_darklab_documents(first_speaker, second_speaker)
  	return first_speaker:object("dar_document4") ~= nil
end

function hasnt_darklab_documents(first_speaker, second_speaker)
    return first_speaker:object("dar_document4") == nil
end

function give_darklab_documents(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "dar_document4", "out")
end
function give_darklab_reward(first_speaker, second_speaker)
	dialogs.relocate_money(second_speaker, 10000, "in")
end

-- Документы с Янтаря
function barman_x16_given(actor,npc)
	if has_alife_info("bar_x16_documents_start") and
	   not has_alife_info("bar_x16_documents_done")
	then
		return true
	end
	return false
end

-- Документы из янтаря
function have_x16_documents(first_speaker, second_speaker)
  	return first_speaker:object("lab_x16_documents") ~= nil
end
function give_x16_documents(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "lab_x16_documents", "out")
end
function give_x16_reward(first_speaker, second_speaker)
	dialogs.relocate_money(second_speaker, 15000, "in")
end

-- Выдача задания на отключение радара
function barman_need_radar(actor,npc)
	if has_alife_info("bar_deactivate_radar_start")	then
		return true
	end
	return false
end

-- ********************************************************
--			БАРМЕН ЗА ПРИЛАВКОМ
-- ********************************************************
--Долг архивные документы
function have_dolg_arhive_document(first_speaker, second_speaker)
  	return first_speaker:object("dolg_arhive_documents") ~= nil
end

function give_dolg_arhive_document(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "dolg_arhive_documents", "out")
end
-- Флешка ученных с ростка
function actor_have_research(first_speaker, second_speaker)
  	return first_speaker:object("bar_ecolog_flash") ~= nil
end
function actor_transfer_research(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "bar_ecolog_flash", "out")
	if has_alife_info("bar_rescue_research_reward") then
        dialogs.relocate_money(second_speaker, 5000, "in")
    end
end


-- ********************************************************
--			Лидер Долга
-- ********************************************************
--Свобода РГ-6
function have_rg6(first_speaker, second_speaker)
  	return first_speaker:object("wpn_rg-6") ~= nil
end

function dont_have_rg6(first_speaker, second_speaker)
  	return first_speaker:object("wpn_rg-6") == nil or not has_alife_info("mil_svoboda_rg6_gain")
end


function give_rg6(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "wpn_rg-6", "out")
end

function enter_to_dolg(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "dolg_scientific_outfit", "in")
end

--Фамильное ружье охотника
function have_hunters_toz(first_speaker, second_speaker)
  	return first_speaker:object("hunters_toz") ~= nil
end
function give_hunters_toz(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "hunters_toz", "out")
end
function have_hunter_reward(first_speaker, second_speaker)
	dialogs.relocate_money(second_speaker, 4000, "in")
end


-- Оплата информации осведомителю.
function has_money_for_informer_1(actor, npc)
	return actor:money() >= 4000
end

function give_money_for_informer_1(actor, npc)
	dialogs.relocate_money(npc, 4000, "out")
end

function has_money_for_informer_2(actor, npc)
	return actor:money() >= 2000
end

function give_money_for_informer_2(actor, npc)	
	dialogs.relocate_money(npc, 2000, "out")
end

function has_money_for_informer_3(actor, npc)
	return actor:money() >= 3500
end

function give_money_for_informer_3(actor, npc)	
	dialogs.relocate_money(npc, 3500, "out")
end

function barman_give_outfit(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "stalker_outfit", "in")
end


function professor_for_resque(npc, actor)
	dialogs.relocate_item_section(npc, "bar_ecolog_flash", "in")
end


--			ARENA
-- ********************************************************

function arena_give_reward(actor, npc)
	local m = 0
	if has_alife_info("bar_arena_fight_1_reward") then
		m = 1000
	elseif has_alife_info("bar_arena_fight_2_reward") then
		m = 2000
	elseif has_alife_info("bar_arena_fight_3_reward") then
		m = 3000
	elseif has_alife_info("bar_arena_fight_4_reward") then
		m = 4000
	elseif has_alife_info("bar_arena_fight_5_reward") then
		m = 6000
	elseif has_alife_info("bar_arena_fight_6_reward") then
		m = 8000
	elseif has_alife_info("bar_arena_fight_7_reward") then
		m = 10000   
	elseif has_alife_info("bar_arena_fight_8_reward") then
		m = 10000
	end
	dialogs.relocate_money(npc, m, "in")
	db.actor:give_info_portion("bar_arena_reset")	
	xr_zones.purge_arena_items("bar_arena")
end


function actor_has_1000(actor,npc)
	return actor:money() > 1000
end
function give_money_1000(actor, npc)	
	dialogs.relocate_money(npc, 1000, "out")
end
function actor_has_2000(actor,npc)
	return actor:money() > 2000
end
function give_money_2000(actor, npc)	
	dialogs.relocate_money(npc, 2000, "out")
end
function actor_has_3000(actor,npc)
	return actor:money() > 3000
end
function give_money_3000(actor, npc)	
	dialogs.relocate_money(npc, 3000, "out")
end
function actor_has_5000(actor,npc)
	return actor:money() > 5000
end
function give_money_5000(actor, npc)	
	dialogs.relocate_money(npc, 5000, "out")
end

-- new arena

function arena_has_reward ()
	return has_alife_info("bar_arena_fight_1_reward") or has_alife_info("bar_arena_fight_2_reward") or has_alife_info("bar_arena_fight_3_reward") or has_alife_info("bar_arena_fight_4_reward") or has_alife_info("bar_arena_fight_5_reward") or has_alife_info("bar_arena_fight_6_reward") or has_alife_info("bar_arena_fight_7_reward") or has_alife_info("bar_arena_fight_8_reward")
end

function arena_hasnt_reward ()
	return not( has_alife_info("bar_arena_fight_1_reward") or has_alife_info("bar_arena_fight_2_reward") or has_alife_info("bar_arena_fight_3_reward") or has_alife_info("bar_arena_fight_4_reward") or has_alife_info("bar_arena_fight_5_reward") or has_alife_info("bar_arena_fight_6_reward") or has_alife_info("bar_arena_fight_7_reward") or has_alife_info("bar_arena_fight_8_reward"))
end

function arena_rank_check_true ()
	if has_alife_info("bar_arena_fight_6_done") or has_alife_info("bar_arena_fight_3_done") then
		if has_alife_info("bar_arena_fight_3_done") and (db.actor:character_rank() > 300) and not(has_alife_info("bar_arena_fight_6_done")) then
			return true
		end
	elseif has_alife_info("bar_arena_fight_6_done") and (db.actor:character_rank() > 600) then
		return true 	
	else 
		return false
	end
end

function arena_rank_check_false ()
	return not arena_rank_check_true ()
end

-- Отметка интересных мест на карте
function locate_bar_bar(actor,npc)
	local sim = alife()
	if sim == nil then
		return
	end
	local obj = sim:story_object(570)
	if obj then
		level.map_add_object_spot(obj.id, "crlc_small", "bar_bar_locator")
	end
end
function locate_bar_arena(actor,npc)
	local sim = alife()
	if sim == nil then
		return
	end
	local obj = sim:story_object(571)
	if obj then
		level.map_add_object_spot(obj.id, "crlc_small", "bar_arena_locator")
	end
end
function locate_bar_dolg(actor,npc)
	local sim = alife()
	if sim == nil then
		return
	end
	local obj = sim:story_object(507)
	if obj then
		level.map_add_object_spot(obj.id, "green_location", "bar_voronin_name")
	end
end