ItemModule = {}

ItemModule['neutralItem'] = {
	--Tier 1
	['item_arcane_ring'] = 1,
	['item_broom_handle'] = 1,
	['item_elixer'] = 1,
	['item_faded_broach'] = 1,
	-- ['item_iron_talon'] = 1,
	['item_keen_optic'] = 1,
	-- ['item_mango_tree'] = 1,
	['item_ocean_heart'] = 1,
	-- ['item_poor_mans_shield'] = 1,
	-- ['item_royal_jelly'] = 1,
	['item_trusty_shovel'] = 1,
	['item_ironwood_tree'] = 1,
	['item_mysterious_hat'] = 1,
	['item_chipped_vest'] = 1,
	['item_possessed_mask'] = 1,
	--Tier 2
	-- ['item_clumsy_net'] = 2,
	['item_dragon_scale'] = 2,
	['item_essence_ring'] = 2,
	['item_grove_bow'] = 2,
	['item_imp_claw'] = 2,
	['item_nether_shawl'] = 2,
	['item_philosophers_stone'] = 2,
	['item_pupils_gift'] = 2,
	['item_ring_of_aquila'] = 2,
	-- ['item_vampire_fangs'] = 2,
	['item_vambrace'] = 2,
	['item_quicksilver_amulet'] = 2,
	['item_bullwhip'] = 2,
	--Tier 3
	-- ['item_craggy_coat'] = 3,
	['item_enchanted_quiver'] = 3,
	-- ['item_greater_faerie_fire'] = 3,
	['item_helm_of_the_undying'] = 3,
	['item_mind_breaker'] = 3,
	['item_orb_of_destruction'] = 3,
	['item_paladin_sword'] = 3,
	['item_quickening_charm'] = 3,
	-- ['item_repair_kit'] = 3,
	['item_spider_legs'] = 3,
	['item_third_eye'] = 3,
	['item_spy_gadget'] = 3,
	['item_titan_sliver'] = 3,
	['item_elven_tunic'] = 3,
	['item_cloak_of_flames'] = 3,
	['item_ceremonial_robe'] = 3,
	['item_psychic_headband'] = 3,
	--Tier 4
	['item_flicker'] = 4,
	['item_havoc_hammer'] = 4,
	['item_illusionsts_cape'] = 4,
	-- ['item_panic_button'] = 4,
	['item_minotaur_horn'] = 4,
	['item_ninja_gear'] = 4,
	-- ['item_princes_knife'] = 4,
	['item_spell_prism'] = 4,
	['item_the_leveller'] = 4,
	['item_timeless_relic'] = 4,
	-- ['item_witless_shako'] = 4,
	['item_penta_edged_sword'] = 4,
	['item_stormcrafter'] = 4,
	['item_trickster_cloak'] = 4,
	--Tier 5
	['item_apex'] = 5,
	['item_ballista'] = 5,
	['item_demonicon'] = 5,
	['item_desolator_2'] = 5,
	['item_ex_machina'] = 5,
	['item_fallen_sky'] = 5,
	['item_force_boots'] = 5,
	['item_fusion_rune'] = 5,
	['item_mirror_shield'] = 5,
	['item_phoenix_ash'] = 5,
	['item_pirate_hat'] = 5,
	['item_seer_stone'] = 5,
	-- ['item_recipe_trident'] = 5,
	-- ['item_woodland_striders'] = 5,
	['item_giants_ring'] = 5,
	['item_book_of_shadows'] = 5,
}

ItemModule['earlyGameItem'] = {
	 "item_tango_single",
	 "item_clarity",
	 "item_faerie_fire",
	 "item_tango",  
	 "item_flask", 
	 "item_infused_raindrop",
	 "item_quelling_blade", 
	 "item_stout_shield", 
	 "item_magic_wand",
	 "item_bottle",  
	 "item_soul_ring",  
	 "item_bracer",
	 "item_wraith_band",
	 "item_null_talisman", 
	 "item_dust",
	 "item_ward_observer",
	 "item_hand_of_midas",
	 "item_ancient_janggo"
	 --"item_tpscroll"
}

