Dim MHWSpeed, OHWSpeed, MHLow, MHHigh, OHLow, OHHigh, MHAvg, OHAvg
Dim AP, Crit, HitBonus, Glance, DodgeBlockParry, Miss
Dim TimeLimit, CombatTime, FinishCrit, FinishAP, FinishHit, StartAP, StartHit, StartCrit, FinishOHSpd, FinishMHspd
Dim WindfuryDmgCount, SSDmgCount, MHDmgCount, OHDmgCount, ESDmgCount
Dim WindfuryCDDone, ArmMitigation, URDone, UROn, WFCandidate, WeapMast, EleWeapTalent, eleBonWF, eleBonRB, eleBonFT
Dim MHNextSwing, OHNextSwing, modMHNextSwing, modOHNextSwing, FlurryCharges, FlurrySpeed, MHFlurrySpeed, OHFlurrySpeed
Dim MHSwingSpeed, OHSwingSpeed, WFOffHandSwings, WFMainHandSwings
Dim SwingResult, ReportString, firstReport
Dim wGlanceThresh, wDodgeBlockParryThresh, wCritThresh, wRealMiss, watttabstr, wMissThresh
Dim yGlanceThresh, yDodgeBlockParryThresh, yCritThresh, yRealMiss, yatttabstr, yMissThresh
Dim SecondSS, FTOH, RBOH, WFOH, FTMH, RBMH, WFMH, SSPeriod
Dim OHRckBiterDmg, OHFTDmg, SpellCrit, BonSpellDmg, MHRckBiterDmg, MHFTDmg, OHRBDmg, MHRBDmg, FTModifier
Dim arrAttackArray(24, 3)
Dim SSOn, OHActive, goOH, FlurryChange, WFCoeff, ohspdpercent, mhspdpercent
Dim WhiteDmg, GlanceDmg, WhiteSwings, TotalSwings, WFDmg, RBDmg, FTDmg, WFSwings, URSwings, SSDmg, WFCounter
Dim objFileSystem, objOutputFile
Dim strOutputFile
Dim MHStartAvg, OHStartAvg, MHStartSpeed, OHStartSpeed
Const OPEN_FILE_FOR_APPENDING = 8


' generate a filename base on the script name
strOutputFile = "./big_test.txt"



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''' you can modify the data before the next comment line ''

OHActive = TRUE ' TRUE for DW, FALSE for shield or non-melee OH
SSOn = TRUE ' Model Stormstrike in?  TRUE or FALSE
SSPeriod = 10500 ' how often to use SS?  default to 10.5 seconds (for lag)
UROn = TRUE ' Model Unleashed Rage procs?
HitBonus = 0.176 ' Your hit bonus:  .251 = 25.1% bonus to hit chance
Crit = 0.229 ' Your crit rate:  .251 = 25.1% chance to crit
Glance = 0.0 ' chance to have a glancing blow.  .25 = 25% of white attacks will glance
AP = 1352 ' unbuffed AP (or put in raid buffed AP, w/e, but dont include Unleashed Rage)
DodgeBlockParry = 0.00 ' chance to have an attack avoided.  .25 = 25% of white attacks will glance
MHWSpeed = 2700 ' Main Hand Weaponspeed 1500 = 1.5 speed, 2600 = 2.6 speed, etc
OHWSpeed = 1800 ' Off Hand Weaponspeed 1500 = 1.5 speed, 2600 = 2.6 speed, etc
MHHigh = 320 ' top end damage of Main Hand Weapon
MHLow = 172 ' low end damage of Main Hand Weapon
OHHigh = 199 ' top end damage of off Hand Weapon
OHLow = 132 ' low end damage of Off Hand Weapon
StartHit = HitBonus
StartCrit = Crit
StartAP = AP
FlurrySpeed = 1.3
MHFlurrySpeed = round(MHWSpeed / FlurrySpeed, 0)
OHFlurrySpeed = round(OHWSpeed / FlurrySpeed, 0)
FTMH = 0 ' 1 for FlameTongue active on main hand, 0 for no FT MH
RBMH = 0 ' 1 for Rockbiter active on main hand, 0 for no RB MH
WFMH = 1 ' 1 for Wind Fury active on main hand, 0 for no WF MH
FTOH = 0 ' 1 for FlameTongue active on off hand, 0 for no FT OH
RBOH = 0 ' 1 for Rockbiter active on off hand, 0 for no RB OH
WFOH = 1 ' 1 for Wind Fury active on off hand, 0 for no WF OH
ArmMitigation = 0.73 ' damage that gets through target's armor.  0.74 = 26% mitigation
WeapMast = 0.1 ' Extra damage due to weapon mastery talent.  .1 = 10% weap dmg bonus
SpellCrit = 0.049 ' spell crit rate.  0.064 = 6.4% crit with spells
BonSpellDmg = 0 ' spell damage
EleWeapTalent = 3 ' Ranks of Elemental Weapons talent.  Currently only 0 or 3 works
FinishAP = 1352
FinishHit = .176
FinishCrit = .229
FinishMHspd = 2700
FinishOHspd = 1800
TimeLimit = 10000000 ' how many milliseconds to run the simulation.  30000 = 30 seconds of combat
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''' dont modify anything below this line
'''''''''''' unless you know what you're doing

