<commit_before>local OVALE, Ovale = ...
local OvaleScripts = Ovale.OvaleScripts

do
	local name = "ovale_monk"
	local desc = "[6.0.2] Ovale: Brewmaster, Windwalker"
	local code = [[
# Ovale monk script based on SimulationCraft.

Include(ovale_common)
Include(ovale_monk_spells)

AddCheckBox(opt_potion_agility ItemName(virmens_bite_potion) default)
AddCheckBox(opt_chi_burst SpellName(chi_burst) default)

AddFunction UsePotionAgility
{
	if CheckBoxOn(opt_potion_agility) and target.Classification(worldboss) Item(virmens_bite_potion usable=1)
}

AddFunction ExpelHarm
{
	Spell(expel_harm)
	Spell(expel_harm_glyphed)
}

AddFunction Guard
{
	Spell(guard)
	Spell(guard_glyphed)
}

AddFunction InterruptActions
{
	if not target.IsFriend() and target.IsInterruptible()
	{
		if target.InRange(spear_hand_strike) Spell(spear_hand_strike)
		if not target.Classification(worldboss)
		{
			if target.InRange(paralysis) Spell(paralysis)
			Spell(arcane_torrent_chi)
			if target.InRange(quaking_palm) Spell(quaking_palm)
			Spell(war_stomp)
		}
	}
}

###
### Brewmaster
###
# Based on SimulationCraft profile "Monk_Brewmaster_1h_T16M".
#	class=monk
#	spec=brewmaster
#	talents=http://us.battle.net/wow/en/tool/talent-calculator#fa!.00.11.
#	glyphs=fortifying_brew,fortuitous_spheres

# ActionList: BrewmasterPrecombatActions --> main, shortcd, cd

AddFunction BrewmasterPrecombatActions
{
	#flask,type=earth
	#food,type=mogu_fish_stew
	# CHANGE: Buff with Legacy of the White Tiger
	if BuffExpires(str_agi_int_buff any=1) Spell(legacy_of_the_white_tiger)
	#stance,choose=sturdy_ox
	Spell(stance_of_the_sturdy_ox)
	#snapshot_stats
}

AddFunction BrewmasterPrecombatShortCdActions
{
	unless BuffExpires(str_agi_int_buff any=1) and Spell(legacy_of_the_white_tiger)
		or Spell(stance_of_the_sturdy_ox)
	{
		#dampen_harm
		Spell(dampen_harm)
	}
}

AddFunction BrewmasterPrecombatCdActions
{
	unless BuffExpires(str_agi_int_buff any=1) and Spell(legacy_of_the_white_tiger)
		or Spell(stance_of_the_sturdy_ox)
	{
		#potion,name=virmens_bite
		UsePotionAgility()
	}
}

# ActionList: BrewmasterDefaultActions --> main, shortcd, cd

AddFunction BrewmasterDefaultActions
{
	#auto_attack
	#chi_brew,if=talent.chi_brew.enabled&chi.max-chi>=2&buff.elusive_brew_stacks.stack<=10
	if Talent(chi_brew_talent) and MaxChi() - Chi() >= 2 and BuffStacks(elusive_brew_stacks_buff) <= 10 Spell(chi_brew)
	#gift_of_the_ox,if=buff.gift_of_the_ox.react&incoming_damage_1500ms
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeActions()
}

AddFunction BrewmasterDefaultShortCdActions
{
	#chi_brew,if=talent.chi_brew.enabled&chi.max-chi>=2&buff.elusive_brew_stacks.stack<=10
	if Talent(chi_brew_talent) and MaxChi() - Chi() >= 2 and BuffStacks(elusive_brew_stacks_buff) <= 10 Spell(chi_brew)
	#dampen_harm,if=incoming_damage_1500ms&buff.fortifying_brew.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(fortifying_brew_buff) and BuffExpires(elusive_brew_activated_buff) Spell(dampen_harm)
	#elusive_brew,if=buff.elusive_brew_stacks.react>=9&buff.dampen_harm.down&buff.elusive_brew_activated.down
	if BuffStacks(elusive_brew_stacks_buff) >= 9 and BuffExpires(dampen_harm_buff) and BuffExpires(elusive_brew_activated_buff) Spell(elusive_brew)
	#serenity,if=talent.serenity.enabled&energy<=40
	if Talent(serenity_talent) and Energy() <= 40 Spell(serenity)
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStShortCdActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeShortCdActions()
}

AddFunction BrewmasterDefaultCdActions
{
	# CHANGE: Touch of Death if it will kill the mob.
	if target.Health() < Health() and BuffPresent(death_note_buff) Spell(touch_of_death)
	# CHANGE: Add interrupt actions missing from SimulationCraft action list.
	InterruptActions()
	# CHANGE: Break snares with Nimble Brew.
	if IsFeared() or IsRooted() or IsStunned() Spell(nimble_brew)
	#blood_fury,if=energy<=40
	if Energy() <= 40 Spell(blood_fury_apsp)
	#berserking,if=energy<=40
	if Energy() <= 40 Spell(berserking)
	#arcane_torrent,if=energy<=40
	if Energy() <= 40 Spell(arcane_torrent_chi)
	#dampen_harm,if=incoming_damage_1500ms&buff.fortifying_brew.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(fortifying_brew_buff) and BuffExpires(elusive_brew_activated_buff) Spell(dampen_harm)
	#fortifying_brew,if=incoming_damage_1500ms&buff.dampen_harm.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(dampen_harm_buff) and BuffExpires(elusive_brew_activated_buff) Spell(fortifying_brew)
	#invoke_xuen,if=talent.invoke_xuen.enabled&time>5
	if Talent(invoke_xuen_talent) and TimeInCombat() > 5 Spell(invoke_xuen)
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStCdActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeCdActions()
}

# ActionList: BrewmasterAoeActions --> main, shortcd, cd

AddFunction BrewmasterAoeActions
{
	# CHANGE: Ensure that Shuffle is never down.
	if BuffExpires(shuffle_buff) Spell(blackout_kick)
	#breath_of_fire,if=chi>=3&buff.shuffle.remains>=6&dot.breath_of_fire.remains<=1&target.debuff.dizzying_haze.up
	if Chi() >= 3 and BuffRemaining(shuffle_buff) >= 6 and target.DebuffRemaining(breath_of_fire_debuff) <= 1 and target.DebuffPresent(dizzying_haze_debuff) Spell(breath_of_fire)
	#chi_explosion,if=chi>=4
	if Chi() >= 4 Spell(chi_explosion_tank)
	#rushing_jade_wind,if=chi.max-chi>=1&talent.rushing_jade_wind.enabled
	if MaxChi() - Chi() >= 1 and Talent(rushing_jade_wind_talent) Spell(rushing_jade_wind)
	#keg_smash,if=chi.max-chi>=2&!buff.serenity.remains
	if MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) Spell(keg_smash)
	#chi_burst,if=talent.chi_burst.enabled&energy.time_to_max>3
	if Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) Spell(chi_burst)
	#chi_wave,if=talent.chi_wave.enabled&energy.time_to_max>3
	if Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 Spell(chi_wave)
	#zen_sphere,cycle_targets=1,if=talent.zen_sphere.enabled&!dot.zen_sphere.ticking
	if Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) Spell(zen_sphere)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&buff.shuffle.remains<=3&cooldown.keg_smash.remains>=gcd
	if Talent(rushing_jade_wind_talent) and BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() Spell(blackout_kick)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&buff.serenity.up
	if Talent(rushing_jade_wind_talent) and BuffPresent(serenity_buff) Spell(blackout_kick)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&chi>=4
	if Talent(rushing_jade_wind_talent) and Chi() >= 4 Spell(blackout_kick)
	#expel_harm,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 ExpelHarm()
	#spinning_crane_kick,if=chi.max-chi>=1&!talent.rushing_jade_wind.enabled
	if MaxChi() - Chi() >= 1 and not Talent(rushing_jade_wind_talent) Spell(spinning_crane_kick)
	#jab,if=talent.rushing_jade_wind.enabled&chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&cooldown.expel_harm.remains>=gcd
	if Talent(rushing_jade_wind_talent) and MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() Spell(jab)
	#tiger_palm,if=talent.rushing_jade_wind.enabled&(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if Talent(rushing_jade_wind_talent) and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 Spell(tiger_palm)
	#tiger_palm,if=talent.rushing_jade_wind.enabled&cooldown.keg_smash.remains>=gcd
	if Talent(rushing_jade_wind_talent) and SpellCooldown(keg_smash) >= GCD() Spell(tiger_palm)
}

