#i think i wrote it wrong, give me a sec
1 messages · Page 1 of 1 (latest)
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);
}
Right yeah I was going to change that part
since its always half of cycle length
regardless of cycle length value
judging from your other conditions, that time > 18f should maybe be a >=?
yeah thanks, missed it
just to be sure, peaks are at 3am, 9am, 3pm, 9pm?
Yes its halfway through 6 hours cycle
i was a bit confused from your original messages so just making sure
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.
you have 0.3f in 3 places, i think that should be deduplicated for ease of change if you need to balance it later
I could remove a firstPeak variable and just do cycleLength/2, but I dont like that 😄
Sounds good
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
I can rename it to cyclePeak, but its really just cycleLength / 2
you could test that to be sure now, but using something like halfCycle might make it clearer what it is