combo counts

This commit is contained in:
ntr 2019-10-15 11:57:57 +11:00
parent 26054eca73
commit 7cab0a6f18

View File

@ -1,5 +1,6 @@
const preact = require('preact');
const range = require('lodash/range');
const countBy = require('lodash/countBy');
const without = require('lodash/without');
const { connect } = require('preact-redux');
@ -262,7 +263,19 @@ function Vbox(args) {
// invalid combo
const combinerItems = combiner.map(j => vbox.bound[j]);
if (!itemInfo.combos.some(combo => combinerItems.every(c => combo.components.includes(c)))) {
const combinerCounts = countBy(combinerItems, c => c);
// unless some combo
// contains every combinerItems
// and combinerItems.count of item >= components.count(item)
if (!itemInfo.combos
.some(combo => {
const comboCount = countBy(combo.components, c => c);
return combinerItems.every(c =>
combo.components.includes(c) && comboCount[c] >= combinerCounts[c]
);
})) {
return combinerChange([i]);
}