Skip to content

Commit e523547

Browse files
Merge branch 'dev'
2 parents af40f21 + 7db5a7c commit e523547

2 files changed

Lines changed: 72 additions & 91 deletions

File tree

app/scripts/services/dimBungieService.factory.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
return cookie.name === 'bungled';
8787
});
8888

89+
//debugger;
90+
8991
if (!_.isUndefined(cookie)) {
9092
resolve(cookie.value);
9193
} else {
@@ -440,7 +442,7 @@
440442
membershipType: membershipType,
441443
itemId: item.id,
442444
itemReferenceHash: item.hash,
443-
stackSize: item.amount,
445+
stackSize: (_.has(item, 'moveAmount') && item.moveAmount > 0) ? item.moveAmount : item.amount,
444446
transferToVault: (store.id === 'vault')
445447
},
446448
dataType: 'json',

app/scripts/services/dimItemService.factory.js

Lines changed: 69 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,67 @@
1515
};
1616

1717
function updateItemModel(item, source, target, equip) {
18+
var matchingItem;
19+
1820
if (source.id !== target.id) {
1921
var index = _.findIndex(source.items, function(i) {
2022
return (item.index === i.index);
2123
});
2224

25+
if (item.maxStackSize > 1 && item.amount < item.maxStackSize) { // Balance the stacks.
26+
if (_.has(item, 'moveAmount') && (item.moveAmount > 0)) {
27+
matchingItem = _.reduce(source.items, function(memo, i) {
28+
if (item.hash === i.hash) {
29+
if (!(_.has(i, 'moveAmount')) || ((_.has(i, 'moveAmount') && i.moveAmount === 0))) {
30+
if (memo === null) {
31+
memo = i;
32+
} else if (memo.amount > i.amount) {
33+
memo = i;
34+
}
35+
}
36+
}
37+
38+
return memo;
39+
}, null);
40+
41+
if (!_.isNull(matchingItem)) {
42+
if (item.moveAmount > item.amount) {
43+
matchingItem.amount = matchingItem.amount + (item.amount - item.moveAmount);
44+
}
45+
}
46+
47+
item.amount = item.moveAmount;
48+
}
49+
50+
item.moveAmount = 0;
51+
52+
matchingItem = _.filter(target.items, function(i) {
53+
return ((i.amount < item.maxStackSize) && (i.hash === item.hash));
54+
});
55+
56+
if (_.size(matchingItem) > 0) {
57+
var mItem = matchingItem[0];
58+
var combinedTotal = mItem.amount + item.amount;
59+
60+
item.moveAmount = item.amount;
61+
62+
if (combinedTotal <= item.maxStackSize) {
63+
mItem.amount = combinedTotal;
64+
item.amount = 0;
65+
} else {
66+
mItem.amount = mItem.maxStackSize;
67+
item.amount = combinedTotal - item.maxStackSize;
68+
}
69+
}
70+
}
71+
72+
item.owner = target.id;
73+
2374
if (index >= 0) {
24-
item.owner = target.id;
2575
source.items.splice(index, 1);
76+
}
77+
78+
if (item.amount > 0) {
2679
target.items.push(item);
2780
}
2881
}
@@ -147,9 +200,9 @@
147200
scope.similarItem = similarItem;
148201

149202
if (!equipExotic && (similarItem) && (similarItem.tier === 'Exotic')) {
150-
return $q.reject('There are no items to equip in the \'' + item.type + '\' slot.')
203+
return $q.reject('There are no items to equip in the \'' + item.type + '\' slot.');
151204
} else if (!similarItem) {
152-
return $q.reject('There are no items to equip in the \'' + item.type + '\' slot.')
205+
return $q.reject('There are no items to equip in the \'' + item.type + '\' slot.');
153206
}
154207

155208
return dimStoreService.getStore(item.owner);
@@ -167,7 +220,7 @@
167220
} else {
168221
return dimBungieService.transfer(scope.similarItem, scope.source)
169222
.then(function() {
170-
updateItemModel(scope.similarItem, scope.target, scope.source, false)
223+
updateItemModel(scope.similarItem, scope.target, scope.source, false);
171224
});
172225
}
173226
})
@@ -199,6 +252,10 @@
199252
.then(function(source) {
200253
scope.source = source;
201254

255+
// if (_.has(item, 'moveAmount') && (item.moveAmount > 0)) {
256+
// item.amount = item.moveAmount;
257+
// }
258+
202259
return dimBungieService.transfer(item, scope.target);
203260
})
204261
.then(function() {
@@ -328,8 +385,8 @@
328385
.catch(function(err) {
329386
// createSpace(vault, item, store)
330387
// .then(function() {
331-
deferred.reject(err);
332-
// });
388+
deferred.reject(err);
389+
// });
333390
});
334391
} else {
335392
deferred.resolve(true);
@@ -341,7 +398,7 @@
341398
// deferred.reject(new Error('There are too many \'' + (store.id === 'vault' ? item.sort : item.type) + '\' items in the ' + (store.id === 'vault' ? 'vault' : 'guardian') + '.'));
342399
// });
343400
// } else {
344-
deferred.reject(new Error('There are too many \'' + (store.id === 'vault' ? item.sort : item.type) + '\' items in the ' + (store.id === 'vault' ? 'vault' : 'guardian') + '.'));
401+
deferred.reject(new Error('There are too many \'' + (store.id === 'vault' ? item.sort : item.type) + '\' items in the ' + (store.id === 'vault' ? 'vault' : 'guardian') + '.'));
345402
// }
346403
}
347404

@@ -354,93 +411,10 @@
354411

355412
var promise = $q.when(dimStoreService.getStores())
356413
.then(function(stores) {
357-
// var sortedStores = _.chain(stores)
358-
// .filter(function(s) {
359-
// return (s.id !== 'vault');
360-
// })
361-
// .sortBy(function(s) {
362-
// if (s.id === store.id) {
363-
// return 2;
364-
// } else if (s.id === target.id) {
365-
// return 0;
366-
// } else {
367-
// return 1;
368-
// }
369-
// })
370-
// .value();
371-
//
372-
// var i = _.findWhere(store.items, { type: item.type, equipped: false });
373-
374414
return $q.reject('woopsie');
375415
});
376416

377417
return promise;
378-
379-
// var source = null;
380-
// var checkVault = true;
381-
//
382-
// return dimStoreService.getStore(item.owner)
383-
// .then(function(store) {
384-
// source = store;
385-
//
386-
// if ((source.id === target.id) || (source.id === 'vault') || (target.id === 'vault')) {
387-
// checkVault = false;
388-
// }
389-
//
390-
// if (checkVault) {
391-
// var itemToMove;
392-
// var stores;
393-
// var vault;
394-
//
395-
// return dimStoreService.getStores()
396-
// .then(function(_stores) {
397-
// stores = _stores;
398-
//
399-
// vault = _.findWhere(stores, {
400-
// id: 'vault'
401-
// });
402-
//
403-
// itemToMove = _.findWhere(store.items, {
404-
// equipped: false,
405-
// type: item.type
406-
// });
407-
// })
408-
// .then(function() {
409-
// // var overflow = _.chain(stores)
410-
// // .sortBy(function(s) {
411-
// // if (s.id === 'vault') {
412-
// // return 0;
413-
// // } else if (s.id === source.id) {
414-
// // return 2;
415-
// // } else if (s.id === target.id) {
416-
// // return 3;
417-
// // } else {
418-
// // return 1;
419-
// // }
420-
// // })
421-
// // .filter(function(s) {
422-
// // var count = _.chain(s.items)
423-
// // .where({
424-
// // equipped: false,
425-
// // type: item.type
426-
// // })
427-
// // .size()
428-
// // .value();
429-
// //
430-
// // if (size < 9)
431-
// //
432-
// // return ((s.id !== 'vault') && (s.id !== source.id) && (s.id !== target.id));
433-
// // });
434-
// //
435-
// // if (_.isUndefined(overflow)) {
436-
// //
437-
// // }
438-
// });
439-
// }
440-
// })
441-
// .then(function() {
442-
//
443-
// });
444418
}
445419

446420
function isVaultToVault(item, store) {
@@ -528,6 +502,11 @@
528502
promise = promise.then(moveToStore.bind(null, item, data.target, equip));
529503
}
530504

505+
promise = promise
506+
.then(function() {
507+
item.moveAmount = 0;
508+
});
509+
531510
return promise;
532511
})
533512
.catch(function(e) {

0 commit comments

Comments
 (0)