Skip to content

Commit 530b4e5

Browse files
Calculate stats on change instead of every tick (#192)
* stuff * Update TankBody.ts * Fix survival * fix AC and mothership * Update ArenaCloser.ts * Update Survival.ts * Remove useless array * Remove useless array * Barrel stat function * Barrel stats * Stat fixes
1 parent cdef803 commit 530b4e5

13 files changed

Lines changed: 139 additions & 110 deletions

File tree

src/Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export default class Client {
358358

359359
if (camera.cameraData.values.statLevels.values[statId] >= statLimit) return;
360360

361-
camera.cameraData.statLevels[statId] += 1;
361+
camera.addStat(statId, 1);
362362
camera.cameraData.statsAvailable -= 1;
363363

364364
return;

src/Const/Commands.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ export const commandCallbacks = {
215215
},
216216
game_set_score: (client: Client, scoreArg: string) => {
217217
const score = parseInt(scoreArg);
218-
const camera = client.camera?.cameraData;
219-
const player = client.camera?.cameraData.player;
218+
const camera = client.camera;
219+
const cameraData = camera?.cameraData;
220+
const player = cameraData?.player;
220221
if (!isFinite(score) || score > Number.MAX_SAFE_INTEGER || score < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
221-
camera.score = score;
222+
camera.setScore(score);
222223
},
223224
game_set_stat_max: (client: Client, statIdArg: string, statMaxArg: string) => {
224225
const statId = StatCount - parseInt(statIdArg);
@@ -233,17 +234,19 @@ export const commandCallbacks = {
233234
game_set_stat: (client: Client, statIdArg: string, statPointsArg: string) => {
234235
const statId = StatCount - parseInt(statIdArg);
235236
const statPoints = parseInt(statPointsArg);
236-
const camera = client.camera?.cameraData;
237-
const player = client.camera?.cameraData.player;
237+
const camera = client.camera;
238+
const cameraData = camera?.cameraData;
239+
const player = camera?.cameraData.player;
238240
if (statId < 0 || statId >= StatCount || !isFinite(statId) || !isFinite(statPoints) || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
239-
camera.statLevels[statId as Stat] = statPoints;
241+
camera.setStat(statId as Stat, statPoints);
240242
},
241243
game_add_upgrade_points: (client: Client, pointsArg: string) => {
242244
const points = parseInt(pointsArg);
243-
const camera = client.camera?.cameraData;
244-
const player = client.camera?.cameraData.player;
245-
if (!isFinite(points) || points > Number.MAX_SAFE_INTEGER || points < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera) return;
246-
camera.statsAvailable += points;
245+
const camera = client.camera;
246+
const cameraData = camera?.cameraData;
247+
const player = cameraData?.player;
248+
if (!isFinite(points) || points > Number.MAX_SAFE_INTEGER || points < Number.MIN_SAFE_INTEGER || !Entity.exists(player) || !TankBody.isTank(player) || !camera || !cameraData) return;
249+
cameraData.statsAvailable += points;
247250
},
248251
game_teleport: (client: Client, xArg: string, yArg: string) => {
249252
const player = client.camera?.cameraData.player;

src/Const/TankDefinitions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6289,6 +6289,7 @@
62896289
"absorbtionFactor": 1,
62906290
"speed": 1,
62916291
"maxHealth": 50,
6292+
"bodyDamage": 2,
62926293
"preAddon": null,
62936294
"postAddon": "spike",
62946295
"sides": 1,

src/Const/TankDefinitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export interface TankDefinition {
151151
absorbtionFactor: number;
152152
/** The base max health of the tank. */
153153
maxHealth: number;
154+
/** Extra body damage addition, such as spike. */
155+
bodyDamage?: number;
154156
/** The addon, if not empty, which is built before the barrels. */
155157
preAddon: addonId | null;
156158
/** The addon, if not empty, which is built after the barrels. */

src/Entity/Boss/Defender.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ const DEFENDER_SIZE = 150;
7878
* Class which represents the boss "Defender"
7979
*/
8080
export default class Defender extends AbstractBoss {
81-
/** Defender's trap launchers */
82-
private trappers: Barrel[] = [];
8381
/** See AbstractBoss.movementSpeed */
8482
public movementSpeed = 0.2;
8583

@@ -99,7 +97,7 @@ export default class Defender extends AbstractBoss {
9997
const offset = 60 / (DEFENDER_SIZE * Math.SQRT1_2);
10098
for (let i = 0; i < count; ++i) {
10199
// Add trap launcher
102-
this.trappers.push(new Barrel(this, {
100+
this.barrels.push(new Barrel(this, {
103101
...TrapperDefinition,
104102
angle: PI2 * ((i / count) + 1 / (count * 2))
105103
}));

src/Entity/Boss/Summoner.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ const SUMMONER_SIZE = 150;
5858
* Class which represents the boss "Summoner"
5959
*/
6060
export default class Summoner extends AbstractBoss {
61-
62-
/** Summoner spawners */
63-
private spawners: Barrel[] = [];
64-
6561
public constructor(game: GameServer) {
6662
super(game);
6763

@@ -71,8 +67,9 @@ export default class Summoner extends AbstractBoss {
7167
this.physicsData.values.size = SUMMONER_SIZE * Math.SQRT1_2;
7268
this.physicsData.values.sides = 4;
7369

74-
for (let i = 0; i < 4; ++i) {
75-
this.spawners.push(new Barrel(this, {
70+
const count = this.physicsData.values.sides;
71+
for (let i = 0; i < count; ++i) {
72+
this.barrels.push(new Barrel(this, {
7673
...SummonerSpawnerDefinition,
7774
angle: PI2 * ((i / 4))
7875
}));

src/Entity/Misc/ArenaCloser.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,21 @@ export default class ArenaCloser extends TankBody {
5353

5454
this.setTank(Tank.ArenaCloser);
5555

56-
const def = (this.definition = Object.assign({}, this.definition));
57-
// 598 is what the normal health increase for stat/level would be, so we just subtract it.
58-
def.maxHealth = 10000 - 598;
59-
// TODO(ABC):
60-
// Fix all the stats
61-
def.speed = this.ai.movementSpeed = this.cameraEntity.cameraData.values.movementSpeed = 80;
62-
63-
Object.defineProperty(this, "damagePerTick", {
64-
get() {
65-
return 45;
66-
},
67-
set() {}
68-
});
69-
7056
this.nameData.values.name = "Arena Closer";
7157
this.styleData.values.color = Color.Neutral;
7258
this.positionData.values.flags |= PositionFlags.canMoveThroughWalls;
7359
this.physicsData.values.flags |= PhysicsFlags.canEscapeArena;
7460

75-
for (let i = Stat.MovementSpeed; i < Stat.BodyDamage; ++i) camera.cameraData.values.statLevels.values[i] = 7;
61+
for (let i = Stat.MovementSpeed; i < Stat.BodyDamage; ++i) camera.setStat(i as Stat, 7);
7662

7763
this.ai.aimSpeed = this.barrels[0].bulletAccel * 1.6;
7864
this.setInvulnerability(true);
65+
66+
// TODO(ABC):
67+
// Fix all the stats
68+
this.ai.movementSpeed = this.cameraEntity.cameraData.values.movementSpeed = 5;
69+
this.healthData.values.health = this.healthData.values.maxHealth = 10000;
70+
this.damagePerTick = 45;
7971
}
8072

8173
public tick(tick: number) {
@@ -91,6 +83,5 @@ export default class ArenaCloser extends TankBody {
9183
}
9284

9385
super.tick(tick);
94-
this.ai.movementSpeed = this.cameraEntity.cameraData.movementSpeed = 80;
9586
}
9687
}

src/Entity/Misc/Dominator.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ export default class Dominator extends TankBody {
9292

9393
this.base = base;
9494

95-
Object.defineProperty(this, "damagePerTick", {
96-
get() {
97-
return 10;
98-
},
99-
set() {}
100-
});
95+
this.damagePerTick = 10;
10196

10297
if (this.styleData.values.flags & StyleFlags.isFlashing) { // Remove spawn shield
10398
this.styleData.values.flags ^= StyleFlags.isFlashing;

src/Entity/Misc/Mothership.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ export default class Mothership extends TankBody {
6363

6464
camera.cameraData.values.player = this;
6565

66-
for (let i = Stat.MovementSpeed; i < Stat.HealthRegen; ++i) camera.cameraData.values.statLevels.values[i] = 7;
67-
camera.cameraData.values.statLevels.values[Stat.HealthRegen] = 1;
68-
69-
const def = (this.definition = Object.assign({}, this.definition));
70-
// 418 is what the normal health increase for stat/level would be, so we just subtract it and force it 7k
71-
def.maxHealth = 7000 - 418;
66+
for (let i = Stat.MovementSpeed; i < Stat.HealthRegen; ++i) camera.setStat(i as Stat, 7);
67+
camera.setStat(Stat.HealthRegen, 1);
68+
69+
this.healthData.values.health = this.healthData.values.maxHealth = 7000;
7270
}
7371

7472
public onDeath(killer: Live): void {
@@ -129,6 +127,7 @@ export default class Mothership extends TankBody {
129127
}
130128
}
131129
}
130+
132131
const team = this.relationsData.values.team;
133132
if (team?.teamData) {
134133
team.teamData.mothershipX = this.positionData.values.x;

src/Entity/Tank/Barrel.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ import CrocSkimmer from "./Projectile/CrocSkimmer";
3737
import { BarrelAddon, BarrelAddonById } from "./BarrelAddons";
3838
import { Swarm } from "./Projectile/Swarm";
3939
import NecromancerSquare from "./Projectile/NecromancerSquare";
40+
4041
/**
4142
* Class that determines when barrels can shoot, and when they can't.
4243
*/
4344
export class ShootCycle {
4445
/** The barrel this cycle is keeping track of. */
45-
private barrelEntity: Barrel;
46+
public barrelEntity: Barrel;
4647
/** The current position in the cycle. */
47-
private pos: number;
48+
public pos: number;
4849
/** The last known reload time of the barrel. */
49-
private reloadTime: number;
50+
public reloadTime: number;
5051

5152
public constructor(barrel: Barrel) {
5253
this.barrelEntity = barrel;
@@ -56,11 +57,6 @@ export class ShootCycle {
5657

5758
public tick() {
5859
const reloadTime = this.barrelEntity.tank.reloadTime * this.barrelEntity.definition.reload;
59-
if (reloadTime !== this.reloadTime) {
60-
this.pos *= reloadTime / this.reloadTime;
61-
this.reloadTime = this.barrelEntity.barrelData.reloadTime = reloadTime;
62-
}
63-
6460
const alwaysShoot = (this.barrelEntity.definition.forceFire) || (this.barrelEntity.definition.bullet.type === "drone") || (this.barrelEntity.definition.bullet.type === "minion");
6561

6662
if (this.pos >= reloadTime) {
@@ -143,7 +139,7 @@ export default class Barrel extends ObjectEntity {
143139
this.barrelData.values.trapezoidDirection = barrelDefinition.trapezoidDirection;
144140
this.shootCycle = new ShootCycle(this);
145141

146-
this.bulletAccel = (20 + (owner.cameraEntity.cameraData?.values.statLevels.values[Stat.BulletSpeed] || 0) * 3) * barrelDefinition.bullet.speed;
142+
this.calculateStatData();
147143
}
148144

149145
/** Shoots a bullet from the barrel. */
@@ -214,9 +210,19 @@ export default class Barrel extends ObjectEntity {
214210
if (this.definition.bullet.color) projectile.styleData.values.color = this.definition.bullet.color;
215211
}
216212
}
213+
214+
public calculateStatData() {
215+
const reloadTime = this.tank.reloadTime * this.definition.reload;
216+
217+
if (reloadTime !== this.shootCycle.reloadTime) {
218+
this.shootCycle.pos *= reloadTime / this.shootCycle.reloadTime;
219+
this.shootCycle.reloadTime = this.barrelData.reloadTime = reloadTime;
220+
}
221+
222+
this.bulletAccel = (20 + (this.tank.cameraEntity.cameraData?.values.statLevels.values[Stat.BulletSpeed] || 0) * 3) * this.definition.bullet.speed;
223+
}
217224

218225
public tick(tick: number) {
219-
this.bulletAccel = (20 + (this.tank.cameraEntity.cameraData?.values.statLevels.values[Stat.BulletSpeed] || 0) * 3) * this.definition.bullet.speed;
220226
this.relationsData.values.team = this.tank.relationsData.values.team;
221227

222228
if (!this.tank.rootParent.deletionAnimation){

0 commit comments

Comments
 (0)