AddFunction BrewmasterAoeShortCdActions
{
	#guard
	Guard()

	unless Chi() >= 3 and BuffRemaining(shuffle_buff) >= 6 and target.DebuffRemaining(breath_of_fire_debuff) <= 1 and target.DebuffPresent(dizzying_haze_debuff) and Spell(breath_of_fire)
		or Chi() >= 4 and Spell(chi_explosion_tank)
		or MaxChi() - Chi() >= 1 and Talent(rushing_jade_wind_talent) and Spell(rushing_jade_wind)
	{
		#purifying_brew,if=!talent.chi_explosion.enabled&stagger.heavy
		if not Talent(chi_explosion_talent) and DebuffPresent(heavy_stagger_debuff) Spell(purifying_brew)
		#guard
		Guard()

		unless MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) and Spell(keg_smash)
			or Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) and Spell(chi_burst)
			or Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 and Spell(chi_wave)
			or Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) and Spell(zen_sphere)
			or Talent(rushing_jade_wind_talent) and BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() and Spell(blackout_kick)
			or Talent(rushing_jade_wind_talent) and BuffPresent(serenity_buff) and Spell(blackout_kick)
			or Talent(rushing_jade_wind_talent) and Chi() >= 4 and Spell(blackout_kick)
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 and ExpelHarm()
			or MaxChi() - Chi() >= 1 and not Talent(rushing_jade_wind_talent) and Spell(spinning_crane_kick)
			or Talent(rushing_jade_wind_talent) and MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() and Spell(jab)
		{
			#purifying_brew,if=!talent.chi_explosion.enabled&talent.rushing_jade_wind.enabled&stagger.moderate&buff.shuffle.remains>=6
			if not Talent(chi_explosion_talent) and Talent(rushing_jade_wind_talent) and DebuffPresent(moderate_stagger_debuff) and BuffRemaining(shuffle_buff) >= 6 Spell(purifying_brew)
		}
	}
}