ItemModule['earlyBoots'] = {  
	"item_phase_boots", 
	"item_power_treads", 
	"item_tranquil_boots", 
	"item_arcane_boots"  
}

ItemModule["basic_items"] = {    
	"item_aegis";
	"item_courier";
	"item_boots_of_elves";
	"item_belt_of_strength";
	"item_blade_of_alacrity";
	"item_blades_of_attack";
	"item_blight_stone";
	"item_blink";
	"item_boots";
	"item_bottle";
	"item_broadsword";
	"item_chainmail";
	"item_cheese";
	"item_circlet";
	"item_clarity";
	"item_claymore";
	"item_cloak";
	"item_demon_edge";
	"item_dust";
	"item_eagle";
	"item_enchanted_mango";
	"item_energy_booster";
	"item_faerie_fire";
	"item_flying_courier";
	"item_gauntlets";
	"item_gem";
	"item_ghost";
	"item_gloves";
	"item_flask";
	"item_helm_of_iron_will";
	"item_hyperstone";
	"item_infused_raindrop";
	"item_branches";
	"item_javelin";
	"item_magic_stick";
	"item_mantle";
	"item_mithril_hammer";
	"item_lifesteal";
	"item_mystic_staff";
	"item_ward_observer";
	"item_ogre_axe";
	"item_orb_of_venom";
	"item_platemail";
	"item_point_booster";
	"item_quarterstaff";
	"item_quelling_blade";
	"item_reaver";
	"item_refresher_shard";
	"item_ring_of_health";
	"item_ring_of_protection";
	"item_ring_of_regen";
	"item_robe";
	"item_relic";
	"item_sobi_mask";
	"item_ward_sentry";
	"item_shadow_amulet";
	"item_slippers";
	"item_smoke_of_deceit";
	"item_staff_of_wizardry";
	"item_stout_shield";
	"item_talisman_of_evasion";
	"item_tango";
	"item_tango_single";
	"item_tome_of_knowledge";
	"item_tpscroll";
	"item_ultimate_orb";
	"item_vitality_booster";
	"item_void_stone";
	"item_wind_lace";
	"item_ring_of_tarrasque";
	"item_crown";    
	"item_blitz_knuckles";    
	"item_voodoo_mask";
	"item_fluffy_hat";
	"item_aghanims_shard";
}

ItemModule["item_abyssal_blade"] = { "item_basher"; "item_vanguard"; "item_recipe_abyssal_blade" }

ItemModule["item_aether_lens"] = { "item_void_stone"; "item_energy_booster"; "item_recipe_aether_lens" }

ItemModule["item_ultimate_scepter"] = { "item_point_booster"; "item_ogre_axe"; "item_staff_of_wizardry"; "item_blade_of_alacrity" }

ItemModule["item_arcane_boots"] = { "item_boots"; "item_energy_booster"}

ItemModule["item_armlet"] = { "item_helm_of_iron_will"; "item_gloves"; "item_blades_of_attack"; "item_recipe_armlet" }

ItemModule["item_assault"] = { "item_platemail"; "item_hyperstone"; "item_recipe_assault"; "item_buckler" }

ItemModule["item_bfury"] = { "item_quelling_blade"; "item_pers"; "item_broadsword"; "item_claymore" }

ItemModule["item_black_king_bar"] = { "item_ogre_axe"; "item_mithril_hammer"; "item_recipe_black_king_bar" }

ItemModule["item_blade_mail"] = {  "item_chainmail"; "item_broadsword"; "item_recipe_blade_mail" }

ItemModule["item_bloodstone"] = { "item_soul_booster" ; "item_kaya"; "item_voodoo_mask" }

