Spaces:
Sleeping
Sleeping
File size: 2,336 Bytes
565f6e7 2f4e64c 565f6e7 2f4e64c 565f6e7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | import { Pilot, GroundTarget, SkyZone } from "../../types";
export class SnapshotSystem {
public broadcastSnapshot(
serverTick: number,
pilots: Map<string, Pilot>,
projectiles: any[],
groundTargets: GroundTarget[],
skyZones: SkyZone[],
team1Score: number,
team2Score: number,
matchTimer: number,
lastSeqs: Record<string, number>,
broadcastFn: (type: string, payload: any) => void
) {
const entitiesArray: any[] = [];
for (const [id, pilot] of pilots.entries()) {
entitiesArray.push([
id,
"aircraft",
Math.round(pilot.x * 10) / 10,
Math.round(pilot.y * 10) / 10,
Math.round(pilot.z * 10) / 10,
Math.round(pilot.vx * 100) / 100,
Math.round(pilot.vy * 100) / 100,
Math.round(pilot.vz * 100) / 100,
Math.round(pilot.qx * 1000) / 1000,
Math.round(pilot.qy * 1000) / 1000,
Math.round(pilot.qz * 1000) / 1000,
Math.round(pilot.qw * 1000) / 1000,
Math.round(pilot.throttle * 100) / 100,
pilot.damage.engine,
pilot.damage.leftWing,
pilot.damage.rightWing,
pilot.damage.tail,
pilot.damage.cockpit,
pilot.damage.fuelTank,
pilot.damage.fuselage,
pilot.damage.hasFire ? 1 : 0,
pilot.damage.hasOilLeak ? 1 : 0,
pilot.ammo[pilot.specs.weapons.find(w => w !== "Rockets" && w !== "Small Bombs") || "7.7mm MG"] || 0,
pilot.ammo["Rockets"] || 0
]);
}
for (const p of projectiles) {
entitiesArray.push([
p.id,
"projectile",
Math.round(p.x * 10) / 10,
Math.round(p.y * 10) / 10,
Math.round(p.z * 10) / 10,
p.ownerId,
p.type
]);
}
for (const t of groundTargets) {
if (t.isDead) continue;
entitiesArray.push([
t.id,
"groundTarget",
Math.round(t.x * 10) / 10,
Math.round(t.y * 10) / 10,
Math.round(t.z * 10) / 10,
t.team,
t.type,
Math.round(t.hp * 100) / 100
]);
}
const payload = [
serverTick,
lastSeqs,
entitiesArray,
team1Score,
team2Score,
Math.round(matchTimer),
skyZones.map(z => [z.id, z.owningTeam, z.captureProgress])
];
broadcastFn("snapshot", payload);
}
}
|