AddFunction BrewmasterAoeCdActions {}

# ActionList: BrewmasterStActions --> main, shortcd, cd

AddFunction BrewmasterStActions
{
	#blackout_kick,if=buff.shuffle.down
	if BuffExpires(shuffle_buff) Spell(blackout_kick)
	#keg_smash,if=chi.max-chi>=2&!buff.serenity.remains
	if MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) Spell(keg_smash)
	#chi_burst,if=talent.chi_burst.enabled&energy.time_to_max>3
	if Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) Spell(chi_burst)
	#chi_wave,if=talent.chi_wave.enabled&energy.time_to_max>3
	if Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 Spell(chi_wave)
	#zen_sphere,cycle_targets=1,if=talent.zen_sphere.enabled&!dot.zen_sphere.ticking
	if Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) Spell(zen_sphere)
	#chi_explosion,if=chi>=3
	if Chi() >= 3 Spell(chi_explosion_tank)
	#blackout_kick,if=buff.shuffle.remains<=3&cooldown.keg_smash.remains>=gcd
	if BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() Spell(blackout_kick)
	#blackout_kick,if=buff.serenity.up
	if BuffPresent(serenity_buff) Spell(blackout_kick)
	#blackout_kick,if=chi>=4
	if Chi() >= 4 Spell(blackout_kick)
	#expel_harm,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() ExpelHarm()
	#jab,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&cooldown.expel_harm.remains>=gcd
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() Spell(jab)
	#tiger_palm,if=(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 Spell(tiger_palm)
	#tiger_palm,if=cooldown.keg_smash.remains>=gcd
	if SpellCooldown(keg_smash) >= GCD() Spell(tiger_palm)
}

