mirror of
https://gitlab.com/lecarore/breakout71.git
synced 2025-05-05 03:07:14 -04:00
wip
This commit is contained in:
parent
d17eba50e5
commit
99930cb77f
13 changed files with 256 additions and 104 deletions
|
@ -13,10 +13,10 @@ import {t} from "./i18n/i18n";
|
|||
import {icons, upgrades} from "./loadGameData";
|
||||
import {asyncAlert} from "./asyncAlert";
|
||||
import {
|
||||
escapeAttribute,
|
||||
getPossibleUpgrades,
|
||||
levelsListHTMl,
|
||||
max_levels,
|
||||
pickedUpgradesHTMl,
|
||||
upgradeLevelAndMaxDisplay
|
||||
} from "./game_utils";
|
||||
import {getNearestUnlockHTML} from "./openScorePanel";
|
||||
|
@ -25,12 +25,13 @@ export async function openUpgradesPicker(gameState: GameState) {
|
|||
const catchRate =
|
||||
gameState.levelCoughtCoins / (gameState.levelSpawnedCoins || 1);
|
||||
|
||||
gameState.extra_lives++
|
||||
let choices = 3 + gameState.perks.one_more_choice
|
||||
let choices = 3
|
||||
let livesWon=1
|
||||
|
||||
if (gameState.levelWallBounces < wallBouncedGood) {
|
||||
choices++;
|
||||
gameState.extra_lives++;
|
||||
|
||||
livesWon++;
|
||||
if (gameState.levelWallBounces < wallBouncedBest) {
|
||||
choices++;
|
||||
}
|
||||
|
@ -38,100 +39,104 @@ export async function openUpgradesPicker(gameState: GameState) {
|
|||
|
||||
if (gameState.levelTime < levelTimeGood * 1000) {
|
||||
choices++;
|
||||
gameState.extra_lives++;
|
||||
livesWon++;
|
||||
if (gameState.levelTime < levelTimeBest * 1000) {
|
||||
choices++;
|
||||
}
|
||||
}
|
||||
if (catchRate > catchRateGood / 100) {
|
||||
choices++;
|
||||
gameState.extra_lives++;
|
||||
livesWon++;
|
||||
if (catchRate > catchRateBest / 100) {
|
||||
choices++;
|
||||
}
|
||||
}
|
||||
if (gameState.levelMisses < missesGood) {
|
||||
choices++;
|
||||
gameState.extra_lives++;
|
||||
livesWon++;
|
||||
if (gameState.levelMisses < missesBest) {
|
||||
choices++;
|
||||
}
|
||||
}
|
||||
|
||||
let offered:PerkId[]= getPossibleUpgrades(gameState)
|
||||
gameState.extra_lives+=livesWon
|
||||
|
||||
let offered: PerkId[] = getPossibleUpgrades(gameState)
|
||||
.map((u) => ({
|
||||
...u,
|
||||
score: Math.random() + (gameState.lastOffered[u.id] || 0),
|
||||
}))
|
||||
.sort((a, b) => a.score - b.score)
|
||||
.filter((u) => gameState.perks[u.id] < u.max + gameState.perks.limitless)
|
||||
.slice(0, choices)
|
||||
.map(u=>u.id)
|
||||
.map(u => u.id)
|
||||
|
||||
|
||||
offered.forEach((id) => {
|
||||
dontOfferTooSoon(gameState, id);
|
||||
});
|
||||
|
||||
let list = upgrades.filter(u=>offered.includes(u.id)||gameState.perks[u.id])
|
||||
const fromStart = upgrades.map(u => u.id).filter(id => gameState.perks[id])
|
||||
|
||||
while (true) {
|
||||
let actions: Array<{
|
||||
text: string;
|
||||
icon: string;
|
||||
value: PerkId | null;
|
||||
help: string;
|
||||
className: string;
|
||||
tooltip: string;
|
||||
}> = list.map((u) => {
|
||||
|
||||
const disabled= !gameState.extra_lives || gameState.perks[u.id] >= u.max + gameState.perks.limitless
|
||||
const lvl= gameState.perks[u.id]
|
||||
|
||||
return ({
|
||||
text: u.name + (lvl ? upgradeLevelAndMaxDisplay(u, gameState):''),
|
||||
help: u.help(Math.max(1, lvl)),
|
||||
tooltip: u.fullHelp(Math.max(1, lvl)),
|
||||
icon: icons["icon:" + u.id],
|
||||
value: u.id as PerkId,
|
||||
className: "upgrade " + (disabled && lvl ? 'no-border ':' ') + ( lvl ? '':'grey-out-unless-hovered ') ,
|
||||
disabled:disabled ,
|
||||
})
|
||||
})
|
||||
actions = [
|
||||
...actions.filter(a=>gameState.perks[a.value]),
|
||||
...actions.filter(a=>!gameState.perks[a.value]),
|
||||
]
|
||||
const updatedChoices = gameState.perks.one_more_choice + choices
|
||||
let list = upgrades.filter(u => offered.slice(0, updatedChoices).includes(u.id) || gameState.perks[u.id])
|
||||
|
||||
list = list.filter(u => fromStart.includes(u.id))
|
||||
.concat(list.filter(u => !fromStart.includes(u.id)))
|
||||
|
||||
list.forEach((u) => {
|
||||
dontOfferTooSoon(gameState, u.id);
|
||||
});
|
||||
|
||||
|
||||
const upgradeId = await asyncAlert<PerkId | null>({
|
||||
title:
|
||||
t("level_up.title", {
|
||||
level: gameState.currentLevel ,
|
||||
t("level_up.title", {
|
||||
level: gameState.currentLevel,
|
||||
max: max_levels(gameState),
|
||||
}),
|
||||
content: [
|
||||
{
|
||||
text: t('level_up.go',{name:gameState.level.name}),
|
||||
icon: icons[gameState.level.name],
|
||||
value:null,
|
||||
text: t('level_up.go', {name: gameState.level.name}),
|
||||
icon: icons[gameState.level.name],
|
||||
value: null,
|
||||
},
|
||||
// pickedUpgradesHTMl(gameState),
|
||||
|
||||
gameState.extra_lives ? `<p>${t("level_up.instructions", {
|
||||
count:gameState.extra_lives
|
||||
})}</p>` :`<p>${t("level_up.no_points")}</p>` ,
|
||||
...actions,
|
||||
levelsListHTMl(gameState, gameState.currentLevel ),
|
||||
gameState.extra_lives ? `<p>${t("level_up.instructions", {
|
||||
count: gameState.extra_lives,
|
||||
gain:livesWon
|
||||
})}</p>` : `<p>${t("level_up.no_points")}</p>`,
|
||||
...list.map((u) => {
|
||||
const max = u.max + gameState.perks.limitless
|
||||
const lvl = gameState.perks[u.id]
|
||||
|
||||
const button = !gameState.extra_lives || gameState.perks[u.id] >= max ?
|
||||
'' : ` <button data-resolve-to="${u.id}">${
|
||||
lvl ? t('level_up.upgrade') : t('level_up.pick')
|
||||
}</button>`
|
||||
|
||||
const lvlInfo = lvl ? upgradeLevelAndMaxDisplay(u, gameState) : ''
|
||||
return `<div class="upgrade choice ${
|
||||
(!lvl && gameState.extra_lives && 'free') ||
|
||||
(lvl && 'used') ||
|
||||
'greyed-out'
|
||||
}" >
|
||||
${icons["icon:" + u.id]}
|
||||
<p data-tooltip="${escapeAttribute(u.fullHelp(Math.max(1, lvl)))}">
|
||||
<strong>${u.name}</strong> ${lvlInfo}
|
||||
${u.help(Math.max(1, lvl))}
|
||||
</p>
|
||||
${button}
|
||||
</div>`
|
||||
})
|
||||
,
|
||||
levelsListHTMl(gameState, gameState.currentLevel),
|
||||
getNearestUnlockHTML(gameState),
|
||||
`<div id="level-recording-container"></div>`,
|
||||
],
|
||||
});
|
||||
|
||||
if (upgradeId ) {
|
||||
if (upgradeId) {
|
||||
gameState.perks[upgradeId]++;
|
||||
gameState.runStatistics.upgrades_picked++;
|
||||
gameState.extra_lives--
|
||||
}else{
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue