View Single Post
03-11-24, 12:53 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,894
1 possible method based on information given and no idea how the interaction between the start times might play into calculating session A/B start times day-to-day etc. etc.

The test times, if you want to un-comment them, should give a rough idea of what's going on as the test cycles over 12 minutes instead of 12 hours.

The * should designate it's running special (session B ) times.

Lua Code:
  1. local addonName, addon = ...
  2. local L, MyRegion
  3. local TotalTime = 43200 -- Overall time 12 hours (6 special, 6 Standard just guessing! 6 Special + ??? standard)
  4. local EventDuration = 240 -- Actual tracked event run time 4 minutes???
  5. local RegionTimes = {
  6.     [1] = {
  7.         standard = { -- session A 6 hours
  8.             starttime = 1709615040,
  9.             eventinterval = 3600, -- runs every 1 hour
  10.             enable = true,
  11.             datablock = {}
  12.         },
  13.         special = { -- session B 6 hours
  14.             starttime = 1709629200,
  15.             eventinterval = 7200, -- but runs every 2 hours
  16.             sessionduration = 21600, -- calculates 6 hours window where eventinterval is increased to 2 hours)
  17.         },
  18.     },
  19. }
  20.  
  21. --[[ TEST TIMES ONLY: over 12 minutes instead of 12 hours ]]--
  22. -- NOT EXACLTLY ACCURATE!!!!!
  23. --[[
  24. TotalTime = 720 -- 12 mins (6 special, 6 standard)
  25. EventDuration = 20 -- event lasts 20 seconds instead of 4 minutes
  26.  
  27. RegionTimes[1].standard.eventinterval = 60 -- i minute instead of 1 hoiur
  28.  
  29. -- Special timming starts 4 intervals - 1 event time after standard start time (probably not completely accurate but just testing)
  30. RegionTimes[1].special.starttime = RegionTimes[1].standard.starttime + ((RegionTimes[1].standard.eventinterval * 4) - EventDuration) -- + 4 mins - 1 event
  31. RegionTimes[1].special.eventinterval = 120 -- Every 2 mins
  32. RegionTimes[1].special.sessionduration = 360 -- Special time lasts 6 minutes (50% of TotalTime ?)
  33. ]]--
  34. --[[ END TEST TIMES ]]--
  35.  
  36. local Localizations = {
  37.     enUS = {
  38.         Waiting = "|c1C7BCEFFEvent:%s\nbefore the start: %s%s|r",
  39.         Running = "|cFF35BE21Event:%s\n%s%s until completion|r",
  40.     },
  41. }
  42.  
  43. ------------------------------------------------------------------------------------------------------
  44. -- These might be converted to Saved Variables so each character can determine
  45. -- wether or not to play a sound, the alert times and colors and sound to play.
  46. -- If so then most of the code below will have to move into an event handler for
  47. -- the PLAYER_LOGIN or PLAYER_ENTERING_WORLD event.
  48. local defaults = {
  49.     useColor = true,
  50.     useSound = true,
  51.     alert1 = 600, -- Alarm 1 set to 10 minutes before event
  52.     alert1Color = "|cffffff00", -- Yellow
  53.     alert2 = 300, -- Alarm 2 set to 5 minutes before event
  54.     alert2Color = "|cffff0000", -- Red
  55.     soundKit = 32585, -- Alarm sound
  56. }
  57.  
  58. ------------------------------------------------------------------------------------------------------
  59. local function CalcTime(starttime, servertime, duration, interval)
  60.     local timeToEvent = (starttime - servertime) % interval
  61.     local inEvent, timeToRun
  62.     if timeToEvent > (interval - duration) then -- Is there between 1:15 and 1:30 to go? If so, we're in the event
  63.         inEvent = true
  64.         timeToRun = duration - (interval - timeToEvent)
  65.     else                    -- Otherwise, set the timer to time to next event
  66.         inEvent = false
  67.         timeToRun = timeToEvent
  68.     end
  69.     return inEvent, timeToRun
  70. end
  71.  
  72. local function printTime(self)
  73.     local serverTime = GetServerTime()
  74.     -- Check to see if we're in the special event time
  75.     local isSpecial = ""
  76.     local inEvent = CalcTime(MyRegion.special.starttime, serverTime, MyRegion.special.sessionduration, TotalTime) -- Are we in the 6 hour window?
  77.     if inEvent then -- if so then calulate 2 hour intervals
  78.         isSpecial = "|cffffff00*|r"
  79.         inEvent, timeToRun = CalcTime(MyRegion.special.starttime, serverTime, EventDuration, MyRegion.special.eventinterval)
  80.     else --  calulate 1 hour intervals (return to normal programming)
  81.         inEvent, timeToRun = CalcTime(MyRegion.standard.starttime, serverTime, EventDuration, MyRegion.standard.eventinterval)
  82.     end
  83.     local hideSeconds = timeToRun >= 120
  84.     local msg = L.Waiting
  85.     local msgColor = "|cffffffff"
  86.     if inEvent then
  87.         msg = L.Running
  88.     else
  89.         if defaults.useColor and timeToRun <= defaults.alert2 then
  90.             msgColor = defaults.alert2Color
  91.         elseif timeToRun <= defaults.alert1 then
  92.             if defaults.useSound and not self.Alerted then
  93.                 self.Alerted = true
  94.                 PlaySound(defaults.soundKit, "Master")
  95.             end
  96.             if defaults.useColor then
  97.                 msgColor = defaults.alert1Color
  98.             end
  99.         end
  100.     end
  101.     self.Text:SetText(format(msg, isSpecial, msgColor, SecondsToTime(timeToRun, hideSeconds)))
  102. end
  103.  
  104. ------------------------------------------------------------------------------------------------------
  105. local Backdrop = {
  106.     bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
  107. }
  108.  
  109. local frame_x = 100    
  110. local frame_y = -250    
  111. local f = CreateFrame("Button", "ZAMTimer777", UIParent, "BackdropTemplate")
  112. f:SetWidth(255)                                          
  113. f:SetHeight(30)
  114. f:SetPoint("CENTER")
  115. f:SetBackdrop(Backdrop)
  116. f:SetClampedToScreen(true)
  117. f:EnableMouse(true)
  118. f:SetMovable(true)
  119. f:SetUserPlaced(true)
  120. f:RegisterForDrag("LeftButton")
  121. f:RegisterForClicks("AnyUp")
  122. f.Text = f:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  123. f.Text:SetPoint("CENTER")
  124. f.Elapsed = 0 -- Set starting timeout (0 second)
  125. f:SetScript("OnDragStart",function(self)
  126.     self:StartMoving()
  127. end)
  128. f:SetScript("OnDragStop",function(self)  
  129.     self:StopMovingOrSizing()
  130. end)
  131. f:RegisterEvent("PLAYER_LOGIN")
  132. f:SetScript("OnEvent", function(self)
  133.     local locale = GetLocale()
  134.     L = Localizations[locale] or Localizations.enUS -- Default to enUS if locale doesn't exist in the table
  135.     MyRegion = RegionTimes[GetCurrentRegion()] or RegionTimes[1] -- Default to region 1 (US) if it doesn't exist in the table
  136.     self:SetScript("OnUpdate", function(self, elapsed)
  137.     self.Elapsed = self.Elapsed - elapsed
  138.     if self.Elapsed > 0 then -- Only check once per second
  139.         return
  140.     end
  141.     self.Elapsed = 1 -- reset the timeout (we've counted down 1 second)
  142.     printTime(self)
  143.     end)
  144. end)

You're essentially asking 2 questions. 1. how do I create a frame to track the process of x event and 2. how does Blizzard calculate the timings of x event.

This shows how 1 might work but as to 2, I have no idea so if this is not right (highly likely) then I'll leave it so maybe someone with more of an idea of what's going or might be able to figure it out.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 03-11-24 at 07:14 PM.
  Reply With Quote