-- File:        ARS_DIALOGS.SCRIPT
-- Copyright:   2009-2010 ARS Team
-- Author:      Xmk, Skunk
-- Description: fonctions pour les dialogues
-- Mod version: 0.5.2
-- Traduction Fr: Dada4_20/03/10

----------- Различные проверки -------------------------
-- проверка по времени суток
function ItsMorning()
	return level.get_time_hours()>=6 and level.get_time_hours()<12
end
function ItsDay()
	return level.get_time_hours()>=12 and level.get_time_hours()<18
end
function ItsEvening()
	return level.get_time_hours()>=18 and level.get_time_hours()<0
end
function ItsNight()
	return level.get_time_hours()>=0 and level.get_time_hours()<6
end

-- проверка инфопоршенов
function have_a_info(has_info,dont_has_info)
	if (has_info==nil and dont_has_info==nil) then
		return false
	elseif (has_info and dont_has_info==nil) then
		if has_alife_info(has_info) then
			return true
		end
	elseif (has_info==nil and dont_has_info) then
		if not has_alife_info(dont_has_info) then
			return true
		end
	else
		if has_alife_info(has_info) and not has_alife_info(dont_has_info) then
			return true
		end
	end
	return false
end

-- проверка на количество предметов в инвентаре гг
function inventory_search(items,n)
	local count=0
	local search=function(dummy,item) if item:section()==items then count=count+1 end end
	db.actor:iterate_inventory(search,nil)
	if count>=n then
		return true
	end
	return false
end

-- проверка на предмет в инвентаре гг
function have_a_item(item)
	if db.actor~=nil and db.actor:object(item)~=nil then
		return true
	end
	return false
end

-- проверка на предметы в инветаре и выдачу инфопоршена
--  К примеру нам надо проверить: если у ГГ в инветоре имеется:
--      АК-74 3шт., 5 Батонов и артефакт "Медуза"
--  то надо дать инфопорцию "have_item". Используем так:
--      have_a_item_info("have_item",{ {"wpn_ak-74",3},{"bread",5},{"af_meduse",1} })
--  если вместо инфопоршня заслать nil и функция вернет true или false
function have_a_item_info(sInfo,aItems)
	local bGiveInfo = false
	local iHaveItems = 0
	for k,v in pairs(aItems) do
		local sItem=v[1]
		local iCount=v[2]
		if not iCount then iCount=1 end
 		if k > 1 then
			if inventory_search(sItem,iCount) then
				iHaveItems = iHaveItems + 1
			end
			if k == iHaveItems then
				bGiveInfo = true
				break
			end
		else
			if inventory_search(sItem,iCount) then
				bGiveInfo = true
				break
			end
		end
	end
	if(sInfo) then
		if(bGiveInfo and db.actor:dont_has_info(sInfo))then
			db.actor:give_info_portion(sInfo)
		end
	else
		if(bGiveInfo)then
			return true
		end
	end
	return false
end

-- проверка пьян ли актор?
function actor_is_drink()
    if(GetGameMinutes()<ars.read_variable("drnk",0)) then
		return true
	end
	ars.write_variable("drnk")
	return false
end

-- проверка ранен ли актор?
function actor_is_wounded()
	if db.actor.bleeding>0.6 or db.actor.health<0.5 then
		return true
	end
	return false
end

-- проверка ранен ли актор?
function actor_is_bad_health()
	if db.actor.health<0.5 then
		return true
	end
	return false
end

-- проверка есть ли кровотечение у актора?
function actor_is_bad_bleeding()
	if db.actor.bleeding>0.6 then
		return true
	end
	return false
end

-- проверка на сонливость
function wants_to_sleep()
--	if(ars_sleep.get_sleep_manager():get_vigour() < 760) then	--new sleep manager
	if ars.read_variable("slp",0)>50 then
		return true
	end
	return false
end

-- проверка, хорошая ли у актора репутация
function is_good_reputation()
	if(ars_cop.get_npc_reputation()>50) then
		return true
	end
	return false
end

-- проверка, плохая ли у актора репутация
function is_bad_reputation()
	if(ars_cop.get_npc_reputation()<-50) then
		return true
	end
	return false
end


----------- Функции для диалогов (перенесены сюда для удобства -------------------------
-- проверка кто из спикеров является актором
function who_is_actor(first_speaker,second_speaker)
	local npc = second_speaker
	if db.actor:id() ~= npc:id() then
		npc	= first_speaker
	end
	return npc
end

-- проверка кто из спикеров является нпц
function who_is_npc(first_speaker,second_speaker)
	local npc = second_speaker
	if db.actor:id() == npc:id() then
		npc	= first_speaker
	end
	return npc
end


----------- Для денежных махинаций -------------------------
-- Проверка денег у гг
function has_money_250(first_speaker,second_speaker)
	return (db.actor:money()>=250)
end
function has_money_500(first_speaker,second_speaker)
	return (db.actor:money()>=500)
end
function has_money_700(first_speaker,second_speaker)
	return (db.actor:money()>=700)
end
function has_money_1000(first_speaker,second_speaker)
	return (db.actor:money()>=1000)
end
function has_money_1500(first_speaker,second_speaker)
	return (db.actor:money()>=1500)
end
function has_money_2000(first_speaker,second_speaker)
	return (db.actor:money()>=2000)
end
function has_money_2500(first_speaker,second_speaker)
	return (db.actor:money()>=2500)
end
function has_money_3000(first_speaker,second_speaker)
	return (db.actor:money()>=3000)
end
function has_money_3500(first_speaker,second_speaker)
	return (db.actor:money()>=3500)
end
function has_money_4000(first_speaker,second_speaker)
	return (db.actor:money()>=4000)
end
function has_money_4500(first_speaker,second_speaker)
	return (db.actor:money()>=4500)
end
function has_money_5000(first_speaker,second_speaker)
	return (db.actor:money()>=5000)
end

-- Проверка отсутствия денег у ГГ
function not_has_money_250(first_speaker,second_speaker)
	return (db.actor:money()<250)
end
function not_has_money_500(first_speaker,second_speaker)
	return (db.actor:money()<500)
end
function not_has_money_700(first_speaker,second_speaker)
	return (db.actor:money()<700)
end
function not_has_money_1000(first_speaker,second_speaker)
	return (db.actor:money()<1000)
end
function not_has_money_1500(first_speaker,second_speaker)
	return (db.actor:money()<1500)
end
function not_has_money_2000(first_speaker,second_speaker)
	return (db.actor:money()<2000)
end
function not_has_money_2500(first_speaker,second_speaker)
	return (db.actor:money()<2500)
end
function not_has_money_3000(first_speaker,second_speaker)
	return (db.actor:money()<3000)
end
function not_has_money_3500(first_speaker,second_speaker)
	return (db.actor:money()<3500)
end
function not_has_money_4000(first_speaker,second_speaker)
	return (db.actor:money()<4000)
end
function not_has_money_4500(first_speaker,second_speaker)
	return (db.actor:money()<4500)
end
function not_has_money_5000(first_speaker,second_speaker)
	return (db.actor:money()<5000)
end

-- Трансфер денег от ГГ к НПЦ
function transfer_money_250(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,250)
end
function transfer_money_500(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,500)
end
function transfer_money_700(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,700)
end
function transfer_money_1000(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,1000)
end
function transfer_money_1500(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,1500)
end
function transfer_money_2000(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,2000)
end
function transfer_money_2500(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,2500)
end
function transfer_money_3000(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,3000)
end
function transfer_money_3500(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,3500)
end
function transfer_money_4000(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,4000)
end
function transfer_money_4500(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,4500)
end
function transfer_money_5000(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,5000)
end


----------- Разные диалоги --------------------------------------
function has_kolbasa_from_noah()
	return inventory_search("kolbasa",2)
end
function transfer_kolbasa_noah(first_speaker, second_speaker)
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"kolbasa")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"kolbasa")
end