ItemModule["item_bloodthorn"] = { "item_orchid"; "item_hyperstone"; "item_recipe_bloodthorn" }

ItemModule["item_travel_boots"] = { "item_boots"; "item_recipe_travel_boots" }

ItemModule["item_travel_boots_2"] = { "item_travel_boots"; "item_recipe_travel_boots" }

ItemModule["item_bracer"] = { "item_gauntlets"; "item_circlet"; "item_recipe_bracer" }

ItemModule["item_buckler"] = { "item_ring_of_protection"; "item_recipe_buckler" }

ItemModule["item_butterfly"] = { "item_talisman_of_evasion"; "item_eagle"; "item_quarterstaff" }

ItemModule["item_crimson_guard"] = { "item_vanguard"; "item_helm_of_iron_will"; "item_recipe_crimson_guard" }

ItemModule["item_lesser_crit"] = { "item_broadsword"; "item_blades_of_attack"; "item_recipe_lesser_crit" }

ItemModule["item_greater_crit"] = { "item_lesser_crit"; "item_demon_edge"; "item_recipe_greater_crit" }

ItemModule["item_dagon"] = { "item_crown"; "item_staff_of_wizardry"; "item_recipe_dagon" }

ItemModule["item_dagon_2"] = { "item_dagon"; "item_recipe_dagon" }

ItemModule["item_dagon_3"] = { "item_dagon_2"; "item_recipe_dagon" }

ItemModule["item_dagon_4"] = { "item_dagon_3"; "item_recipe_dagon" }

ItemModule["item_dagon_5"] = { "item_dagon_4"; "item_recipe_dagon" }

ItemModule["item_desolator"] = { "item_mithril_hammer"; "item_mithril_hammer"; "item_blight_stone" }

ItemModule["item_diffusal_blade"] = { "item_blade_of_alacrity"; "item_blade_of_alacrity"; "item_robe"; "item_recipe_diffusal_blade" }

ItemModule["item_diffusal_blade_2"] = { "item_diffusal_blade"; "item_recipe_diffusal_blade" }

ItemModule["item_dragon_lance"] = { "item_boots_of_elves"; "item_boots_of_elves"; "item_ogre_axe" }

ItemModule["item_ancient_janggo"] = { "item_wind_lace"; "item_belt_of_strength"; "item_robe"; "item_recipe_ancient_janggo" }

ItemModule["item_echo_sabre"] = { "item_oblivion_staff"; "item_ogre_axe" }

ItemModule["item_ethereal_blade"] = { "item_ghost"; "item_eagle" }

ItemModule["item_cyclone"] = { "item_wind_lace"; "item_void_stone"; "item_staff_of_wizardry"; "item_recipe_cyclone" }

ItemModule["item_skadi"] = { "item_point_booster"; "item_ultimate_orb"; "item_ultimate_orb" }

ItemModule["item_force_staff"] = { "item_staff_of_wizardry"; "item_fluffy_hat"; "item_recipe_force_staff" }

ItemModule["item_glimmer_cape"] = { "item_cloak"; "item_shadow_amulet"; "item_recipe_glimmer_cape" }

ItemModule["item_guardian_greaves"] = { "item_arcane_boots"; "item_mekansm"; "item_buckler"; "item_recipe_guardian_greaves" }

ItemModule["item_hand_of_midas"] = { "item_gloves"; "item_recipe_hand_of_midas" }

ItemModule["item_headdress"] = { "item_ring_of_regen"; "item_recipe_headdress" }

ItemModule["item_heart"] = { "item_vitality_booster"; "item_reaver"; "item_recipe_heart" }

ItemModule["item_heavens_halberd"] = { "item_sange"; "item_talisman_of_evasion"; "item_recipe_heavens_halberd"}

ItemModule["item_helm_of_the_dominator"] = { "item_helm_of_iron_will"; "item_crown"; "item_recipe_helm_of_the_dominator" }