AddFunction BrewmasterStShortCdActions
{
	unless BuffExpires(shuffle_buff) and Spell(blackout_kick)
	{
		#purifying_brew,if=!talent.chi_explosion.enabled&stagger.heavy
		if not Talent(chi_explosion_talent) and DebuffPresent(heavy_stagger_debuff) Spell(purifying_brew)
		# CHANGE: Ignore this next Purifying Brew suggestion since blocks casting Guard later on.
		#purifying_brew,if=!buff.serenity.up
		#if not BuffPresent(serenity_buff) Spell(purifying_brew)
		#guard
		Guard()

		unless MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) and Spell(keg_smash)
			or Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) and Spell(chi_burst)
			or Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 and Spell(chi_wave)
			or Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) and Spell(zen_sphere)
			or Chi() >= 3 and Spell(chi_explosion_tank)
			or BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() and Spell(blackout_kick)
			or BuffPresent(serenity_buff) and Spell(blackout_kick)
			or Chi() >= 4 and Spell(blackout_kick)
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and ExpelHarm()
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() and Spell(jab)
		{
			#purifying_brew,if=!talent.chi_explosion.enabled&stagger.moderate&buff.shuffle.remains>=6
			if not Talent(chi_explosion_talent) and DebuffPresent(moderate_stagger_debuff) and BuffRemaining(shuffle_buff) >= 6 Spell(purifying_brew)
		}
	}
}

AddFunction BrewmasterStCdActions {}

### Brewmaster icons.
AddCheckBox(opt_monk_brewmaster_aoe L(AOE) specialization=brewmaster default)

AddIcon specialization=brewmaster help=cd
{
	if InCombat(no) BrewmasterPrecombatShortCdActions()
	BrewmasterDefaultShortCdActions()
}

AddIcon specialization=brewmaster help=main
{
	if InCombat(no) BrewmasterPrecombatActions()
	BrewmasterDefaultActions()
}

AddIcon specialization=brewmaster help=aoe checkbox=opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatActions()
	BrewmasterDefaultActions()
}

AddIcon specialization=brewmaster help=cd
{
	if InCombat(no) BrewmasterPrecombatCdActions()
	BrewmasterDefaultCdActions()
}

# Based on SimulationCraft profile "Monk_Windwalker_1h_T16M".
#	class=monk
#	spec=windwalker
#	talents=http://us.battle.net/wow/en/tool/talent-calculator#fb!002221.

# ActionList: WindwalkerPrecombatActions --> main, shortcd, cd

AddFunction WindwalkerPrecombatActions
{
	#flask,type=spring_blossoms
	#food,type=sea_mist_rice_noodles
	# CHANGE: Buff with Legacy of the White Tiger
	if BuffExpires(str_agi_int_buff any=1) Spell(legacy_of_the_white_tiger)
	#stance,choose=fierce_tiger
	Spell(stance_of_the_fierce_tiger)
	#snapshot_stats
}

AddFunction WindwalkerPrecombatShortCdActions {}

