2015-01-28 00:00:00 +00:00
|
|
|
/// <reference path="BaseEffect.ts"/>
|
|
|
|
|
2017-09-24 22:23:22 +00:00
|
|
|
module TK.SpaceTac {
|
2017-02-07 19:15:21 +00:00
|
|
|
/**
|
|
|
|
* Apply damage on a ship.
|
|
|
|
*
|
|
|
|
* Damage is applied on shield while there is some, then on the hull.
|
|
|
|
*/
|
2015-01-28 00:00:00 +00:00
|
|
|
export class DamageEffect extends BaseEffect {
|
|
|
|
// Base damage points
|
2018-03-20 23:23:00 +00:00
|
|
|
value: number
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2018-03-20 23:23:00 +00:00
|
|
|
constructor(value = 0) {
|
2015-01-28 00:00:00 +00:00
|
|
|
super("damage");
|
|
|
|
|
2018-03-20 23:23:00 +00:00
|
|
|
this.value = value;
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-06-12 22:28:54 +00:00
|
|
|
/**
|
|
|
|
* Apply damage modifiers to get the final damage factor
|
|
|
|
*/
|
|
|
|
getFactor(ship: Ship): number {
|
|
|
|
let percent = 0;
|
|
|
|
iforeach(ship.ieffects(), effect => {
|
|
|
|
if (effect instanceof DamageModifierEffect) {
|
|
|
|
percent += effect.factor;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return (clamp(percent, -100, 100) + 100) / 100;
|
|
|
|
}
|
|
|
|
|
2017-02-27 00:42:12 +00:00
|
|
|
/**
|
|
|
|
* Get the effective damage done to both shield and hull (in this order)
|
|
|
|
*/
|
2018-03-20 23:23:00 +00:00
|
|
|
getEffectiveDamage(ship: Ship): ShipDamageDiff {
|
2017-06-12 22:28:54 +00:00
|
|
|
// Apply modifiers
|
2018-03-20 23:23:00 +00:00
|
|
|
let theoritical = Math.round(this.value * this.getFactor(ship));
|
2017-12-08 00:18:15 +00:00
|
|
|
let damage = theoritical;
|
2017-06-12 22:28:54 +00:00
|
|
|
|
2015-01-28 00:00:00 +00:00
|
|
|
// Apply on shields
|
2017-12-08 00:18:15 +00:00
|
|
|
let shield = (damage >= ship.getValue("shield")) ? ship.getValue("shield") : damage;
|
2015-02-03 00:00:00 +00:00
|
|
|
damage -= shield;
|
2015-01-28 00:00:00 +00:00
|
|
|
|
|
|
|
// Apply on hull
|
2017-12-08 00:18:15 +00:00
|
|
|
let hull = (damage >= ship.getValue("hull")) ? ship.getValue("hull") : damage;
|
2015-01-28 00:00:00 +00:00
|
|
|
|
2017-12-08 00:18:15 +00:00
|
|
|
return new ShipDamageDiff(ship, hull, shield, theoritical);
|
2017-02-27 00:42:12 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 23:23:00 +00:00
|
|
|
getOnDiffs(ship: Ship, source: Ship | Drone): BaseBattleDiff[] {
|
2017-11-14 00:07:06 +00:00
|
|
|
let result: BaseBattleDiff[] = [];
|
2015-02-03 00:00:00 +00:00
|
|
|
|
2018-03-20 23:23:00 +00:00
|
|
|
let damage = this.getEffectiveDamage(ship);
|
2017-12-08 00:18:15 +00:00
|
|
|
|
|
|
|
if (damage.shield || damage.hull) {
|
|
|
|
result.push(damage);
|
2017-04-24 17:59:16 +00:00
|
|
|
}
|
2017-11-14 00:07:06 +00:00
|
|
|
|
2017-12-08 00:18:15 +00:00
|
|
|
if (damage.shield) {
|
|
|
|
result.push(new ShipValueDiff(ship, "shield", -damage.shield));
|
2017-11-14 00:07:06 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 00:18:15 +00:00
|
|
|
if (damage.hull) {
|
|
|
|
result.push(new ShipValueDiff(ship, "hull", -damage.hull));
|
2017-04-24 17:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 00:07:06 +00:00
|
|
|
return result;
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
2017-01-17 00:02:38 +00:00
|
|
|
|
|
|
|
getDescription(): string {
|
2018-03-20 23:23:00 +00:00
|
|
|
return `do ${this.value} damage`;
|
2017-01-17 00:02:38 +00:00
|
|
|
}
|
2015-01-28 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|