poi-plugin-koushu-rate 2.0.13 → 2.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +36 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2837,6 +2837,7 @@ class StrongPage extends React.Component {
2837
2837
  if (n >= 10) return "max"
2838
2838
  return "+" + String(n)
2839
2839
  }
2840
+ const demandMap = {}
2840
2841
  for (const row of rows || []) {
2841
2842
  const sel = (selection || {})[row.id] || { selected: true, target: "max", qty: 1 }
2842
2843
  const qty = Math.max(1, Math.min(99, Math.round(Number(sel.qty) || 1)))
@@ -2845,32 +2846,49 @@ class StrongPage extends React.Component {
2845
2846
  const displayRow = evoUpgrade
2846
2847
  ? Object.assign({}, row, { id: row.id + ":evo:" + evoUpgrade.upgrade_id, name: evoUpgrade.targetName, category: evoUpgrade.targetCategory || row.category })
2847
2848
  : row
2848
- const invId = evoUpgrade ? String(evoUpgrade.upgrade_id) : row.id
2849
+ const targetEquipId = evoUpgrade ? String(evoUpgrade.upgrade_id) : row.id
2849
2850
  const targetLevelValue = evoUpgrade ? 0 : (sel.target === "max" ? 10 : 6)
2850
- const targetLevel = levelText(targetLevelValue)
2851
- const inv = (inventoryByEquip || {})[invId]
2852
- const levels = []
2851
+ const bucket = demandMap[targetEquipId] || (demandMap[targetEquipId] = { equipId: targetEquipId, displayRow, demands: {} })
2852
+ bucket.demands[String(targetLevelValue)] = (bucket.demands[String(targetLevelValue)] || 0) + qty
2853
+ }
2854
+ for (const bucket of Object.values(demandMap)) {
2855
+ const inv = (inventoryByEquip || {})[bucket.equipId]
2856
+ const inventoryLevels = []
2853
2857
  if (inv && inv.levels) {
2854
2858
  for (const level of Object.keys(inv.levels)) {
2855
2859
  const count = Math.max(0, Math.round(Number(inv.levels[level]) || 0))
2856
- if (count > 0) levels.push({ level: Number(level), count })
2860
+ if (count > 0) inventoryLevels.push({ level: Number(level), count })
2857
2861
  }
2858
- levels.sort((a, b) => b.level - a.level)
2862
+ inventoryLevels.sort((a, b) => b.level - a.level)
2859
2863
  }
2860
- const rowEntries = []
2861
- if (levels.length === 0) {
2862
- rowEntries.push({ key: displayRow.id + ":none", row: displayRow, targetLevel, targetLevelValue, inventoryLevel: null, stock: inventoryLoaded ? 0 : null, notFound: true })
2863
- } else {
2864
- for (const lv of levels) rowEntries.push({ key: displayRow.id + ":" + String(lv.level), row: displayRow, targetLevel, targetLevelValue, inventoryLevel: lv.level, stock: lv.count })
2864
+ const remaining = {}
2865
+ for (const lv of inventoryLevels) remaining[String(lv.level)] = lv.count
2866
+ const targetLevels = Object.keys(bucket.demands).map(Number).sort((a, b) => b - a)
2867
+ const allocation = {}
2868
+ const shortfall = {}
2869
+ for (const tl of targetLevels) {
2870
+ let need = bucket.demands[String(tl)] || 0
2871
+ for (const lv of inventoryLevels) {
2872
+ if (need <= 0) break
2873
+ const avail = remaining[String(lv.level)] || 0
2874
+ if (avail <= 0) continue
2875
+ const take = Math.min(need, avail)
2876
+ const key = String(tl) + "|" + String(lv.level)
2877
+ const alloc = allocation[key] || (allocation[key] = { targetLevelValue: tl, inventoryLevel: lv.level, qty: 0, stock: 0 })
2878
+ alloc.qty += take
2879
+ alloc.stock += take
2880
+ remaining[String(lv.level)] = avail - take
2881
+ need -= take
2882
+ }
2883
+ if (need > 0) shortfall[String(tl)] = need
2865
2884
  }
2866
- const base = Math.floor(qty / rowEntries.length)
2867
- let remainder = qty % rowEntries.length
2868
- for (const item of rowEntries) {
2869
- item.qty = base + (remainder > 0 ? 1 : 0)
2870
- if (remainder > 0) remainder -= 1
2885
+ for (const key of Object.keys(allocation)) {
2886
+ const alloc = allocation[key]
2887
+ entries.push({ key: bucket.equipId + ":" + key, row: bucket.displayRow, targetLevel: levelText(alloc.targetLevelValue), targetLevelValue: alloc.targetLevelValue, qty: alloc.qty, inventoryLevel: alloc.inventoryLevel, stock: alloc.stock })
2871
2888
  }
2872
- for (const item of rowEntries) {
2873
- if (item.qty > 0) entries.push(item)
2889
+ for (const tl of Object.keys(shortfall)) {
2890
+ const value = Number(tl)
2891
+ entries.push({ key: bucket.equipId + ":short:" + tl, row: bucket.displayRow, targetLevel: levelText(value), targetLevelValue: value, qty: shortfall[tl], inventoryLevel: null, stock: inventoryLoaded ? 0 : null, notFound: true })
2874
2892
  }
2875
2893
  }
2876
2894
  for (const item of entries) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poi-plugin-koushu-rate",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "全装备改修资材计算与推荐",
5
5
  "main": "index.js",
6
6
  "files": [