--------------------------------------------------------------------------------------------------------
-- Dialog & InfoPortions Function
-------------------------------------------------------------------------------------------------------

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

---------------------------
-- Trader
--------------------------------------------------------------------------------------------------------
function sayga_have()
	if db.actor:object("sayga_varjaga") then
		return true
	end
	return false
end

function sayga_no_have()
	if db.actor:object("sayga_varjaga") then
		return false
	end
	return true
end

function relocate_sayga(gg, npc)
    dialogs.relocate_item_section(npc, "sayga_varjaga", "out")
end

function kostum_have()
	if db.actor:object("ecolog_outfit_super") then
		return true
	end
	return false
end

function kostum_relocate(npc, gg)
    dialogs.relocate_item_section(gg, "ecolog_outfit_super", "in")
end

function kostum_relocate_2(npc, gg)
    dialogs.relocate_item_section(gg, "ecolog_outfit_super", "out")
end

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

function registrator_have()
	if db.actor:object("mil_scanner_2") then
		return true
	end
	return false
end


function vss_tk1_have()
	if db.actor:object("wpn_vss_tk1") then
		return true
	end
	return false
end

function dengi_vss_tk1_relocate(gg, npc)
	dialogs.relocate_item_section(npc, "wpn_vss_tk1", "out")
	dialogs.relocate_money(gg, 100000, "in")
end

function relocate_to_trader(gg, npc)
    dialogs.relocate_item_section(npc, "instr_sidor", "out")
end

function canner_relocate(gg, npc)
    dialogs.relocate_item_section(npc, "mil_scanner", "out")
end

function doki_relocate(gg, npc)
    dialogs.relocate_item_section(npc, "doc_mil_scanner", "out")
end

function box_have()
	if db.actor:object("mil_scanner") then
		return true
	end
	return false
end

function doki_have()
	if db.actor:object("doc_mil_scanner") then
		return true
	end
	return false
end

function dengi_relocate(npc, gg)
	dialogs.relocate_money(gg, 20000, "in")
end

function start_timer_sms_sidor()
    amk.g_start_timer("sms_sidor",0,0,5)
end

function sms_sidor(first_speaker,second_speaker) 
	news_manager.send_tip(db.actor, "%c[255,255,128,128]Сидорович:\n%c[default] Кайдан, как я понимаю, ты обзавёлся хорошей одёжкой. Я сбросил тебе на ПДА инструкцию и нужные координаты!", nil, nil, 30000)
	db.actor:give_info_portion("sidor_arts")
	alife():create("af_phantom",vector():set(193.643,3.321,277.755),502527, 4375)
	alife():create("af_bat",vector():set(196.667,4.954,275.628),505724,4375) 
	alife():create("af_pero",vector():set(191.231,4.912,278.893),499358,4375)
end

function arts_have()
	if 	db.actor:object("af_phantom") and
		db.actor:object("af_bat") and
		db.actor:object("af_pero") then
		return true
	end
	return false
end

function relocate_arts_sidor(npc,gg)
	dialogs.relocate_item_section(gg,"af_phantom","out")
	dialogs.relocate_item_section(gg,"af_bat","out")
	dialogs.relocate_item_section(gg,"af_pero","out")
end

function trader_alredy_give_job(trader, actor)
	if (has_alife_info("agroprom_military_case") and not has_alife_info("agroprom_military_case_done")) or
	   (has_alife_info("escape_blockpost_case") and not has_alife_info("escape_blockpost_case_done")) or
	   (has_alife_info("tutorial_artefact_start") and not has_alife_info("tutorial_artefact_done")) or
	   (has_alife_info("tutorial_wounded_start") and not has_alife_info("esc_serious_talk"))
	then
		return true
	end
	return false 
end

function trader_give_extra_job(trader, actor)
	local actor = db.actor
	if has_alife_info("escape_blockpost_case") and not has_alife_info("escape_blockpost_case_done")
	then
		return true
	end
	return false
end

function bandits_die(actor,npc)
	local actor = db.actor
	if has_alife_info("esc_kill_bandits_quest_kill") and not has_alife_info("esc_kill_bandits_noquest_kill")
	then
		return true
	end
	return false
end

function trader_need_extra_job(trader, actor)
	if not has_alife_info("escape_blockpost_case") and 
	    has_alife_info("esc_return")
	then
		return true
	end
	return false
end

function is_tutorial()
	return not has_alife_info("tutorial_end")
end

function is_not_tutorial()
	return has_alife_info("tutorial_end")
end

function is_not_tutorial_art(actor, trader)
	local tutorial_artefact = db.actor:object("af_blood_tutorial")
	if (has_alife_info("tutorial_artefact_start") and not has_alife_info("tutorial_artefact_done")
		and  tutorial_artefact ~= nil) or has_alife_info("tutorial_artefact_done")
	then
		return true
	end
	return false
end

function not_final_job(trader, actor)
	local actor = db.actor
	return not has_alife_info("escape_blockpost_case_done")
end

function trader_test(actor, npc)
 	printf ("!!!!!")	
	return true
end



function trader_dont_give_job(first_speaker, second_speaker)
	return not trader_alredy_give_job(first_speaker, second_speaker)
end

function finalize_quests(first_speaker, second_speaker)
	if tutorial_artefact_end(first_speaker, second_speaker) == true or
	   tutorial_wounded_end(first_speaker, second_speaker) == true
	then
		return true
	end
	return false
end

function not_finalize_quests(first_speaker, second_speaker)
	return not this.finalize_quests(first_speaker, second_speaker)	
end

function tutorial_artefact_end(first_speaker, second_speaker)
	local actor = db.actor
	local tutorial_artefact = first_speaker:object("af_blood_tutorial")
	if has_alife_info("tutorial_artefact_start") and 
	   not has_alife_info("tutorial_artefact_done") and
	   tutorial_artefact ~= nil
	then
		return true
	end
	return false
end

function tutorial_artefact_have_not(first_speaker, second_speaker)
	local actor = db.actor
	local tutorial_artefact = first_speaker:object("af_blood_tutorial")
	if has_alife_info("tutorial_artefact_start") and 
	   not has_alife_info("tutorial_artefact_done") and
	   tutorial_artefact == nil
	then
		return true
	end
	return false
end

function tutorial_wounded_end(first_speaker, second_speaker)
	local actor = db.actor
	-- local wounded_flash = first_speaker:object("esc_wounded_flash")
	if has_alife_info("tutorial_wounded_start")	and 
		has_alife_info("tutorial_wounded_give_info")	and 	
	   not has_alife_info("esc_serious_talk")
 -- and   wounded_flash ~= nil
	then
		return true
	end
	return false
end

function trader_dont_has_job(first_speaker, second_speaker)
    if trader_need_military_case(first_speaker, second_speaker) == false and
	   trader_need_blockpost_box(first_speaker, second_speaker) == false
	then
		return true
	end
	return false
end


--' Escape tutorial artefact
function have_tutorial_artefact(first_speaker, second_speaker)
  	return first_speaker:object("af_blood_tutorial") ~= nil
end
function give_medkit(first_speaker, second_speaker)
	dialogs.relocate_item_section(first_speaker, "medkit", "in")
end
function give_tutorial_artefact(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "af_blood_tutorial", "out")
end


--' Meet fox
function have_fox_info(first_speaker, second_speaker)
  	return first_speaker:object("fox_flash") ~= nil
end

--' fox help

function transfer_medikit_to_fox (player, wounded)
	wounded:set_relation(game_object.friend, player)
	db.actor:give_info_portion("escape_fox_heal")
end

function give_weapon_to_actor (trader, actor)
    dialogs.relocate_item_section(trader, "wpn_pm", "in")
    dialogs.relocate_item_section(trader, "ammo_9x18_fmj", "in")
    dialogs.relocate_item_section(trader, "ammo_9x18_fmj", "in")
    dialogs.relocate_item_section(trader, "ammo_9x18_fmj", "in")
    dialogs.relocate_item_section(trader, "medkit", "in")
    dialogs.relocate_item_section(trader, "bandage", "in")
    dialogs.relocate_item_section(trader, "racya_b", "in")
end


--' Escape blockpost box
function have_blockpost_case(first_speaker, second_speaker)
  	return first_speaker:object("quest_case_01") ~= nil
