1
0
Fork 0
spacetac/src/scripts/game/actions/FireWeaponAction.ts

61 lines
2 KiB
TypeScript
Raw Normal View History

/// <reference path="BaseAction.ts"/>
module SpaceTac.Game {
"use strict";
// Action to fire a weapon on another ship, or in space
export class FireWeaponAction extends BaseAction {
2015-01-28 00:00:00 +00:00
// Boolean set to true if the weapon can target space
can_target_space: boolean;
constructor(equipment: Equipment, can_target_space: boolean = false) {
2015-02-23 00:00:00 +00:00
super("fire-" + equipment.code, true, equipment);
2015-01-28 00:00:00 +00:00
this.can_target_space = can_target_space;
}
checkLocationTarget(battle: Battle, ship: Ship, target: Target): Target {
2015-01-28 00:00:00 +00:00
if (this.can_target_space) {
target = target.constraintInRange(ship.arena_x, ship.arena_y, this.equipment.distance);
return target;
} else {
return null;
}
}
checkShipTarget(battle: Battle, ship: Ship, target: Target): Target {
if (ship.getPlayer() === target.ship.getPlayer()) {
// No friendly fire
return null;
} else {
2015-01-28 00:00:00 +00:00
// Check if target is in range
if (target.isInRange(ship.arena_x, ship.arena_y, this.equipment.distance)) {
return target;
} else {
return null;
}
}
}
protected customApply(battle: Battle, ship: Ship, target: Target): boolean {
2015-01-28 00:00:00 +00:00
if (target.ship) {
2015-02-20 00:00:00 +00:00
// Fire event
ship.addBattleEvent(new FireEvent(ship, this.equipment, target));
2015-01-28 00:00:00 +00:00
// Apply all target effects
var result = false;
this.equipment.target_effects.forEach((effect: BaseEffect) => {
var eff_result = effect.applyOnShip(target.ship);
result = result || eff_result;
});
2015-01-28 00:00:00 +00:00
return result;
} else {
// TODO target in space (=> apply blast radius)
return false;
}
}
}
}