AddFunction WindwalkerPrecombatCdActions
{<commit_msg>Monk: Fix Brewmaster script when the AoE option is toggled on.<commit_after>local OVALE, Ovale = ...
local OvaleScripts = Ovale.OvaleScripts

do
	local name = "ovale_monk"
	local desc = "[6.0.2] Ovale: Brewmaster, Windwalker"
	local code = [[
# Ovale monk script based on SimulationCraft.

Include(ovale_common)
Include(ovale_monk_spells)

AddCheckBox(opt_potion_agility ItemName(virmens_bite_potion) default)
AddCheckBox(opt_chi_burst SpellName(chi_burst) default)

AddFunction UsePotionAgility
{
	if CheckBoxOn(opt_potion_agility) and target.Classification(worldboss) Item(virmens_bite_potion usable=1)
}

AddFunction ExpelHarm
{
	Spell(expel_harm)
	Spell(expel_harm_glyphed)
}

AddFunction Guard
{
	Spell(guard)
	Spell(guard_glyphed)
}

AddFunction InterruptActions
{
	if not target.IsFriend() and target.IsInterruptible()
	{
		if target.InRange(spear_hand_strike) Spell(spear_hand_strike)
		if not target.Classification(worldboss)
		{
			if target.InRange(paralysis) Spell(paralysis)
			Spell(arcane_torrent_chi)
			if target.InRange(quaking_palm) Spell(quaking_palm)
			Spell(war_stomp)
		}
	}
}

###
### Brewmaster
###
# Based on SimulationCraft profile "Monk_Brewmaster_1h_T16M".
#	class=monk
#	spec=brewmaster
#	talents=http://us.battle.net/wow/en/tool/talent-calculator#fa!.00.11.
#	glyphs=fortifying_brew,fortuitous_spheres

# ActionList: BrewmasterPrecombatActions --> main, shortcd, cd

AddFunction BrewmasterPrecombatActions
{
	#flask,type=earth
	#food,type=mogu_fish_stew
	# CHANGE: Buff with Legacy of the White Tiger
	if BuffExpires(str_agi_int_buff any=1) Spell(legacy_of_the_white_tiger)
	#stance,choose=sturdy_ox
	Spell(stance_of_the_sturdy_ox)
	#snapshot_stats
}

AddFunction BrewmasterPrecombatShortCdActions
{
	unless BuffExpires(str_agi_int_buff any=1) and Spell(legacy_of_the_white_tiger)
		or Spell(stance_of_the_sturdy_ox)
	{
		#dampen_harm
		Spell(dampen_harm)
	}
}

AddFunction BrewmasterPrecombatCdActions
{
	unless BuffExpires(str_agi_int_buff any=1) and Spell(legacy_of_the_white_tiger)
		or Spell(stance_of_the_sturdy_ox)
	{
		#potion,name=virmens_bite
		UsePotionAgility()
	}
}

# ActionList: BrewmasterDefaultActions --> main, shortcd, cd

AddFunction BrewmasterDefaultActions
{
	#auto_attack
	#chi_brew,if=talent.chi_brew.enabled&chi.max-chi>=2&buff.elusive_brew_stacks.stack<=10
	if Talent(chi_brew_talent) and MaxChi() - Chi() >= 2 and BuffStacks(elusive_brew_stacks_buff) <= 10 Spell(chi_brew)
	#gift_of_the_ox,if=buff.gift_of_the_ox.react&incoming_damage_1500ms
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeActions()
}

AddFunction BrewmasterDefaultShortCdActions
{
	#chi_brew,if=talent.chi_brew.enabled&chi.max-chi>=2&buff.elusive_brew_stacks.stack<=10
	if Talent(chi_brew_talent) and MaxChi() - Chi() >= 2 and BuffStacks(elusive_brew_stacks_buff) <= 10 Spell(chi_brew)
	#dampen_harm,if=incoming_damage_1500ms&buff.fortifying_brew.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(fortifying_brew_buff) and BuffExpires(elusive_brew_activated_buff) Spell(dampen_harm)
	#elusive_brew,if=buff.elusive_brew_stacks.react>=9&buff.dampen_harm.down&buff.elusive_brew_activated.down
	if BuffStacks(elusive_brew_stacks_buff) >= 9 and BuffExpires(dampen_harm_buff) and BuffExpires(elusive_brew_activated_buff) Spell(elusive_brew)
	#serenity,if=talent.serenity.enabled&energy<=40
	if Talent(serenity_talent) and Energy() <= 40 Spell(serenity)
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStShortCdActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeShortCdActions()
}

AddFunction BrewmasterDefaultCdActions
{
	# CHANGE: Touch of Death if it will kill the mob.
	if target.Health() < Health() and BuffPresent(death_note_buff) Spell(touch_of_death)
	# CHANGE: Add interrupt actions missing from SimulationCraft action list.
	InterruptActions()
	# CHANGE: Break snares with Nimble Brew.
	if IsFeared() or IsRooted() or IsStunned() Spell(nimble_brew)
	#blood_fury,if=energy<=40
	if Energy() <= 40 Spell(blood_fury_apsp)
	#berserking,if=energy<=40
	if Energy() <= 40 Spell(berserking)
	#arcane_torrent,if=energy<=40
	if Energy() <= 40 Spell(arcane_torrent_chi)
	#dampen_harm,if=incoming_damage_1500ms&buff.fortifying_brew.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(fortifying_brew_buff) and BuffExpires(elusive_brew_activated_buff) Spell(dampen_harm)
	#fortifying_brew,if=incoming_damage_1500ms&buff.dampen_harm.down&buff.elusive_brew_activated.down
	if IncomingDamage(1.5) and BuffExpires(dampen_harm_buff) and BuffExpires(elusive_brew_activated_buff) Spell(fortifying_brew)
	#invoke_xuen,if=talent.invoke_xuen.enabled&time>5
	if Talent(invoke_xuen_talent) and TimeInCombat() > 5 Spell(invoke_xuen)
	#call_action_list,name=st,if=active_enemies<3
	if Enemies() < 3 BrewmasterStCdActions()
	#call_action_list,name=aoe,if=active_enemies>=3
	if Enemies() >= 3 BrewmasterAoeCdActions()
}

# ActionList: BrewmasterAoeActions --> main, shortcd, cd

AddFunction BrewmasterAoeActions
{
	# CHANGE: Ensure that Shuffle is never down.
	if BuffExpires(shuffle_buff) Spell(blackout_kick)
	#breath_of_fire,if=chi>=3&buff.shuffle.remains>=6&dot.breath_of_fire.remains<=1&target.debuff.dizzying_haze.up
	if Chi() >= 3 and BuffRemaining(shuffle_buff) >= 6 and target.DebuffRemaining(breath_of_fire_debuff) <= 1 and target.DebuffPresent(dizzying_haze_debuff) Spell(breath_of_fire)
	#chi_explosion,if=chi>=4
	if Chi() >= 4 Spell(chi_explosion_tank)
	#rushing_jade_wind,if=chi.max-chi>=1&talent.rushing_jade_wind.enabled
	if MaxChi() - Chi() >= 1 and Talent(rushing_jade_wind_talent) Spell(rushing_jade_wind)
	#keg_smash,if=chi.max-chi>=2&!buff.serenity.remains
	if MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) Spell(keg_smash)
	#chi_burst,if=talent.chi_burst.enabled&energy.time_to_max>3
	if Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) Spell(chi_burst)
	#chi_wave,if=talent.chi_wave.enabled&energy.time_to_max>3
	if Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 Spell(chi_wave)
	#zen_sphere,cycle_targets=1,if=talent.zen_sphere.enabled&!dot.zen_sphere.ticking
	if Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) Spell(zen_sphere)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&buff.shuffle.remains<=3&cooldown.keg_smash.remains>=gcd
	if Talent(rushing_jade_wind_talent) and BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() Spell(blackout_kick)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&buff.serenity.up
	if Talent(rushing_jade_wind_talent) and BuffPresent(serenity_buff) Spell(blackout_kick)
	#blackout_kick,if=talent.rushing_jade_wind.enabled&chi>=4
	if Talent(rushing_jade_wind_talent) and Chi() >= 4 Spell(blackout_kick)
	#expel_harm,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 ExpelHarm()
	#spinning_crane_kick,if=chi.max-chi>=1&!talent.rushing_jade_wind.enabled
	if MaxChi() - Chi() >= 1 and not Talent(rushing_jade_wind_talent) Spell(spinning_crane_kick)
	#jab,if=talent.rushing_jade_wind.enabled&chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&cooldown.expel_harm.remains>=gcd
	if Talent(rushing_jade_wind_talent) and MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() Spell(jab)
	#tiger_palm,if=talent.rushing_jade_wind.enabled&(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if Talent(rushing_jade_wind_talent) and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 Spell(tiger_palm)
	#tiger_palm,if=talent.rushing_jade_wind.enabled&cooldown.keg_smash.remains>=gcd
	if Talent(rushing_jade_wind_talent) and SpellCooldown(keg_smash) >= GCD() Spell(tiger_palm)
}

