Site News
Warning: This wiki contains spoilers. Read at your own risk!

Social media: If you would like, please join our Discord server, and/or follow us on Twitter (X) or Tumblr!

Module:GhbRotation: Difference between revisions

From Fire Emblem Wiki, your source on Fire Emblem information. By fans, for fans.
mNo edit summary
No edit summary
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


--[[
function p.main(frame)
Functions for each Grand Hero Battle. Lloyd was the first rotation GHB, on
args = frame.args
9 February 2018, so he is number 0; the others follow on up to 6 (Ursula).
date_begin = os.time({year=args[1], month=args[2], day=args[3], hour=7})
Then, call the main functions down below.
    next_rerun_days_away = 7 - math.floor(os.difftime( os.time(), date_begin ) / (24*60*60)) % 7
]]


function p.Lloyd()
-- Subtracting seven hours to calibrate daily reset time (07:00 UTC)
     return p.getGHBData(0)
    next_rerun = os.date("%B %e, %Y", math.max(os.time()-7*60*60+(24*60*60*next_rerun_days_away), date_begin))
end
      
    rotation_since = os.date("%B %e, %Y", date_begin)


function p.Michalis()
-- Using ceiling function to account currently running GHB
    return p.getGHBData(1)
    total_reruns = math.max(0, math.ceil(os.difftime( os.time(), date_begin ) / (24*60*60)/7))
end


function p.Xander()
     if ( next_rerun_days_away == 7 and os.time() >= date_begin ) then
    return p.getGHBData(2)
end
 
function p.Narcian()
    return p.getGHBData(3)
end
 
function p.Navarre()
    return p.getGHBData(4)
end
 
function p.RobinF()
    return p.getGHBData(5)
end
 
function p.Ursula()
    return p.getGHBData(6)
end
 
--[[
This gets the current Grand Hero Battle, by comparing today's date to
the rotation start date (8 February, 2018).
]]
 
function p.getGrandHeroBattle()
    start_day = os.time( { year=2018, month=02, day=09, hour=07 } )
    days_since_start = math.floor(os.difftime( os.time(), start_day ) / (24*60*60))
    curr_ghb = days_since_start % 7
    return curr_ghb
end
 
--[[
Produce the Grand Hero Battle data; first get the date of the next rerun,
then count how many reruns we've had so far, then check to see
which Grand Hero Battle is currently active.
]]
 
function p.getGHBData(ghb_number)
    curr_ghb = p.getGrandHeroBattle()
 
    -- Need to wrap around for Hero Battles with an ID number lower than the current one
     if( ghb_number <= curr_ghb ) then
        next_rerun_wrap = ghb_number + 7
    else
        next_rerun_wrap = ghb_number
    end
 
    next_rerun_days_away = next_rerun_wrap - curr_ghb
 
    next_rerun = os.date("%B %e, %Y", os.time()+(24*60*60*next_rerun_days_away))
 
    total_reruns = math.floor(os.difftime( os.time(), os.time( { year=2018, month=02, day=09+ghb_number } ) ) / (24*60*60)/7)
 
    if( ghb_number == curr_ghb ) then
         is_active = "<b>Currently available</b><br/>"
         is_active = "<b>Currently available</b><br/>"
     else
     else
Line 75: Line 20:
     end
     end


     return string.format("Rerun in rotation %s times to date<br/>%sNext rerun: %s", total_reruns, is_active, next_rerun)
     return string.format("In rotation since %s<br/>Rerun in rotation %s times to date<br/>%sNext rerun: %s",
    rotation_since, total_reruns, is_active, next_rerun)
end
end


return p
return p

Latest revision as of 12:55, 3 February 2024

For use on Grand Hero Battle and possibly other locations later on. This module can be used to output Grand Hero Battle data, including the first rerun date, the next rerun date, total number of reruns, and the current active Grand Hero Battle.

The only function, main, takes three parameters, each of them corresponding to a year, a month number, and a day of a month, where the full date represents the first rerun date of a Grand Hero Battle.

{{#invoke:GhbRotation|main|2018|02|10}}

This outputs:

In rotation since February 10, 2018
Rerun in rotation 325 times to date
Next rerun: May 4, 2024


local p = {}

function p.main(frame)
	args = frame.args
	date_begin = os.time({year=args[1], month=args[2], day=args[3], hour=7})
    next_rerun_days_away = 7 - math.floor(os.difftime( os.time(), date_begin ) / (24*60*60)) % 7

	-- Subtracting seven hours to calibrate daily reset time (07:00 UTC)
    next_rerun = os.date("%B %e, %Y", math.max(os.time()-7*60*60+(24*60*60*next_rerun_days_away), date_begin))
    
    rotation_since = os.date("%B %e, %Y", date_begin)

	-- Using ceiling function to account currently running GHB
    total_reruns = math.max(0, math.ceil(os.difftime( os.time(), date_begin ) / (24*60*60)/7))

    if ( next_rerun_days_away == 7 and os.time() >= date_begin ) then
        is_active = "<b>Currently available</b><br/>"
    else
        is_active = ""
    end

    return string.format("In rotation since %s<br/>Rerun in rotation %s times to date<br/>%sNext rerun: %s",
    	rotation_since, total_reruns, is_active, next_rerun)
end

return p