----------- Для информационных диалогов -------------------------
-- проверка записной книжки в инвентаре
function have_a_notepad()
	if db.actor~=nil and db.actor:object("notepad")~=nil then
		return true
	end
	return false
end

-- выдача информации о аномалии
function note_anomaly_surge_info()
	ars_cop.send_tip(GetString("surge"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_jarka_info()
	ars_cop.send_tip(GetString("jarka"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_gazirovka_info()
	ars_cop.send_tip(GetString("gazirovka"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_electra_info()
	ars_cop.send_tip(GetString("electra"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_tramplin_info()
	ars_cop.send_tip(GetString("tramplin"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_voronka_info()
	ars_cop.send_tip(GetString("voronka"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_karusel_info()
	ars_cop.send_tip(GetString("karusel"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_anomaly_kameta_info()
	ars_cop.send_tip(GetString("kameta"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end
function note_amomaly_tesla_info()
	ars_cop.send_tip(GetString("tesla"),GetString("notepad_tip_anomaly"),nil,5,"surge")
end

-- выдача информации о мутанте
function note_monster_tushkano_info()
	ars_cop.send_tip(GetString("tushkano"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_boar_info()
	ars_cop.send_tip(GetString("boar"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_flesh_info()
	ars_cop.send_tip(GetString("flesh"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_dog_info()
	ars_cop.send_tip(GetString("dog"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_pseudodog_info()
	ars_cop.send_tip(GetString("pseudodog"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_chimera_info()
	ars_cop.send_tip(GetString("chimera"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_bloodsucker_info()
	ars_cop.send_tip(GetString("bloodsucker"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_bloodsucker_marsh_info()
	ars_cop.send_tip(GetString("bloodsucker_marsh"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_pseudogigant_info()
	ars_cop.send_tip(GetString("pseudogigant"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_snork_info()
	ars_cop.send_tip(GetString("snork"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_burer_info()
	ars_cop.send_tip(GetString("burer"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_poltergeist_info()
	ars_cop.send_tip("poltergeist",GetString("notepad_tip_mutants"),nil,5,"monsters")
end
function note_monster_controller_info()
	ars_cop.send_tip(GetString("controller"),GetString("notepad_tip_mutants"),nil,5,"monsters")
end

function zat_b106_gonta_about_mutants_not_done(first_speaker,second_speaker)
	if has_alife_info("tushkano_dead") and has_alife_info("boar_dead") and
	   has_alife_info("flesh_dead") and has_alife_info("dog_dead") and
	   has_alife_info("pseudodog_dead") and has_alife_info("snork_dead") and
	   has_alife_info("bloodsucker_dead")
	then
		return false
	end
	return true
end
function zat_b106_gonta_about_mutants_done(first_speaker,second_speaker)
	if has_alife_info("tushkano_dead") and has_alife_info("boar_dead") and
	   has_alife_info("flesh_dead") and has_alife_info("dog_dead") and
	   has_alife_info("pseudodog_dead") and has_alife_info("snork_dead") and
	   has_alife_info("bloodsucker_dead")
	then
		return true
	end
	return false
end

function jup_b220_trapper_about_mutants_not_done(first_speaker,second_speaker)
	if has_alife_info("burer_dead") and has_alife_info("poltergeist_dead") and
	   has_alife_info("controller_dead") and has_alife_info("chimera_dead") and
	   has_alife_info("pseudogigant_dead")
	then
		return false
	end
	return true
end
function jup_b220_trapper_about_mutants_done(first_speaker,second_speaker)
	if has_alife_info("burer_dead") and has_alife_info("poltergeist_dead") and
	   has_alife_info("controller_dead") and has_alife_info("chimera_dead") and
	   has_alife_info("pseudogigant_dead")
	then
		return true
	end
	return false
end


----------- Для термосов -------------------------
function has_empty_termoses()
	return (have_a_item("termos_empty")) or (have_a_item("termos_small_empty"))
end
function has_empty_termos()
	return (have_a_item("termos_empty"))
end
function has_empty_termos_small()
	return (have_a_item("termos_small_empty"))
end
function has_money_na_vodu(first_speaker,second_speaker)
	return (db.actor:money()>=150)
end
function has_money_na_vodu_small(first_speaker,second_speaker)
	return (db.actor:money()>=50)
end
function has_money_na_tea(first_speaker,second_speaker)
	return (db.actor:money()>=225)
end
function has_money_na_tea_small(first_speaker,second_speaker)
	return (db.actor:money()>=75)
end
function has_money_na_coffee(first_speaker,second_speaker)
	return (db.actor:money()>=300)
end
function has_money_na_coffee_small(first_speaker,second_speaker)
	return (db.actor:money()>=100)
end
function transfer_money_to_barmen_voda(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,150)
end
function transfer_termos_voda_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_full_voda")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_empty")
end
function transfer_money_to_barmen_tea(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,225)
end
function transfer_termos_tea_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_full_tea")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_empty")
end
function transfer_money_to_barmen_cofee(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,300)
end
function transfer_termos_cofee_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_full_cofee")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_empty")
end
function transfer_money_to_barmen_voda_small(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,50)
end
function transfer_termos_small_voda_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_small_full_voda")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_small_empty")
end
function transfer_money_to_barmen_tea_small(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,75)
end
function transfer_termos_small_tea_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_small_full_tea")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_small_empty")
end
function transfer_money_to_barmen_cofee_small(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,100)
end
function transfer_termos_small_cofee_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"termos_small_full_cofee")
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"termos_small_empty")
end
function po_zubam(first_speaker,second_speaker)
	dialogs.break_dialog(first_speaker,second_speaker)
	local npc=who_is_npc(first_speaker,second_speaker)
	xr_abuse.add_abuse(npc,100)
	local money=db.actor:money()
	local itogo
	if money<=500 then
		itogo=money
	elseif money>10000 then
		itogo=math.ceil(money*math.random(5,7)/100)
	else
		itogo=math.ceil(money*math.random(1,3)/10)
	end
	db.actor:give_money(-itogo)
	game_stats.money_quest_update(-itogo)
end
function returner_dd_zat()
	if has_alife_info("zat_a2_barmen_termos_indebted") then
		db.actor:disable_info_portion("zat_a2_barmen_termos_indebted")
	end
	if has_alife_info("zat_a2_barmen_termos_no_dialog") then
		db.actor:disable_info_portion("zat_a2_barmen_termos_no_dialog")
	end
	if has_alife_info("zat_a2_barmen_termos_by_barmen") then
		db.actor:disable_info_portion("zat_a2_barmen_termos_by_barmen")
	end
end
function returner_dd_jup()
	if has_alife_info("jup_a6_barmen_termos_indebted") then
		db.actor:disable_info_portion("jup_a6_barmen_termos_indebted")
	end
	if has_alife_info("jup_a6_barmen_termos_no_dialog") then
		db.actor:disable_info_portion("jup_a6_barmen_termos_no_dialog")
	end
	if has_alife_info("jup_a6_barmen_termos_by_barmen") then
		db.actor:disable_info_portion("jup_a6_barmen_termos_by_barmen")
	end
end


----------- Для кредитных и арендных диалогов -------------------------
function has_money_na_zat_treasure_ned(first_speaker,second_speaker)
	return (db.actor:money()>=3500)
end
function has_money_na_zat_treasure_mes(first_speaker,second_speaker)
	return (db.actor:money()>=10000)
end
function transfer_money_to_barmen_zat_treasure_ned(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,3500)
	ars_cop.send_tip(GetString("st_actor_box_news"),nil,nil,5,"actor")
	fCall("ars_mod","actor_box_pay_rent")
end
function transfer_money_to_barmen_zat_treasure_mes(first_speaker,second_speaker)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,10000)
	ars_cop.send_tip(GetString("st_actor_box_news"),nil,nil,5,"actor")
	fCall("ars_mod","actor_box_pay_rent")
end


----------- Для охотничьих диалогов ------------------------- 
function transfer_lite_knife_to_actor(first_speaker,second_speaker)
	dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
end
function have_jup_b220_trapper_burers_hand(first_speaker,second_speaker)
	if have_a_item("jup_b208_burer_hand") then 
		return true
	end
	return false
end
function have_jup_b211_swamp_bloodsucker_jaw(first_speaker,second_speaker)
	if have_a_item("jup_b211_swamp_bloodsucker_jaw") then
		return true
	end
	return false
end
function have_jup_b212_chimera_kogot(first_speaker,second_speaker)
	if have_a_item("jup_b212_chimera_kogot") then
		return true
	end
	return false
end
function transfer_jup_b220_trapper_burers_hand(first_speaker,second_speaker)
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"jup_b208_burer_hand")
end
function transfer_jup_b211_swamp_bloodsucker_jaw(first_speaker,second_speaker)
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"jup_b211_swamp_bloodsucker_jaw")
end
function transfer_jup_b212_chimera_kogot(first_speaker,second_speaker)
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"jup_b212_chimera_kogot")
end

function mutanter_traning_gonta_done(first_speaker,second_speaker)
	if has_alife_info("ars_mutanter_bloodsucker_rank") and
	   has_alife_info("ars_mutanter_snork_rank") and
	   has_alife_info("ars_mutanter_boar_rank") and
	   has_alife_info("ars_mutanter_flesh_rank") and
	   has_alife_info("ars_mutanter_dogs_rank") and
	   has_alife_info("ars_mutanter_tushkano_rank")
	then
		return true
	end
	return false
end
function mutanter_traning_trapper_done(first_speaker,second_speaker)
	if has_alife_info("ars_mutanter_pseudogigant_rank") and
	   has_alife_info("ars_mutanter_burer_rank") and
	   has_alife_info("ars_mutanter_controller_rank") and
	   has_alife_info("ars_mutanter_chimera_rank")
	then
		return true
	end
	return false
end

function mutanter_traning_gonta_not_done(first_speaker,second_speaker)
	if has_alife_info("ars_mutanter_bloodsucker_rank") and
	   has_alife_info("ars_mutanter_snork_rank") and
	   has_alife_info("ars_mutanter_boar_rank") and
	   has_alife_info("ars_mutanter_flesh_rank") and
	   has_alife_info("ars_mutanter_dogs_rank") and
	   has_alife_info("ars_mutanter_tushkano_rank")
	then
		return false
	end
	return true
end
function mutanter_traning_trapper_not_done(first_speaker,second_speaker)
	if has_alife_info("ars_mutanter_pseudogigant_rank") and
	   has_alife_info("ars_mutanter_burer_rank") and
	   has_alife_info("ars_mutanter_controller_rank") and
	   has_alife_info("ars_mutanter_chimera_rank")
	then
		return false
	end
	return true
end

function mutanter_intructions(first_speaker,second_speaker,dialog_id,phrase_id)
	if(dialog_id=="zat_b106_stalker_gonta_about_mutanter_dialog_base")then
		if(phrase_id=="3111")then
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
		elseif(phrase_id=="2113")then
			fCall("ars_mutanter","SetRang",2)
			ars_cop.send_tip(GetString("mutanter_instructions_1"),GetString("mutanter_instructions_0"),2,nil,"actor")
		end
	elseif(dialog_id=="zat_b106_stalker_gonta_about_mutanter_dialog")then
		if(phrase_id=="7113")then
			fCall("ars_mutanter","SetRang",2)
			fCall("ars_mutanter","SetRangMutants",5,"bloodsucker")
			ars_cop.send_tip(GetString("mutanter_instructions_2"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="6113")then
			fCall("ars_mutanter","SetRang",2)
			fCall("ars_mutanter","SetRangMutants",5,"snork")
			ars_cop.send_tip(GetString("mutanter_instructions_3"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="5113")then
			fCall("ars_mutanter","SetRang",1)
			fCall("ars_mutanter","SetRangMutants",5,"boar")
			ars_cop.send_tip(GetString("mutanter_instructions_4"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="4113")then
			fCall("ars_mutanter","SetRang",1)
			fCall("ars_mutanter","SetRangMutants",5,"flesh")
			ars_cop.send_tip(GetString("mutanter_instructions_5"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="3113")then
			fCall("ars_mutanter","SetRang",1)
			fCall("ars_mutanter","SetRangMutants",5,"dog")
			ars_cop.send_tip(GetString("mutanter_instructions_6"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="2111")then
			fCall("ars_mutanter","SetRang",1)
			fCall("ars_mutanter","SetRangMutants",5,"tushkano")
			ars_cop.send_tip(GetString("mutanter_instructions_7"),GetString("mutanter_instructions_0"),2,nil,"actor")
		end
	elseif(dialog_id=="jup_b220_trapper_about_mutanter_dialog")then
		if(phrase_id=="4117")then
			fCall("ars_mutanter","SetRang",3)
			fCall("ars_mutanter","SetRangMutants",5,"pseudogigant")
			ars_cop.send_tip(GetString("mutanter_instructions_8"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="3113")then
			fCall("ars_mutanter","SetRang",4)
			fCall("ars_mutanter","SetRangMutants",5,"burer")
			fCall("ars_mutanter","SetRangMutants",5,"controller")
			ars_cop.send_tip(GetString("mutanter_instructions_9"),GetString("mutanter_instructions_0"),2,nil,"actor")
		elseif(phrase_id=="2113")then
			fCall("ars_mutanter","SetRang",3)
			fCall("ars_mutanter","SetRangMutants",5,"chimera")
			ars_cop.send_tip(GetString("mutanter_instructions_10"),GetString("mutanter_instructions_0"),2,nil,"actor")
		end
	end
end


----------- Заказ ножа. ЗАТОН -------------------------
local MutKnfListZat = {	[1]={sect="ars_mutanter_knife_lite",info="zat_b106_stalker_gonta_about_himself_lock"},
						[2]={sect="ars_mutanter_knife_ext",info="zat_b106_found_soroka_done"},
						[3]={sect="ars_mutanter_knife_pro",info="jup_b212_jupiter_chimera_hunt_done"}
}
function mutanter_knife_order_parse_phrase(first_speaker,second_speaker,id)
	local result=""
	local f_first=true
	for i=1,3 do
		if has_alife_info(MutKnfListZat[i].info) then
			if f_first then
				result="Maintenant, je peux vous l'obtenir:\\n"..GetString(GetItemName(MutKnfListZat[i].sect))
				f_first=false
			else
				result=result..", "..GetString(GetItemName(MutKnfListZat[i].sect))
			end
		end
	end
	if result~="" then
		result=result..". \\n"..GetString("Choisir.")
	else
		result=GetString("Ceychas je ne peux rien vous obtenir.")
	end
	return result
end

function munanter_knife_order_knife_precond_1(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("zat_b106_stalker_gonta_about_himself_lock") then
		return true
	end
	return false
end
function munanter_knife_order_knife_precond_2(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("zat_b106_chimera_dead") or has_alife_info("zat_b106_found_soroka_done") then
		return true
	end
	return false
end
function munanter_knife_order_knife_precond_3(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("jup_b212_jupiter_chimera_hunt_done") then
		return true
	end
	return false
end

function mutanter_knife_order_parse_phrase_cost(first_speaker,second_speaker,id)
	local result=""
	if(id=="111")then i=1
	elseif(id=="121")then i=2
	elseif(id=="131")then i=3
	else return
	end
	local cost=GetItemCost(MutKnfListZat[i].sect)
	if ars.read_variable("MutZatBadOrderC",0) > 0 then
		cost=cost*1.10
		result="Pour vous "..cost
	elseif ars.read_variable("MutZatBadOrderC",0) > 1 then
		cost=cost*1.20
		result="Pour toi ce sera "..cost
	elseif ars.read_variable("MutZatBadOrderC",0) > 2 then
		cost=cost*1.30
		result="Pour toi ce sera "..cost
	else
		cost=cost
		result="en tout "..cost
	end
	local c_before=math.ceil( (cost/100)*30 )	-- 30% предоплата
	local c_after=math.ceil( (cost/100)*70 )	-- 70% по окончанию заказа
	ars.write_variable("MutZatKnCostBef"..i,c_before)
	ars.write_variable("MutZatKnCostAft"..i,c_after)
	result=result..", avec "..tostring(c_before).." en caution "..tostring(c_after).." aprиs reception de la commande."
	return result
end

local mkop_tmp_phrase
function mutanter_knife_order_parse_phrase_not_place(first_speaker,second_speaker,id)
	local result = ""
	local phrases = {
					"je me suis mal exprimй, c'est pas encore pret.",
					"C'est pas pret.",
					"Non, la commande n'est pas encore prиte.",
					"Reviens plus tard.",
					"Ne me dйrangez pas, s'il vous plait, revenez plus tard",
					"Revenez me voir un peu plus tard.",
					"Impatient?, moi aussi. Mais, y'a rien pour le moment.",
					"Bouge de lа! Le couteau n'ont pas encore arrivй.",
					"T'es un malade! Attends ton tour.",
					"Une solution? Attendre."
					}
	-- удаляем предыдущую фразу
	if mkop_tmp_phrase ~= nil then
		table.remove(phrases, mkop_tmp_phrase)
	end
	-- и генерируем следующую
	local phrase = math.random(#phrases)
	result = GetString(phrases[phrase])
	mkop_tmp_phrase = phrase
	return result
end

function mutanter_knife_order_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="111")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostBef1",0))
	elseif(parent_id=="121")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostBef2",0))
	elseif(parent_id=="131")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostBef3",0))
	end
	return false
end
function mutanter_knife_order_not_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="111")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostBef1",0))
	elseif(parent_id=="121")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostBef2",0))
	elseif(parent_id=="131")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostBef3",0))
	end
	return false
end
function mutanter_knife_order_transfer_money(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="1111")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostBef1",0))
	elseif(phrase_id=="1211")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostBef2",0))
	elseif(phrase_id=="1311")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostBef3",0))
	end
	ars_cop.g_start_timer("give_info",0,math.random(12,24),0,"ars_mutanter_zat_knife_order_place")
--	if math.random(100)<20 then
--		ars_cop.g_start_timer("give_info",0,12,0,"ars_mutanter_zat_knife_order_zb")
--	end
end

function mutanter_knife_order_place_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft1",0))
	elseif(parent_id=="3")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft2",0))
	elseif(parent_id=="4")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft3",0))
	end
end
function mutanter_knife_order_place_not_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft1",0))
	elseif(parent_id=="3")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft2",0))
	elseif(parent_id=="4")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft3",0))
	end
end
function mutanter_knife_order_place_transfer_money(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="21")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft1",0))
	elseif(phrase_id=="31")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft2",0))
	elseif(phrase_id=="41")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft3",0))
	end
end
function mutanter_knife_order_transfer_item(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="211")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
	elseif(phrase_id=="311")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_ext")
	elseif(phrase_id=="411")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_pro")
	end
end

function mutanter_knife_order_delay_set_time(first_speaker,second_speaker,dialog_id,phrase_id)
    ars.write_variable("MutZatKnDelayTime",GetGameMinutes())
end

function mutanter_knife_order_delay_get_time(i)
	local proc = math.ceil( (GetItemCost(MutKnfListZat[i].sect)/100)*10 )
	return ars_cop.calculator_money(ars.read_variable("MutZatKnDelayTime",0),proc,5)
end
function mutanter_knife_order_delay_time_came(first_speaker,second_speaker)
	local max_time = 60*24*4 -- 4 days
	if ars_cop.get_npc_relation(first_speaker,second_speaker)=="friend" then
		max_time = 60*24*7 -- week
	end
	local delta = GetGameMinutes() - ars.read_variable("MutZatKnDelayTime",0)
	if delta > max_time then
		return true
	end
	return false
end
function mutanter_knife_order_delay_del_vars(first_speaker,second_speaker,dialog_id,phrase_id)
    ars.del_variable("MutZatKnDelayTime")
	ars.del_variable("MutZatKnCostBef1")
	ars.del_variable("MutZatKnCostBef2")
	ars.del_variable("MutZatKnCostBef3")
	ars.del_variable("MutZatKnCostAft1")
	ars.del_variable("MutZatKnCostAft2")
	ars.del_variable("MutZatKnCostAft3")
	disable_info("ars_mutanter_zat_knife_order_place")
	disable_info("ars_mutanter_zat_order_knife_1")
	disable_info("ars_mutanter_zat_order_knife_2")
	disable_info("ars_mutanter_zat_order_knife_3")
	disable_info("ars_mutanter_zat_order_knife_1_delay")
	disable_info("ars_mutanter_zat_order_knife_2_delay")
	disable_info("ars_mutanter_zat_order_knife_3_delay")
--	disable_info("ars_mutanter_zat_knife_order_fp")
--	disable_info("ars_mutanter_zat_knife_order_zb")
end

function mutanter_knife_order_delay_parse_phrase_money(first_speaker,second_speaker,id)
	local result=""
	local m1,m2
	if(id=="2")then
		m1=ars.read_variable("MutZatKnCostAft1",0)
		m2=mutanter_knife_order_delay_get_time(1)
	elseif(id=="3")then
		m1=ars.read_variable("MutZatKnCostAft2",0)
		m2=mutanter_knife_order_delay_get_time(2)
	elseif(id=="4")then
		m1=ars.read_variable("MutZatKnCostAft3",0)
		m2=mutanter_knife_order_delay_get_time(3)
	end
	if m1~=nil and m2~=nil then
		local money=m1+m2
		result="Ah, il est arrive. Je n'ai vraiment pas vendu ton couteau a un autre stalker. En general de vous  "..tostring(money)..". "..tostring(m1).." pour la commande elle-meme, "..tostring(m2).." les indemnitйs de retard."
	end
	return result
end
function mutanter_knife_order_delay_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft1",0)+mutanter_knife_order_delay_get_time(1))
	elseif(parent_id=="3")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft2",0)+mutanter_knife_order_delay_get_time(2))
	elseif(parent_id=="4")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft3",0)+mutanter_knife_order_delay_get_time(3))
	end
end
function mutanter_knife_order_delay_not_has_money(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft1",0)+mutanter_knife_order_delay_get_time(1))
	elseif(parent_id=="3")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft2",0)+mutanter_knife_order_delay_get_time(2))
	elseif(parent_id=="4")then
		return (db.actor:money()<ars.read_variable("MutZatKnCostAft3",0)+mutanter_knife_order_delay_get_time(3))
	end
end
function mutanter_knife_order_delay_have_money(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("ars_mutanter_zat_order_knife_1_delay")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft1",0))
	elseif has_alife_info("ars_mutanter_zat_order_knife_2_delay")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft2",0))
	elseif has_alife_info("ars_mutanter_zat_order_knife_3_delay")then
		return (db.actor:money()>=ars.read_variable("MutZatKnCostAft3",0))
	end
end
function mutanter_knife_order_delay_transfer_money(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="21")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft1",0)+mutanter_knife_order_delay_get_time(1))
	elseif(phrase_id=="31")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft2",0)+mutanter_knife_order_delay_get_time(2))
	elseif(phrase_id=="41")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutZatKnCostAft3",0)+mutanter_knife_order_delay_get_time(3))
	end
end
function mutanter_knife_order_delay_transfer_item(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="211")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
	elseif(phrase_id=="311")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_ext")
	elseif(phrase_id=="411")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_pro")
	end
end

function mutanter_knife_good_order_counter()
	if ars.read_variable("MutZatBadOrderC",0)>0 then
	    ars.write_variable("MutZatBadOrderC",ars.read_variable("MutZatBadOrderC",0)-1)
	end
end
function mutanter_knife_bad_order_counter()
    ars.write_variable("MutZatBadOrderC",ars.read_variable("MutZatBadOrderC",0)+1)
end
function mutanter_knife_get_bad_order()
	local cnt = ars.read_variable("MutZatBadOrderC",0)
	if cnt > 3 then
		return false
	end
	return true
end


----------- Заказ ножа. ЯНОВ -------------------------
local MutKnfListJup = {	[1]={sect="ars_mutanter_knife_lite",info="jup_b220_trapper_about_himself_told"},
						[2]={sect="ars_mutanter_knife_ext",info="jup_b211_swamp_bloodsuckers_hunt_done",info2="jup_b208_burers_hunt_done"},
						[3]={sect="ars_mutanter_knife_pro",info="jup_b212_jupiter_chimera_hunt_done"}
}
function mutanter_knife_order_parse_phrase_jup(first_speaker,second_speaker,id)
	local result=""
	local f_first=true
	for i=1,3 do
		if has_alife_info(MutKnfListJup[i].info) or (MutKnfListJup[i].info2~=nil and has_alife_info(MutKnfListJup[i].info2)) then
			if f_first then
				result="Pour vous, j'ai reзus:\\n"..GetString(GetItemName(MutKnfListJup[i].sect))
				f_first=false
			else
				result=result..", "..GetString(GetItemName(MutKnfListJup[i].sect))
			end
		end
	end
	if result~="" then
		result=result..". \\n"..GetString("choisir.")
	else
		result=GetString("Ceychas je ne peux pas obtenir quelque chose.")
	end
	return result
end

function munanter_knife_order_knife_precond_1_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("jup_b220_trapper_about_himself_told") then
		return true
	end
	return false
end
function munanter_knife_order_knife_precond_2_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("jup_b211_swamp_bloodsuckers_hunt_done") or has_alife_info("jup_b208_burers_hunt_done") then
		return true
	end
	return false
end
function munanter_knife_order_knife_precond_3_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("jup_b212_jupiter_chimera_hunt_done") then
		return true
	end
	return false
end

function mutanter_knife_order_parse_phrase_cost_jup(first_speaker,second_speaker,id)
	local result=""
	if(id=="111")then i=1
	elseif(id=="121")then i=2
	elseif(id=="131")then i=3
	else return
	end
	local cost=GetItemCost(MutKnfListJup[i].sect)
	if ars.read_variable("MutJupBadOrderC",0) > 0 then
		cost=cost*1.15
		result="Pour vous "..cost
	elseif ars.read_variable("MutJupBadOrderC",0) > 1 then
		cost=cost*1.30
		result="Pour toi ce sera "..cost
	elseif ars.read_variable("MutJupBadOrderC",0) > 2 then
		cost=cost*1.45
		result="Pour toi ce sera "..cost
	else
		cost=cost
		result="en tout "..cost
	end
	local c_before=math.ceil( (cost/100)*40 )	-- 40% предоплата
	local c_after=math.ceil( (cost/100)*60 )	-- 60% по окончанию заказа
	ars.write_variable("MutJupKnCostBef"..i,c_before)
	ars.write_variable("MutJupKnCostAft"..i,c_after)
	result=result..", avec "..tostring(c_before).." en caution "..tostring(c_after).." aprиs reception de la commande."
	return result
end

function mutanter_knife_order_parse_phrase_not_place_jup(first_speaker,second_speaker,id)
	local result = ""
	local phrases = {
					"je me suis mal exprimй, c'est pas encore pret.",
					"C'est pas pret.",
					"Non, la commande n'est pas encore prиte.",
					"Reviens plus tard.",
					"Ne me dйrangez pas, s'il vous plait, revenez plus tard",
					"Revenez me voir un peu plus tard.",
					"Impatient?, moi aussi. Mais, y'a rien pour le moment.",
					"Bouge de lа! Le couteau n'ont pas encore arrivй.",
					"T'es un malade! Attends ton tour.",
					"Une solution? Attendre."
					}
	-- генерируем фразу
	local phrase = math.random(#phrases)
	result = GetString(phrases[phrase])
	return result
end

function mutanter_knife_order_has_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="111")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostBef1",0))
	elseif(parent_id=="121")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostBef2",0))
	elseif(parent_id=="131")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostBef3",0))
	end
	return false
end
function mutanter_knife_order_not_has_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="111")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostBef1",0))
	elseif(parent_id=="121")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostBef2",0))
	elseif(parent_id=="131")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostBef3",0))
	end
	return false
end
function mutanter_knife_order_transfer_money_jup(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="1111")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostBef1",0))
	elseif(phrase_id=="1211")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostBef2",0))
	elseif(phrase_id=="1311")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostBef3",0))
	end
	ars_cop.g_start_timer("give_info",0,math.random(12,24),0,"ars_mutanter_jup_knife_order_place")
end

function mutanter_knife_order_place_has_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft1",0))
	elseif(parent_id=="3")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft2",0))
	elseif(parent_id=="4")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft3",0))
	end
end
function mutanter_knife_order_place_transfer_money_jup(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="21")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft1",0))
	elseif(phrase_id=="31")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft2",0))
	elseif(phrase_id=="41")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft3",0))
	end
end
function mutanter_knife_order_transfer_item_jup(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="211")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
	elseif(phrase_id=="311")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_ext")
	elseif(phrase_id=="411")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_pro")
	end
end

function mutanter_knife_order_delay_set_time_jup(first_speaker,second_speaker,dialog_id,phrase_id)
    ars.write_variable("MutJupKnDelayTime",GetGameMinutes())
end

function mutanter_knife_order_delay_get_time_jup(i)
	local proc = math.ceil( (GetItemCost(MutKnfListJup[i].sect)/100)*10 )
	return ars_cop.calculator_money(ars.read_variable("MutJupKnDelayTime",0),proc,3)
end
function mutanter_knife_order_delay_time_came_jup(first_speaker,second_speaker)
	local max_time = 60*24*5 -- 5 days
	local delta = GetGameMinutes() - ars.read_variable("MutJupKnDelayTime",0)
	if delta > max_time then
		return true
	end
	return false
end
function mutanter_knife_order_delay_del_vars_jup(first_speaker,second_speaker,dialog_id,phrase_id)
    ars.del_variable("MutJupKnDelayTime")
	ars.del_variable("MutJupKnCostBef1")
	ars.del_variable("MutJupKnCostBef2")
	ars.del_variable("MutJupKnCostBef3")
	ars.del_variable("MutJupKnCostAft1")
	ars.del_variable("MutJupKnCostAft2")
	ars.del_variable("MutJupKnCostAft3")
	disable_info("ars_mutanter_jup_knife_order_place")
	disable_info("ars_mutanter_jup_order_knife_1")
	disable_info("ars_mutanter_jup_order_knife_2")
	disable_info("ars_mutanter_jup_order_knife_3")
	disable_info("ars_mutanter_jup_order_knife_1_delay")
	disable_info("ars_mutanter_jup_order_knife_2_delay")
	disable_info("ars_mutanter_jup_order_knife_3_delay")
end

function mutanter_knife_order_delay_parse_phrase_money_jup(first_speaker,second_speaker,id)
	local result=""
	local m1,m2
	if(id=="2")then
		m1=ars.read_variable("MutJupKnCostAft1",0)
		m2=mutanter_knife_order_delay_get_time_jup(1)
	elseif(id=="3")then
		m1=ars.read_variable("MutJupKnCostAft2",0)
		m2=mutanter_knife_order_delay_get_time_jup(2)
	elseif(id=="4")then
		m1=ars.read_variable("MutJupKnCostAft3",0)
		m2=mutanter_knife_order_delay_get_time_jup(3)
	end
	if m1~=nil and m2~=nil then
		local money=m1+m2
		result="Je n'ai pas revendu ton couteau juste parce que j'ai une rйputation. Donc ce sera "..tostring(money)..". "..tostring(m1).." et pour moi-mкme "..tostring(m2).." d'intйrкts pour le retard."
	end
	return result
end
function mutanter_knife_order_delay_has_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft1",0)+mutanter_knife_order_delay_get_time_jup(1))
	elseif(parent_id=="3")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft2",0)+mutanter_knife_order_delay_get_time_jup(2))
	elseif(parent_id=="4")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft3",0)+mutanter_knife_order_delay_get_time_jup(3))
	end
end
function mutanter_knife_order_delay_not_has_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if(parent_id=="2")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostAft1",0)+mutanter_knife_order_delay_get_time_jup(1))
	elseif(parent_id=="3")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostAft2",0)+mutanter_knife_order_delay_get_time_jup(2))
	elseif(parent_id=="4")then
		return (db.actor:money()<ars.read_variable("MutJupKnCostAft3",0)+mutanter_knife_order_delay_get_time_jup(3))
	end
end
function mutanter_knife_order_delay_have_money_jup(first_speaker,second_speaker,dialog_id,parent_id)
	if has_alife_info("ars_mutanter_jup_order_knife_1_delay")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft1",0))
	elseif has_alife_info("ars_mutanter_jup_order_knife_2_delay")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft2",0))
	elseif has_alife_info("ars_mutanter_jup_order_knife_3_delay")then
		return (db.actor:money()>=ars.read_variable("MutJupKnCostAft3",0))
	end
end
function mutanter_knife_order_delay_transfer_money_jup(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="21")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft1",0)+mutanter_knife_order_delay_get_time_jup(1))
	elseif(phrase_id=="31")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft2",0)+mutanter_knife_order_delay_get_time_jup(2))
	elseif(phrase_id=="41")then
		dialogs.relocate_money_from_actor(first_speaker,second_speaker,ars.read_variable("MutJupKnCostAft3",0)+mutanter_knife_order_delay_get_time_jup(3))
	end
end
function mutanter_knife_order_delay_transfer_item_jup(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="211")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_lite")
	elseif(phrase_id=="311")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_ext")
	elseif(phrase_id=="411")then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_pro")
	end
end

function mutanter_knife_good_order_counter_jup()
	if ars.read_variable("MutJupBadOrderC",0)>0 then
	    ars.write_variable("MutJupBadOrderC",ars.read_variable("MutJupBadOrderC",0)-1)
	end
end
function mutanter_knife_bad_order_counter_jup()
    ars.write_variable("MutJupBadOrderC",ars.read_variable("MutJupBadOrderC",0)+1)
end
function mutanter_knife_get_bad_order_jup()
	local cnt = ars.read_variable("MutJupBadOrderC",0)
	if cnt > 3 then
		return false
	end
	return true
end



----------- О заточке ножа (Edit. Repair Mod from SoC by Shebuka) ------------------------- 
local knife_profit_margin=math.random(5,8)/10
function mutanter_knife_repair_precond(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local mutanter_knife_1=actor:object("ars_mutanter_knife_lite")
	local mutanter_knife_2=actor:object("ars_mutanter_knife_ext")
	local mutanter_knife_3=actor:object("ars_mutanter_knife_pro")
	if mutanter_knife_1~=nil and ars_mutanter.GetCondition(mutanter_knife_1:id())+0.01 < 1 then return true
	elseif mutanter_knife_2~=nil and ars_mutanter.GetCondition(mutanter_knife_2:id())+0.01 < 1 then return true
	elseif mutanter_knife_3~=nil and ars_mutanter.GetCondition(mutanter_knife_3:id())+0.01 < 1 then return true
	else return false
	end
end
function mutanter_knife_check_money_s1(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local mutanter_knife_1=actor:object("ars_mutanter_knife_lite")
	if mutanter_knife_1~=nil then 
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_1:id()))*mutanter_knife_1:cost()*knife_profit_margin)
		if item_repair_cost>0 and actor:money()>=item_repair_cost and ars_mutanter.GetCondition(mutanter_knife_1:id())+0.01 < 1 then
			return true
		end 
	end
	return false
end
function mutanter_knife_check_money_s2(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local mutanter_knife_2=actor:object("ars_mutanter_knife_ext")
	if mutanter_knife_2~=nil then 
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_2:id()))*mutanter_knife_2:cost()*knife_profit_margin)
		if item_repair_cost>0 and actor:money()>=item_repair_cost and ars_mutanter.GetCondition(mutanter_knife_2:id())+0.01 < 1 then
			return true
		end
	end
	return false
end
function mutanter_knife_check_money_s3(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local mutanter_knife_3=actor:object("ars_mutanter_knife_pro")
	if mutanter_knife_3~=nil then 
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_3:id()))*mutanter_knife_3:cost()*knife_profit_margin)
		if item_repair_cost>0 and actor:money()>=item_repair_cost and ars_mutanter.GetCondition(mutanter_knife_3:id())+0.01 < 1 then
			return true
		end 
	end
	return false
end
function mutanter_knife_repiar_s1(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local mutanter_knife_1=actor:object("ars_mutanter_knife_lite")
	if mutanter_knife_1~=nil then
		local item_id=mutanter_knife_1:id()
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_1:id()))*mutanter_knife_1:cost()*knife_profit_margin)
		ars_mutanter.SetCondition(item_id,1)
		dialogs.relocate_money(actor,item_repair_cost,"out")
	end
end
function mutanter_knife_repiar_s2(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker, second_speaker)
	local mutanter_knife_2=actor:object("ars_mutanter_knife_ext")
	if mutanter_knife_2~=nil then
		local item_id=mutanter_knife_2:id()
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_2:id()))*mutanter_knife_2:cost()*knife_profit_margin)
		ars_mutanter.SetCondition(item_id,1)
		dialogs.relocate_money(actor,item_repair_cost,"out")
	end
end
function mutanter_knife_repiar_s3(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker, second_speaker)
	local mutanter_knife_3=actor:object("ars_mutanter_knife_pro")
	if mutanter_knife_3~=nil then
		local item_id=mutanter_knife_3:id()
		local item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_3:id()))*mutanter_knife_3:cost()*knife_profit_margin)
		ars_mutanter.SetCondition(item_id,1)
		dialogs.relocate_money(actor,item_repair_cost,"out")
	end
end
function mutanter_knife_repair_costs(first_speaker,second_speaker)
	local item_name_and_price=""
	local item_repair_cost=0
	if db.actor~=nil then
		local mutanter_knife_1=db.actor:object("ars_mutanter_knife_lite")
		local mutanter_knife_2=db.actor:object("ars_mutanter_knife_ext")
		local mutanter_knife_3=db.actor:object("ars_mutanter_knife_pro")
		if mutanter_knife_1~=nil then
			item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_1:id()))*mutanter_knife_1:cost()*knife_profit_margin)
			if item_repair_cost>0 then
				item_name_and_price="%c[255,238,155,23]"..item_repair_cost.."Ru%c[default]"
				db.actor:give_talk_message2(GetString("list_knife_repair_lite"),item_name_and_price,"ui_inGame2_Dengi_otdani","iconed_trade_info")
			end
		end
		if mutanter_knife_2~=nil then
			item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_2:id()))*mutanter_knife_2:cost()*knife_profit_margin)
			if item_repair_cost>0 then
				item_name_and_price="%c[255,238,155,23]"..item_repair_cost.."Ru%c[default]"
				db.actor:give_talk_message2(GetString("list_knife_repair_ext"),item_name_and_price,"ui_inGame2_Dengi_otdani","iconed_trade_info")
			end
		end
		if mutanter_knife_3~=nil then
			item_repair_cost=math.floor((1-ars_mutanter.GetCondition(mutanter_knife_3:id()))*mutanter_knife_3:cost()*knife_profit_margin)
			if item_repair_cost>0 then
				item_name_and_price="%c[255,238,155,23]"..item_repair_cost.."Ru%c[default]"
				db.actor:give_talk_message2(GetString("list_knife_repair_pro"),item_name_and_price,"ui_inGame2_Dengi_otdani","iconed_trade_info")
			end
		end
	end
end


----------- Продажа когтя химеры -------------------------
function actor_has_chimera_kogot(first_speaker,second_speaker,id)
	return db.actor:object("mutant_chimera_kogot")~=nil
end
function npc_has_chimera_kogot(first_speaker,second_speaker,id)
	local npc=who_is_npc(first_speaker,second_speaker)
	return npc:object("mutant_chimera_kogot")~=nil
end
function npc_not_has_chimera_kogot(first_speaker,second_speaker,id)
	local npc=who_is_npc(first_speaker,second_speaker)
	return npc:object("mutant_chimera_kogot")==nil
end
function prob_buy_chimera_kogot()
	return math.random(100)<30
end
function start_timer_not_buy_chimera_kogot()
	ars_cop.g_start_timer("disable_info",0,0,30,"ars_hunters_dont_trade_chimera_kogot")
end
function transfer_chimera_kogot(first_speaker,second_speaker)
	dialogs.relocate_item_section_from_actor(first_speaker,second_speaker,"mutant_chimera_kogot")
end
function transfer_money_from_chimera_kogot(first_speaker,second_speaker,dialog_id,phrase_id)
	if(phrase_id=="11")then
		dialogs.relocate_money_to_actor(first_speaker,second_speaker,1500)
	else
		dialogs.relocate_money_to_actor(first_speaker,second_speaker,1000)
	end
end


----------- Награды за достижения -------------------------
local ars_ach_rewards = {	[1]={info="ars_potroshitel_reward",calc="ars_potroshitel"},
							[2]={info="ars_medic_reward",calc="ars_medic"},
							[3]={info="ars_medic_reward_p",calc="ars_medic_p"},
							[4]={info="ars_headshoter_reward_p",calc="ars_headshoter_p"},
							[5]={info="detective_reward_p",calc="detective_p"}
}
local ach_rewards_money,ach_rewards_result=0,""
function parse_list(first_speaker,second_speaker,id)
	ach_rewards_money,ach_rewards_result=0,""
	local f_first=true
	for i=1,5 do
		if has_alife_info(ars_ach_rewards[i].info) then
			ach_rewards_money=ach_rewards_money+ars_achievements.get_money_from_rewards(ars_ach_rewards[i].calc)
			if f_first then
				ach_rewards_result="Pour toi voici "..GetString("zat_a2_stalker_barmen_achievements_reward_list_"..i)
				f_first=false
			else
				if i==5 and has_alife_info("ars_medic_reward_p") then
					ach_rewards_result=ach_rewards_result..", "..GetString("zat_a2_stalker_barmen_achievements_reward_list_"..i+1)
				else
					ach_rewards_result=ach_rewards_result..", "..GetString("zat_a2_stalker_barmen_achievements_reward_list_"..i)
				end
			end
		end
	end
	if ach_rewards_result~="" then
		ach_rewards_result=ach_rewards_result..". \\n"..GetString("zat_a2_stalker_barmen_achievements_reward_list_7").."%c[255,160,160,160] "..tostring(ach_rewards_money).." RU. %c[default]"..GetString("zat_a2_stalker_barmen_achievements_reward_list_8")
	else
		ach_rewards_result=GetString("zat_a2_stalker_barmen_achievements_reward_list_0")
	end
	return ach_rewards_result
end

function actor_have_money_and_have_list()
	if ach_rewards_money~=0 and db.actor:money()>=ach_rewards_money and ach_rewards_result~="" and ach_rewards_result~=GetString("zat_a2_stalker_barmen_achievements_reward_list_0") then
		return true
	end
	return false
end
function actor_not_have_money_and_have_list()
	if (ach_rewards_money==0 or db.actor:money()<ach_rewards_money) and ach_rewards_result~="" and ach_rewards_result~=GetString("zat_a2_stalker_barmen_achievements_reward_list_0") then
		return true
	end
	return false
end
function actor_not_have_list()
	if (ach_rewards_money==0 or db.actor:money()<ach_rewards_money) and ach_rewards_result~="" and ach_rewards_result==GetString("zat_a2_stalker_barmen_achievements_reward_list_0") then
		return true
	end
	return false
end

function transfer_money(first_speaker,second_speaker,dialog_id,phrase_id)
	dialogs.relocate_money_from_actor(first_speaker,second_speaker,ach_rewards_money)
	ach_rewards_money=0
end
function transfer_items(first_speaker,second_speaker,dialog_id,phrase_id)
	if ach_rewards_result=="" then return end
	if has_alife_info("ars_potroshitel_reward") then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ars_mutanter_knife_uniq")
		db.actor:disable_info_portion("ars_potroshitel_reward")
	end
	if has_alife_info("ars_medic_reward") then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"stalker_medic_outfit")
		db.actor:disable_info_portion("ars_medic_reward")
	end
	if has_alife_info("ars_medic_reward_p") then
		for i=1,ars.read_variable("ArsMedicRewardP",1) do
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"vodka",3)
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"medkit",3)
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"bandage",3)
		end
		ars.del_variable("ArsMedicRewardP")
		db.actor:disable_info_portion("ars_medic_reward_p")
	end
	if has_alife_info("ars_headshoter_reward_p") then
		for i=1,ars.read_variable("ArsHeadshoterRewardP",1) do
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"ammo_7.62x54_7h1",3)
		end
		ars.del_variable("ArsHeadshoterRewardP")
		db.actor:disable_info_portion("ars_headshoter_reward_p")
	end
	if has_alife_info("detective_reward_p") then
		for i=1,ars.read_variable("DetectiveRewardP",1) do
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"antirad",3)
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"medkit",3)
			dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"bandage",3)
		end
		ars.del_variable("DetectiveRewardP")
		db.actor:disable_info_portion("detective_reward_p")
	end
end


----------- Помощь актору -------------------------
local dlg_medkit_phrase_npc=0
function parse_phrase_npc(first_speaker,second_speaker,id)
	local result=""
	if is_bad_reputation() then
		result=GetString("ars_help_actor_dialogs_01")
		dlg_medkit_phrase_npc=1
	elseif npc_not_have_medkit(first_speaker,second_speaker) then
		result=GetString("ars_help_actor_dialogs_02")
		dlg_medkit_phrase_npc=2
	elseif(npc_have_medkit(first_speaker,second_speaker) and npc_have_one_medkit(first_speaker,second_speaker) and prob_give_last_medkit()) then
		transfer_medkit_to_actor(first_speaker,second_speaker)
		result=GetString("ars_help_actor_dialogs_03")
		dlg_medkit_phrase_npc=3
	elseif(npc_have_more_medkits(first_speaker,second_speaker) and prob_give_medkit()) then
		transfer_medkit_to_actor(first_speaker,second_speaker)
		result=GetString("ars_help_actor_dialogs_04")
		dlg_medkit_phrase_npc=4
	else
		result=GetString("ars_help_actor_dialogs_05")
		dlg_medkit_phrase_npc=5
	end
	return result
end
function get_phrase_actor_bye(first_speaker,second_speaker,dialog_id,phrase_id)
	local phrase_npc=dlg_medkit_phrase_npc
	if phrase_npc==1 or phrase_npc==2 then
		return true
	end
	return false
end
function get_phrase_actor_thx(first_speaker,second_speaker,dialog_id,phrase_id)
	local phrase_npc=dlg_medkit_phrase_npc
	if phrase_npc==3 or phrase_npc==4 then
		return true
	end
	return false
end
function get_phrase_actor_fuck(first_speaker,second_speaker,dialog_id,phrase_id)
	local phrase_npc=dlg_medkit_phrase_npc
	if phrase_npc==5 then
		return true
	end
	return false
end
function npc_have_medkit(first_speaker,second_speaker)
	local npc=who_is_npc(first_speaker,second_speaker)
	return npc:object("medkit")~=nil or
		   npc:object("medkit_army")~=nil or
		   npc:object("medkit_scientic")~=nil
end
function npc_not_have_medkit(first_speaker,second_speaker)
	return npc_have_medkit(first_speaker,second_speaker)==false
end
function npc_have_one_medkit(first_speaker,second_speaker)
	if npc_have_more_medkits(first_speaker,second_speaker) then
		return false
	end
	return true
end
function npc_have_more_medkits(first_speaker,second_speaker)
	local npc=who_is_npc(first_speaker,second_speaker)
	local item_sections={
		[1]="medkit",
		[2]="medkit_army",
		[3]="medkit_scientic",
	}
	local needed=2
	local count=0
	local item_section
	local function calc(temp, item)
		if item:section()==item_section then
			count=count+1
		end
	end
	for k,v in ipairs(item_sections) do
		item_section=v
		npc:iterate_inventory(calc,actor)
	end
	return count>=needed
end
function transfer_medkit_to_actor(first_speaker,second_speaker)
	local actor=who_is_actor(first_speaker,second_speaker)
	local npc=who_is_npc(first_speaker,second_speaker)
	if npc:object("medkit")~=nil then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"medkit")
	elseif npc:object("medkit_army")~=nil then
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"medkit_army")
	else
		dialogs.relocate_item_section_to_actor(first_speaker,second_speaker,"medkit_scientic")
	end
end
function prob_give_last_medkit()
	if is_good_reputation() then
		return math.random(100)<60
	elseif is_bad_reputation() then
		return false
	else
		return math.random(100)<20
	end
end
function prob_give_medkit()
	if is_good_reputation() then
		return math.random(100)<90
	elseif is_bad_reputation() then
		return false
	else
		return math.random(100)<50
	end
end


------------------------------ ARS CoP MOD v0.5.x ------------------------------
--[[

If you're going to use the whole of this script or its parts in your own creative 
developments for the S.T.A.L.K.E.R. game. Leave the copyrights, note the real
author(s) and don't claim others' ideas and their realization to be your own ones.
It's just simple Modmakers' Ethics. Thank you!

Если вы собираетесь использовать данный скрипт целиком или частично в своих 
разработках по игре S.T.A.L.K.E.R. Не удаляйте копирайты, указывайте настоящего 
автора(ов) и не выдавайте чужие идеи и их реализацию за свои. Ведь это элементарная 
этика модостроителей! Спасибо за понимание.

]]--