Skip to content

Commit

Permalink
fix armor measurement logic, damage and test (#1733)
Browse files Browse the repository at this point in the history
* fix armor measurement logic, damage and test
  • Loading branch information
amir-arad committed Apr 29, 2024
1 parent 2a824de commit da124e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 3 additions & 1 deletion modules/core/src/ship/armor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class Armor extends Schema {
}

public numberOfPlatesInRange(localAngleHitRange: RTuple2): number {
return Math.ceil(toPositiveDegreesDelta(localAngleHitRange[1] - localAngleHitRange[0]) / this.degreesPerPlate);
const firstPlateHitOffset = toPositiveDegreesDelta(localAngleHitRange[0]) % this.degreesPerPlate;
const hitRangeSize = toPositiveDegreesDelta(localAngleHitRange[1] - localAngleHitRange[0]);
return Math.ceil((firstPlateHitOffset + hitRangeSize) / this.degreesPerPlate);
}

public *platesInRange(localAngleHitRange: RTuple2): IterableIterator<[number, ArmorPlate]> {
Expand Down
3 changes: 1 addition & 2 deletions modules/core/src/ship/damage-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Reactor } from './reactor';
import { ShipState } from './ship-state';
import { Thruster } from './thruster';
import { Warp } from './warp';
import { gaussianRandom } from '..';

export class DamageManager {
constructor(
Expand Down Expand Up @@ -201,7 +200,7 @@ export class DamageManager {
private applyDamageToArmor(damageFactor: number, localAnglesHitRange: RTuple2) {
for (const [_, plate] of this.state.armor.platesInRange(localAnglesHitRange)) {
if (plate.health > 0) {
const newHealth = plate.health - damageFactor * gaussianRandom(20, 4);
const newHealth = plate.health - damageFactor;
plate.health = Math.max(newHealth, 0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions modules/core/test/ship-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe.each([ShipManagerPc, ShipManagerNpc])('%p', (shipManagerCtor) => {
spaceMgr,
die,
);
shipMgr.state.armor.design.healRate = 0;
die.expectedRoll = 1;
spaceMgr.insert(shipObj);
shipMgr.setSmartPilotManeuveringMode(SmartPilotMode.DIRECT);
Expand All @@ -65,19 +66,18 @@ describe.each([ShipManagerPc, ShipManagerNpc])('%p', (shipManagerCtor) => {
shipMgr.update(id);
spaceMgr.update(id);
}

const expectedHitPlatesRange = padArch(
[explosionAngleToShip, explosionAngleToShip],
sizeOfPlate + EPSILON,
);
//@ts-ignore : access private property
const brokenOutsideExplosion = shipMgr.damageManager.getNumberOfBrokenPlatesInRange([EPSILON, 360]);
expect(brokenOutsideExplosion).to.equal(2);
const brokenTotal = shipMgr.damageManager.getNumberOfBrokenPlatesInRange([EPSILON, 360]);
expect(brokenTotal).to.oneOf([2, 3]);

const brokenInsideExplosion =
//@ts-ignore : access private property
shipMgr.damageManager.getNumberOfBrokenPlatesInRange(expectedHitPlatesRange);
expect(brokenInsideExplosion).to.equal(2);
expect(brokenInsideExplosion).to.equal(brokenTotal);
expect(shipMgr.state.chainGun!.broken).to.be.false;
expect(shipMgr.state.chainGun!.angleOffset).to.equal(0);
expect(shipMgr.state.chainGun!.rateOfFireFactor).to.equal(1);
Expand Down

0 comments on commit da124e0

Please sign in to comment.