DevChatterBot icon indicating copy to clipboard operation
DevChatterBot copied to clipboard

Add in Achievements for Chatters/Viewers

Open benrick opened this issue 6 years ago • 1 comments

For a long time we've been planning on having viewers and chatters be able to earn achievements through their participation in the stream. This will likely need some on-screen support, but we can start building it.

benrick avatar Apr 07 '18 21:04 benrick

First attempt at getting some sort of model and design in writing

Implementing Achievements will require the bot to register data per char user, or use existing data. Perhaps it is a good ide to gather some examples of achievements first to get a feel of which data is required to actually award these achievements.

What might trigger awarding an achievement

  • The amount of coins. Of course that would lead to the question whether to use the actual current amount of coins, or a historical total
  • Number of streams participated in. That would required detecting a user entering chat during a live stream
  • How active is someone in the chat. That would require counting the number of chat messages. Do we include chat commands, I think so, just simply count every chat line as activity. Even though someone could simply spam the chat. [Side-note. That might be something for the cool-down issue to take care of]
  • Award an Achievement for the Follow
  • Award an Achievement for a Subscribe
  • Award Achievements for winning games (multiple times)

Usually Achievements are awards for specific things such a in the case of "Following" or for doing things multiple times. In the end both can be based on a counting achievement system.

New tables and changed tables I'm just using names as I would do, they might conflict with the current naming conventions but at least it gives a starting point for discussion

ChatUser This is an additional field that keeps track of the total Points awarded. I know this is just a total on the UserAchievements table, or even on the Achievements after joining things together but what if this bot is used on Twitch and we have 100000 users all with 10000 achievements and we want to show a leaderboard. We will need some to update this field every time we award an achievement. And perhaps some maintenance task to recalculate this if needed

Name Type Description
TotalPoints int Keeps track of the total points awarded.

UserAchievements I se this table as a log of the achievements that were awarded to the user. The fields Points and Label might not be necessary but I included them so we don't have to join with Achievements and can withstand a delete or change of the achievement.

Name Type Description
ChatUserId guid
AchievementId guid
AwaredDate datetime
Points int The number of points awarded by the achievement. We might not need this since we can always get it from the achievement. But what If we tweak achievements and lower hight points, or delete an achievement.
Label string This might just be the Name of the awarded Achievement but we could also do something with a text that included actual data. Otherwise this could be left out since we could always get it from the original achievement. Unless we want it to be delete save

Achievements The table holding the actual list of achievements.

Name Type Description
Id guid
Name string The Display label for this achievement
Explain string A longer text explaining what this achievement is about. We might also name this HelpText in line with exsting properties
Points int The number of points awarded for this Achievement

AchievementCycles I am calling this table "Cycles" because it will keep track of progress for alle achievements for all users. Once awarded we could remove the data, but we might also keep the completed cycles so we can do some analytics later and simply start a new cycle for that particular achievement.

Name Type Description
Id guid
ChatUserId guid
AchievementId guid
BeginDate Datetime Determines the beginning of this cycle
EndDate DateTime Determines the end of the current cycle
Awarded Bool Is set to true once the counters in this cycle are enough to award the achievement. We now the cycle cannot award an achievement twice while the cycle is active
CoinsCounter int This counter is used for achievements that use points
...

I'm not sure about the exact structure because it depends on the types of data we want the achievements to be able to trigger on.

Design To be able to award achievements we will require some data structures to keep track of achievement progress for CharUsers. I imagine we need to start these cycles some might have an EndDate of 12-31-9999 and some might have a month cycle or even shorter. During that time we tally up the counters -- which I have not included in the table proposal yet -- and update from code. Once the needed counts have been reach we award the achievement and mark the cycle as awarded. If the cycle expires before we award we can do nice analytics on that. What counter we need and how many should be discussed. As example I included a CoinsCounter that would get updated every time a user get coins. So if we have an achievement for "User has accrued XXX coins over time" we could award it if the CounCounter > XXX. How to do that awarding is tricky. I think we need some method in code that does it and is linked to the achievement.

Final notes

  • Personally I hate guids as Id values because they are very bad as Primary keys. An int is smaller and I think still processes faster and having a clusted index on them Is better since guid would get sorted. I left it all guid but this is something we might want to look at in the future. Or let somebody prove me wrong about guids in databases (I might be old-skool on this)
  • I'm not sure creating design documents in the comments is the best place so anybody know of a better way.

summer600 avatar Apr 27 '18 11:04 summer600