AddFunction BrewmasterAoeShortCdActions
{
	#guard
	Guard()

	unless Chi() >= 3 and BuffRemaining(shuffle_buff) >= 6 and target.DebuffRemaining(breath_of_fire_debuff) <= 1 and target.DebuffPresent(dizzying_haze_debuff) and Spell(breath_of_fire)
		or Chi() >= 4 and Spell(chi_explosion_tank)
		or MaxChi() - Chi() >= 1 and Talent(rushing_jade_wind_talent) and Spell(rushing_jade_wind)
	{
		#purifying_brew,if=!talent.chi_explosion.enabled&stagger.heavy
		if not Talent(chi_explosion_talent) and DebuffPresent(heavy_stagger_debuff) Spell(purifying_brew)
		#guard
		Guard()

		unless MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) and Spell(keg_smash)
			or Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) and Spell(chi_burst)
			or Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 and Spell(chi_wave)
			or Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) and Spell(zen_sphere)
			or Talent(rushing_jade_wind_talent) and BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() and Spell(blackout_kick)
			or Talent(rushing_jade_wind_talent) and BuffPresent(serenity_buff) and Spell(blackout_kick)
			or Talent(rushing_jade_wind_talent) and Chi() >= 4 and Spell(blackout_kick)
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 and ExpelHarm()
			or MaxChi() - Chi() >= 1 and not Talent(rushing_jade_wind_talent) and Spell(spinning_crane_kick)
			or Talent(rushing_jade_wind_talent) and MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() and Spell(jab)
		{
			#purifying_brew,if=!talent.chi_explosion.enabled&talent.rushing_jade_wind.enabled&stagger.moderate&buff.shuffle.remains>=6
			if not Talent(chi_explosion_talent) and Talent(rushing_jade_wind_talent) and DebuffPresent(moderate_stagger_debuff) and BuffRemaining(shuffle_buff) >= 6 Spell(purifying_brew)
		}
	}
}

