function get_sets()
		
	sets.aftercast_Idle_noSub = {main="Owleyes",sub="Genbu's Shield",ammo="Incantor Stone",
		head="Savant's bonnet +2",neck="Twilight Torque",ear1="Lifestorm Earring",ear2="Loquacious Earring",
		body="Hagondes Coat",hands="Serpentes Cuffs",ring1="Sangoma Ring",ring2="Maquette Ring",
		back="Shadow Mantle",waist="Korin Obi",legs="Nares Trews",feet="Serpentes Sabots"}
	
	sets.aftercast_Idle_Sub = {main="Owleyes",sub="Genbu's Shield",ammo="Incantor Stone",
		head="Savant's bonnet +2",neck="Twilight Torque",ear1="Savant's Earring",ear2="Loquacious Earring",
		body="Hagondes Coat",hands="Serpentes Cuffs",ring1="Sangoma Ring",ring2="Maquette Ring",
		back="Shadow Mantle",waist="Korin Obi",legs="Nares Trews",feet="Serpentes Sabots"}
	
	sets.aftercast_Idle = sets.aftercast_Idle_noSub
		
	sets.precast_FastCast = {ammo="Incantor Stone",head="Nahtirah Hat",ear2="Loquacious Earring",
		body="Anhur Robe",hands="Gendewitha Gages",back="Swith Cape",legs="Orvail Pants",feet="Chelona Boots"}
	
	sets.Resting = {main="Chatoyant Staff",sub="Mephitis Grip",
		head="Nahtirah Hat",neck="Twilight Torque",ear1="Lifestorm Earring",ear2="Loquacious Earring",
		body="Hagondes Coat",hands="Nares Cuffs",ring1="Sangoma Ring",ring2="Maquette Ring",
		back="Shadow Mantle",waist="Korin Obi",legs="Nares Trews",feet="Chelona Boots"}
	
	sets.midcast_ElementalMagic = {main="Atinian Staff",sub="Wizzan Grip",ammo="Witchstone",
		head="Nares Cap",neck="Eddy Necklace",ear1="Hecate's Earring",ear2="Novio Earring",
		body="Hagondes Coat",hands="Yaoyotl Gloves",ring1="Strendu Ring",ring2="Icesoul Ring",
		back="Searing Cape",waist="Maniacus Sash",legs="Hagondes Pants",feet="Bokwus Boots"}
	
	sets.midcast_DarkMagic = {main="Chatoyant Staff",sub="Arbuda Grip",ammo="Hasty Pinion +1",
		head="Appetence Crown",neck="Aesir Torque",ear1="Hirudinea Earring",ear2="Loquacious Earring",
		body="Hedera Cotehardie",hands="Ayao's Gages",ring1="Balrahn's Ring",ring2="Excelsis Ring",
		back="Merciful Cape",waist="Goading Belt",legs="Auspex Slops",feet="Bokwus Boots"}
	
	sets.midcast_EnfeeblingMagic = {main="Atinian Staff",sub="Mephitis Grip",ammo="Savant's Treatise",
		head="Nahtirah Hat",neck="Eddy Necklace",ear1="Lifestorm Earring",ear2="Psystorm Earring",
		body="Hedera Cotehardie",hands="Hagondes Cuffs",ring1="Sangoma Ring",ring2="Maquette Ring",
		back="Merciful Cape",waist="Cascade Belt",legs="Orvail Pants",feet="Rubeus Boots"}
	
	sets.midcast_Impact = {main="Atinian Staff",sub="Wizzan Grip",ammo="Witchstone",
		neck="Eddy Necklace",ear1="Hecate's Earring",ear2="Novio Earring",
		hands="Yaoyotl Gloves",ring1="Strendu Ring",ring2="Icesoul Ring",
		back="Searing Cape",waist="Maniacus Sash",legs="Hagondes Pants",feet="Bokwus Boots"}
	
	sets.midcast_Embrava = {main="Kirin's Pole",sub="Fulcio Grip",ammo="Savant's Treatise",
		head="Svnt. Bonnet +2",neck="Colossus's Torque",ear1="Lifestorm Earring",ear2="Loquacious Earring",
		body="Anhur Robe",hands="Savant's Bracers +2",
		back="Merciful Cape",waist="Cascade Belt",legs="Shedir Seraweels",feet="Rubeus Boots"}
	
	sets.midcast_EnhancingMagic = {main="Kirin's Pole",sub="Fulcio Grip",ammo="Incantor Stone",
		head="Nahtirah Hat",neck="Colossus's Torque",ear1="Lifestorm Earring",ear2="Loquacious Earring",
		body="Anhur Robe",hands="Gendewitha Gages",
		back="Swith Cape",waist="Ninurta's Sash",legs="Orvail Pants",feet="Chelona Boots"}
	
	sets.precast_Stun = {main="Apamajas II",sub="Mephitis Grip",ranged="Aureole",
		head="Nahtirah Hat",neck="Eddy Necklace",ear1="Lifestorm Earring",ear2="Psystorm Earring",
		body="Hedera Cotehardie",hands="Gendewitha Gages",ring1="Sangoma Ring",ring2="Maquette Ring",
		back="Swith Cape",waist="Ninurta's Sash",legs="Bokwus Slops",feet="Argute Loafers +2"}
		
	
	sets.midcast_Cure = {main="Chatoyant Staff",head="Paean Mitra",neck="Phalaina Locket",
	body="Anhur Robe",hands="Bokwus Gloves",back="Oretanis's Cape",legs="Nares Trews"}
	
	sets.midcast_Helix = {main="Chatoyant Staff",sub="Wizzan Grip",ammo="Snow Sachet",
		head="Nahtirah Hat",neck="Stoicheion Medal",ear1="Hecate's Earring",ear2="Novio Earring",
		body="Nares Saio",hands="Nares Cuffs",ring1="Icesoul Ring",ring2="Icesoul Ring",
		back="Twilight Cape",waist="Wanion Belt",legs="Akasha Chaps",feet="Nares Clogs"}
	
	sets.midcast_Stoneskin = {main="Kirin's Pole",neck="Stone Gorget",waist="Siegel Sash",legs="Shedir Seraweels"}
	
	sets.Obi = {}
	sets.Obi.Fire = {waist='Karin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Earth = {waist='Dorin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Water = {waist='Suirin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Wind = {waist='Furin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Ice = {waist='Hyorin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Thunder = {waist='Rairin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Light = {waist='Korin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	sets.Obi.Dark = {waist='Anrin Obi',back='Twilight Cape',lring='Zodiac Ring'}
	
	sets.staves = {}
	
	sets.staves.damage = {}
	sets.staves.damage.Thunder = {main="Apamajas I"}
	sets.staves.damage.Fire = {main="Atar I"}
	
	sets.staves.accuracy = {}
	sets.staves.damage.Thunder = {main="Apamajas II"}
	sets.staves.damage.Ice = {main="Vourukasha II"}
	
	stuntarg = 'Shantotto'


end

function precast(spell)
	if spell.english == 'Impact' then
		equip(sets['precast_FastCast'],{body="Twilight Cloak"})
		if not buffactive['elemental seal'] then
			add_to_chat(8,'--------- Elemental Seal is down ---------')
		end
	
	elseif spell.skill=='ElementalMagic' and spell.cast_time < 3 then
		equip(sets.midcast_ElementalMagic)
		if spell.element == 'Earth' then
			equip({neck="Quanpur Necklace"})
		end
		if spell.element == world.weather_element or spell_element == world.day_element and sets.Obi[spell.element] then
			equip(sets.Obi[spell.element])
		end
	elseif spell.english == 'Stun' then
		equip(sets['precast_Stun'])
		if not buffactive.thunderstorm then
			add_to_chat(8,'--------- Thunderstorm is down ---------')
		elseif not buffactive.klimaform then
			add_to_chat(8,'----------- Klimaform is down -----------')
		end
		if stuntarg ~= 'Shantotto' then
			send_command('@input /t '..stuntarg..' ---- Byrth Stunned!!! ---- ')
		end
	else
		equip(sets['precast_FastCast'])
	end

	if (buffactive.alacrity or buffactive.celerity) and world.weather_element == spell.element then
		equip({feet='Argute Loafers +2'})
	end
end

function midcast(spell)
	if string.find(spell.english,'Cur') then 
		equip(sets.midcast_Cure)
		if spell.element == world.weather_element or spell_element == world.day_element then
			equip({main="Chatoyant Staff"},sets.Obi[spell.element])
		end
		if buffactive.rapture then
			equip({head="Savant's Bonnet +2"})
		end
	elseif spell.english == 'Impact' then
		local tempset = sets['midcast_Impact']
		tempset['body'] = 'Twilight Cloak'
		tempset['head'] = empty
		equip(tempset)
		if spell.element == world.weather_element or spell_element == world.day_element then
			equip(sets.Obi[spell.element])
		end
		if sets.staves.damage[spell.element] then
			equip(sets.staves.damage[spell.element])
		end
	elseif spell.skill=="ElementalMagic" then
		if string.find(spell.english,'helix') then
			equip(sets['midcast_Helix'])
		else
			equip(sets.midcast_ElementalMagic)
			if spell.element=='Earth' then
				equip({neck="Quanpur Necklace"})
			end
			if spell.element == world.weather_element or spell_element == world.day_element then
				equip(sets.Obi[spell.element])
			end
		end
		if buffactive.ebullience then
			equip({head="Savant's Bonnet +2"})
		end
		if buffactive.klimform then
			equip ({feet="Savant's Loafers +2"})
		end
	
	elseif spell.english == 'Stoneskin' then
		equip(sets['midcast_Stoneskin'])
	elseif spell.skill == 'EnhancingMagic' then
		if spell.english == 'Embrava' then
			equip(sets['midcast_Embrava'])
			if not buffactive.perpetuance then
				add_to_chat(8,'--------- Perpetuance is down ---------')
			end
			if not buffactive.accession then
				add_to_chat(8,'--------- Accession is down ---------')
			end
			if not buffactive.penury then
				add_to_chat(8,'--------- Penury is down ---------')
			end
		end
		if buffactive.perpetuance then
			equip(sets['midcast_EnhancingMagic'],{hands="Savant's Bracers +2"})
		else
			equip(sets['midcast_EnhancingMagic'])
		end
	else
		weathercheck(spell.element,sets['midcast_'..spell.skill])
	end
	
	if spell.english == 'Sneak' then
		send_command('@wait 1.8;cancel 71;')
	end
end		

function aftercast(spell)
	equip(sets['aftercast_Idle'])
	
	if spell.english == 'Sleep' or spell.english == 'Sleepga' then
		send_command('@wait 50;input /echo ------- '..spell.english..' is wearing off in 10 seconds -------')
	elseif spell.english == 'Sleep II' or spell.english == 'Sleepga II' then
		send_command('@wait 80;input /echo ------- '..spell.english..' is wearing off in 10 seconds -------')
	elseif spell.english == 'Break' or spell.english == 'Breakga' then
		send_command('@wait 20;input /echo ------- '..spell.english..' is wearing off in 10 seconds -------')
	end
end

function status_change(new,tab)
	if new == 'Resting' then
		equip(sets['Resting'])
	else
		equip(sets['aftercast_Idle'])
	end
end

function buff_change(status,gain_or_loss)
	if status == 'Sublimation: Complete' and gain_or_loss and not 'stunmode' then -- True whether gained or lost
		sets.aftercast_Idle = sets.aftercast_Idle_noSub
	elseif status == 'Sublimation: Activated' and gain_or_loss and not 'stunmode' then
		sets.aftercast_Idle = sets.aftercast_Idle_Sub
	end
	equip(sets.aftercast_Idle)
end

	

function self_command(command)
	if command == 'stuntarg' then
			stuntarg = target.name
	elseif command == 'stunmode' then
	windower.add_to_chat(100,'Stun Mode')
				if sets.aftercast_Idle ~= sets.precast_Stun then
						stunmode = true
						sets.aftercast_Idle = sets.precast_Stun
				elseif buffactive['Sublimation: Activated'] then
						stunmode = false
						sets.aftercast_Idle = sets.aftercast_Idle_Sub
				else
						stunmode = false
						sets.aftercast_Idle = sets.aftercast_Idle_noSub
				end
				equip(sets.aftercast_Idle)
		end
end



-- This function is user defined, but never called by GearSwap itself. It's just a user function that's only called from user functions. I wanted to check the weather and equip a weather-based set for some spells, so it made sense to make a function for it instead of replicating the conditional in multiple places.

function weathercheck(spell_element,set)
	if spell_element == world.weather_element or spell_element == world.day_element then
		equip(set,sets['Obi_'..spell_element])
	else
		equip(set)
	end
end