Skip to content

Commit cd13863

Browse files
Copilotabcxff
andauthored
Address code review feedback: remove unused imports, fix validation, add missing factory spawn (#187)
* Initial plan * Address review feedback: fix typos, remove unused imports, use isFinite, add factory spawning to Domination Co-authored-by: abcxff <79597906+abcxff@users.noreply.github.com> * Remove redundant MAX_SAFE_INTEGER checks with isFinite Co-authored-by: abcxff <79597906+abcxff@users.noreply.github.com> * Add back bounds checking for score and points in commands --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: abcxff <79597906+abcxff@users.noreply.github.com>
1 parent 1c269a1 commit cd13863

8 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/Const/Commands.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,23 @@ export const commandCallbacks = {
209209
game_set_level: (client: Client, levelArg: string) => {
210210
const level = parseInt(levelArg);
211211
const player = client.camera?.cameraData.player;
212-
if (isNaN(level) || !Entity.exists(player) || !TankBody.isTank(player)) return;
212+
if (!isFinite(level) || !Entity.exists(player) || !TankBody.isTank(player)) return;
213213
const finalLevel = client.accessLevel == AccessLevel.FullAccess ? level : Math.min(maxPlayerLevel, level);
214214
client.camera?.setLevel(finalLevel);
215215
},
216216
game_set_score: (client: Client, scoreArg: string) => {
217217
const score = parseInt(scoreArg);
218218
const camera = client.camera?.cameraData;
219219
const player = client.camera?.cameraData.player;
220-
if (isNaN(score) || score > Number.MAX_SAFE_INTEGER || score < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
220+
if (!isFinite(score) || score > Number.MAX_SAFE_INTEGER || score < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
221221
camera.score = score;
222222
},
223223
game_set_stat_max: (client: Client, statIdArg: string, statMaxArg: string) => {
224224
const statId = StatCount - parseInt(statIdArg);
225225
const statMax = parseInt(statMaxArg);
226226
const camera = client.camera?.cameraData;
227227
const player = client.camera?.cameraData.player;
228-
if (statId < 0 || statId >= StatCount || isNaN(statId) || isNaN(statMax) || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
228+
if (statId < 0 || statId >= StatCount || !isFinite(statId) || !isFinite(statMax) || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
229229
const clampedStatMax = Math.max(statMax, 0);
230230
camera.statLimits[statId as Stat] = clampedStatMax;
231231
camera.statLevels[statId as Stat] = Math.min(camera.statLevels[statId as Stat], clampedStatMax);
@@ -235,14 +235,14 @@ export const commandCallbacks = {
235235
const statPoints = parseInt(statPointsArg);
236236
const camera = client.camera?.cameraData;
237237
const player = client.camera?.cameraData.player;
238-
if (statId < 0 || statId >= StatCount || isNaN(statId) || isNaN(statPoints) || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
238+
if (statId < 0 || statId >= StatCount || !isFinite(statId) || !isFinite(statPoints) || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
239239
camera.statLevels[statId as Stat] = statPoints;
240240
},
241241
game_add_upgrade_points: (client: Client, pointsArg: string) => {
242242
const points = parseInt(pointsArg);
243243
const camera = client.camera?.cameraData;
244244
const player = client.camera?.cameraData.player;
245-
if (isNaN(points) || points > Number.MAX_SAFE_INTEGER || points < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
245+
if (!isFinite(points) || points > Number.MAX_SAFE_INTEGER || points < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
246246
camera.statsAvailable += points;
247247
},
248248
game_teleport: (client: Client, xArg: string, yArg: string) => {
@@ -254,7 +254,7 @@ export const commandCallbacks = {
254254
const x = xArg.match(RELATIVE_POS_REGEX) ? player.positionData.x + parseInt(xArg.slice(1) || "0", 10) : parseInt(xArg, 10);
255255
const y = yArg.match(RELATIVE_POS_REGEX) ? player.positionData.y + parseInt(yArg.slice(1) || "0", 10) : parseInt(yArg, 10);
256256

257-
if (isNaN(x) || isNaN(y)) return;
257+
if (!isFinite(x) || !isFinite(y)) return;
258258

259259
player.positionData.x = x;
260260
player.positionData.y = y;
@@ -355,11 +355,11 @@ export const commandCallbacks = {
355355
["Triangle", Triangle]
356356
] as [string, typeof ObjectEntity][]).get(entityArg);
357357

358-
if (isNaN(count) || count < 0 || !game || !TEntity) return;
358+
if (!isFinite(count) || count < 0 || !game || !TEntity) return;
359359

360360
for (let i = 0; i < count; ++i) {
361361
const boss = new TEntity(game);
362-
if (!isNaN(x) && !isNaN(y)) {
362+
if (isFinite(x) && isFinite(y)) {
363363
boss.positionData.x = x;
364364
boss.positionData.y = y;
365365
}

src/Entity/Object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import * as util from "../util";
2020
import GameServer from "../Game";
21-
import Vector, { VectorAbstract } from "../Physics/Vector";
21+
import Vector from "../Physics/Vector";
2222

2323
import { PhysicsGroup, PositionGroup, RelationsGroup, StyleGroup } from "../Native/FieldGroups";
2424
import { Entity } from "../Native/Entity";

src/Entity/Tank/Barrel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default class Barrel extends ObjectEntity {
105105
/** Number of drones that this barrel shot that are still alive. */
106106
public droneCount = 0;
107107

108-
/** The barrel"s addons */
108+
/** The barrel's addons */
109109
public addons: BarrelAddon[] = [];
110110

111111
/** Always existant barrel field group, present on all barrels. */

src/Gamemodes/Domination.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import Client from "../Client";
2020
import { Color, ColorsHexCode, ArenaFlags, ValidScoreboardIndex, ClientBound } from "../Const/Enums";
21-
import ObjectEntity from "../Entity/Object";
2221
import Dominator from "../Entity/Misc/Dominator";
2322
import TeamBase from "../Entity/Misc/TeamBase";
2423
import { TeamEntity } from "../Entity/Misc/TeamEntity";
@@ -94,6 +93,9 @@ export default class DominationArena extends ArenaEntity {
9493
const team = this.decideTeam(client);
9594
TeamEntity.setTeam(team, tank);
9695

96+
const success = this.attemptFactorySpawn(tank);
97+
if (success) return;
98+
9799
const teamBase = team.base;
98100
if (!teamBase) return super.spawnPlayer(tank, client);
99101

src/Gamemodes/Survival.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import TankBody from "../Entity/Tank/TankBody";
2424

2525
import ShapeManager from "../Misc/ShapeManager";
2626
import { ArenaFlags, ClientBound } from "../Const/Enums";
27-
import { tps, countdownDuration, scoreboardUpdateInterval } from "../config";
27+
import { countdownDuration, scoreboardUpdateInterval } from "../config";
2828

2929
const MIN_PLAYERS = 4; // 6 in Diep.io
3030

src/Gamemodes/Team2.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import GameServer from "../Game";
2020
import ArenaEntity from "../Native/Arena";
2121
import Client from "../Client";
2222

23-
import ObjectEntity from "../Entity/Object";
2423
import TeamBase from "../Entity/Misc/TeamBase";
2524
import TankBody from "../Entity/Tank/TankBody";
2625

src/Gamemodes/Team4.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import GameServer from "../Game";
2020
import ArenaEntity from "../Native/Arena";
2121
import Client from "../Client";
2222

23-
import ObjectEntity from "../Entity/Object";
2423
import TeamBase from "../Entity/Misc/TeamBase";
2524
import TankBody from "../Entity/Tank/TankBody";
2625

src/Native/Arena.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { TeamEntity, TeamGroupEntity } from "../Entity/Misc/TeamEntity";
3232

3333
import Client from "../Client";
3434

35-
import { countdownDuration, bossSpawningInterval, factorySpawnChance, scoreboardUpdateInterval } from "../config";
35+
import { countdownDuration, factorySpawnChance, scoreboardUpdateInterval } from "../config";
3636

3737
export const enum ArenaState {
3838
/** Countdown, waiting for players screen */

0 commit comments

Comments
 (0)