''''''''' system parameters
firstReport = TRUE
FTModifier = 35
eleBonWF = 0
eleBonRB = 0
eleBonFT = 0
if WFOH = 1 then
	WFCoeff = .36
else
	WFCoeff = .2
end if

MHAvg = (MHHigh + MHLow) / 2
OHAvg = (OHHigh + OHLow) / 2
MHStartAvg = MHAvg
OHStartAvg = OHAvg
MHStartSpeed = MHWSpeed
OHStartSpeed = OHWSpeed

if EleWeapTalent = 3 Then
	eleBonWF = .4
	eleBonRB = .2
	eleBonFT = .15
end if
MHFTDmg =round((((BonSpellDmg/10)+(FTModifier*MHWspeed/1000))*(1+SpellCrit))*(1+eleBonFT),0)
MHRckBiterDmg = round((49*MHWSpeed/1000)*(1+eleBonRB)*ArmMitigation, 0)
OHFTDmg = round((((BonSpellDmg/10)+(FTModifier*OHWspeed/1000))*(1+SpellCrit))*(1+eleBonFT),0)
OHRckBiterDmg = round((49*OHWSpeed/2000)*(1+eleBonRB)*ArmMitigation, 0)
URSwings = 0

Do While MHWSpeed < FinishMHspd + 1
	Do While OHWspeed < FinishOHspd + 1
		Do While Crit < FinishCrit +.001
			Do While HitBonus < FinishHit +.001
				Do While AP < FinishAP + 1
					AttackSimulation
					AP = AP + 100
				Loop
			AP = StartAP
			HitBonus = HitBonus + 0.0316
			Loop
			HitBonus = StartHit
			Crit = Crit + 0.0225
		Loop
		Crit = StartCrit
		ohspdpercent = 200 / OHWspeed
		OHWspeed = OHWSpeed + 200
		OHAvg = round(OHAvg * (1+ohspdpercent),1)
	Loop
	OHWspeed = OHStartSpeed
	OHAvg = OHStartAvg
	mhspdpercent = 200 / MHWspeed
	MHWspeed = MHWSpeed + 200
	MHAvg = round(MHAvg * (1+mhspdpercent),1)
Loop

Wscript.quit




Sub AttackSimulation()
' clear out saved vars
for i = 1 to 24
	arrAttackArray(i, 2) = 0
	arrAttackArray(i, 3) = 0
next



'reset counters
URup = FALSE
URDone = 0
FlurryChange = FALSE
FlurryCharges = 0
CombatTime = 0
WindfuryCDDone = -1
WFCandidate = TRUE
MHNextSwing = 0
OHNextSwing = 0
modMHNextSwing = 0
modOHNextSwing = 0
OHTDmg = 0
OHRckBiterDmg = 0
URSwings = 0
WhiteDmg = 0
GlanceDmg = 0
WhiteSwings = 0
TotalSwings = 0
goOH = FALSE
WFCounter = 0
if OHActive Then
	goOH = TRUE
end if

' Set up Attack Tables
wGlanceThresh = Glance
wDodgeBlockParryThresh = wGlanceThresh + DodgeBlockParry
wRealMiss = Max(.25 - HitBonus, 0)
wMissThresh = wRealMiss + wDodgeBlockParryThresh
wCritThresh = Min(Crit, 1 - wMissThresh) + wMissThresh
'wscript.echo wGlanceThresh & " are Glancing."
'wscript.echo wDodgeBlockParryThresh - wGlanceThresh & " are dodgeblockparry"
'wscript.echo wMissThresh - wDodgeBlockParryThresh & " are Misses"
'wscript.echo wCritThresh - wMissThresh & " are Crits"
'wscript.echo round(1 - wCritThresh,3) & " are normal Hits"
'watttabstr = wGlanceThresh & " dodge: " & wDodgeBlockParryThresh & " Miss: " & wMissThresh & " Crit: " & wCritThresh
'wscript.echo watttabstr

yGlanceThresh = 0
yDodgeBlockParryThresh = yGlanceThresh + DodgeBlockParry
yRealMiss = Max(.056 - HitBonus, 0)
yMissThresh = yRealMiss + yDodgeBlockParryThresh
yCritThresh = Min(Crit, 1 - yMissThresh) + yMissThresh
'wscript.echo yGlanceThresh & " are Glancing."
'wscript.echo yDodgeBlockParryThresh - yGlanceThresh & " are dodgeblockparry"
'wscript.echo yMissThresh - yDodgeBlockParryThresh & " are Misses"
'wscript.echo yCritThresh - yMissThresh & " are Crits"
'wscript.echo round(1 - yCritThresh,3) & " are normal Hits yellow"
'yatttabstr = yGlanceThresh & " dodge: " & yDodgeBlockParryThresh & " Miss: " & yMissThresh & " Crit: " & yCritThresh
'wscript.echo yatttabstr


Dim MHFlurried, OHFlurried, whichFlurryLast

''''''''''''' Main loop of Attacking Function
For CombatTime = 0 to TimeLimit

	if FlurryChange then
		'wscript.echo "FLURRY DONE: " & CombatTime & " Next MH Swing @ " & modMHNextSwing & " FlurryCharge: " & FlurryCharges
		'modMHNextSwing = round(CombatTime + (modMHNextSwing - CombatTime) * FlurrySpeed,0)
		'modOHNextSwing = round(CombatTime + (modOHNextSwing - CombatTime) * FlurrySpeed,0)
		'wscript.echo "after calcs: " & CombatTime & " Next MH Swing @ " & modMHNextSwing & " FlurryCharge: " & FlurryCharges
		FlurryChange = FALSE
	end if

	'''''' is StormStrike up?
	if SSOn Then
		if (CombatTime Mod SSPeriod) = 0 Then
			SecondSS = TRUE
			'wscript.echo CombatTime & " StormStrike"
			Call GetSwingResults("yellow", "SSMH")
			Swings = Swings + 1
			if SecondSS and OHActive Then
				Call GetSwingResults("yellow", "SSOH")
			end if
		end if
	end if

	'''''' is MainHand Swinging?
	if modMHNextSwing = CombatTime Then
		'wscript.echo CombatTime & " MHSwing"
		if FlurryCharges > 0 Then
			FlurryCharges = FlurryCharges - 1
			if FlurryCharges = 0 then
				FlurryChange = TRUE
				modMHNextSwing = CombatTime + MHWSpeed
			else
				modMHNextSwing = CombatTime + MHFlurrySpeed
			end if

		else
			FlurryCharges = 0
			modMHNextSwing = CombatTime + MHWSpeed
		end if
		Call GetSwingResults("white", "MH")
		' wscript.echo CombatTime & " Next MH Swing @ " & modMHNextSwing & " FlurryCharge: " & FlurryCharges
	end if

	'''''' is OffHand Swinging?

	if ((modOHNextSwing = CombatTime) AND (goOH)) Then
		'wscript.echo CombatTime & " OHSwing"
		if FlurryCharges > 0 Then
			FlurryCharges = FlurryCharges - 1
			if FlurryCharges = 0 then
				FlurryChange = TRUE
				modOHNextSwing = CombatTime + OHWSpeed
			else
				modOHNextSwing = CombatTime + OHFlurrySpeed
			end if
		else
			modOHNextSwing = CombatTime + OHWSpeed
			FlurryCharges = 0
		end if
		Call GetSwingResults("white", "OH")
		' wscript.echo CombatTime & " Next OH Swing @ " & modOHNextSwing & " FlurryCharge: " & FlurryCharges
	end if
Next
DoReporting
End Sub


''''''''''''''''' basic functions

