From b6bde457cd52048cc7a1b15452dbfc26befa81d1 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 20 Feb 2024 00:02:44 -0500 Subject: [PATCH] Update boss bar logic --- index.css | 1 + src/pokemon.ts | 25 ++++++++++++++----------- src/ui/battle-info.ts | 13 ++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/index.css b/index.css index 0fd1e083b..716f06321 100644 --- a/index.css +++ b/index.css @@ -160,4 +160,5 @@ body { input:-internal-autofill-selected { -webkit-background-clip: text; + background-clip: text; } \ No newline at end of file diff --git a/src/pokemon.ts b/src/pokemon.ts index 29b6373ec..01a23f2b1 100644 --- a/src/pokemon.ts +++ b/src/pokemon.ts @@ -2296,20 +2296,23 @@ export class EnemyPokemon extends Pokemon { if (this.isFainted()) return 0; - if (!ignoreSegments && this.isBoss()) { - const segmentSize = this.getMaxHp() / this.bossSegments; - for (let s = this.bossSegments - 1; s > 0; s--) { - const hpThreshold = segmentSize * s; - const roundedHpThreshold = Math.round(hpThreshold); - if (this.hp > roundedHpThreshold) { - if (this.hp - damage < roundedHpThreshold) { - const bypassSegment = this.canBypassBossSegments() && (this.hp - roundedHpThreshold) / damage < 0.1; - damage = this.hp - (bypassSegment ? Math.round(hpThreshold - segmentSize) : roundedHpThreshold); - this.handleBossSegmentCleared(s); + if (this.isBoss()) { + if (!ignoreSegments) { + const segmentSize = this.getMaxHp() / this.bossSegments; + for (let s = this.bossSegmentIndex; s > 0; s--) { + const hpThreshold = segmentSize * s; + const roundedHpThreshold = Math.round(hpThreshold); + if (this.hp >= roundedHpThreshold) { + if (this.hp - damage < roundedHpThreshold) { + const bypassSegment = this.canBypassBossSegments() && (this.hp - roundedHpThreshold) / damage < 0.1; + damage = this.hp - (bypassSegment ? Math.round(hpThreshold - segmentSize) : roundedHpThreshold); + this.handleBossSegmentCleared(s); + } + break; } - break; } } + this.battleInfo.updateBossSegments(this); } return super.damage(damage, ignoreSegments, preventEndure); diff --git a/src/ui/battle-info.ts b/src/ui/battle-info.ts index 89ef9630b..4a8a7b945 100644 --- a/src/ui/battle-info.ts +++ b/src/ui/battle-info.ts @@ -167,7 +167,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.ownedIcon.setTint(0x808080); if (this.boss) - this.updateBossSegmentDividers(pokemon.getMaxHp()); + this.updateBossSegmentDividers(pokemon as EnemyPokemon); } this.hpBar.setScale(pokemon.getHpRatio(), 1); @@ -200,9 +200,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container { this.box.setTexture(this.getTextureName()); - if (this.player) { + if (this.player) this.y -= 12 * (mini ? 1 : -1); - } const offsetElements = [ this.nameText, this.genderText, this.statusIndicator, this.levelContainer ]; offsetElements.forEach(el => el.y += 1.5 * (mini ? -1 : 1)); @@ -227,17 +226,17 @@ export default class BattleInfo extends Phaser.GameObjects.Container { } this.bossSegments = boss ? pokemon.bossSegments : 0; - this.updateBossSegmentDividers(pokemon.hp); + this.updateBossSegmentDividers(pokemon); } - updateBossSegmentDividers(hp: number): void { + updateBossSegmentDividers(pokemon: EnemyPokemon): void { while (this.hpBarSegmentDividers.length) this.hpBarSegmentDividers.pop().destroy(); if (this.boss && this.bossSegments > 1) { for (let s = 1; s < this.bossSegments; s++) { - const dividerX = (Math.round((hp / this.bossSegments) * s) / hp) * this.hpBar.width; - const divider = this.scene.add.rectangle(0, 0, 1, this.hpBar.height, 0xffffff); + const dividerX = (Math.round((pokemon.hp / this.bossSegments) * s) / pokemon.hp) * this.hpBar.width; + const divider = this.scene.add.rectangle(0, 0, 1, this.hpBar.height, pokemon.bossSegmentIndex >= s ? 0xFFFFFF : 0x404040); divider.setOrigin(0.5, 0); this.add(divider);