AddFunction BrewmasterAoeCdActions {}

# ActionList: BrewmasterStActions --> main, shortcd, cd

AddFunction BrewmasterStActions
{
	#blackout_kick,if=buff.shuffle.down
	if BuffExpires(shuffle_buff) Spell(blackout_kick)
	#keg_smash,if=chi.max-chi>=2&!buff.serenity.remains
	if MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) Spell(keg_smash)
	#chi_burst,if=talent.chi_burst.enabled&energy.time_to_max>3
	if Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) Spell(chi_burst)
	#chi_wave,if=talent.chi_wave.enabled&energy.time_to_max>3
	if Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 Spell(chi_wave)
	#zen_sphere,cycle_targets=1,if=talent.zen_sphere.enabled&!dot.zen_sphere.ticking
	if Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) Spell(zen_sphere)
	#chi_explosion,if=chi>=3
	if Chi() >= 3 Spell(chi_explosion_tank)
	#blackout_kick,if=buff.shuffle.remains<=3&cooldown.keg_smash.remains>=gcd
	if BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() Spell(blackout_kick)
	#blackout_kick,if=buff.serenity.up
	if BuffPresent(serenity_buff) Spell(blackout_kick)
	#blackout_kick,if=chi>=4
	if Chi() >= 4 Spell(blackout_kick)
	#expel_harm,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() ExpelHarm()
	#jab,if=chi.max-chi>=1&cooldown.keg_smash.remains>=gcd&cooldown.expel_harm.remains>=gcd
	if MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() Spell(jab)
	#tiger_palm,if=(energy+(energy.regen*(cooldown.keg_smash.remains)))>=40
	if Energy() + EnergyRegenRate() * SpellCooldown(keg_smash) >= 40 Spell(tiger_palm)
	#tiger_palm,if=cooldown.keg_smash.remains>=gcd
	if SpellCooldown(keg_smash) >= GCD() Spell(tiger_palm)
}

