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.
m (circumventing "Rerun in rotation -1 times to date")
(Calibration in order to provide more exact data)
Line 268: Line 268:
     next_rerun_days_away = next_rerun_wrap - curr_ghb
     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))
-- Subtracting Seven hours to calibrate daily reset time (07:00 UTC)
     next_rerun = os.date("%B %e, %Y", os.time()-7*60*60+(24*60*60*next_rerun_days_away))
      
      
     date_set = {
     date_set = {
     { year=2018, month=02, day=09+ghb_number },
     { year=2018, month=02, day=09+ghb_number , hour=7 },
     { year=2018, month=04, day=11+ghb_number%7 },
     { year=2018, month=04, day=11+ghb_number%7, hour=7 },
     { year=2022, month=02, day=02+ghb_number%7 },
     { year=2022, month=02, day=02+ghb_number%7, hour=7 },
     { year=2023, month=02, day=02+ghb_number%7 },
     { year=2023, month=02, day=02+ghb_number%7, hour=7 },
     { year=2024, month=01, day=30+ghb_number%7 }
     { year=2024, month=01, day=30+ghb_number%7, hour=7 }
     }
     }
      
      
     rotation_since = os.date("%B %e, %Y", os.time( date_set[math.floor(ghb_number/7)+1] ))
     rotation_since = os.date("%B %e, %Y", os.time( date_set[math.floor(ghb_number/7)+1] ))


     total_reruns = math.max(math.floor(os.difftime( os.time(), os.time( date_set[math.floor(ghb_number/7)+1] ) ) / (24*60*60)/7), 0)
-- Using ceiling function to account currently running GHB
     total_reruns = math.ceil(os.difftime( os.time(), os.time( date_set[math.floor(ghb_number/7)+1] ) ) / (24*60*60)/7) + 0


     if( ghb_number%7 == curr_ghb ) then
     if( ghb_number%7 == curr_ghb ) then

Revision as of 03:41, 31 January 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:

Script error: The function "main" does not exist.


local p = {}

--[[
Functions for each Grand Hero Battle. Lloyd was the first rotation GHB, on
9 February 2018, so he is number 0; the others follow on up to 6 (Ursula).
Then, call the main functions down below.
]]

function p.Lloyd()
    return p.getGHBData(0)
end

function p.Michalis()
    return p.getGHBData(1)
end

function p.Xander()
    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

function p.Legion()
	return p.getGHBData(7)
end

function p.Clarisse()
	return p.getGHBData(8)
end

function p.Berkut()
	return p.getGHBData(9)
end

function p.Valter()
	return p.getGHBData(10)
end

function p.Arvis()
	return p.getGHBData(11)
end

function p.Zephiel()
	return p.getGHBData(12)
end

function p.Camus()
	return p.getGHBData(13)
end

function p.Oliver()
	return p.getGHBData(14)
end

function p.Lyon()
	return p.getGHBData(15)
end

function p.Takumi()
	return p.getGHBData(16)
end

function p.Saias()
	return p.getGHBData(17)
end

function p.KanaM()
	return p.getGHBData(18)
end

function p.Julius()
	return p.getGHBData(19)
end

function p.Linus()
	return p.getGHBData(20)
end

function p.Walhart()
	return p.getGHBData(14)
end

function p.Jamke()
	return p.getGHBData(15)
end

function p.Garon()
	return p.getGHBData(16)
end

function p.Aversa()
	return p.getGHBData(17)
end

function p.Gharnef()
	return p.getGHBData(18)
end

function p.Naesala()
	return p.getGHBData(19)
end

function p.Panne()
	return p.getGHBData(20)
end

function p.Rutger()
	return p.getGHBData(21)
end

function p.Haar()
	return p.getGHBData(22)
end

function p.Delthea()
	return p.getGHBData(23)
end

function p.Cynthia()
	return p.getGHBData(24)
end

function p.Kronya()
	return p.getGHBData(25)
end

function p.DeathKnight()
	return p.getGHBData(26)
end

function p.Astram()
	return p.getGHBData(27)
end

function p.Conrad()
	return p.getGHBData(21)
end

function p.Cormag()
	return p.getGHBData(22)
end

function p.Kempf()
	return p.getGHBData(23)
end

function p.Travant()
	return p.getGHBData(24)
end

function p.Heath()
	return p.getGHBData(25)
end

function p.FlameEmperor()
	return p.getGHBData(26)
end

function p.Iago()
	return p.getGHBData(27)
end

function p.Ashnard()
	return p.getGHBData(28)
end

function p.Gangrel()
	return p.getGHBData(29)
end

function p.Eremiya()
	return p.getGHBData(30)
end

function p.Jorge()
	return p.getGHBData(31)
end

function p.Petrine()
	return p.getGHBData(32)
end

function p.Nemesis()
	return p.getGHBData(33)
end

function p.Galle()
	return p.getGHBData(34)
end

function p.Caellach()
	return p.getGHBData(28)
end

function p.Veld()
	return p.getGHBData(29)
end

function p.Dithorba()
	return p.getGHBData(30)
end

function p.Solon()
	return p.getGHBData(31)
end

function p.Sonia()
	return p.getGHBData(32)
end

function p.Orson()
	return p.getGHBData(33)
end

function p.Fernand()
	return p.getGHBData(34)
end

--[[
This gets the current Grand Hero Battle, by comparing today's date to
the rotation start date (8 February, 2018).
]]

function p.getGrandHeroBattle(ghb_number)
    date_set = {
    	{ year=2018, month=02, day=09, hour=07 },
    	{ year=2018, month=04, day=11, hour=07 },
    	{ year=2022, month=02, day=02, hour=07 },
    	{ year=2023, month=02, day=02, hour=07 },
    	{ year=2024, month=01, day=30, hour=07 },
    }
    start_day = os.time( date_set[math.floor(ghb_number/7)+1])
    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(ghb_number)

    -- Need to wrap around for Hero Battles with an ID number lower than the current one
    if( ghb_number%7 <= curr_ghb ) then
        next_rerun_wrap = ghb_number%7 + 7
    else
        next_rerun_wrap = ghb_number%7
    end

    next_rerun_days_away = next_rerun_wrap - curr_ghb

	-- Subtracting Seven hours to calibrate daily reset time (07:00 UTC)
    next_rerun = os.date("%B %e, %Y", os.time()-7*60*60+(24*60*60*next_rerun_days_away))
    
    date_set = {
    	{ year=2018, month=02, day=09+ghb_number  , hour=7 },
    	{ year=2018, month=04, day=11+ghb_number%7, hour=7 },
    	{ year=2022, month=02, day=02+ghb_number%7, hour=7 },
    	{ year=2023, month=02, day=02+ghb_number%7, hour=7 },
    	{ year=2024, month=01, day=30+ghb_number%7, hour=7 }
    }
    
    rotation_since = os.date("%B %e, %Y", os.time( date_set[math.floor(ghb_number/7)+1] ))

	-- Using ceiling function to account currently running GHB
    total_reruns = math.ceil(os.difftime( os.time(), os.time( date_set[math.floor(ghb_number/7)+1] ) ) / (24*60*60)/7) + 0

    if( ghb_number%7 == curr_ghb ) 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