Reduce armour and spellshield bars during combat

This commit is contained in:
Mashy 2019-01-15 12:02:30 +10:00
parent 2d918af744
commit 6b4662dd2f
4 changed files with 28 additions and 11 deletions

View File

@ -84,7 +84,7 @@ class CrypImage extends Phaser.GameObjects.Image {
// Add cryp name
scene.add.text(nameX, nameY, cryp.name, TEXT.NORMAL).setOrigin(team, 0);
// Add cryp stat bars
this.healthBar = scene.add.existing(new StatBar(scene, this, 'HP'));
this.health = scene.add.existing(new StatBar(scene, this, 'HP'));
this.armour = scene.add.existing(new StatBar(scene, this, 'Armour'));
this.evasion = scene.add.existing(new StatBar(scene, this, 'Evasion'));
this.spellShield = scene.add.existing(new StatBar(scene, this, 'Spell Shield'));
@ -114,10 +114,27 @@ class CrypImage extends Phaser.GameObjects.Image {
this.statusText.text = '';
}
takeDamage(damage) {
if (damage > 0) this.setTint(0xff0000);
else this.setTint(0x00bb00);
this.healthBar.takeDamage(damage);
reduceDefense(amount, type) {
if (type === 'PhysDmg') {
this.armour.takeDamage(amount);
} else if (type === 'SpellDmg') {
this.spellShield.takeDamage(amount);
}
}
takeDamage(props) {
const { amount, mitigation, category } = props;
if (mitigation) this.reduceDefense(mitigation, category);
this.setTint(0xff0000);
this.health.takeDamage(amount);
this.scene.time.delayedCall(DELAYS.DAMAGE_TICK, () => {
if (this.state !== 'ko') this.clearTint();
});
}
takeHealing(amount) {
this.setTint(0x00bb00);
this.health.takeDamage(amount * -1);
this.scene.time.delayedCall(DELAYS.DAMAGE_TICK, () => {
if (this.state !== 'ko') this.clearTint();
});
@ -171,8 +188,8 @@ class CombatCryps extends Phaser.Scene {
const crypObj = this.cryps.children.entries
.find(c => c.cryp.id === cryp.id)
|| renderCryp(cryp, iter, team);
crypObj.healthBar.hp = cryp.hp.base;
crypObj.healthBar.drawStatBar();
crypObj.health.hp = cryp.hp.base;
crypObj.health.drawStatBar();
crypObj.effects.update(cryp.effects);
};

View File

@ -88,12 +88,12 @@ function animatePhase(scene, game, resolution, cb) {
const [resultType, values] = result;
if (resultType === 'Damage') {
targetSpawn.takeDamage(values.amount);
targetSpawn.takeDamage(values);
scene.registry.set('gameLog', scene.registry.get('gameLog') + 1);
return setTimeout(tickCb, DAMAGE_TICK);
}
if (resultType === 'Healing') {
targetSpawn.takeDamage(values.amount * -1);
targetSpawn.takeHealing(values.amount);
scene.registry.set('gameLog', scene.registry.get('gameLog') + 1);
return setTimeout(tickCb, DAMAGE_TICK);
}

View File

@ -78,7 +78,7 @@ class StatBar extends Phaser.GameObjects.Graphics {
} else {
this.val = (this.val - value > this.max) ? this.max : this.val -= value;
}
if (this.val === 0) this.crypObj.setKo();
if (this.val === 0 && this.type === 'HP') this.crypObj.setKo();
this.drawStatBar();
}
}

View File

@ -12,7 +12,7 @@ const Y = ITEM_LIST.y();
const WIDTH = ITEM_LIST.width();
const HEIGHT = ITEM_LIST.height();
const ITEM_WIDTH = WIDTH * 0.4;
const ITEM_HEIGHT = HEIGHT * 0.1;
const ITEM_HEIGHT = HEIGHT * 0.08;
const itemCheckHitbox = (scenePlugin, pointer) => {
const { list } = scenePlugin.get('MenuCrypList').children;