wangfukang 4 days ago
parent
commit
6922c04247
  1. 72
      package1/planet/adventure.vue

72
package1/planet/adventure.vue

@ -353,8 +353,8 @@
if (!cards.length) { if (!cards.length) {
cards = this.assignEmergencyIcons(this.buildCardPositions(this.roundSeed + '_emergency'), icons, garbageIcons) cards = this.assignEmergencyIcons(this.buildCardPositions(this.roundSeed + '_emergency'), icons, garbageIcons)
} }
if (this.shouldBuildUnwinnableLevel()) { if (this.shouldBuildTrapLayout()) {
this.applyUnwinnableTwist(cards, icons, garbageIcons) this.applyTrapLayout(cards)
} }
this.cards = cards this.cards = cards
this.slots = [] this.slots = []
@ -438,7 +438,6 @@
return templates[type] || templates.hell return templates[type] || templates.hell
}, },
assignTrapLayoutIcons(positions, icons, garbageIcons, seed, forceBuild) { assignTrapLayoutIcons(positions, icons, garbageIcons, seed, forceBuild) {
const rand = this.seededRandom(seed + '_layout')
const cards = positions.slice() const cards = positions.slice()
cards.forEach(card => { cards.forEach(card => {
card.icon = '' card.icon = ''
@ -490,9 +489,11 @@
card.garbage = true card.garbage = true
assigned[card.id] = true assigned[card.id] = true
}) })
let fillIndex = 0
cards.forEach((card, index) => { cards.forEach((card, index) => {
if (!card.icon) { if (!card.icon) {
card.icon = icons[(index + Math.floor(rand() * icons.length)) % icons.length] card.icon = icons[Math.floor(fillIndex / 3) % icons.length]
fillIndex++
} }
card.displayIcon = this.displayIcon(card.icon) card.displayIcon = this.displayIcon(card.icon)
card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};` card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};`
@ -510,11 +511,11 @@
}) })
return positions return positions
}, },
shouldBuildUnwinnableLevel() { shouldBuildTrapLayout() {
const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_win_rate') const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_win_rate')
return rand() < 0.5 return rand() < 0.5
}, },
applyUnwinnableTwist(cards, icons, garbageIcons) { applyTrapLayout(cards) {
const iconMap = {} const iconMap = {}
cards.forEach(card => { cards.forEach(card => {
if (this.isGarbageIcon(card.icon)) return if (this.isGarbageIcon(card.icon)) return
@ -523,41 +524,52 @@
}) })
const candidates = Object.keys(iconMap).filter(icon => iconMap[icon].length >= 3) const candidates = Object.keys(iconMap).filter(icon => iconMap[icon].length >= 3)
if (!candidates.length) return if (!candidates.length) return
const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_unwinnable') const rand = this.seededRandom((this.roundSeed || this.levelSeed()) + '_trap_layout')
this.shuffleWithRandom(candidates, rand) this.shuffleWithRandom(candidates, rand)
const trapIcons = candidates.slice(0, 4) const trapIcons = candidates.slice(0, 8 + Math.floor(rand() * 5))
trapIcons.forEach((targetIcon, trapIndex) => { trapIcons.forEach((targetIcon, trapIndex) => {
const group = iconMap[targetIcon].slice().sort((a, b) => { const group = iconMap[targetIcon].slice(0, 3)
const scoreA = (a.locked ? 10 : 0) + a.layer * 3 + (this.isCenterCard(a) ? 2 : 0) if (group.length < 3) return
const scoreB = (b.locked ? 10 : 0) + b.layer * 3 + (this.isCenterCard(b) ? 2 : 0)
return scoreB - scoreA
})
const key = group[0] const key = group[0]
const replacement = garbageIcons[trapIndex % garbageIcons.length] const pair = group.slice(1, 3)
if (!key || !replacement) return this.placeDeepKeyCard(key, trapIndex, rand)
key.icon = replacement this.exposePairEarly(pair, trapIndex)
key.displayIcon = this.displayIcon(key.icon) this.buildCoverChain(key, cards, trapIndex, rand)
key.unwinnableKey = true
key.trap = true
this.exposeBadCardEarly(key, trapIndex)
this.exposePairEarly(iconMap[targetIcon].filter(card => card.id !== key.id).slice(0, 2), trapIndex)
}) })
}, },
exposeBadCardEarly(card, index) { placeDeepKeyCard(card, index, rand) {
card.layer = 2 card.layer = 0
card.x = 116 + index * 74 card.keyCard = true
card.y = 178 + (index % 2) * 70 card.trap = true
card.x = 180 + Math.floor(rand() * 180)
card.y = 140 + Math.floor(rand() * 260)
card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};` card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};`
}, },
exposePairEarly(pair, index) { exposePairEarly(pair, index) {
const baseX = 74 + index * 88 const baseX = 66 + (index % 4) * 100
const baseY = 24 + Math.floor(index / 4) * 88
pair.forEach((card, i) => { pair.forEach((card, i) => {
card.layer = 2 card.layer = 2
card.trap = true
card.x = baseX + i * 8 card.x = baseX + i * 8
card.y = 26 + i * 78 card.y = baseY + i * 58
card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};` card.style = `left:${card.x}rpx;top:${card.y}rpx;z-index:${this.cardZIndex(card)};`
}) })
}, },
buildCoverChain(key, cards, index, rand) {
const covers = cards.filter(card => {
return card.id !== key.id && !card.garbage && !card.keyCard && !card.trap && card.layer > 0
})
this.shuffleWithRandom(covers, rand)
const count = 4 + (index % 2)
for (let i = 0; i < count && i < covers.length; i++) {
const cover = covers[i]
cover.layer = i % 2 === 0 ? 1 : 2
cover.x = key.x + (i % 2 === 0 ? 16 : -16) + Math.floor(rand() * 10)
cover.y = key.y + (i < 2 ? 16 : -16) + Math.floor(rand() * 10)
cover.style = `left:${cover.x}rpx;top:${cover.y}rpx;z-index:${this.cardZIndex(cover)};`
}
},
repositionKeyCovers(cards, seed) { repositionKeyCovers(cards, seed) {
const rand = this.seededRandom(seed + '_cover') const rand = this.seededRandom(seed + '_cover')
const keys = cards.filter(card => card.keyCard && card.layer === 0 && this.isCenterCard(card)).slice(0, 10) const keys = cards.filter(card => card.keyCard && card.layer === 0 && this.isCenterCard(card)).slice(0, 10)
@ -685,7 +697,7 @@
if (this.cards.every(item => item.removed) && this.slots.length === 0) { if (this.cards.every(item => item.removed) && this.slots.length === 0) {
this.finishClear() this.finishClear()
} else if (this.cards.every(item => item.removed || item.selected) && this.slots.length > 0) { } else if (this.cards.every(item => item.removed || item.selected) && this.slots.length > 0) {
this.failLevel() this.failLevel('没有可消组合', '剩余卡牌无法凑成消除,本关失败。不消耗次数,换个顺序再来一次。')
} else if (this.slots.length >= this.slotLimit) { } else if (this.slots.length >= this.slotLimit) {
this.failLevel() this.failLevel()
} }
@ -713,11 +725,11 @@
}, },
tryClear(icon) { tryClear(icon) {
if (this.isGarbageIcon(icon)) { if (this.isGarbageIcon(icon)) {
const garbage = this.slots.filter(item => item.icon === icon && !item.unwinnableKey) const garbage = this.slots.filter(item => item.icon === icon)
if (garbage.length < 2) return if (garbage.length < 2) return
let removedGarbage = 0 let removedGarbage = 0
this.slots = this.slots.filter(item => { this.slots = this.slots.filter(item => {
if (item.icon === icon && !item.unwinnableKey && removedGarbage < 2) { if (item.icon === icon && removedGarbage < 2) {
item.removed = true item.removed = true
removedGarbage++ removedGarbage++
return false return false

Loading…
Cancel
Save