diff --git a/common/script/count.js b/common/script/count.js index b0ae608675..8832d6379f 100644 --- a/common/script/count.js +++ b/common/script/count.js @@ -2,7 +2,7 @@ require('coffee-script'); var _ = require('lodash'); -var content = require('./content'); +var content = require('./content.coffee'); var DROP_ANIMALS = _.keys(content.pets); diff --git a/common/script/index.coffee b/common/script/index.coffee index 9b7002bdf5..1670d0398a 100644 --- a/common/script/index.coffee +++ b/common/script/index.coffee @@ -378,35 +378,15 @@ api.appliedTags = (userTags, taskTags) -> arr.push(t.name) if taskTags?[t.id] arr.join(', ') -DROP_ANIMALS = _.keys(content.pets) - -api.countBeastMasterProgress = (pets) -> - count = 0 - for animal in DROP_ANIMALS - if pets[animal] > 0 || pets[animal] == -1 - count++ - - count - -api.countMountMasterProgress = (mounts) -> - count = 0 - for animal in DROP_ANIMALS - if mounts[animal] - count++ - - count - -api.countTriad = (pets) -> - count3 = 0 - for egg of content.dropEggs - for potion of content.hatchingPotions - if pets[egg + "-" + potion] > 0 then count3++ - count3 - api.countArmoire = (gear) -> count = _.size(_.filter(content.gear.flat, ((i)->i.klass is 'armoire' and !gear[i.key]))) count +### +Various counting functions +### +api.count = require('./count') + ### ------------------------------------------------------ User (prototype wrapper to give it ops, helper funcs, and virtuals diff --git a/website/public/js/controllers/inventoryCtrl.js b/website/public/js/controllers/inventoryCtrl.js index a07d43fa7e..d8cb369cc5 100644 --- a/website/public/js/controllers/inventoryCtrl.js +++ b/website/public/js/controllers/inventoryCtrl.js @@ -104,7 +104,7 @@ habitrpg.controller("InventoryCtrl", // Checks if Triad Bingo has been reached for the first time if(!user.achievements.triadBingo && $scope.mountCount >= 90 - && Shared.countTriad(User.user.items.pets) >= 90) { + && Shared.count.dropPetsCurrentlyOwned(User.user.items.pets) >= 90) { User.user.achievements.triadBingo = true; $rootScope.openModal('achievements/triadBingo'); } @@ -214,8 +214,8 @@ habitrpg.controller("InventoryCtrl", }; function _updateDropAnimalCount(items) { - $scope.petCount = Shared.countBeastMasterProgress(items.pets); - $scope.mountCount = Shared.countMountMasterProgress(items.mounts); + $scope.petCount = Shared.count.beastMasterProgress(items.pets); + $scope.mountCount = Shared.count.mountMasterProgress(items.mounts); $scope.beastMasterProgress = Stats.beastMasterProgress(items.pets); $scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts); } diff --git a/website/public/js/services/statServices.js b/website/public/js/services/statServices.js index 2935eaa798..e836b39fb2 100644 --- a/website/public/js/services/statServices.js +++ b/website/public/js/services/statServices.js @@ -15,7 +15,7 @@ var TOTAL_NUMBER_OF_DROP_ANIMALS = DROP_ANIMALS.length; function beastMasterProgress(pets) { - var dropPetsFound = Shared.countBeastMasterProgress(pets); + var dropPetsFound = Shared.count.beastMasterProgress(pets); var display = _formatOutOfTotalDisplay(dropPetsFound, TOTAL_NUMBER_OF_DROP_ANIMALS); return display; @@ -87,7 +87,7 @@ } function mountMasterProgress(mounts) { - var dropMountsFound = Shared.countMountMasterProgress(mounts); + var dropMountsFound = Shared.count.mountMasterProgress(mounts); var display = _formatOutOfTotalDisplay(dropMountsFound, TOTAL_NUMBER_OF_DROP_ANIMALS); return display; diff --git a/website/src/models/user.js b/website/src/models/user.js index f699145e2e..e8dc06e60f 100644 --- a/website/src/models/user.js +++ b/website/src/models/user.js @@ -495,13 +495,13 @@ UserSchema.pre('save', function(next) { } // Determines if Beast Master should be awarded - var beastMasterProgress = shared.countBeastMasterProgress(this.items.pets); + var beastMasterProgress = shared.count.beastMasterProgress(this.items.pets); if (beastMasterProgress >= 90 || this.achievements.beastMasterCount > 0) { this.achievements.beastMaster = true; } // Determines if Mount Master should be awarded - var mountMasterProgress = shared.countMountMasterProgress(this.items.mounts); + var mountMasterProgress = shared.count.mountMasterProgress(this.items.mounts); if (mountMasterProgress >= 90 || this.achievements.mountMasterCount > 0) { this.achievements.mountMaster = true @@ -509,9 +509,10 @@ UserSchema.pre('save', function(next) { // Determines if Triad Bingo should be awarded - var triadCount = shared.countTriad(this.items.pets); + var dropPetCount = shared.count.dropPetsCurrentlyOwned(this.items.pets); + var qualifiesForTriad = dropPetCount >= 90 && mountMasterProgress >= 90; - if ((mountMasterProgress >= 90 && triadCount >= 90) || this.achievements.triadBingoCount > 0) { + if (qualifiesForTriad || this.achievements.triadBingoCount > 0) { this.achievements.triadBingo = true; }