How To Run Logic Periodically Based On In-Game Calendar.(Calendar is "selfmade" Time.time)

This Runs In Update, And I Wonder How Would You Suggest To Do RegenTick Every 300 (5 minutes)

        gameTimer += Time.deltaTime * 12;
        seconds = (ulong)(gameTimer % 60);
        minutes = (ulong)(gameTimer / 60) % 60;
        hours = (ulong)(gameTimer / 3600) % 24;
        days =  ((ulong)(gameTimer / 86400) % 7) + 1;
        weeks = ((ulong)(gameTimer / 604800) % 4) + 1;
        months = ((ulong)(gameTimer / 2419200) % 12) + 1;
        years = ((ulong)(gameTimer / 29030400)) % 100 + 2010;

I have these if it makes for any better

public int GetSeconds()    { return(int)(gameTimer % 60);                }
    public int GetMinutes()    { return(int) (gameTimer / 60) % 60;         }
    public int GetHours()       { return(int) (gameTimer / 3600) % 24;        }
    public int GetDaysOfWeek() { return(int) (gameTimer / 86400) % 7 + 1;    }
    public int GetDaysOfMonth(){ return(int) (gameTimer / 86400) % 28 + 1;    }
    public int GetMonth()       { return(int) (gameTimer / 2419200) % 12 + 1;}

the reason i ask is because let’s say i have a regeneration buff, which lasts for 2 hours,…
suppose it should tick every 5 minutes, but in the mean time if i call

public void Add_8_Hour()
    {
        gameTimer += 28800;
    }

it’s not gonna regen in the time between each those 300 periods

Divide 28800 by your regen period and use the result to make a loop that runs the regen routine that many times. Or instead, if the regen amount is always the same, multiply that by the result of the division to get the total regen amount.

the trouble with that is , if im buff for next hour, wait 8 that would be 7 bonus hours when the buff should no longer count.
I think that’ll have to be done somehow else,
Don’t you have an idea how to run something every 300 once?

If your buff time only lasts an hour that’s 3600 seconds, so just divide by 300 either that or the amount of time added, (whichever is the lower value), as your multiplier/loop counter.

it lasts dependant on skill so the duration is dynamic.

public void Add_8_Hours()
    {
        if (SMA.I.spellBuffs[(int)PLAYER_BUFFS . BUFF_REGENERATION].Active())
        {
            // Here i should do the divisions or calculations?
            SMA.I.spellBuffs[(int)PLAYER_BUFFS.BUFF_REGENERATION].timer  //<- timer is just gametime + duration
        }
        gameTimer += 28800;
    }

Yes, where you’ve indicated is where you should be able to work it out.

1 Like

so with a little bit of tweaking i worked it out,. thanks a bunch. ! :- )

1 Like