#i think i wrote it wrong, give me a sec

1 messages · Page 1 of 1 (latest)

analog lintel
#

Just to avoid spam, here is my final code. Let me know if you think it can be improved?

    internal float GetYinYangTimeBonus(CultivationElement cultivationElement, float time)
    {
        float cycleLength = 6f;
        float firstPeak = 3f;
        float maxBonus = 0f;

        if (cultivationElement == CultivationElement.None) return 0.3f;

        else if (cultivationElement == CultivationElement.Water ||
                 cultivationElement == CultivationElement.Metal)
        {
            if (time >= 0f && time <= 6f || time > 18f && time <= 24f) maxBonus = 0.3f;
        }
        else if(cultivationElement == CultivationElement.Wood ||
                cultivationElement == CultivationElement.Fire)
        {
            if (time >= 6f || time <= 18f) maxBonus = 0.3f;
        }

        return Mathf.Lerp(0f, maxBonus, 1 - Mathf.Abs(time % cycleLength - firstPeak) / firstPeak);
    }
ocean anchor
analog lintel
#

Right yeah I was going to change that part

#

since its always half of cycle length

#

regardless of cycle length value

ocean anchor
#

judging from your other conditions, that time > 18f should maybe be a >=?

analog lintel
#

yeah thanks, missed it

ocean anchor
#

just to be sure, peaks are at 3am, 9am, 3pm, 9pm?

analog lintel
#

Yes its halfway through 6 hours cycle

ocean anchor
#

i was a bit confused from your original messages so just making sure

analog lintel
#

Which in theory could start at different hour, but I can always add an offset I think

#
        return Mathf.Lerp(0f, maxBonus, 1 - Mathf.Abs(time % cycleLength - firstPeak) / firstPeak);

Not sure if I can improve this part, I tried to change it a bit, but I think its needed.

ocean anchor
#

you have 0.3f in 3 places, i think that should be deduplicated for ease of change if you need to balance it later

analog lintel
#

I could remove a firstPeak variable and just do cycleLength/2, but I dont like that 😄

#

Sounds good

ocean anchor
#

im not sure that code would work if the cycle isn't aligned with midnight

#

at first i assumed it would so i put firstPeak, but that could be confusing later on

analog lintel
#

I can rename it to cyclePeak, but its really just cycleLength / 2

ocean anchor
#

you could test that to be sure now, but using something like halfCycle might make it clearer what it is

analog lintel
#

peakCycle will make more sense to me I think

#

Also I can always add offset in Time script later, and this script can just use 0f-24f

#

Not sure if thats a good idea tho

#

so 0f would become 6am for example