end


function give_blockpost_case(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "quest_case_01", "out")
end

function give_blockpost_case_reward(first_speaker, second_speaker)
	dialogs.relocate_money(first_speaker, 2000, "in")
end

--' Agroprom military case
function trader_need_military_case(first_speaker, second_speaker)
    if not has_alife_info("agroprom_military_case")
	then
		return true
	end
	return false
end

--' Escape trader artefact
function have_artefact_from_fleshes(first_speaker, second_speaker)
	local actor = db.actor
	if actor ~= nil and
	   (actor:object("af_vyvert") ~= nil or
	   actor:object("af_gravi") ~= nil or
	   actor:object("af_gold_fish") ~= nil)
	then
		return true
	end
  	return false
end


--' Ящик с блокпоста
function trader_need_blockpost_box(first_speaker, second_speaker)
    if has_alife_info("tutorial_end") and
	   has_alife_info("esc_trader_speak") and
	   not has_alife_info("escape_blockpost_case")
	then
		return true
	end
	return false
end

--' tutorial wounded in vagon
function wounded_need_help(first_speaker, second_speaker)
	local actor = db.actor
	return actor ~= nil and not has_alife_info( "tutorial_wounded_help" )
end

--' trader needs military documents
function trader_need_military_document(first_speaker, second_speaker)
    if has_alife_info("escape_blockpost_case_done") and
	   not has_alife_info("agroprom_military_case")
	then
		return true
	end
	return false
end

--' trader dialog about docs from labx18
function actor_has_documents (actor, npc)
	if actor:object("dar_document4") then
		return true
	else
		return false
	end
end

--' Escape dynamite for Wolf
function transfer_wolf_reward(first_speaker, second_speaker)
	dialogs.relocate_item_section(first_speaker, "af_medusa", "in")
end

function wolf_additional_reward(first_speaker, second_speaker)
    dialogs.relocate_item_section(first_speaker, "medkit", "in")
    dialogs.relocate_item_section(first_speaker, "bandage", "in")
    dialogs.relocate_item_section(first_speaker, "wpn_ak74", "in")
    dialogs.relocate_item_section(first_speaker, "grenade_f1", "in")        
end


--' Escape Wounded's flash
function wounded_give_flash(first_speaker, second_speaker)
	dialogs.relocate_item_section(first_speaker, "esc_wounded_flash", "in")
end

function have_wounded_flash(first_speaker, second_speaker)
  	return first_speaker:object("esc_wounded_flash") ~= nil
end
function dont_have_wounded_flash(first_speaker, second_speaker)
  	return not have_wounded_flash(first_speaker, second_speaker)
end

function give_wounded_flash(first_speaker, second_speaker)
	dialogs.relocate_item_section(second_speaker, "esc_wounded_flash", "out")
	dialogs.relocate_money(second_speaker, 1500, "in")
end

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

--' Escape bandits factory
function give_factory_reward_trader(first_speaker, second_speaker)
	dialogs.relocate_money(first_speaker, 500, "in")
end

--' Give X-18 documents read

function give_documents_reward (first_speaker, second_speaker)
	dialogs.relocate_money(first_speaker, 1000, "in")
end


--' Kill killers raid
function give_reward_killers(first_speaker, second_speaker)
	dialogs.relocate_money(first_speaker, 5000, "in")
end


--' Soldiers on bridge
function has_soldiers_bribe(actor, npc)
	return actor:money() >= 500
end

function give_soldiers_bribe(actor, npc)
	dialogs.relocate_money(npc, 500, "out")	
end

function fox_pay_money(actor, npc)
	dialogs.relocate_money(npc, 1500, "in")	
	treasure_manager.get_treasure_manager():give_treasure("esc_secret_truck_goods")
end

function run_tutorial_pda(first_speaker, second_speaker)
	printf("!-!-!")
	first_speaker:stop_talk()
    second_speaker:stop_talk()
	game.start_tutorial("part_1_pda")
end

function wolf_precond_univ (actor, npc)
	return has_alife_info("esc_kill_bandits_quest_done") or (has_alife_info("tutorial_wounded_give_info") and not has_alife_info("esc_kill_bandits_quest_have"))

end