Skip to content

Commit 9fb08c1

Browse files
init
1 parent 5d1aebd commit 9fb08c1

29 files changed

Lines changed: 185 additions & 69 deletions

src/Client.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ export default class Client {
258258
this.inputs.mouse.y = util.constrain(mouseY, minY, maxY);
259259

260260
const player = camera.cameraData.values.player;
261-
if (!Entity.exists(player) || !(player instanceof TankBody)) return;
262-
261+
if (!TankBody.isTank(player)) return;
263262
// No AI
264263
if (this.inputs.isPossessing && this.accessLevel !== config.AccessLevel.FullAccess) return;
265264

@@ -346,7 +345,7 @@ export default class Client {
346345
if (camera.cameraData.statsAvailable <= 0) return;
347346

348347
const player = camera.cameraData.values.player;
349-
if (!Entity.exists(player) || !(player instanceof TankBody)) return;
348+
if (!TankBody.isTank(player)) return;
350349

351350
const definition = getTankById(player.currentTank);
352351
if (!definition || !definition.stats.length) return;
@@ -366,7 +365,7 @@ export default class Client {
366365
}
367366
case ServerBound.TankUpgrade: {
368367
const player = camera.cameraData.values.player;
369-
if (!Entity.exists(player) || !(player instanceof TankBody)) return;
368+
if (!TankBody.isTank(player)) return;
370369

371370
const definition = getTankById(player.currentTank);
372371
const tankId: Tank = r.vi() ^ TANK_XOR;
@@ -460,7 +459,7 @@ export default class Client {
460459
ai.state = AIState.possessed;
461460

462461
// Silly workaround to change color of player when needed
463-
if (this.camera?.cameraData.values.player instanceof ObjectEntity) {
462+
if (ObjectEntity.isObject(this.camera?.cameraData.values.player)) {
464463
const color = this.camera.cameraData.values.player.styleData.values.color;
465464
this.camera.cameraData.values.player.styleData.values.color = -1 as Color;
466465
this.camera.cameraData.values.player.styleData.color = color;
@@ -480,7 +479,7 @@ export default class Client {
480479
this.camera.cameraData.player = ai.owner;
481480
this.camera.cameraData.movementSpeed = ai.movementSpeed;
482481

483-
if (ai.owner instanceof TankBody) {
482+
if (TankBody.isTank(ai.owner)) {
484483
// If its a TankBody, set the stats, level, and tank to that of the TankBody
485484
this.camera.cameraData.tank = ai.owner.cameraEntity.cameraData.values.tank;
486485
this.camera.setLevel(ai.owner.cameraEntity.cameraData.values.level);
@@ -490,13 +489,13 @@ export default class Client {
490489
for (let i = 0; i < StatCount; ++i) this.camera.cameraData.statNames[i as Stat] = ai.owner.cameraEntity.cameraData.statNames.values[i];
491490

492491
this.camera.cameraData.FOV = ai.owner.cameraEntity.cameraData.FOV;
493-
} else if (ai.owner instanceof AbstractBoss) {
492+
} else if (AbstractBoss.isBoss(ai.owner)) {
494493
this.camera.setLevel(75);
495494
this.camera.cameraData.FOV = 0.35;
496495
} else {
497496
this.camera.setLevel(30);
498497
}
499-
498+
500499
this.camera.cameraData.statsAvailable = 0;
501500
this.camera.cameraData.score = 0;
502501
this.camera.entityState = EntityStateFlags.needsCreate | EntityStateFlags.needsDelete;

src/Const/Enums.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export const enum Color {
4040
EnemyTank = 15,
4141
NecromancerSquare = 16,
4242
Fallen = 17,
43+
EnemyHexagon = 18,
4344

44-
kMaxColors = 18
45+
kMaxColors = 19
4546
}
4647

4748
/**
@@ -66,6 +67,7 @@ export const ColorsHexCode: Record<Color, number> = {
6667
[Color.EnemyTank]: 0xF14E54,
6768
[Color.NecromancerSquare]: 0xFCC376,
6869
[Color.Fallen]: 0xC0C0C0,
70+
[Color.EnemyHexagon]: 0xFCAD76,
6971
[Color.kMaxColors]: 0x000000
7072
}
7173

@@ -281,6 +283,17 @@ export const enum NameFlags {
281283
highlightedName = 1 << 1
282284
}
283285

286+
/**
287+
* Entity type flags.
288+
*/
289+
export const enum EntityTags {
290+
isShape = 1 << 0,
291+
isTank = 1 << 1,
292+
isDominator = 1 << 2,
293+
isBoss = 1 << 3,
294+
isShiny= 1 << 4,
295+
}
296+
284297
/**
285298
* Credits to CX for discovering this.
286299
* This is not fully correct but it works up to the decimal (float rounding likely causes this).
@@ -306,4 +319,4 @@ export function levelToScore(level: number): number {
306319
if (level <= 0) return 0;
307320

308321
return levelToScoreTable[level - 1];
309-
}
322+
}

src/Entity/Boss/AbstractBoss.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
*/
1818

1919
import GameServer from "../../Game";
20+
import ObjectEntity from "../Object";
21+
import LivingEntity from "../Live";
2022
import Barrel from "../Tank/Barrel";
23+
import TankBody from "../Tank/TankBody";
2124

22-
import { ClientBound, Color, PositionFlags, NameFlags } from "../../Const/Enums";
25+
import { ClientBound, Color, PositionFlags, NameFlags, EntityTags } from "../../Const/Enums";
2326
import { VectorAbstract } from "../../Physics/Vector";
2427
import { AI, AIState, Inputs } from "../AI";
2528
import { NameGroup } from "../../Native/FieldGroups";
26-
import LivingEntity from "../Live";
27-
import TankBody from "../Tank/TankBody";
29+
import { Entity } from "../../Native/Entity";
2830
import { CameraEntity } from "../../Native/Camera";
2931

3032

@@ -137,6 +139,14 @@ export default class AbstractBoss extends LivingEntity {
137139
this.reloadTime = 15 * Math.pow(0.914, 7);
138140

139141
this.healthData.values.health = this.healthData.values.maxHealth = 3000;
142+
143+
this.entityTags |= EntityTags.isBoss;
144+
}
145+
146+
public static isBoss(entity: Entity | null | undefined): entity is AbstractBoss {
147+
if (!ObjectEntity.isObject(entity)) return false;
148+
149+
return !!(entity.entityTags & EntityTags.isBoss);
140150
}
141151

142152
public get sizeFactor() {
@@ -158,8 +168,8 @@ export default class AbstractBoss extends LivingEntity {
158168

159169
let killerName: string;
160170

161-
if ((killer.nameData && killer.nameData.values.name && !(killer.nameData.values.flags & NameFlags.hiddenName))) {
162-
killerName = killer.nameData.values.name; // in Diep.io, it should only show the name in notification if it is visible above the killer entity for whatever reason
171+
if (TankBody.isTank(killer)) {
172+
killerName = killer.nameData.values.name;
163173
} else {
164174
killerName = "an unnamed tank";
165175
}

src/Entity/Live.ts

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

1919
import ObjectEntity from "./Object";
2020

21-
import { StyleFlags } from "../Const/Enums";
21+
import { Entity } from "../Native/Entity";
22+
import { StyleFlags, EntityTags } from "../Const/Enums";
2223
import { HealthGroup } from "../Native/FieldGroups";
2324

2425
/**
@@ -57,6 +58,12 @@ export default class LivingEntity extends ObjectEntity {
5758

5859
super.destroy(animate);
5960
}
61+
62+
public static isLive(entity: Entity | null | undefined): entity is LivingEntity {
63+
if (!ObjectEntity.isObject(entity)) return false;
64+
65+
return !!entity.healthData;
66+
}
6067

6168
/** Applies damage to two entity after colliding with eachother. */
6269
public static handleCollision(entity1: LivingEntity, entity2: LivingEntity) {

src/Entity/Misc/Dominator.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ export default class Dominator extends TankBody {
100100
}
101101

102102
public onDeath(killer: LivingEntity) {
103-
if (this.relationsData.values.team === this.game.arena && killer.relationsData.values.team instanceof TeamEntity) {
104-
const killerTeam = killer.relationsData.values.team;
105-
this.relationsData.team = killerTeam || this.game.arena;
106-
this.styleData.color = this.relationsData.team.teamData?.teamColor || killer.styleData.values.color;
103+
const killerTeam = killer.relationsData.values.team;
104+
105+
if (TeamEntity.isTeam(killerTeam) && this.relationsData.values.team === this.game.arena) { // Only proper teams should capture doms
106+
// capture neutral dominator
107+
this.relationsData.team = killerTeam;
108+
this.styleData.color = killerTeam.teamData.values.teamColor
107109
this.game.broadcast()
108110
.u8(ClientBound.Notification)
109111
.stringNT(`The ${this.prefix}${this.nameData.values.name} is now controlled by ${killerTeam.teamName}`)

src/Entity/Misc/Mothership.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ export default class Mothership extends TankBody {
7979
if ((this.game.arena.state >= ArenaState.OVER)) return; // Do not send a defeat notification if the game has been won already
8080

8181
const team = this.relationsData.values.team;
82-
const teamIsATeam = team instanceof TeamEntity;
82+
const teamIsATeam = TeamEntity.isTeam(team);
8383

8484
const killerTeam = killer.relationsData.values.team;
85-
const killerTeamIsATeam = killerTeam instanceof TeamEntity;
85+
const killerTeamIsATeam = TeamEntity.isTeam(killerTeam);
8686

8787
// UNCOMMENT TO ALLOW SOLO KILLS
8888
// if (!killerTeamIsATeam) return;

src/Entity/Misc/TeamEntity.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ export class TeamEntity extends Entity implements TeamGroupEntity {
5858
this.teamData.values.teamColor = color;
5959
this.teamName = name;
6060
}
61+
62+
public static isTeam(entity: Entity | null | undefined): entity is TeamEntity {
63+
if (!entity) return false;
64+
65+
return !!entity.teamData
66+
}
6167
}

src/Entity/Object.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Vector from "../Physics/Vector";
2222

2323
import { PhysicsGroup, PositionGroup, RelationsGroup, StyleGroup } from "../Native/FieldGroups";
2424
import { Entity } from "../Native/Entity";
25-
import { PositionFlags, PhysicsFlags } from "../Const/Enums";
25+
import { PositionFlags, PhysicsFlags, EntityTags } from "../Const/Enums";
2626

2727
/**
2828
* The animator for how entities delete (the opacity and size fade out).
@@ -70,10 +70,13 @@ class DeletionAnimation {
7070
export default class ObjectEntity extends Entity {
7171
/** Always existant relations field group. Present in all objects. */
7272
public relationsData: RelationsGroup = new RelationsGroup(this);
73+
7374
/** Always existant physics field group. Present in all objects. */
7475
public physicsData: PhysicsGroup = new PhysicsGroup(this);
76+
7577
/** Always existant position field group. Present in all objects. */
7678
public positionData: PositionGroup = new PositionGroup(this);
79+
7780
/** Always existant style field group. Present in all objects. */
7881
public styleData: StyleGroup = new StyleGroup(this);
7982

@@ -92,6 +95,12 @@ export default class ObjectEntity extends Entity {
9295
/** Used to determine the parent of all parents. */
9396
public rootParent: ObjectEntity = this;
9497

98+
/** Entity tags. */
99+
public entityTags: number = 0;
100+
101+
/** Entity type ID. */
102+
public arenaMobID: string = ""
103+
95104
/** Velocity used for physics. */
96105
public velocity = new Vector();
97106

@@ -108,6 +117,12 @@ export default class ObjectEntity extends Entity {
108117

109118
this.styleData.zIndex = game.entities.zIndex++;
110119
}
120+
121+
public static isObject(entity: Entity | null | undefined): entity is ObjectEntity {
122+
if (!entity) return false;
123+
124+
return !!entity.physicsData;
125+
}
111126

112127
/** Receives collision pairs from CollisionManager and applies kb */
113128
public static handleCollision(objA: ObjectEntity, objB: ObjectEntity) {

src/Entity/Shape/AbstractShape.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818

1919
import GameServer from "../../Game";
20+
import ObjectEntity from "../Object";
2021
import LivingEntity from "../Live";
2122

22-
import { Color, PositionFlags, NameFlags } from "../../Const/Enums";
23+
import { Entity } from "../../Native/Entity";
24+
import { Color, PositionFlags, NameFlags, EntityTags } from "../../Const/Enums";
2325
import { NameGroup } from "../../Native/FieldGroups";
2426
import { AI } from "../AI";
2527
import { normalizeAngle, PI2 } from "../../util";
@@ -74,6 +76,14 @@ export default class AbstractShape extends LivingEntity {
7476
this.orbitAngle = this.positionData.values.angle = (Math.random() * PI2);
7577

7678
this.maxDamageMultiplier = 4.0;
79+
80+
this.entityTags |= EntityTags.isShape;
81+
}
82+
83+
public static isShape(entity: Entity | null | undefined): entity is AbstractShape {
84+
if (!ObjectEntity.isObject(entity)) return false;
85+
86+
return !!(entity.entityTags & EntityTags.isShape);
7787
}
7888

7989
protected turnTo(angle: number) {

src/Entity/Shape/Crasher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export default class Crasher extends AbstractShape {
5959
this.ai.viewRange = 2000;
6060
this.ai.aimSpeed = (this.ai.movementSpeed = this.targettingSpeed);
6161
this.ai['_findTargetInterval'] = tps;
62+
63+
this.arenaMobID = "crasher";
6264
}
6365

6466
tick(tick: number) {

0 commit comments

Comments
 (0)