Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
fix: i forgor explosion file
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Mar 3, 2024
1 parent dd69f23 commit 51c175e
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions server/src/objects/explosion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { GameObjectDefs } from "../../../shared/defs/gameObjectDefs";
import { util } from "../../../shared/utils/util";
import { type Vec2, v2 } from "../../../shared/utils/v2";
import { type Game } from "../game";
import { Decal } from "./decal";
import { type GameObject } from "./gameObject";

export class Explosion {
constructor(
public type: string,
public pos: Vec2,
public layer: number,
public sourceType: string,
public damageType: number,
public source?: GameObject
) {
}

explode(game: Game): void {
// List of all near objects

const def = GameObjectDefs[this.type];
if (def.type !== "explosion") {
throw new Error(`Invalid explosion with type ${this.type}`);
}

// TODO
// const coll = collider.createCircle(this.pos, def.rad.max);

// const objects = game.grid.intersectCollider(coll);
// const damagedObjects = new Map<number, boolean>();

// const obstacles: Obstacle[] = objects.filter(obj => obj.__type === ObjectType.Obstacle);

const bulletDef = GameObjectDefs[def.shrapnelType];
if (bulletDef && bulletDef.type === "bullet") {
for (let i = 0, count = def.shrapnelCount ?? 0; i < count; i++) {
game.bulletManager.fireBullet(
{
bulletType: def.shrapnelType,
pos: this.pos,
layer: this.layer,
damageType: this.damageType,
playerId: this.source?.id ?? 0,
shotFx: false,
damageMult: 1,
variance: util.random(0, bulletDef.variance),
sourceType: this.sourceType,
maxDistance: bulletDef.distance,
dir: v2.randomUnit()
}
);
}
}

if (def.decalType) {
game.grid.addObject(
new Decal(
game,
def.decalType,
this.pos,
this.layer,
0,
1
)
);
}
}
}

0 comments on commit 51c175e

Please sign in to comment.