AddFunction BrewmasterStShortCdActions
{
	unless BuffExpires(shuffle_buff) and Spell(blackout_kick)
	{
		#purifying_brew,if=!talent.chi_explosion.enabled&stagger.heavy
		if not Talent(chi_explosion_talent) and DebuffPresent(heavy_stagger_debuff) Spell(purifying_brew)
		# CHANGE: Ignore this next Purifying Brew suggestion since blocks casting Guard later on.
		#purifying_brew,if=!buff.serenity.up
		#if not BuffPresent(serenity_buff) Spell(purifying_brew)
		#guard
		Guard()

		unless MaxChi() - Chi() >= 2 and not BuffRemaining(serenity_buff) and Spell(keg_smash)
			or Talent(chi_burst_talent) and TimeToMaxEnergy() > 3 and CheckBoxOn(opt_chi_burst) and Spell(chi_burst)
			or Talent(chi_wave_talent) and TimeToMaxEnergy() > 3 and Spell(chi_wave)
			or Talent(zen_sphere_talent) and not BuffPresent(zen_sphere_buff) and Spell(zen_sphere)
			or Chi() >= 3 and Spell(chi_explosion_tank)
			or BuffRemaining(shuffle_buff) <= 3 and SpellCooldown(keg_smash) >= GCD() and Spell(blackout_kick)
			or BuffPresent(serenity_buff) and Spell(blackout_kick)
			or Chi() >= 4 and Spell(blackout_kick)
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and ExpelHarm()
			or MaxChi() - Chi() >= 1 and SpellCooldown(keg_smash) >= GCD() and SpellCooldown(expel_harm) >= GCD() and Spell(jab)
		{
			#purifying_brew,if=!talent.chi_explosion.enabled&stagger.moderate&buff.shuffle.remains>=6
			if not Talent(chi_explosion_talent) and DebuffPresent(moderate_stagger_debuff) and BuffRemaining(shuffle_buff) >= 6 Spell(purifying_brew)
		}
	}
}

AddFunction BrewmasterStCdActions {}

### Brewmaster icons.
AddCheckBox(opt_monk_brewmaster_aoe L(AOE) specialization=brewmaster default)

AddIcon specialization=brewmaster help=shortcd enemies=1 checkbox=!opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatShortCdActions()
	BrewmasterDefaultShortCdActions()
}

AddIcon specialization=brewmaster help=shortcd checkbox=opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatShortCdActions()
	BrewmasterDefaultShortCdActions()
}

AddIcon specialization=brewmaster help=main enemies=1
{
	if InCombat(no) BrewmasterPrecombatActions()
	BrewmasterDefaultActions()
}

AddIcon specialization=brewmaster help=aoe checkbox=opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatActions()
	BrewmasterDefaultActions()
}

AddIcon specialization=brewmaster help=cd enemies=1 checkbox=!opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatCdActions()
	BrewmasterDefaultCdActions()
}

AddIcon specialization=brewmaster help=cd checkbox=opt_monk_brewmaster_aoe
{
	if InCombat(no) BrewmasterPrecombatCdActions()
	BrewmasterDefaultCdActions()
}

# Based on SimulationCraft profile "Monk_Windwalker_1h_T16M".
#	class=monk
#	spec=windwalker
#	talents=http://us.battle.net/wow/en/tool/talent-calculator#fb!002221.

# ActionList: WindwalkerPrecombatActions --> main, shortcd, cd

AddFunction WindwalkerPrecombatActions
{
	#flask,type=spring_blossoms
	#food,type=sea_mist_rice_noodles
	# CHANGE: Buff with Legacy of the White Tiger
	if BuffExpires(str_agi_int_buff any=1) Spell(legacy_of_the_white_tiger)
	#stance,choose=fierce_tiger
	Spell(stance_of_the_fierce_tiger)
	#snapshot_stats
}

AddFunction WindwalkerPrecombatShortCdActions {}

AddFunction WindwalkerPrecombatCdActions
{
{'fraction_non_alphanumeric': 0.11075105485232067, 'fraction_numerical': 0.011780590717299578, 'mean_word_length': 7.926182585115999, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 227, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588915', 'n_tokens_mistral': 12532, 'n_tokens_neox': 11736, 'n_words': 1783}