diff --git a/src/lib/classes/managers/LocationManager.ts b/src/lib/classes/managers/LocationManager.ts index edb44f9..a766a4e 100644 --- a/src/lib/classes/managers/LocationManager.ts +++ b/src/lib/classes/managers/LocationManager.ts @@ -130,6 +130,20 @@ class LocationManager { return foundSystem } + getSystemsOwnedBy(id: ObjectId) { + const systems: System[] = []; + + for(const galaxy of this.galaxies) { + for(const sector of galaxy.sectors) { + for(const system of sector.systems) { + if(system.ownedBy.id.equals(id)) systems.push(system); + } + } + } + + return systems; + } + getPlanet(_id: ObjectId) { let foundPlanet: Planet | undefined; diff --git a/src/pages/game/fleet.astro b/src/pages/game/fleet.astro index dc9ce67..2fa0298 100644 --- a/src/pages/game/fleet.astro +++ b/src/pages/game/fleet.astro @@ -22,6 +22,28 @@ const ships = await getAllShips(); const fleet = await getAllFleetByUser(user.id); +const userSystems = locationManager.getSystemsOwnedBy(user.id); + +let own = 0; +let friendly = 0; +let enemy = 0; + +for(const system of userSystems) { + for(const planet of system.planets.planets) { + for(const f of fleet) { + if(f.source.equals(planet._id)) own++; + else if(f.destination.equals(planet._id)) { + if(f.mission === 'attack') enemy++; + else { + const source = locationManager.getPlanet(f.source)?.manager.owner.id; + const destination = locationManager.getPlanet(f.destination)?.manager.owner.id; + if(!source?.equals(destination)) friendly++; + } + } + } + } +} + const lang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language'))); --- @@ -29,15 +51,25 @@ const lang = await getLocales(await getHighestWeightedLanguage(Astro.request.hea - {fleet.map(f => <> -
- {locationManager.getPlanet(f.source)?.name ?? "?"} => {locationManager.getPlanet(f.destination)?.name ?? "?"}
- Containing: {f.ships.map(s => { - const ship = ships.find(ship => ship.id === s.id); - return `${getName(lang, 'ships', s.id)} x${s.amount}`; - }).join(', ')}
+ + + \ No newline at end of file