ItemModule["item_hood_of_defiance"] = { "item_ring_of_health"; "item_cloak"; "item_ring_of_regen" }

ItemModule["item_hurricane_pike"] = { "item_dragon_lance"; "item_force_staff"; "item_recipe_hurricane_pike" }

ItemModule["item_iron_talon"] = { "item_quelling_blade"; "item_ring_of_protection"; "item_recipe_iron_talon" }

ItemModule["item_sphere"] = { "item_pers"; "item_ultimate_orb"; "item_recipe_sphere" }

ItemModule["item_lotus_orb"] = { "item_pers"; "item_platemail"; "item_energy_booster" }

ItemModule["item_maelstrom"] = { "item_javelin"; "item_mithril_hammer" }

ItemModule["item_magic_wand"] = { "item_branches"; "item_branches"; "item_magic_stick"; "item_recipe_magic_wand" }

ItemModule["item_manta"] = { "item_yasha"; "item_ultimate_orb"; "item_recipe_manta" }

ItemModule["item_mask_of_madness"] = { "item_lifesteal"; "item_quarterstaff" }

ItemModule["item_medallion_of_courage"] = { "item_chainmail"; "item_sobi_mask"; "item_blight_stone" }

ItemModule["item_mekansm"] = { "item_headdress"; "item_chainmail"; "item_recipe_mekansm" }

ItemModule["item_mjollnir"] = { "item_maelstrom"; "item_hyperstone"; "item_recipe_mjollnir" }

ItemModule["item_monkey_king_bar"] = { "item_blitz_knuckles"; "item_javelin"; "item_demon_edge"; "item_recipe_monkey_king_bar" }

ItemModule["item_moon_shard"] = { "item_hyperstone"; "item_hyperstone"}

ItemModule["item_necronomicon"] = { "item_sobi_mask"; "item_sobi_mask"; "item_belt_of_strength"; "item_recipe_necronomicon" }

ItemModule["item_necronomicon_2"] = { "item_necronomicon"; "item_recipe_necronomicon" }

ItemModule["item_necronomicon_3"] = { "item_necronomicon_2"; "item_recipe_necronomicon" }
	    
ItemModule["item_null_talisman"] = { "item_mantle"; "item_circlet"; "item_recipe_null_talisman" }

ItemModule["item_oblivion_staff"] = { "item_quarterstaff"; "item_robe"; "item_sobi_mask" }

ItemModule["item_octarine_core"] = { "item_soul_booster"; "item_aether_lens" }

ItemModule["item_orchid"] = { "item_oblivion_staff"; "item_oblivion_staff"; "item_recipe_orchid" }

ItemModule["item_pers"] = { "item_ring_of_health"; "item_void_stone" }

ItemModule["item_phase_boots"] = { "item_boots"; "item_chainmail"; "item_blades_of_attack" }

ItemModule["item_pipe"] = { "item_hood_of_defiance"; "item_headdress"; "item_recipe_pipe" }

ItemModule["item_poor_mans_shield"] = { "item_stout_shield"; "item_slippers"; "item_slippers" }

ItemModule["item_power_treads_agi"] = { "item_boots"; "item_boots_of_elves"; "item_gloves" }

ItemModule["item_power_treads_int"] = { "item_boots"; "item_robe"; "item_gloves" }

ItemModule["item_power_treads_str"] = { "item_boots"; "item_belt_of_strength"; "item_gloves" }

ItemModule["item_power_treads"] = { "item_boots"; "item_belt_of_strength"; "item_gloves" }

ItemModule["item_radiance"] = { "item_relic"; "item_recipe_radiance" }

ItemModule["item_rapier"] = { "item_relic"; "item_demon_edge" }

ItemModule["item_refresher"] = { "item_pers"; "item_pers"; "item_recipe_refresher" }
				
ItemModule["item_ring_of_aquila"] = { "item_ring_of_basilius"; "item_crown" }
			    
