NathanCollaert / RewardsLite

A lightweight, advanced and very customizable plugin that gives rewards to players at specific playtimes.
MIT License
15 stars 12 forks source link

Limit amount of loops per day #7

Closed Binero closed 2 years ago

Binero commented 4 years ago

The specific use case I am targetting is where players receive rewards every hour, for up to three hours per day.

Every time players finish a reward track, their amount of track completions increases by one. Then 24 hours after they completed the track, it subtracts by 1 again. While their current count of track completion is equal to the maximum, they cannot progress on a track any more.

Example backwards-compatible config:

    PlaytimeNeeded: 60  # They get the reward after 60 minutes
    Loop: true # Once they complete the track, they can do it again.
    MaxLoops: 3 # They can do it 3 times in a row.
    TrackResetsAfter: 24h # 24 hours after a track, it resets its completion. 

Example not-backwards compatible config:

    PlaytimeNeeded: 60  # They get the reward after 60 minutes
    MaxLoops: 3 # They can do it 3 times in a row, set to 1 for no-looping.
    TrackResetsAfter: 24h # 24 hours after a track, it resets its completion. Set to -1 to disable resetting. 
NathanCollaert commented 4 years ago

If I understand your request correctly a simple "limit" config setting per reward would suffice. Let's say the playtimeneeded is set to 60,60,60 and loop set to true and limit set to 1:day, the player would be able to claim that reward every hour, 3 times a day. Let's say playtimeneeded is set to 60, loop to true and limit to 5:hours, the player would be able to claim a reward after 1 hour of playtime every 5 hours. Now let's say in the first example the loop was set to false, the player would be able to claim a reward every hour, 3 times a day, but only for that day. Do you think that's correct and what you're looking for?

My questions:

Binero commented 4 years ago

I think your method of doing things might also work, but although it sounds nice in English I am unsure how you're thinking it'll work.

When does the counter start to count? Once the first reward is claimed, once the player starts earning playtime towards that reward or once all rewards in that limit are claimed?

The counter would go +1 every time a reward track is completed, and -1 one TracksResetAfter after each +1.

What happens (in the first example) if a player is half way through the last claim (30 minutes left for the 3rd claim in that day) and the limit is exceeded and it should reset the loop. Would the next reward be in 30 minutes or would it also reset that time to 1 hour?

Well the limit cannot exceed 30 minutes through a claim. The count only goes up when a reward track is completed.

Is the limit counting playtime or also offline time?

For my use case, TracksResetAfter counts actual time, regardless of online/AFK/offline status.

In very rough pseudo-code, how I imagine the algorithm would work:

while (rewardTrack.counter < rewardTrack.maxLoops && player.isOnline()) 
    rewardTrack.increaseTimePlayed(); // gives rewards when a claim has been reached

    // a reward track is complete when all claims in PlaytimeNeeded have been claimed
    if (rewardTrack.completed)
        rewardTrack.counter += 1;
        queueEventAfter(rewardTrack.tracksResetAfter, { rewardTrack.counter -= 1 })
Binero commented 4 years ago

As an additional example:

    PlaytimeNeeded: 30,30
    Loop: true
    MaxLoops: 2
    TrackResetsAfter: 4h

Then the timeline:

NathanCollaert commented 4 years ago

Ah so I didn't really 100% get you there. I was more so thinking like this:

Config:

PlaytimeNeeded: 30,30
Loop: true
Limit: 4h

Timeline:

¹Counting starts when player logs in (count playtime) ²Counting starts when player claims first reward (count playtime) ³Counting starts when player has claimed all rewards (count playtime)

Alternate timeline:

²Counting starts when player claims first reward (count playtime). ³Counting starts when player claims first reward (count overall time).

Binero commented 4 years ago

How can the player claim the first reward two times in a row? Surely the second reward would have to be claimed first, then the cooldown would have to expire, before they can claim the first reward again?

Maybe another mechanism which is simpler yet satisfies the same use case, is to have the counter go +1 every time a reward track (i.e. all claims) has been completed, and reset the counter every day at a fixed time, for instance midnight.

NathanCollaert commented 4 years ago

The numbering is for different use cases so they are different rewards, you cannot claim the first reward twice in a row without claiming the second one first + have the counter reset.

Binero commented 4 years ago

I see now, my original suggestion is closest to your (3), although with the caveat that players can complete the track multiple times before the cooldown applies.

In retrospect, it might genuinely be easier to just have a counter that resets on a fixed time every day. This is easy to explain, easy to configure, and generally manages to serve the same use-case.

Then the counter goes up every time a reward track (all rewards) is complete, until it maxes out. Then players cannot start progress on a new reward track until the timer resets at midnight.

NathanCollaert commented 4 years ago

Isn't that the same as all my use cases without the fixed time tho? So better?

NathanCollaert commented 4 years ago

You know what, I'll make you a private jar with this feature and send it over so you can test and see if you like it.

Binero commented 4 years ago

Isn't that the same as all my use cases without the fixed time tho? So better?

The issue with (my understanding) of your suggestion is that if we configure it like this, that is, every 24 hours they can get three hourly rewards, if they get two claims done on day one, they can't get three rewards on day two any more, since they will complete the track after the first reward and initiate the cooldown.

PlaytimeNeeded: 60, 60, 60
Loop: true
Limit: 24h

Similarly if we say the counter starts after they start progress on the track, that means they can get nothing done on the first day, but 6 rewards on the second.

NathanCollaert commented 4 years ago

How I see it is, player logs on, plays for an hour, claims reward, has 24 hours to claim other 2 rewards. Yes it would mean the time he can claim rewards would always shift but it's always 24 hours from the first reward he claims.

NathanCollaert commented 2 years ago

Unfortunately is out of the scope of this plugin and won't be implemented.