Fix bug with server crashing when there's over 30k ships in fleet
This commit is contained in:
parent
bf54589069
commit
db7abbb997
|
@ -102,7 +102,12 @@ export default class FleetManager {
|
||||||
} else {
|
} else {
|
||||||
switch(this.data.mission) {
|
switch(this.data.mission) {
|
||||||
case 'ATTACK':
|
case 'ATTACK':
|
||||||
return await this.battleResults([{ id: 'fighter', amount: 100 }]);
|
if(!("expedition" in this.data.destination)) {
|
||||||
|
const enemyShips = this.data.destination.ships.ships;
|
||||||
|
return await this.battleResults(enemyShips.map(ship => { return { id: ship.data.id, amount: ship.amount } }));
|
||||||
|
} else {
|
||||||
|
throw new Error("Cannot attack sector.");
|
||||||
|
}
|
||||||
case 'TRANSPORT':
|
case 'TRANSPORT':
|
||||||
await (this.data.destination as Planet | SystemManager).resources.updateAmount(this.data.cargo);
|
await (this.data.destination as Planet | SystemManager).resources.updateAmount(this.data.cargo);
|
||||||
await (this.data.destination as Planet | SystemManager).resources.sync();
|
await (this.data.destination as Planet | SystemManager).resources.sync();
|
||||||
|
@ -205,6 +210,11 @@ export default class FleetManager {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(playerStats.attack > enemyStats.defense * 2 && playerStats.defense > enemyStats.attack * 2) {
|
||||||
|
enemyShipsStructure.forEach((_, index) => enemyShipsStructure.splice(index, 1));
|
||||||
|
} else if(enemyStats.attack > playerStats.defense * 2 && enemyStats.defense > playerStats.attack * 2) {
|
||||||
|
playerShipsStructure.forEach((_, index) => playerShipsStructure.splice(index, 1));
|
||||||
|
} else {
|
||||||
roundLoop: for(let i = 0; i < 3; i++) {
|
roundLoop: for(let i = 0; i < 3; i++) {
|
||||||
for(const playerShip of playerShipsStructure) {
|
for(const playerShip of playerShipsStructure) {
|
||||||
const enemyShip = enemyShipsStructure[Math.floor(Math.random() * enemyShipsStructure.length)];
|
const enemyShip = enemyShipsStructure[Math.floor(Math.random() * enemyShipsStructure.length)];
|
||||||
|
@ -234,6 +244,7 @@ export default class FleetManager {
|
||||||
if(ship.hitpoints <= 0) enemyShipsStructure.splice(index, 1);
|
if(ship.hitpoints <= 0) enemyShipsStructure.splice(index, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const playerBalance = playerStats.defense - enemyStats.attack;
|
const playerBalance = playerStats.defense - enemyStats.attack;
|
||||||
const enemyBalance = enemyStats.defense - playerStats.attack;
|
const enemyBalance = enemyStats.defense - playerStats.attack;
|
||||||
|
@ -270,13 +281,14 @@ export default class FleetManager {
|
||||||
|
|
||||||
await this.sendMail(
|
await this.sendMail(
|
||||||
`Battle Results (${playerBalance > enemyBalance ? "Victory" : playerBalance < enemyBalance ? "Defeat" : "Draw"})`,
|
`Battle Results (${playerBalance > enemyBalance ? "Victory" : playerBalance < enemyBalance ? "Defeat" : "Draw"})`,
|
||||||
`Player ships:\n${previousShips.map(ship => `${ship.amount} ${ship.id}`).join(', ')}\n
|
`Results of battle at ${(this.data.destination instanceof SystemManager ? this.data.destination.data.name : this.data.destination.name)}:\n
|
||||||
Enemy ships:\n${enemyFleet.map(ship => `${ship.amount} ${ship.id}`).join(', ')}\n\n
|
Player ships:\n${previousShips.map(ship => `${ship.amount} ${ship.id}`).join('\n')}\n
|
||||||
|
Enemy ships:\n${enemyFleet.map(ship => `${ship.amount} ${ship.id}`).join('\n')}\n\n
|
||||||
Player stats: ${playerStats.hitpoints} HP, ${playerStats.attack} ATK, ${playerStats.defense} DEF\n
|
Player stats: ${playerStats.hitpoints} HP, ${playerStats.attack} ATK, ${playerStats.defense} DEF\n
|
||||||
Enemy stats: ${enemyStats.hitpoints} HP, ${enemyStats.attack} ATK, ${enemyStats.defense} DEF\n\n
|
Enemy stats: ${enemyStats.hitpoints} HP, ${enemyStats.attack} ATK, ${enemyStats.defense} DEF\n\n
|
||||||
Player ships left:\n${Object.keys(playerShipsLeft).map(key => `${key} - ${playerShipsLeft[key]}\n`)}\n
|
Player ships left:\n${Object.keys(playerShipsLeft).map(key => `${key} - ${playerShipsLeft[key]}`).join('\n')}\n
|
||||||
Enemy ships left:\n${Object.keys(enemyShipsLeft).map(key => `${key} - ${enemyShipsLeft[key]}\n`)}\n
|
Enemy ships left:\n${Object.keys(enemyShipsLeft).map(key => `${key} - ${enemyShipsLeft[key]}`).join('\n')}\n
|
||||||
${playerBalance > enemyBalance ? `Resources stolen:\n${resourcesStolen.map(res => `${res.id} - ${res.amount}\n`)}` : ""}`
|
${playerBalance > enemyBalance ? `Resources stolen:\n${resourcesStolen.map(res => `${res.id} - ${res.amount}`).join('\n')}` : ""}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return !(playerShipsStructure.length > 0);
|
return !(playerShipsStructure.length > 0);
|
||||||
|
|
Loading…
Reference in New Issue