REM Exobit and Lockbox Counter
REM version 1.1
REM Scans the combat.log files for log entries for received Exobits and Promethium lockboxes


REM Function that takes in a Unix Epoch timestamp and returns a date string
function unUDate(intTimeStamp)
    unUDate = DateAdd("s", CLng(intTimeStamp), "01/01/1970 00:00:00")
end function


set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("MyDocuments")

aggressive_exobits  = 0
fortified_exobits   = 0
support_exobits     = 0
tenacious_exobytes  = 0
vengeful_exobytes   = 0
durable_exobytes    = 0
aggressive_exobytes = 0
fortified_exobytes  = 0
support_exobytes    = 0
superspeed_exobits  = 0
class_a             = 0

total_promethium_boxes = 0
total_opened_boxes = 0

Set promethium_boxes = CreateObject ("Scripting.Dictionary")
Set promethium_dates = CreateObject ("Scripting.Dictionary")
Set promethium_users = CreateObject ("Scripting.Dictionary")
Set death_count = CreateObject ("Scripting.Dictionary")

REM Scan both combat logs and read in all the data

ScanLog strDesktop & "\my games\DC Universe Online\Logs\combat.log", aggressive_exobits, fortified_exobits, support_exobits, tenacious_exobytes, vengeful_exobytes, durable_exobytes, aggressive_exobytes, fortified_exobytes, support_exobytes, superspeed_exobits, class_a, total_opened_boxes, promethium_boxes, total_promethium_boxes, promethium_dates, death_count
ScanLog strDesktop & "\my games\DC Universe Online\DCGame\logs\combat.log", aggressive_exobits, fortified_exobits, support_exobits, tenacious_exobytes, vengeful_exobytes, durable_exobytes, aggressive_exobytes, fortified_exobytes, support_exobytes, superspeed_exobits, class_a, total_opened_boxes, promethium_boxes, total_promethium_boxes, promethium_dates, death_count

total_exos = (aggressive_exobits + fortified_exobits + support_exobits + tenacious_exobytes + vengeful_exobytes + durable_exobytes + aggressive_exobytes + fortified_exobytes + support_exobytes + superspeed_exobits)

REM Construct a message to display to user

message = "Total Exos: " & total_exos & chr(13) & chr(13)

if total_exos = 0 then
  msgbox "No exobits found in combat log", 16

else
  message = message & "Aggressive Exobits: " & aggressive_exobits & " (" & Round(aggressive_exobits/total_exos * 100) & "%)" & chr(13)
 message = message & "Fortified Exobits: " & fortified_exobits & " (" & Round(fortified_exobits/total_exos * 100) & "%)" & chr(13)
 message = message & "Support Exobits: " & support_exobits & " (" & Round(support_exobits/total_exos * 100) & "%)" & chr(13) & chr(13)

 if superspeed_exobits  > 0 Then message = message & "Super-Speed Exobits: " & superspeed_exobits & " (" & Round(superspeed_exobits/total_exos * 100) & "%)" & chr(13)
 if tenacious_exobytes  > 0 Then message = message & "Tenacious Exobytes: " & tenacious_exobytes & " (" & Round(tenacious_exobytes/total_exos * 100) & "%)" & chr(13)
 if vengeful_exobytes   > 0 Then message = message & "Vengeful Exobytes: " & vengeful_exobytes & " (" & Round(vengeful_exobytes/total_exos * 100) & "%)" & chr(13)
 if durable_exobytes    > 0 Then message = message & "Durable Exobytes: " & durable_exobytes & " (" & Round(durable_exobytes/total_exos * 100) & "%)" & chr(13)
 if aggressive_exobytes > 0 Then message = message & "Aggressive Exobytes: " & aggressive_exobytes & " (" & Round(aggressive_exobytes/total_exos * 100) & "%)" & chr(13)
 if fortified_exobytes  > 0 Then message = message & "Fortified Exobytes: " & fortified_exobytes & " (" & Round(fortified_exobytes/total_exos * 100) & "%)" & chr(13)
 if support_exobytes    > 0 Then message = message & "Support Exobytes: " & support_exobytes & " (" & Round(support_exobytes/total_exos * 100) & "%)" & chr(13) & chr(13)

