mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-07 10:34:46 -04:00
In middle of debugging non-functioning repeatable achievements.
This commit is contained in:
parent
2f36884456
commit
4ea2a51ff6
3 changed files with 9 additions and 2 deletions
app/views/play/level/modal
server
|
@ -110,6 +110,8 @@ module.exports = class HeroVictoryModal extends ModalView
|
|||
# rewards = achievement.get('rewards') or {}
|
||||
# rewards.gems *= (index + 1)
|
||||
|
||||
# TODO: use earned achievement worths or somehow pull in recalculated exp/gems
|
||||
|
||||
c.thangTypes = @thangTypes
|
||||
c.me = me
|
||||
c.readyToRank = @level.get('type', true) is 'hero-ladder' and @session.readyToRank()
|
||||
|
|
|
@ -31,7 +31,7 @@ EarnedAchievementSchema.statics.createForAchievement = (achievement, doc, origin
|
|||
gemWorth = achievement.get('rewards')?.gems ? 0
|
||||
earnedPoints = 0
|
||||
earnedGems = 0
|
||||
|
||||
|
||||
wrapUp = (earnedAchievementDoc) ->
|
||||
# Update user's experience points
|
||||
update = {$inc: {points: earnedPoints, 'earned.gems': earnedGems}}
|
||||
|
@ -50,12 +50,14 @@ EarnedAchievementSchema.statics.createForAchievement = (achievement, doc, origin
|
|||
proportionalTo = achievement.get 'proportionalTo'
|
||||
originalAmount = if originalDocObj then util.getByPath(originalDocObj, proportionalTo) or 0 else 0
|
||||
docObj = doc.toObject()
|
||||
newAmount = docObj[proportionalTo]
|
||||
newAmount = util.getByPath(docObj, proportionalTo) or 0
|
||||
console.log 'original amount is', originalAmount, 'and new amount is', newAmount, 'for', proportionalTo, 'with doc', docObj
|
||||
|
||||
if originalAmount isnt newAmount
|
||||
expFunction = achievement.getExpFunction()
|
||||
earned.notified = false
|
||||
earned.achievedAmount = newAmount
|
||||
console.log 'earnedPoints is', (expFunction(newAmount) - expFunction(originalAmount)) * pointWorth, 'was', earned.earnedPoints, earned.previouslyAchievedAmount, 'got exp function for new amount', newAmount, expFunction(newAmount), 'for original amount', originalAmount, expFunction(originalAmount), 'with point worth', pointWorth
|
||||
earnedPoints = earned.earnedPoints = (expFunction(newAmount) - expFunction(originalAmount)) * pointWorth
|
||||
earnedGems = earned.earnedGems = (expFunction(newAmount) - expFunction(originalAmount)) * gemWorth
|
||||
earned.previouslyAchievedAmount = originalAmount
|
||||
|
|
|
@ -15,6 +15,9 @@ AchievablePlugin = (schema, options) ->
|
|||
# Keep track the document before it's saved
|
||||
schema.post 'init', (doc) ->
|
||||
doc.unchangedCopy = doc.toObject()
|
||||
## Haaaaaaack, but better than cloneDeeping everything TODOOOO: otherwise the achievement doesn't realize that the document just changed
|
||||
#doc.unchangedCopy.state = _.cloneDeep doc.unchangedCopy.state if doc.unchangedCopy.state
|
||||
## Actually, it doesn't work still.
|
||||
|
||||
# Check if an achievement has been earned
|
||||
schema.post 'save', (doc) ->
|
||||
|
|
Loading…
Add table
Reference in a new issue