ItemModule["item_ring_of_basilius"] = {  "item_sobi_mask" ; "item_recipe_ring_of_basilius" }
				
ItemModule["item_rod_of_atos"] = { "item_crown"; "item_crown"; "item_staff_of_wizardry"; "item_recipe_rod_of_atos" }

ItemModule["item_sange"] = { "item_belt_of_strength"; "item_ogre_axe"; "item_recipe_sange" }
			    
ItemModule["item_sange_and_yasha"] = { "item_yasha"; "item_sange" }

ItemModule["item_satanic"] = { "item_lifesteal"; "item_reaver"; "item_claymore" }

ItemModule["item_sheepstick"] = { "item_mystic_staff"; "item_ultimate_orb"; "item_void_stone" }

ItemModule["item_invis_sword"] = { "item_shadow_amulet"; "item_broadsword"; "item_blitz_knuckles" }

ItemModule["item_shivas_guard"] = { "item_platemail"; "item_mystic_staff"; "item_recipe_shivas_guard" }

ItemModule["item_silver_edge"] = { "item_invis_sword"; "item_oblivion_staff"; "item_recipe_silver_edge" }

ItemModule["item_basher"] = { "item_mithril_hammer"; "item_belt_of_strength"; "item_recipe_basher" }

ItemModule["item_solar_crest"] = { "item_medallion_of_courage"; "item_wind_lace"; "item_crown"; "item_recipe_solar_crest" }

ItemModule["item_soul_booster"] = { "item_point_booster"; "item_vitality_booster"; "item_energy_booster" }

ItemModule["item_soul_ring"] = { "item_ring_of_protection"; "item_gauntlets"; "item_gauntlets"; "item_recipe_soul_ring" }

ItemModule["item_tranquil_boots"] = { "item_wind_lace"; "item_boots"; "item_ring_of_regen" }

ItemModule["item_urn_of_shadows"] = { "item_sobi_mask" ; "item_circlet"; "item_ring_of_protection"; "item_recipe_urn_of_shadows" }

ItemModule["item_vanguard"] = { "item_vitality_booster"; "item_ring_of_health"  }

ItemModule["item_veil_of_discord"] = { "item_crown"; "item_ring_of_basilius"; "item_recipe_veil_of_discord" }

ItemModule["item_vladmir"] = { "item_ring_of_basilius"; "item_buckler"; "item_blades_of_attack"; "item_lifesteal"; "item_recipe_vladmir" }

ItemModule["item_wraith_band"] = { "item_slippers"; "item_circlet"; "item_recipe_wraith_band" }

ItemModule["item_yasha"] = { "item_boots_of_elves"; "item_blade_of_alacrity"; "item_recipe_yasha" }

---------- NEW ITEM BELOW ----------------
ItemModule["item_meteor_hammer"] = { "item_crown"; "item_pers"; "item_recipe_meteor_hammer" }
--aeon disk
ItemModule["item_aeon_disk"] = { "item_vitality_booster"; "item_energy_booster"; "item_recipe_aeon_disk" }

ItemModule["item_spirit_vessel"] = { "item_urn_of_shadows"; "item_vitality_booster"; "item_recipe_spirit_vessel" }

ItemModule["item_nullifier"] = { "item_helm_of_iron_will"; "item_relic" }
--kaya
ItemModule["item_kaya"] = { "item_robe"; "item_staff_of_wizardry"; "item_recipe_kaya" }
--kaya and sange
ItemModule["item_kaya_and_sange"] = { "item_sange"; "item_kaya" }
--yasha and kaya
ItemModule["item_yasha_and_kaya"] = { "item_yasha"; "item_kaya" }
--item_holy_locket
ItemModule["item_holy_locket"] = { "item_magic_wand"; "item_headdress"; "item_fluffy_hat"; "item_energy_booster"; "item_recipe_holy_locket" }
--Aghanims Scpeter Upgrade
ItemModule["item_ultimate_scepter_2"] = { "item_ultimate_scepter"; "item_recipe_ultimate_scepter_2" }

