mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Refactor inventory ctrl variables
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
habitrpg.controller("InventoryCtrl",
|
||||
['$rootScope', '$scope', 'Shared', '$window', 'User', 'Content', 'Analytics', 'Quests',
|
||||
function($rootScope, $scope, Shared, $window, User, Content, Analytics, Quests) {
|
||||
['$rootScope', '$scope', 'Shared', '$window', 'User', 'Content', 'Analytics', 'Quests', 'Stats',
|
||||
function($rootScope, $scope, Shared, $window, User, Content, Analytics, Quests, Stats) {
|
||||
|
||||
var user = User.user;
|
||||
|
||||
@@ -8,8 +8,8 @@ habitrpg.controller("InventoryCtrl",
|
||||
|
||||
$scope.selectedEgg = null; // {index: 1, name: "Tiger", value: 5}
|
||||
$scope.selectedPotion = null; // {index: 5, name: "Red", value: 3}
|
||||
$scope.totalPets = _.size(Content.dropEggs) * _.size(Content.hatchingPotions);
|
||||
$scope.totalMounts = _.size(Content.dropEggs) * _.size(Content.hatchingPotions);
|
||||
|
||||
_updateDropAnimalCount(user.items);
|
||||
|
||||
// Functions from Quests service
|
||||
$scope.lockQuest = Quests.lockQuest;
|
||||
@@ -92,16 +92,18 @@ habitrpg.controller("InventoryCtrl",
|
||||
$scope.selectedEgg = null;
|
||||
$scope.selectedPotion = null;
|
||||
|
||||
_updateDropAnimalCount(user.items);
|
||||
|
||||
// Checks if beastmaster has been reached for the first time
|
||||
if(!User.user.achievements.beastMaster
|
||||
&& $rootScope.petCount >= 90) {
|
||||
if(!user.achievements.beastMaster
|
||||
&& $scope.petCount >= 90) {
|
||||
User.user.achievements.beastMaster = true;
|
||||
$rootScope.openModal('achievements/beastMaster');
|
||||
}
|
||||
|
||||
// Checks if Triad Bingo has been reached for the first time
|
||||
if(!User.user.achievements.triadBingo
|
||||
&& $rootScope.mountCount >= 90
|
||||
if(!user.achievements.triadBingo
|
||||
&& $scope.mountCount >= 90
|
||||
&& Shared.countTriad(User.user.items.pets) >= 90) {
|
||||
User.user.achievements.triadBingo = true;
|
||||
$rootScope.openModal('achievements/triadBingo');
|
||||
@@ -125,14 +127,15 @@ habitrpg.controller("InventoryCtrl",
|
||||
}
|
||||
User.user.ops.feed({params:{pet: pet, food: food.key}});
|
||||
$scope.selectedFood = null;
|
||||
$rootScope.mountCount = Shared.countMounts($rootScope.countExists(User.user.items.mounts), User.user.items.mounts);
|
||||
|
||||
// Checks if mountmaster has been reached for the first time
|
||||
if(!User.user.achievements.mountMaster
|
||||
&& $rootScope.mountCount >= 90) {
|
||||
User.user.achievements.mountMaster = true;
|
||||
$rootScope.openModal('achievements/mountMaster');
|
||||
}
|
||||
_updateDropAnimalCount(user.items);
|
||||
|
||||
// Checks if mountmaster has been reached for the first time
|
||||
if(!user.achievements.mountMaster
|
||||
&& $scope.mountCount >= 90) {
|
||||
User.user.achievements.mountMaster = true;
|
||||
$rootScope.openModal('achievements/mountMaster');
|
||||
}
|
||||
|
||||
// Selecting Pet
|
||||
} else {
|
||||
@@ -209,5 +212,12 @@ habitrpg.controller("InventoryCtrl",
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
function _updateDropAnimalCount(items) {
|
||||
$scope.petCount = Shared.countBeastMasterProgress(items.pets);
|
||||
$scope.mountCount = Shared.countMountMasterProgress(items.mounts);
|
||||
$scope.beastMasterProgress = Stats.beastMasterProgress(items.pets);
|
||||
$scope.mountMasterProgress = Stats.mountMasterProgress(items.mounts);
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
@@ -162,13 +162,11 @@ habitrpg.controller('SettingsCtrl',
|
||||
|
||||
$scope.releaseMounts = function() {
|
||||
User.user.ops.releaseMounts({});
|
||||
$rootScope.mountCount = 0;
|
||||
$rootScope.$state.go('tasks');
|
||||
}
|
||||
|
||||
$scope.releaseBoth = function() {
|
||||
User.user.ops.releaseBoth({});
|
||||
$rootScope.mountCount = 0;
|
||||
$rootScope.$state.go('tasks');
|
||||
}
|
||||
|
||||
|
||||
@@ -495,15 +495,15 @@ UserSchema.pre('save', function(next) {
|
||||
}
|
||||
|
||||
// Determines if Beast Master should be awarded
|
||||
var petCount = shared.countBeastMasterProgress(this.items.pets);
|
||||
if (petCount >= 90 || this.achievements.beastMasterCount > 0) {
|
||||
var beastMasterProgress = shared.countBeastMasterProgress(this.items.pets);
|
||||
if (beastMasterProgress >= 90 || this.achievements.beastMasterCount > 0) {
|
||||
this.achievements.beastMaster = true;
|
||||
}
|
||||
|
||||
// Determines if Mount Master should be awarded
|
||||
var mountCount = shared.countMountMasterProgress(this.items.mounts);
|
||||
var mountMasterProgress = shared.countMountMasterProgress(this.items.mounts);
|
||||
|
||||
if (mountCount >= 90 || this.achievements.mountMasterCount > 0) {
|
||||
if (mountMasterProgress >= 90 || this.achievements.mountMasterCount > 0) {
|
||||
this.achievements.mountMaster = true
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ UserSchema.pre('save', function(next) {
|
||||
|
||||
var triadCount = shared.countTriad(this.items.pets);
|
||||
|
||||
if ((mountCount >= 90 && triadCount >= 90) || this.achievements.triadBingoCount > 0) {
|
||||
if ((mountMasterProgress >= 90 && triadCount >= 90) || this.achievements.triadBingoCount > 0) {
|
||||
this.achievements.triadBingo = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ mixin mountList(source)
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/mattboch')=env.t('mattBoch')
|
||||
.popover-content
|
||||
p=env.t('mattShall', {name: "{{user.profile.name}}"})
|
||||
h4= env.t('mountMasterProgress') + ': {{mountCount}} / {{totalMounts}} ' + env.t('mountsTamed')
|
||||
h4= env.t('mountMasterProgress') + ': {{::mountMasterProgress}} ' + env.t('mountsTamed')
|
||||
.row: .col-md-12
|
||||
+mountList(env.Content.dropEggs)
|
||||
.row: .col-md-12
|
||||
|
||||
@@ -22,7 +22,7 @@ mixin petList(source)
|
||||
a(target='_blank', href='http://www.kickstarter.com/profile/mattboch')=env.t('mattBoch')
|
||||
.popover-content
|
||||
p=env.t('mattBochText1')
|
||||
h4=env.t('beastMasterProgress') + ': {{petCount}} / {{totalPets}} ' + env.t('petsFound')
|
||||
h4=env.t('beastMasterProgress') + ': {{::beastMasterProgress}} ' + env.t('petsFound')
|
||||
|
||||
.row: .col-md-12
|
||||
+petList(env.Content.dropEggs)
|
||||
|
||||
Reference in New Issue
Block a user