Skip to content

Commit

Permalink
Improved aura weapon damage handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivancea committed Sep 16, 2024
1 parent b561b6f commit 1756411
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion common/physics.weapon.aura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function handleAuraWeaponCollisions(
type: "weaponCollision",
damagedPlayerId: otherPlayer.id,
playerId: player.id,
amount: otherPlayerWeaponDamage / elapsedTime,
amount:
(otherPlayerWeaponDamage * weapon.damageMultiplier) / elapsedTime,
});
}

Expand Down
7 changes: 6 additions & 1 deletion common/types/weapon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ export type AuraWeapon = BaseWeapon & {
* The radius the aura extends from the player.
*/
radiusFromPlayer: number;
/**
* A multiplier on the damage dealt by the aura to other players.
*/
damageMultiplier: number;
};

export function makeAuraWeapon(): AuraWeapon {
return {
type: "aura",
playerCollisionWeightMultiplier: 3,
playerCollisionWeightMultiplier: 2,
radiusFromPlayer: 5,
damageMultiplier: 1.5,
};
}
8 changes: 8 additions & 0 deletions server/logic/room-controller.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ export class BaseRoomController implements RoomController {
const damagedPlayer = this.room.players[damage.damagedPlayerId];
assert(damagedPlayer, "Damaged player not found");

if (
damage.type === "playerCollision" &&
damagedPlayer.weapon.type === "aura"
) {
// Players with aura weapons are immune to player collisions
continue;
}

// TODO: Ignore damage if damaged by same source in the last N milliseconds

damagedPlayer.health -= damage.amount;
Expand Down

0 comments on commit 1756411

Please sign in to comment.