function Max(a, b)
	if a > b then
		Max = a
	else
		Max = b
	end if
end function

function Min(a, b)
	if a < b then
		Min = a
	else
		Min = b
	end if
end function

''''''''''''''''' what happened to that attack?

Sub GetSwingResults(color, source)
	
	Randomize
	SwingResult = Rnd()
	if color = "white" then
		if SwingResult < wGlanceThresh Then
			Call Damage("Glance", source)
		elseif SwingResult < wDodgeBlockParryThresh Then
			Call Damage("Dodge", "white")
		elseif SwingResult < wMissThresh Then
			Call Damage("Miss", "white")
		elseif SwingResult < wCritThresh Then
			Call Damage("Crit", source)
		else
			Call Damage("Hit", source)
		end if
	elseif color = "yellow" Then
		if SwingResult < yGlanceThresh Then
			Call Damage("Glance", source)
		elseif SwingResult < yDodgeBlockParryThresh Then
			Call Damage("Dodge", "yellow")
		elseif SwingResult < yMissThresh Then
			Call Damage("Miss", "yellow")
		elseif SwingResult < yCritThresh Then
			Call Damage("Crit", source)
		else
			Call Damage("Hit", source)
		end if
	end if
	SwingResult = 0
end Sub

''''''''''''''''' now that we have the spot on the hit table, tell us more