end if

if class_a > 0 then
  message = message & "Class A Exoskeletal System: " & class_a & chr(13) & chr(13)
end if

REM Display message box containing entire message to the screen
MsgBox message, 64 , "Exobit data"

REM Display contents of promethium boxes to the screen and counts of each

message2 = "Promethium Lockboxes" & chr(13)

keys = promethium_boxes.Keys
items = promethium_boxes.Items
For i = 0 to promethium_boxes.Count - 1
  message2 = message2 & items(i) & " x " & keys(i) & chr(13)
Next

message2 = message2 & chr(13) & "Total Promethium Boxes : " & total_promethium_boxes & chr(13)

REM We already created a dictionary of all the timestamps we saw a promethium box and associated a user with it
REM Now create a list of users and count up how many boxes per user

keys = promethium_dates.Keys
items = promethium_dates.Items

For i = 0 to promethium_dates.Count - 1
  if promethium_users.exists(items(i)) then
    promethium_users.item(items(i)) = promethium_users.item(items(i)) + 1
  else
    promethium_users.add items(i), 1
  end if
Next

message2 = message2 & "Total Users Getting Promethium Boxes : " & promethium_users.Count & chr(13)
message2 = message2 & "Total Opened Promethium Boxes : " & total_opened_boxes & chr(13)

REM Go through the list of users and find out who has gotten the most boxes

keys = promethium_users.Keys
items = promethium_users.Items
max_count = 0
max_id = 0

For i = 0 to promethium_users.Count - 1
  if (CInt(items(i)) > max_count) Then
    max_count = items(i)
    max_id = i
  end if
Next

message2 = message2 & "Most Promethium boxes for user: " & keys(max_id) & " with " & items(max_id) & " boxes" & chr(13)
message2 = message2 & "Dates boxes obtained:" & chr(13)

REM Display the timestamps for that user with the most

keys2 = promethium_dates.Keys
items2 = promethium_dates.Items

For i = 0 to promethium_dates.Count - 1
  REM message2 = message2 & "items2(i=" & i & ") = " & items2(i) & "keys(max_count=" & max_count & ") = " & keys(max_count) & chr(13)
  if (items2(i) = keys(max_id)) Then
    message2 = message2 & unUDate(keys2(i)) & chr(13)
  end if
Next

REM Display message box containing entire message to the screen
MsgBox message2, 64 , "Lockbox data"

message3 = "Death counts" & chr(13)

keys3 = death_count.Keys
items3 = death_count.Items

For i = 0 to death_count.Count - 1
	message3 = "Player " & keys3(i) & " died " & items3(i) & " times" & chr(13)
Next

MsgBox "Noxx" & chr(13) & "ClassicFumbles", 64, "Credits"


