Update boss bar logic

pull/16/head
Flashfyre 2024-02-20 00:02:44 -05:00
parent 6b036b112f
commit b6bde457cd
3 changed files with 21 additions and 18 deletions

View File

@ -160,4 +160,5 @@ body {
input:-internal-autofill-selected { input:-internal-autofill-selected {
-webkit-background-clip: text; -webkit-background-clip: text;
background-clip: text;
} }

View File

@ -2296,12 +2296,13 @@ export class EnemyPokemon extends Pokemon {
if (this.isFainted()) if (this.isFainted())
return 0; return 0;
if (!ignoreSegments && this.isBoss()) { if (this.isBoss()) {
if (!ignoreSegments) {
const segmentSize = this.getMaxHp() / this.bossSegments; const segmentSize = this.getMaxHp() / this.bossSegments;
for (let s = this.bossSegments - 1; s > 0; s--) { for (let s = this.bossSegmentIndex; s > 0; s--) {
const hpThreshold = segmentSize * s; const hpThreshold = segmentSize * s;
const roundedHpThreshold = Math.round(hpThreshold); const roundedHpThreshold = Math.round(hpThreshold);
if (this.hp > roundedHpThreshold) { if (this.hp >= roundedHpThreshold) {
if (this.hp - damage < roundedHpThreshold) { if (this.hp - damage < roundedHpThreshold) {
const bypassSegment = this.canBypassBossSegments() && (this.hp - roundedHpThreshold) / damage < 0.1; const bypassSegment = this.canBypassBossSegments() && (this.hp - roundedHpThreshold) / damage < 0.1;
damage = this.hp - (bypassSegment ? Math.round(hpThreshold - segmentSize) : roundedHpThreshold); damage = this.hp - (bypassSegment ? Math.round(hpThreshold - segmentSize) : roundedHpThreshold);
@ -2311,6 +2312,8 @@ export class EnemyPokemon extends Pokemon {
} }
} }
} }
this.battleInfo.updateBossSegments(this);
}
return super.damage(damage, ignoreSegments, preventEndure); return super.damage(damage, ignoreSegments, preventEndure);
} }

View File

@ -167,7 +167,7 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.ownedIcon.setTint(0x808080); this.ownedIcon.setTint(0x808080);
if (this.boss) if (this.boss)
this.updateBossSegmentDividers(pokemon.getMaxHp()); this.updateBossSegmentDividers(pokemon as EnemyPokemon);
} }
this.hpBar.setScale(pokemon.getHpRatio(), 1); this.hpBar.setScale(pokemon.getHpRatio(), 1);
@ -200,9 +200,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
this.box.setTexture(this.getTextureName()); this.box.setTexture(this.getTextureName());
if (this.player) { if (this.player)
this.y -= 12 * (mini ? 1 : -1); this.y -= 12 * (mini ? 1 : -1);
}
const offsetElements = [ this.nameText, this.genderText, this.statusIndicator, this.levelContainer ]; const offsetElements = [ this.nameText, this.genderText, this.statusIndicator, this.levelContainer ];
offsetElements.forEach(el => el.y += 1.5 * (mini ? -1 : 1)); 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.bossSegments = boss ? pokemon.bossSegments : 0;
this.updateBossSegmentDividers(pokemon.hp); this.updateBossSegmentDividers(pokemon);
} }
updateBossSegmentDividers(hp: number): void { updateBossSegmentDividers(pokemon: EnemyPokemon): void {
while (this.hpBarSegmentDividers.length) while (this.hpBarSegmentDividers.length)
this.hpBarSegmentDividers.pop().destroy(); this.hpBarSegmentDividers.pop().destroy();
if (this.boss && this.bossSegments > 1) { if (this.boss && this.bossSegments > 1) {
for (let s = 1; s < this.bossSegments; s++) { for (let s = 1; s < this.bossSegments; s++) {
const dividerX = (Math.round((hp / this.bossSegments) * s) / hp) * this.hpBar.width; 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, 0xffffff); const divider = this.scene.add.rectangle(0, 0, 1, this.hpBar.height, pokemon.bossSegmentIndex >= s ? 0xFFFFFF : 0x404040);
divider.setOrigin(0.5, 0); divider.setOrigin(0.5, 0);
this.add(divider); this.add(divider);