Dim DamageCase, SwingDmg, effAP
Sub Damage(swngRslt, source)

''''''''''''''''' first, give us a status report, and find out about WF procs
'	wscript.echo "At: " & CombatTime & ", " & source & ": " & swngRslt & " WFPossible: " & WFCandidate & " Next WF Possible: " & WindFuryCDDone
	if WindFuryCDDone > CombatTime then
		WFCandidate = FALSE
	else
		if (inStr(Source, "OH") > 0 ) and (WFOH <> 1) Then
			WFCandidate = FALSE
		elseif (inStr(Source, "MH") > 0 ) and (WFMH <> 1) Then
			WFCandidate = FALSE
		else
			Select Case swngRslt
				Case "Miss"
					WFCandidate = FALSE
					SecondSS = FALSE
				Case "Dodge"
					WFCandidate = FALSE
					SecondSS = FALSE
				Case Else
					WFCandidate = TRUE
			End Select
		End if
	end if
	if WFCandidate Then
		' wscript.echo "tried windfury"
		Randomize
		if (Rnd() < WFCoeff) then
			WFCandidate = FALSE
			WFCounter = WFCounter + 1
			WindFuryCDDone = CombatTime + 3000
			Call GetSwingResults("yellow", "WF"&source)
			Call GetSwingResults("yellow", "WF"&source)
		end if
	end if


''''''''''''''' with all that out of the way, now lets start calculating damage!

	If swngRslt = "Miss" Then
		DamageCase = "Miss" & source
	elseif swngRslt = "Dodge" Then
		DamageCase = "Dodge" & source
	else
		DamageCase = swngRslt & source
	end if
	if URDone > CombatTime Then
		if UROn Then
			URSwings = URSwings + 1
			effAP = AP * 1.1
		else
			effAP = AP
		end if
	else
		effAP = AP
	end if
	select case DamageCase
		case "HitMH"
				SwingDmg = round((MHAvg + (effAP/14)*(MHWSpeed/1000)) * ArmMitigation * (1 + WeapMast),0)
				arrAttackArray(14, 2) = arrAttackArray(14, 2) + 1
				arrAttackArray(14, 3) = arrAttackArray(14, 3) + SwingDmg
				GetMHEnchDmg
		case "CritMH"
				SwingDmg = round(2*((MHAvg + (effAP/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(13, 2) = arrAttackArray(13, 2) + 1
				arrAttackArray(13, 3) = arrAttackArray(13, 3) + SwingDmg
				GetMHEnchDmg
		case "HitOH"
				SwingDmg = round(((OHAvg + (effAP/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation)/2,0)
				arrAttackArray(1, 2) = arrAttackArray(1, 2) + 1
				arrAttackArray(1, 3) = arrAttackArray(1, 3) + SwingDmg
				GetOHEnchDmg
		case "CritOH"
				SwingDmg = round((2*((OHAvg + (effAP/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation))/2,0)
				arrAttackArray(2, 2) = arrAttackArray(2, 2) + 1
				arrAttackArray(2, 3) = arrAttackArray(2, 3) + SwingDmg
				GetOHEnchDmg
		case "HitSSMH"
				SwingDmg = round((MHAvg + (effAP/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation,0)
				GetMHEnchDmg
				arrAttackArray(3, 2) = arrAttackArray(3, 2) + 1
				arrAttackArray(3, 3) = arrAttackArray(3, 3) + SwingDmg
		case "CritSSMH"
				SwingDmg = round(2*((MHAvg + (effAP/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(4, 2) = arrAttackArray(4, 2) + 1
				arrAttackArray(4, 3) = arrAttackArray(4, 3) + SwingDmg
				GetMHEnchDmg
		case "HitSSOH"
				SwingDmg = round(((OHAvg + (effAP/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation)/2,0)
				GetOHEnchDmg
				arrAttackArray(5, 2) = arrAttackArray(5, 2) + 1
				arrAttackArray(5, 3) = arrAttackArray(5, 3) + SwingDmg
		case "CritSSOH"
				SwingDmg = round((2*((OHAvg + (effAP/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation))/2,0)
				arrAttackArray(6, 2) = arrAttackArray(6, 2) + 1
				arrAttackArray(6, 3) = arrAttackArray(6, 3) + SwingDmg
				GetOHEnchDmg
		case "GlanceMH"
				SwingDmg = round(0.76*(MHAvg + (effAP/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation,0)
				arrAttackArray(7, 2) = arrAttackArray(7, 2) + 1
				arrAttackArray(7, 3) = arrAttackArray(7, 3) + SwingDmg
				GetMHEnchDmg
		case "GlanceOH"
				SwingDmg = round((0.76*(OHAvg + (effAP/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation)/2,0)
				arrAttackArray(8, 2) = arrAttackArray(8, 2) + 1
				arrAttackArray(8, 3) = arrAttackArray(8, 3) + SwingDmg
				GetOHEnchDmg
		case "CritWFMH"
				SwingDmg = round(2*(1+eleBonWF)*((MHAvg + ((460+effAP)/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(9, 2) = arrAttackArray(9, 2) + 1
				arrAttackArray(9, 3) = arrAttackArray(9, 3) + SwingDmg
				GetMHEnchDmg
		case "CritWFOH"
				SwingDmg = round(1*(1+eleBonWF)*((OHAvg + ((460+effAP)/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(10, 2) = arrAttackArray(10, 2) + 1
				arrAttackArray(10, 3) = arrAttackArray(10, 3) + SwingDmg
				GetMHEnchDmg
		case "HitWFMH"
				SwingDmg = round((1+eleBonWF)*((MHAvg + ((460+effAP)/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(11, 2) = arrAttackArray(11, 2) + 1
				arrAttackArray(11, 3) = arrAttackArray(11, 3) + SwingDmg
				GetMHEnchDmg
		case "HitWFOH"
				SwingDmg = round(0.5*(1+eleBonWF)*((OHAvg + ((460+effAP)/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(12, 2) = arrAttackArray(12, 2) + 1
				arrAttackArray(12, 3) = arrAttackArray(12, 3) + SwingDmg
				GetMHEnchDmg
		case "CritWFSSMH"
				SwingDmg = round(2*(1+eleBonWF)*((MHAvg + ((460+effAP)/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(9, 2) = arrAttackArray(9, 2) + 1
				arrAttackArray(9, 3) = arrAttackArray(9, 3) + SwingDmg
				GetMHEnchDmg
		case "CritWFSSOH"
				SwingDmg = round(1*(1+eleBonWF)*((OHAvg + ((460+effAP)/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(10, 2) = arrAttackArray(10, 2) + 1
				arrAttackArray(10, 3) = arrAttackArray(10, 3) + SwingDmg
				GetMHEnchDmg
		case "HitWFSSMH"
				SwingDmg = round((1+eleBonWF)*((MHAvg + ((460+effAP)/14)*(MHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(11, 2) = arrAttackArray(11, 2) + 1
				arrAttackArray(11, 3) = arrAttackArray(11, 3) + SwingDmg
				GetMHEnchDmg
		case "HitWFSSOH"
				SwingDmg = round(0.5*(1+eleBonWF)*((OHAvg + ((460+effAP)/14)*(OHWSpeed/1000)) * (1 + WeapMast) * ArmMitigation),0)
				arrAttackArray(12, 2) = arrAttackArray(12, 2) + 1
				arrAttackArray(12, 3) = arrAttackArray(12, 3) + SwingDmg
				GetMHEnchDmg
		case "Missyellow"
				arrAttackArray(19, 2) = arrAttackArray(19, 2) + 1
				arrAttackArray(21, 2) = arrAttackArray(21, 2) + 1
		case "Dodgeyellow"
				arrAttackArray(20, 2) = arrAttackArray(20, 2) + 1
				arrAttackArray(22, 2) = arrAttackArray(22, 2) + 1
		case "Misswhite"
				arrAttackArray(19, 2) = arrAttackArray(19, 2) + 1
				arrAttackArray(23, 2) = arrAttackArray(23, 2) + 1
		case "Dodgewhite"
				arrAttackArray(20, 2) = arrAttackArray(20, 2) + 1
				arrAttackArray(24, 2) = arrAttackArray(24, 2) + 1
	end select

''''''''''''''''' now that we know about WF, tell us about Flurry and Unleashed Rage

	if swngRslt = "Crit" Then
		if NOT FlurryCharges > 0 Then
			modMHNextSwing = CombatTime + round((modMHNextSwing-CombatTime)/FlurrySpeed,0)
			modOHNextSwing = CombatTime + round((modOHNextSwing-CombatTime)/FlurrySpeed,0)
		end if
		FlurryCharges = 3
		URDone = CombatTime + 10000
	end if
	' wscript.echo "At: " & CombatTime & ", " & source & ": " & swngRslt & " Damage: " & SwingDmg & " DamageCase: " & DamageCase & " URswings " & URSwings
	SwingDmg = 0
end Sub

Sub GetOHEnchDmg()
	If WFOH <> 1 Then
		if FTOH = 1 Then
			'wscript.echo "At: " & CombatTime & ", " & source & ": OH Enchant Damage: Flametongue: " & OHFTDmg
			arrAttackArray(15, 2) = arrAttackArray(15, 2) + 1
			arrAttackArray(15, 3) = arrAttackArray(15, 3) + OHFTDmg
		end if
		if RBOH = 1 Then
			if Instr(DamageCase, "Crit") > 0 Then
				OHRBDmg = OHRckBiterDmg * 2
			elseif Instr(DamageCase, "Glance") > 0 Then
				OHRBDmg = round(OHRckBiterDmg * .75,0)
			else
				OHRBDmg = OHRckBiterDmg
			end if
			arrAttackArray(16, 2) = arrAttackArray(16, 2) + 1
			arrAttackArray(16, 3) = arrAttackArray(16, 3) + OHRBDmg
			'wscript.echo "At: " & CombatTime & ", " & source & ": OH Enchant Damage: Rockbiter: " & OHRBDmg
		end if
	End If
End Sub
Sub GetMHEnchDmg()
	If WFMH <> 1 Then
		if FTMH = 1 Then
			'wscript.echo "At: " & CombatTime & ", " & source & ": OH Enchant Damage: Flametongue: " & MHFTDmg
			arrAttackArray(17, 2) = arrAttackArray(17, 2) + 1
			arrAttackArray(17, 3) = arrAttackArray(17, 3) + MHFTDmg
		end if
		if RBMH = 1 Then
			if Instr(DamageCase, "Crit") > 0 Then
				MHRBDmg = MHRckBiterDmg * 2
			elseif Instr(DamageCase, "Glance") > 0 Then
				MHRBDmg = round(MHRckBiterDmg * .75,0)
			else
				MHRBDmg = MHRckBiterDmg
			end if
			arrAttackArray(18, 2) = arrAttackArray(18, 2) + 1
			arrAttackArray(18, 3) = arrAttackArray(18, 3) + MHRBDmg
			'wscript.echo "At: " & CombatTime & ", " & source & ": OH Enchant Damage: Rockbiter: " & MHRBDmg
		end if
	End If
End Sub

Sub DoReporting()
	arrAttackArray(1, 1) = "HitOH"
	arrAttackArray(2, 1) = "CritOH"
	arrAttackArray(3, 1) = "HitSSMH"
	arrAttackArray(4, 1) = "CritSSMH"
	arrAttackArray(5, 1) = "HitSSOH"
	arrAttackArray(6, 1) = "CritSSOH"
	arrAttackArray(7, 1) = "GlanceMH"
	arrAttackArray(8, 1) = "GlanceOH"
	arrAttackArray(9, 1) = "CritWFMH"
	arrAttackArray(10, 1) = "CritWFOH"
	arrAttackArray(11, 1) = "HitWFMH"
	arrAttackArray(12, 1) = "HitWFOH"
	arrAttackArray(13, 1) = "CritMH"
	arrAttackArray(14, 1) = "HitMH"
	arrAttackArray(15, 1) = "OHFT"
	arrAttackArray(16, 1) = "OHRB"
	arrAttackArray(17, 1) = "MHFT"
	arrAttackArray(18, 1) = "MHRB"
	arrAttackArray(19, 1) = "Miss"
	arrAttackArray(20, 1) = "Dodge"
	arrAttackArray(19, 3) = 0
	arrAttackArray(20, 3) = 0
	arrAttackArray(21, 1) = "MissY"
	arrAttackArray(22, 1) = "DodgeY"
	arrAttackArray(23, 1) = "MissWhite"
	arrAttackArray(24, 1) = "DodgeWhite"
	arrAttackArray(21, 3) = 0
	arrAttackArray(22, 3) = 0
	arrAttackArray(23, 3) = 0
	arrAttackArray(24, 3) = 0


	TotalDmg = 0
	for RowLooper = 1 to 24
		' wscript.echo arrAttackArray(RowLooper, 1) & " " & arrAttackArray(RowLooper, 2) & " " & arrAttackArray(RowLooper, 3) & " DPS: " & round(arrAttackArray(RowLooper,3)/(CombatTime/1000),2)
		TotalDmg = TotalDmg + arrAttackArray(RowLooper, 3)
	next

	for RowLooper = 1 to 24
		'wscript.echo arrAttackArray(RowLooper, 1) & " " & arrAttackArray(RowLooper, 2) & " " & arrAttackArray(RowLooper, 3) & " DPS: " & round(arrAttackArray(RowLooper,3)/(CombatTime/1000),2) & " = " & round(arrAttackArray(RowLooper, 3)/TotalDmg,2)
	next

	' get totalSwings, excluding RB and FT events
	TotalSwings = 0
	for RowLooper = 1 to 14
		TotalSwings = TotalSwings + arrAttackArray(RowLooper, 2)
	next
	for RowLooper = 19 to 20
		TotalSwings = TotalSwings + arrAttackArray(RowLooper, 2)
	next

	SSSWings = 0
	SSSwings = SSSwings + arrAttackArray(3, 2)
	SSSwings = SSSwings + arrAttackArray(4, 2)
	SSSwings = SSSwings + arrAttackArray(5, 2)
	SSSwings = SSSwings + arrAttackArray(6, 2)

	WhiteDmg = 0
	WhiteDmg = WhiteDmg + arrAttackArray(1,3)
	WhiteDmg = WhiteDmg + arrAttackArray(2,3)
	WhiteDmg = WhiteDmg + arrAttackArray(7,3)
	WhiteDmg = WhiteDmg + arrAttackArray(8,3)
	WhiteDmg = WhiteDmg + arrAttackArray(13,3)
	WhiteDmg = WhiteDmg + arrAttackArray(14,3)

	WFDmg = 0
	WFDmg = WFDmg + arrAttackArray(9, 3)
	WFDmg = WFDmg + arrAttackArray(10, 3)
	WFDmg = WFDmg + arrAttackArray(11, 3)
	WFDmg = WFDmg + arrAttackArray(12, 3)

	WFOffHandSwings = 0
	WFOffHandSwings = WFOffHandSwings + arrAttackArray(12, 2)
	WFOffHandSwings = WFOffHandSwings + arrAttackArray(10, 2)

	WFMainHandSwings = 0
	WFMainHandSwings = WFMainHandSwings + arrAttackArray(9, 2)
	WFMainHandSwings = WFMainHandSwings + arrAttackArray(11, 2)

	WFSwings = 0
	WFSwings = WFSwings + arrAttackArray(9, 2)
	WFSwings = WFSwings + arrAttackArray(10, 2)
	WFSwings = WFSwings + arrAttackArray(11, 2)
	WFSwings = WFSwings + arrAttackArray(12, 2)

	SSDmg = 0
	SSDmg = SSDmg + arrAttackArray(3, 3)
	SSDmg = SSDmg + arrAttackArray(4, 3)
	SSDmg = SSDmg + arrAttackArray(5, 3)
	SSDmg = SSDmg + arrAttackArray(6, 3)

	RBDmg = 0
	RBDmg = RBDmg + arrAttackArray(16, 3)
 	RBDmg = RBDmg + arrAttackArray(18, 3)

	FTDmg = 0
	FTDmg = FTDmg + arrAttackArray(15, 3)
	FTDmg = FTDmg + arrAttackArray(17, 3)

	WhiteSwings = 0
	WhiteSwings = WhiteSwings + arrAttackArray(1, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(2, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(7, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(8, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(13, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(14, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(19, 2)
	WhiteSwings = WhiteSwings + arrAttackArray(20, 2)

	wscript.echo round(TotalDmg/(CombatTime/1000),2) & " DPS. MH/OH-Spd/Avg:" & MHWspeed & "-" & MHAvg & " " & OHWSpeed & "-" & OHAvg & ". AP/Hit/Crit: " & AP & " " & HitBonus & " " & crit & " " & Time()
	' wscript.echo TotalSwings & " Total Swings."

	'wscript.echo "Dmg = " & TotalDmg & " over " & round(CombatTime/1000,0) & " sec, for " & round(TotalDmg/(CombatTime/1000),2) & " DPS. MH/OH-Spd/Avg:" & MHWspeed & "-" & MHAvg & " " & OHWSpeed & "-" & OHAvg
	'ReportString = ReportString & "Dmg = " & TotalDmg & " over " & round(CombatTime/1000,0) & " sec, for " & round(TotalDmg/(CombatTime/1000),2) & " DPS. "
	'ReportString = ReportString & "Total Damage = " & TotalDmg & " over " & round(CombatTime/1000,0) & " seconds, which comes to " & round(TotalDmg/(CombatTime/1000),2) & " DPS" & VbCrLF
	'ReportString = ReportString & "White Damage: " & WhiteDmg & ".  DPS = " & round(1000*WhiteDmg/CombatTime, 2) & " comprising " & round(WhiteDmg*100/TotalDmg,1) & "% of Dmg Done" & VbCrLF
	'ReportString = ReportString & "StormStrike Damage: " & SSDmg & ".  DPS = " & round(1000*SSDmg/CombatTime, 2) & " comprising " & round(SSDmg*100/TotalDmg,1) & "% of Dmg Done" & VbCrLF
	'ReportString = ReportString & "Windfury Damage: " & WFDmg & ".  DPS = " & round(1000*WFDmg/CombatTime, 2) & " comprising " & round(WFDmg*100/TotalDmg,1) & "% of Dmg Done on " & Wfswings & " WF hit/crits" & VbCrLF
	'ReportString = ReportString & "FlameTongue Damage: " & FTDmg & ".  DPS = " & round(1000*FTDmg/CombatTime, 2) & " comprising " & round(FTDmg*100/TotalDmg,1) & "% of Dmg Done" & VbCrLF
	'ReportString = ReportString & "RockBiter Damage: " & RBDmg & ".  DPS = " & round(1000*RBDmg/CombatTime, 2) & " comprising " & round(RBDmg*100/TotalDmg,1) & "% of Dmg Done" & VbCrLF
	'ReportString = ReportString & "Unleashed Rage was active on " & round(100*URSwings/TotalSwings,1) & "% of attacks" & URSwings & " tot: " & TotalSwings & VbCrLF
	'ReportString = ReportString & "Windfury proc'd on = " & round(100*WFCounter/(WhiteSwings+SSSwings),2) & "% of all " & WhiteSwings+SSSwings & " white and StormStrike hits" & VbCrLF
	'ReportString = ReportString & WFMainHandSwings & " of the windfury attacks came from the main hand, and " & WFOffHandSwings & " from the off hand."

	if FirstReport = TRUE then
		reportstring = "DMG^Time^DPS^AP^Hit^Crit^Misses^WhiteSwings^WhiteDmg^SSDmg^WFDmg^WFLanded^FTDmg^RBDmg^URUptime^WFOverall%^WFMainHand^WFOffHand^MHSpeed^OHSpeed^"
		for RowLooper = 1 to 24
			reportstring = reportstring & arrAttackArray(RowLooper, 1) & "^"
		next
		reportstring = reportstring & vbcrlf
		FirstReport = False
	end if



	ReportString = ReportString & TotalDmg & "^" & round(CombatTime/1000,0) & "^" & round(TotalDmg/(CombatTime/1000),2) & "^"
	ReportString = ReportString & AP & "^" & HitBonus & "^" & Crit & "^" & arrAttackArray(19, 2) & "^" & WhiteSwings & "^"
	'ReportString = ReportString & "Total Damage = " & TotalDmg & " over " & round(CombatTime/1000,0) & " seconds, which comes to " & round(TotalDmg/(CombatTime/1000),2) & " DPS" 
	ReportString = ReportString & WhiteDmg & "^"
	ReportString = ReportString & SSDmg & "^"
	ReportString = ReportString & WFDmg & "^" & Wfswings & "^" 
	ReportString = ReportString & FTDmg & "^" 
	ReportString = ReportString & RBDmg & "^" 
	ReportString = ReportString & round(100*URSwings/TotalSwings,1) & "^" 
	ReportString = ReportString & round(100*WFCounter/(WhiteSwings+SSSwings),2) & "^" 
	ReportString = ReportString & WFMainHandSwings & "^" & WFOffHandSwings & "^"
	ReportString = ReportString & MHWSpeed & "^" & OHWSpeed & "^"
	for RowLooper = 1 to 24
		reportstring = reportstring & arrAttackArray(RowLooper, 2) & "^"
	next

	'wscript.echo Time()
	'wscript.echo ReportString

	Set objFileSystem = CreateObject("Scripting.fileSystemObject")
	Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, _
	  OPEN_FILE_FOR_APPENDING, TRUE)

	objOutputFile.WriteLine(ReportString)
	objOutputFile.Close

	Set objFileSystem = Nothing

	ReportString = ""

End Sub

