2014-07-28 14:13:38 +02:00
database = require ' ../server/commons/database '
mongoose = require ' mongoose '
log = require ' winston '
async = require ' async '
### SET UP ###
do (setupLodash = this) ->
GLOBAL._ = require ' lodash '
_.str = require ' underscore.string '
_ . mixin _ . str . exports ( )
database . connect ( )
2014-08-03 23:58:51 +02:00
## Util
## Types
contributor = (obj) ->
_ . extend obj , # This way we get the name etc on top
collection: ' users '
userField: ' _id '
category: ' contributor '
### UNLOCKABLES ###
# Generally ordered according to user.stats schema
unlockableAchievements =
2014-07-28 14:13:38 +02:00
signup:
2014-08-03 23:58:51 +02:00
name: ' Signed Up '
2014-07-28 14:13:38 +02:00
description: ' Signed up to the most awesome coding game around. '
query: ' anonymous ' : false
worth: 10
collection: ' users '
userField: ' _id '
2014-08-14 16:40:35 -07:00
category: ' misc '
2014-07-28 14:13:38 +02:00
difficulty: 1
2014-08-03 23:58:51 +02:00
recalculable: true
2014-07-28 14:13:38 +02:00
completedFirstLevel:
2014-08-03 23:58:51 +02:00
name: ' Completed 1 Level '
2014-07-28 14:13:38 +02:00
description: ' Completed your very first level. '
query: ' stats.gamesCompleted ' : $gte: 1
2014-08-03 23:58:51 +02:00
worth: 20
2014-07-28 14:13:38 +02:00
collection: ' users '
userField: ' _id '
2014-08-14 16:40:35 -07:00
category: ' level '
2014-07-30 22:23:43 +02:00
difficulty: 1
2014-08-03 23:58:51 +02:00
recalculable: true
2014-07-30 22:23:43 +02:00
completedFiveLevels:
2014-08-03 23:58:51 +02:00
name: ' Completed 5 Levels '
description: ' Completed 5 Levels. '
query: ' stats.gamesCompleted ' : $gte: 5
2014-07-30 22:23:43 +02:00
worth: 50
collection: ' users '
userField: ' _id '
2014-08-14 16:40:35 -07:00
category: ' level '
2014-08-03 23:58:51 +02:00
difficulty: 2
recalculable: true
completedTwentyLevels:
name: ' Completed 20 Levels '
description: ' Completed 20 Levels. '
query: ' stats.gamesCompleted ' : $gte: 20
worth: 500
collection: ' users '
userField: ' _id '
2014-08-14 16:40:35 -07:00
category: ' level '
2014-08-03 23:58:51 +02:00
difficulty: 3
recalculable: true
editedOneArticle: contributor
name: ' Edited an Article '
description: ' Edited your first Article. '
query: ' stats.articleEdits ' : $gte: 1
worth: 50
difficulty: 1
editedOneLevel: contributor
name: ' Edited a Level '
description: ' Edited your first Level. '
query: ' stats.levelEdits ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
editedOneLevelSystem: contributor
name: ' Edited a Level System '
description: ' Edited your first Level System. '
query: ' stats.levelSystemEdits ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
editedOneLevelComponent: contributor
name: ' Edited a Level Component '
description: ' Edited your first Level Component. '
query: ' stats.levelComponentEdits ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
editedOneThangType: contributor
name: ' Edited a Thang Type '
description: ' Edited your first Thang Type. '
query: ' stats.thangTypeEdits ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
submittedOnePatch: contributor
name: ' Submitted a Patch '
description: ' Submitted your very first patch. '
query: ' stats.patchesSubmitted ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
contributedOnePatch: contributor
name: ' Contributed a Patch '
description: ' Got your very first accepted Patch. '
query: ' stats.patchesContributed ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
acceptedOnePatch: contributor
name: ' Accepted a Patch '
description: ' Accepted your very first patch. '
query: ' stats.patchesAccepted ' : $gte: 1
worth: 50
difficulty: 1
recalculable: false
oneTranslationPatch: contributor
name: ' First Translation '
description: ' Did your very first translation. '
query: ' stats.totalTranslationPatches ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
oneMiscPatch: contributor
name: ' First Miscellaneous Patch '
description: ' Did your first miscellaneous patch. '
query: ' stats.totalMiscPatches ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
oneArticleTranslationPatch: contributor
name: ' First Article Translation '
description: ' Did your very first Article translation. '
query: ' stats.articleTranslationPatches ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
oneArticleMiscPatch: contributor
name: ' First Misc Article Patch '
description: ' Did your first miscellaneous Article patch. '
query: ' stats.totalMiscPatches ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
oneLevelTranslationPatch: contributor
name: ' First Level Translation '
description: ' Did your very first Level translation. '
query: ' stats.levelTranslationPatches ' : $gte: 1
worth: 50
difficulty: 1
recalculable: true
oneLevelMiscPatch: contributor
name: ' First Misc Level Patch '
description: ' Did your first misc Level patch. '
query: ' stats.levelMiscPatches ' : $gte: 1
worth: 50
2014-07-28 14:13:38 +02:00
difficulty: 1
2014-08-03 23:58:51 +02:00
recalculable: true
2014-07-28 14:13:38 +02:00
2014-08-03 23:58:51 +02:00
### REPEATABLES ###
repeatableAchievements =
2014-07-28 14:13:38 +02:00
simulatedBy:
name: ' Simulated ladder game '
description: ' Simulated a ladder game. '
query: ' simulatedBy ' : $gte: 1
worth: 1
collection: ' users '
userField: ' _id '
2014-08-14 16:40:35 -07:00
category: ' ladder '
2014-07-28 14:13:38 +02:00
difficulty: 1
proportionalTo: ' simulatedBy '
function:
kind: ' logarithmic '
parameters: # TODO tweak
a: 5
b: 1
c: 0
2016-04-06 10:56:06 -07:00
Achievement = require ' ../server/models/Achievement '
EarnedAchievement = require ' ../server/models/EarnedAchievement '
2014-07-28 14:13:38 +02:00
2014-08-03 23:58:51 +02:00
Achievement . find { } , (err, achievements) ->
achievementIDs = ( achievement . get ( ' _id ' ) + ' ' for achievement in achievements )
EarnedAchievement . remove { achievement: $in: achievementIDs } , (err, count) ->
return log . error err if err ?
log . info " Removed #{ count } earned achievements that were related "
2014-07-28 14:13:38 +02:00
2014-08-03 23:58:51 +02:00
Achievement . remove { } , (err) ->
2014-07-28 14:13:38 +02:00
log . error err if err ?
2014-08-03 23:58:51 +02:00
log . info ' Removed all achievements. '
log . info " Got #{ Object . keys ( unlockableAchievements ) . length } unlockable achievements "
log . info " and #{ Object . keys ( repeatableAchievements ) . length } repeatable achievements "
achievements = _ . extend unlockableAchievements , repeatableAchievements
async . each Object . keys ( achievements ) , (key, callback) ->
achievement = achievements [ key ]
log . info " Setting up ' #{ achievement . name } ' ... "
achievementM = new Achievement achievement
# What the actual * Mongoose? It automatically converts 'stats.edits' to a nested object
achievementM . set ' query ' , achievement . query
log . debug JSON . stringify achievementM . get ' query '
achievementM . save (err) ->
log . error err if err ?
callback ( )
, (err) ->
log . error err if err ?
log . info ' Finished setting up achievements. '
process . exit ( )