sub ScanLog(inputFile, aggressive_exobits, fortified_exobits, support_exobits, tenacious_exobytes, vengeful_exobytes, durable_exobytes, aggressive_exobytes, fortified_exobytes, support_exobytes, superspeed_exobits, class_a, total_opened_boxes, promethium_boxes, total_promethium_boxes, promethium_dates, death_count)

  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFile = objFSO.OpenTextFile(inputFile)  
  
  MsgBox "File " & chr(13) & inputFile & chr(13) & "successfully opened.. it may take a while", 64, "Exobit and lockbox counter"

  Do Until objFile.AtEndOfStream

    str = objFile.ReadLine

    if (InStr(str,"received Aggressive Exobit"))  Then aggressive_exobits = aggressive_exobits + 1
    if (InStr(str,"received Fortified Exobit"))   Then fortified_exobits = fortified_exobits + 1
    if (InStr(str,"received Support Exobit"))     Then support_exobits = support_exobits + 1
    if (InStr(str,"received Tenacious Exobyte"))  Then tenacious_exobytes = tenacious_exobytes + 1
    if (InStr(str,"received Vengeful Exobyte"))   Then vengeful_exobytes = vengeful_exobytes + 1
    if (InStr(str,"received Durable Exobyte"))    Then durable_exobytes = durable_exobytes + 1
    if (InStr(str,"received Aggressive Exobyte")) Then aggressive_exobytes = aggressive_exobytes + 1
    if (InStr(str,"received Fortified Exobyte"))  Then fortified_exobytes = fortified_exobytes + 1
    if (InStr(str,"received Support Exobyte"))    Then support_exobytes = support_exobytes + 1
    if (InStr(str,"received Super-Speed Exobit")) Then superspeed_exobits = superspeed_exobits + 1

    if InStr(str," received Class A Exoskeletal System") Then class_a = class_a + 1

    if InStr(str," received Promethium Lockbox") Then
        newdate = Left(str, InStr(str,":")-1)
        newstr = Right(str, Len(str) - InStr(str,":"))
        newuser = Left(newstr, InStr(newstr," received "))
		if not promethium_dates.exists(newdate) then
			promethium_dates.add newdate, newuser
		end if
        total_promethium_boxes = total_promethium_boxes + 1
    end if
	
	if InStr(str, " knocked out ") Then
		target = Right(str, Len(str) - InStr(str,":"))
		newuser = Left(newstr, InStr(newstr," knocked out "))
		if death_count.exists(newuser) then
			death_count.item(newuser) = death_count.item(newuser) + 1
		else
			death_count.add newuser, 1
		end if
	end if

    if InStr(str," received ") Then
      if InStr(str," received Compound A") Then
        newbox = Mid(str, InStr(str,"received") + 9)
        if promethium_boxes.exists(newbox) then
          promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
        else
          promethium_boxes.add newbox, 1
        end if
        total_opened_boxes = total_opened_boxes + 1
      else
        if InStr(str," Eternium ") Then
          newbox = Mid(str, InStr(str,"received") + 9)
          if promethium_boxes.exists(newbox) then
            promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
          else
            promethium_boxes.add newbox, 1
          end if
          total_opened_boxes = total_opened_boxes + 1
        else
          if InStr(str," Champion's ") Then
            newbox = Mid(str, InStr(str,"received") + 9)
            if promethium_boxes.exists(newbox) then
              promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
            else
              promethium_boxes.add newbox, 1
            end if
            total_opened_boxes = total_opened_boxes + 1
          else
            if InStr(str," of Endurance") Then
              newbox = Mid(str, InStr(str,"received") + 9)   
              if promethium_boxes.exists(newbox) then
                promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
              else
                promethium_boxes.add newbox, 1
              end if
              total_opened_boxes = total_opened_boxes + 1
            else
              if InStr(str," of Panacea") Then
                newbox = Mid(str, InStr(str,"received") + 9)
                if promethium_boxes.exists(newbox) then
                  promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
                else
                  promethium_boxes.add newbox, 1
                end if   
                total_opened_boxes = total_opened_boxes + 1
              else
                if InStr(str," of Relief") Then
                  newbox = Mid(str, InStr(str,"received") + 9)
                  if promethium_boxes.exists(newbox) then
                    promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
                  else
                    promethium_boxes.add newbox, 1
                  end if
                  total_opened_boxes = total_opened_boxes + 1
                else
                  if InStr(str," of Accuracy") Then
                    newbox = Mid(str, InStr(str,"received") + 9)
                    if promethium_boxes.exists(newbox) then
                      promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
                    else
                      promethium_boxes.add newbox, 1
                    end if
                    total_opened_boxes = total_opened_boxes + 1
                  else
                    if InStr(str," Extraordinary ") Then
                      newbox = Mid(str, InStr(str,"received") + 9)
                      if promethium_boxes.exists(newbox) then
                        promethium_boxes.item(newbox) = promethium_boxes.item(newbox) + 1
                      else
                        promethium_boxes.add newbox, 1
                      end if
                      total_opened_boxes = total_opened_boxes + 1
                    end if
                  end if
                end if
              end if
            end if
          end if
        end if
      end if
    end if

  Loop

  objFile.Close

end sub