---------- 7.28 NEW ITEMS ---------------
ItemModule["item_falcon_blade"] = { "item_fluffy_hat"; "item_sobi_mask"; "item_blades_of_attack"; "item_recipe_falcon_blade" }
ItemModule["item_orb_of_corrosion"] = { "item_blight_stone"; "item_orb_of_venom"; "item_fluffy_hat"; "item_recipe_orb_of_corrosion" }
ItemModule["item_witch_blade"] = { "item_blitz_knuckles"; "item_chainmail"; "item_robe"; "item_recipe_witch_blade" }
ItemModule["item_gungir"] = { "item_maelstrom"; "item_rod_of_atos"; "item_recipe_gungir" }
ItemModule["item_mage_slayer"] = { "item_cloak"; "item_blade_of_alacrity"; "item_claymore"; "item_recipe_mage_slayer" }
ItemModule["item_eternal_shroud"] = { "item_hood_of_defiance"; "item_voodoo_mask"; "item_recipe_eternal_shroud" }
ItemModule["item_helm_of_the_dominator_2"] = { "item_helm_of_the_dominator"; "item_ultimate_orb"; "item_recipe_helm_of_the_dominator_2" }
ItemModule["item_overwhelming_blink"] = { "item_blink"; "item_reaver"; "item_recipe_overwhelming_blink" }
ItemModule["item_swift_blink"] = { "item_blink"; "item_eagle"; "item_recipe_swift_blink" }
ItemModule["item_arcane_blink"] = { "item_blink"; "item_mystic_staff"; "item_recipe_arcane_blink" }
ItemModule["item_wind_waker"] = { "item_cyclone"; "item_mystic_staff"; "item_recipe_wind_waker" }

--Normalize some item names 
function ItemModule.NormItemName(item_name)
	if item_name == "item_power_treads_agi" or  item_name == "item_power_treads_str" or  item_name == "item_power_treads_int" then
		return 'item_power_treads';
	--[[elseif item_name == 'item_shadow_blade' then
		return 'item_invis_sword';
	elseif item_name == 'item_diffusal_blade_1' then
		return 'item_diffusal_blade';	
	elseif item_name == 'item_eye_of_skadi' then
		return 'item_skadi';]]--		
	end
	return item_name;
end

--Check if hero have the current itemToBuy in main inventory
function ItemModule.IsItemInHero(item_name)
	if item_name == 'item_infused_raindrop' then 
		return false; 
	else 
		local bot = GetBot();
		item_name = ItemModule.NormItemName(item_name);
		local slot = bot:FindItemSlot(item_name);
		local slotType = bot:GetItemSlotType(slot);
		return slotType == ITEM_SLOT_TYPE_MAIN or slotType == ITEM_SLOT_TYPE_BACKPACK;	
	end
end

