1
0
Fork 0
spacetac/src/game/effects/DamageEffect.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

/// <reference path="BaseEffect.ts"/>
module TS.SpaceTac.Game {
// Apply damage to a ship
export class DamageEffect extends BaseEffect {
// Base damage points
value: number;
constructor(value: number) {
super("damage");
this.value = value;
}
2015-01-28 00:00:00 +00:00
applyOnShip(ship: Ship): boolean {
var damage = this.value;
2015-02-03 00:00:00 +00:00
var hull: number;
var shield: number;
// Apply on shields
if (damage >= ship.shield.current) {
2015-02-03 00:00:00 +00:00
shield = ship.shield.current;
} else {
2015-02-03 00:00:00 +00:00
shield = damage;
}
2015-02-03 00:00:00 +00:00
damage -= shield;
// Apply on hull
if (damage >= ship.hull.current) {
2015-02-03 00:00:00 +00:00
hull = ship.hull.current;
} else {
2015-02-03 00:00:00 +00:00
hull = damage;
}
2015-02-03 00:00:00 +00:00
// Effective damages on ship
ship.addDamage(hull, shield);
2015-01-28 00:00:00 +00:00
return true;
}
getDescription(): string {
return `${this.value} damage`;
}
}
}