mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Move all pet counting to shared count scripts
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require('coffee-script');
|
require('coffee-script');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var content = require('./content');
|
var content = require('./content.coffee');
|
||||||
|
|
||||||
var DROP_ANIMALS = _.keys(content.pets);
|
var DROP_ANIMALS = _.keys(content.pets);
|
||||||
|
|
||||||
|
|||||||
@@ -378,35 +378,15 @@ api.appliedTags = (userTags, taskTags) ->
|
|||||||
arr.push(t.name) if taskTags?[t.id]
|
arr.push(t.name) if taskTags?[t.id]
|
||||||
arr.join(', ')
|
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) ->
|
api.countArmoire = (gear) ->
|
||||||
count = _.size(_.filter(content.gear.flat, ((i)->i.klass is 'armoire' and !gear[i.key])))
|
count = _.size(_.filter(content.gear.flat, ((i)->i.klass is 'armoire' and !gear[i.key])))
|
||||||
count
|
count
|
||||||
|
|
||||||
|
###
|
||||||
|
Various counting functions
|
||||||
|
###
|
||||||
|
api.count = require('./count')
|
||||||
|
|
||||||
###
|
###
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
User (prototype wrapper to give it ops, helper funcs, and virtuals
|
User (prototype wrapper to give it ops, helper funcs, and virtuals
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ habitrpg.controller("InventoryCtrl",
|
|||||||
// Checks if Triad Bingo has been reached for the first time
|
// Checks if Triad Bingo has been reached for the first time
|
||||||
if(!user.achievements.triadBingo
|
if(!user.achievements.triadBingo
|
||||||
&& $scope.mountCount >= 90
|
&& $scope.mountCount >= 90
|
||||||
&& Shared.countTriad(User.user.items.pets) >= 90) {
|
&& Shared.count.dropPetsCurrentlyOwned(User.user.items.pets) >= 90) {
|
||||||
User.user.achievements.triadBingo = true;
|
User.user.achievements.triadBingo = true;
|
||||||
$rootScope.openModal('achievements/triadBingo');
|
$rootScope.openModal('achievements/triadBingo');
|
||||||
}
|
}
|
||||||
@@ -214,8 +214,8 @@ habitrpg.controller("InventoryCtrl",
|
|||||||
};
|
};
|
||||||
|
|
||||||
function _updateDropAnimalCount(items) {
|
function _updateDropAnimalCount(items) {
|
||||||
$scope.petCount = Shared.countBeastMasterProgress(items.pets);
|
$scope.petCount = Shared.count.beastMasterProgress(items.pets);
|
||||||
$scope.mountCount = Shared.countMountMasterProgress(items.mounts);
|
$scope.mountCount = Shared.count.mountMasterProgress(items.mounts);
|
||||||
$scope.beastMasterProgress = Stats.beastMasterProgress(items.pets);
|
$scope.beastMasterProgress = Stats.beastMasterProgress(items.pets);
|
||||||
$scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts);
|
$scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
var TOTAL_NUMBER_OF_DROP_ANIMALS = DROP_ANIMALS.length;
|
var TOTAL_NUMBER_OF_DROP_ANIMALS = DROP_ANIMALS.length;
|
||||||
|
|
||||||
function beastMasterProgress(pets) {
|
function beastMasterProgress(pets) {
|
||||||
var dropPetsFound = Shared.countBeastMasterProgress(pets);
|
var dropPetsFound = Shared.count.beastMasterProgress(pets);
|
||||||
var display = _formatOutOfTotalDisplay(dropPetsFound, TOTAL_NUMBER_OF_DROP_ANIMALS);
|
var display = _formatOutOfTotalDisplay(dropPetsFound, TOTAL_NUMBER_OF_DROP_ANIMALS);
|
||||||
|
|
||||||
return display;
|
return display;
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mountMasterProgress(mounts) {
|
function mountMasterProgress(mounts) {
|
||||||
var dropMountsFound = Shared.countMountMasterProgress(mounts);
|
var dropMountsFound = Shared.count.mountMasterProgress(mounts);
|
||||||
var display = _formatOutOfTotalDisplay(dropMountsFound, TOTAL_NUMBER_OF_DROP_ANIMALS);
|
var display = _formatOutOfTotalDisplay(dropMountsFound, TOTAL_NUMBER_OF_DROP_ANIMALS);
|
||||||
|
|
||||||
return display;
|
return display;
|
||||||
|
|||||||
@@ -495,13 +495,13 @@ UserSchema.pre('save', function(next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determines if Beast Master should be awarded
|
// 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) {
|
if (beastMasterProgress >= 90 || this.achievements.beastMasterCount > 0) {
|
||||||
this.achievements.beastMaster = true;
|
this.achievements.beastMaster = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determines if Mount Master should be awarded
|
// 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) {
|
if (mountMasterProgress >= 90 || this.achievements.mountMasterCount > 0) {
|
||||||
this.achievements.mountMaster = true
|
this.achievements.mountMaster = true
|
||||||
@@ -509,9 +509,10 @@ UserSchema.pre('save', function(next) {
|
|||||||
|
|
||||||
// Determines if Triad Bingo should be awarded
|
// 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;
|
this.achievements.triadBingo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user