--Get basic item recursively from ItemUtility data
function ItemModule.GetBasicItems( ... )
    local basicItemTable = {}
    for i,v in pairs(...) do
        if ItemModule[v] ~= nil and ItemModule.IsItemInHero(v) == false then
            for _,w in pairs(ItemModule.GetBasicItems(ItemModule[v])) do
				basicItemTable[#basicItemTable+1] = w;
            end
        elseif ItemModule[v] == nil and ItemModule.IsItemInHero(v) == false then
			basicItemTable[#basicItemTable+1] = v;
        end
    end
    return basicItemTable
end

function ItemModule.GetBasicItemsNew( ... )
    local basicItemTable = {}
    for i,v in pairs(...) do
		--print(tostring(v))
		local comps = GetItemComponents(v);
		--print(tostring(#comps))
        if #comps > 0 and ItemModule.IsItemInHero(v) == false then
            for _,w in pairs(ItemModule.GetBasicItems(comps[1])) do
				basicItemTable[#basicItemTable+1] = w;
            end
        elseif #comps == 0 and ItemModule.IsItemInHero(v) == false then
			basicItemTable[#basicItemTable+1] = v;
        end
    end
    return basicItemTable
end

function ItemModule.GetEmptyInventoryAmount(bot)
	local amount = 0;
	for i=0,8 do	
		local item = bot:GetItemInSlot(i);
		if item == nil then
			amount = amount + 1;
		end
	end
	return amount;
end

function ItemModule.RemoveItem(tTable, item_name)
	local temp = {};
	for i=1, #tTable do
		if tTable[i] ~= item_name then
			temp[#temp+1] = tTable[i];
		end
	end
	return temp;
end

function ItemModule.GetItemCharges(bot, item_name)
	local charges = 0;
	for i = 0, 15 do
		local item = bot:GetItemInSlot(i);
		if item ~= nil and item:GetName() == item_name then
			charges = charges + item:GetCurrentCharges();
		end
	end
	return charges;
end

function ItemModule.HasItem(bot, item_name)
	return bot:FindItemSlot(item_name) >= 0;
end

function ItemModule.UpdateBuyBootStatus(bot)
	local bootsSlot = bot:FindItemSlot('item_boots');
	if bootsSlot == - 1 then
		for i=1,#ItemModule['earlyBoots'] do
		    bootsSlot = bot:FindItemSlot(ItemModule['earlyBoots'][i]);
			if bootsSlot >= 0 then
				break;
			end
		end
	end
	return bootsSlot >= 0;
end

function ItemModule.GetMainInvLessValItemSlot(bot)
	local minPrice = 10000;
	local minSlot = -1;
	for i=0,5,1 do
		local item = bot:GetItemInSlot(i);
		if  item ~= nil and item:GetName() ~= "item_aegis" 
		    and item:GetName() ~= "item_refresher_shard" 
		    and item:GetName() ~= "item_cheese" 
		    and item:GetName() ~= "item_bloodstone" 
		then
			local cost = GetItemCost(item:GetName()); 
			if  cost < minPrice then
				minPrice = cost;
				minSlot = i;
			end
		end
	end
	return minSlot;
end

function ItemModule.GetBPInvLessValItemSlot(bot)
	local minPrice = 10000;
	local minSlot = -1;
	for i=6,9,1 do
		local item = bot:GetItemInSlot(i);
		if  item ~= nil 
		then
			local cost = GetItemCost(item:GetName()); 
			if  cost < minPrice then
				minPrice = cost;
				minSlot = i;
			end
		end
	end
	return minSlot;
end

function ItemModule.GetNeutralItemTier(sName)
	if ItemModule['neutralItem'][sName] ~= nil then
		return ItemModule['neutralItem'][sName];
	end
	return 0;
end

function ItemModule.GetNeutralItemInBP(bot)
	for i=6, 9 do
		local bpit = bot:GetItemInSlot(i);
		if bpit ~= nil and ItemModule.GetNeutralItemTier(bpit:GetName()) > 0 then
			return i, bpit;
		end
	end
	return -1, nil;
end

function ItemModule.IsRecipeNeutralItem(sItem)
	return sItem == "item_recipe_ironwood_tree" or sItem == "item_recipe_vambrace" or sItem == "item_recipe_fallen_sky" or sItem == "item_recipe_tri";
end

function ItemModule.CanDropNeutralItem(bot)
	if ItemModule.GetEmptySlotAmount(bot, ITEM_SLOT_TYPE_BACKPACK) <= 3 and bot:DistanceFromFountain() < 200 then
		for i=6,8 do	
			local item = bot:GetItemInSlot(i);
			if item ~= nil and ItemModule.GetNeutralItemTier(item:GetName()) > 0 then
				return true, item;
			end
		end
	end
	return false, nil;
end

function ItemModule.GetLowestNeutralItemInBackpackIfExcess(bot)
	local lowest_lvl = 6;
	local lowest = nil;
	local num_n_item = 0;
	for i=6,8 do	
		local item = bot:GetItemInSlot(i);
		if item ~= nil 
		then
			local curr_lvl = ItemModule.GetNeutralItemTier(item:GetName());
			if curr_lvl > 0 then num_n_item = num_n_item + 1 end
			if curr_lvl > 0 and curr_lvl < lowest_lvl then
				lowest_lvl = curr_lvl;
				lowest = item;
			end
		end
	end
	return num_n_item, lowest;
end

function ItemModule.CanDropExcessNeutralItem(bot)
	local neutral_item = bot:GetItemInSlot(16);
	if neutral_item ~= nil then
		if ItemModule.GetEmptySlotAmount(bot, ITEM_SLOT_TYPE_BACKPACK) == 0  
		   and ItemModule.GetEmptySlotAmount(bot, ITEM_SLOT_TYPE_MAIN) == 0  
		then
			local num, lowest = ItemModule.GetLowestNeutralItemInBackpackIfExcess(bot)
			if num >= 2 then
				return true, lowest;
			end
		end
	end
	return false, nil;
end

function ItemModule.GetEmptySlotAmount(bot, nType)
	local startIdx = 0;
	local endIdx = 16;
	if nType == ITEM_SLOT_TYPE_MAIN then
		startIdx = 0;
		endIdx = 5;
	elseif nType == ITEM_SLOT_TYPE_BACKPACK then
		startIdx = 6;
		endIdx = 8;
	elseif nType == ITEM_SLOT_TYPE_STASH then	
		startIdx = 9;
		endIdx = 14;
	end
	local amount = 0;
	for i=startIdx,endIdx do	
		local item = bot:GetItemInSlot(i);
		if item == nil then
			amount = amount + 1;
		end
	end
	return amount;
end

function ItemModule.IsMeepoClone(bot)
	local nItem = ItemModule.GetEmptySlotAmount(bot, ITEM_SLOT_TYPE_MAIN);
	return bot:GetUnitName() == "npc_dota_hero_meepo" and nItem >= 5;
end

function ItemModule.CanCastNeutralItem(bot, item_name)
	local neutral_item_slot = 16;
	local n_item = bot:GetItemInSlot(neutral_item_slot);
	if n_item ~= nil and n_item:GetName() == item_name then
		return n_item;
	end
	return nil;
end

function ItemModule.IsNeutralItemSlotEmpty(bot)
	local neutral_item_slot = 16;
	return bot:GetItemInSlot(neutral_item_slot) == nil;
end

function ItemModule.GetHighestTierNeutralItem(bot)
	local maxLvl = 0;
	local highest_slot = -1;
	for i=6,8 do	
		local item = bot:GetItemInSlot(i);
		if item ~= nil then
			local curLvl = ItemModule.GetNeutralItemTier(item:GetName());
			if curLvl > maxLvl then
				maxLvl = curLvl;
				highest_slot = i;
			end
		end
	end
	return maxLvl, highest_slot;
end

function ItemModule.CanSwapNeutralItem(bot)
	local neutral_item_slot = 16;
	local active_neutral_item = bot:GetItemInSlot(neutral_item_slot);
	if active_neutral_item ~= nil then
		local ani_lvl = ItemModule.GetNeutralItemTier(active_neutral_item:GetName());
		local nani_lvl, sni_slot = ItemModule.GetHighestTierNeutralItem(bot);
		if sni_slot ~= -1 and ani_lvl < nani_lvl then
			return true, neutral_item_slot, sni_slot; 
		end
	else
		local nani_lvl, sni_slot = ItemModule.GetHighestTierNeutralItem(bot);
		if sni_slot ~= -1 then
			return true, neutral_item_slot, sni_slot; 
		end
	end
	return false, -1, -1;
end

return ItemModule