2014-05-19 17:20:50 -04:00
|
|
|
CocoModel = require './CocoModel'
|
2014-06-16 08:27:16 -04:00
|
|
|
utils = require '../lib/utils'
|
2014-05-19 17:20:50 -04:00
|
|
|
|
|
|
|
module.exports = class Achievement extends CocoModel
|
|
|
|
@className: 'Achievement'
|
|
|
|
@schema: require 'schemas/models/achievement'
|
2014-05-24 14:45:53 -04:00
|
|
|
urlRoot: '/db/achievement'
|
|
|
|
|
2014-05-26 12:21:56 -04:00
|
|
|
isRepeatable: ->
|
2014-07-30 16:23:43 -04:00
|
|
|
@get('proportionalTo')?
|
2014-06-03 06:40:47 -04:00
|
|
|
|
|
|
|
# TODO logic is duplicated in Mongoose Achievement schema
|
|
|
|
getExpFunction: ->
|
2014-06-14 14:12:17 -04:00
|
|
|
kind = @get('function')?.kind or jsonschema.properties.function.default.kind
|
|
|
|
parameters = @get('function')?.parameters or jsonschema.properties.function.default.parameters
|
2014-06-12 13:39:45 -04:00
|
|
|
return utils.functionCreators[kind](parameters) if kind of utils.functionCreators
|
2014-07-28 09:14:11 -04:00
|
|
|
|
|
|
|
@styleMapping:
|
|
|
|
1: 'achievement-wood'
|
|
|
|
2: 'achievement-stone'
|
|
|
|
3: 'achievement-silver'
|
|
|
|
4: 'achievement-gold'
|
|
|
|
5: 'achievement-diamond'
|
|
|
|
|
|
|
|
getNotifyStyle: -> Achievement.styleMapping[@get 'difficulty']
|
|
|
|
|
|
|
|
getImageURL: ->
|
2014-07-28 14:04:44 -04:00
|
|
|
if @get 'icon' then '/file/' + @get('icon') else '/images/achievements/default.png'
|