@victor_monakhov/tanks
Version:
Game Tanks for browser
1,209 lines • 81.8 kB
JavaScript
var Y = Object.defineProperty;
var A = (p, t, i) => t in p ? Y(p, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : p[t] = i;
var e = (p, t, i) => A(p, typeof t != "symbol" ? t + "" : t, i);
const w = Object.freeze({
Dev: "dev",
Prod: "prod"
}), k = w.Prod;
let x = class {
constructor(t, i, s) {
e(this, "renderX", 0);
e(this, "renderY", 0);
e(this, "deltaWidth", 0);
e(this, "deltaHeight", 0);
e(this, "unitWidth", 0);
e(this, "unitPerim", 0);
e(this, "baseWidth", 280);
e(this, "frontWidth", 0);
e(this, "frontHeight", 0);
e(this, "backWidth", 0);
e(this, "backHeight", 0);
e(this, "barrier", 1e3);
this.canvas = t, this.mapImg = i, this.unitWidth = s.width, this.unitPerim = 4 * s.width, this.frontWidth = i.width, this.frontHeight = i.height, this.backWidth = this.frontWidth + 2 * this.barrier, this.backHeight = this.frontHeight + 2 * this.barrier;
}
calculateDelta() {
this.deltaWidth = this.frontWidth - this.canvas.width, this.deltaHeight = this.frontHeight - this.canvas.height;
}
moveMap(t, i) {
this.calculateDelta(), t <= 10 && this.renderX > 0 ? this.renderX -= 10 : this.renderX < 0 && (this.renderX = 0), i <= 10 && this.renderY > 0 ? this.renderY -= 10 : this.renderY < 0 && (this.renderY = 0), t >= this.canvas.width - 10 && this.renderX < this.deltaWidth ? this.renderX += 10 : this.renderX > this.deltaWidth && (this.renderX = this.deltaWidth), i >= this.canvas.height - 10 && this.renderY < this.deltaHeight ? this.renderY += 10 : this.renderY > this.deltaHeight && (this.renderY = this.deltaHeight);
}
};
class c {
constructor(t, i) {
e(this, "X", 0);
e(this, "Y", 0);
this.X = t, this.Y = i;
}
}
class n {
}
e(n, "right", 0), e(n, "bottom", 1), e(n, "left", 2), e(n, "top", 3);
class T {
constructor(t, i, s) {
e(this, "road", 0);
e(this, "wall", 1);
e(this, "closeRoad", 2);
e(this, "redBase", 3);
e(this, "blueBase", 4);
e(this, "bullet", 5);
e(this, "water", 6);
e(this, "sand", 7);
e(this, "hpRegenRed", 8);
e(this, "hpRegenBlue", 9);
e(this, "cpRegen", 10);
e(this, "next", 11);
e(this, "units", []);
e(this, "towers", []);
e(this, "mobs", []);
e(this, "homes", []);
for (let h = 0; h < t; ++h)
this.units.push(this.next + h);
for (let h = 0; h < t; ++h)
this.homes.push(this.next + t + h);
for (let h = 0; h < i; ++h)
this.towers.push(this.next + 2 * t + h);
for (let h = 0; h < s; ++h)
this.mobs.push(this.next + 2 * t + i + h);
}
}
class y {
constructor() {
e(this, "coords", new c(0, 0));
e(this, "pastCoords", new c(0, 0));
e(this, "renderCoords", new c(0, 0));
e(this, "crashCoords", new c(0, 0));
e(this, "renderCrashCoords", new c(0, 0));
e(this, "deltaCoords", new c(0, 0));
e(this, "perimCoords", []);
}
}
class o {
constructor(t = 0, i = 0, s = 0, h = 0, d = 0) {
this.id = d, this.width = s, this.height = h, this.TLX = t, this.TLY = i, this.BRX = this.TLX + this.width, this.BRY = this.TLY + this.height;
}
update(t) {
this.TLX = t.X, this.TLY = t.Y, this.BRX = this.TLX + this.width, this.BRY = this.TLY + this.height;
}
}
class C {
constructor(t = "T_2", i = 20, s = 20, h = 6, d = 2, a = 200, r = 600, l = 1, u = 0, f = 0) {
this.model = t, this.health = i, this.armor = s, this.speed = h, this.shotPower = d, this.shotDistance = a, this.respawnTime = r, this.level = l, this.experience = u, this.commandPoints = f;
}
}
function I(p, t) {
return Math.floor(Math.random() * (t - p) + p);
}
class M extends o {
constructor(i) {
super();
e(this, "map", null);
e(this, "pos", null);
e(this, "owner", null);
e(this, "target", null);
e(this, "turn", 0);
e(this, "speed", 0);
e(this, "bulletType", {
model: "bullet_1",
damage: 1,
quantity: 1e4,
shot_model: "bullet_1_shot",
boom_model: "bullet_1_boom",
shot_coords: new c(0, 0),
boom_coords: new c(0, 0)
});
e(this, "hit", !1);
e(this, "hitMiss", !1);
e(this, "degree", 0);
this.map = i.map, this.pos = new y(), this.owner = i, this.id = i.id, this.bulletType = i.ammunition[i.bulletType];
}
look() {
let i = this.pos.coords.X + Math.round(this.map.unitWidth / 3), s = this.pos.coords.Y + Math.round(this.map.unitWidth / 3), h = [];
this.update(new c(i, s));
for (let d = 0; d < this.map.backArray.length; ++d)
this.BRX < this.map.backArray[d].TLX || this.TLX > this.map.backArray[d].BRX || this.BRY < this.map.backArray[d].TLY || this.TLY > this.map.backArray[d].BRY || h.push(this.map.backArray[d].id);
return h.length === 0 && h.push(this.map.backId.road), h;
}
fatalHit() {
return this.target !== null && this.target.uc.health <= 0 ? (this.target.uc.health = 0, this.target) : (this.target = null, null);
}
hitResult() {
return I(this.bulletType.damage, this.owner.uc.shotPower + this.bulletType.damage);
}
checkHitMiss(i) {
return i.forEach((s) => {
this.hitMiss = s === this.map.backId.wall;
}), this.hitMiss;
}
checkHit(i) {
this.hit = !1;
for (let s of this.owner.targets)
i.forEach((h) => {
if (h === s.id && s.uc.health > 0) {
this.target = s;
let d = this.hitResult();
s.uc.armor = s.uc.armor - d * 2 / 3, s.uc.armor <= 0 ? (s.uc.armor = 0, s.uc.health = s.uc.health - d) : s.uc.health = s.uc.health - d / 3, this.hit = !0;
}
});
return this.hit;
}
moveHelper(i, s) {
let h = Math.cos(this.degree * Math.PI / 180) * s, d = Math.sin(this.degree * Math.PI / 180) * s;
i.X += Math.round(h), i.Y += Math.round(d);
}
move() {
this.speed === 0 && (this.pos.coords = Object.assign({}, this.owner.pos.coords), this.pos.renderCoords = Object.assign({}, this.owner.pos.renderCoords), this.degree = this.owner.gun.degree, this.turn = this.owner.turn, this.bulletType = this.owner.ammunition[this.owner.bulletType], --this.owner.ammunition[this.owner.bulletType].quantity);
let i = Math.floor(this.owner.uc.shotDistance / 10);
this.moveHelper(this.pos.coords, i), this.moveHelper(this.pos.renderCoords, i);
let s = this.look();
++this.speed, (this.checkHitMiss(s) || this.checkHit(s)) && (this.speed = 0), this.speed > 10 && (this.speed = 0);
}
}
class X extends o {
constructor(i = new C(), s = {
model: "gun_2",
degree: 0
}, h = [
{
model: "bullet_1",
damage: 1,
quantity: 1e4,
shot_model: "bullet_1_shot",
boom_model: "bullet_1_boom",
shot_coords: new c(0, 0),
boom_coords: new c(0, 0)
}
], d = 0) {
super();
e(this, "userId", "None");
e(this, "name", "NoName");
e(this, "side", "red");
e(this, "homeId", 1111);
e(this, "ability", 0);
e(this, "turn", 0);
e(this, "bulletType", 0);
e(this, "reload", 0);
e(this, "speedController", 1);
e(this, "trigger", !1);
e(this, "uc", null);
e(this, "etalonUc", null);
e(this, "kill", null);
e(this, "map", null);
e(this, "bullet", null);
e(this, "pos", null);
e(this, "targets", null);
e(this, "allies", null);
e(this, "ammunition", null);
e(this, "gun", null);
this.uc = i, this.etalonUc = Object.assign({}, this.uc), this.ammunition = h, this.bullet = new M(this), this.pos = new y(), this.gun = s, this.ability = d;
}
levelUp() {
this.kill !== null && (this.uc.experience += this.kill.etalonUc.health, this.uc.experience > this.uc.level * 20 && (this.uc.experience -= this.uc.level * 20, ++this.uc.level, ++this.etalonUc.level, ++this.uc.commandPoints, ++this.etalonUc.commandPoints, this.uc.level % 2 === 0 && (this.etalonUc.health += 5), this.uc.level % 2 !== 0 && (this.etalonUc.armor += 5), this.etalonUc.speed < 12 && this.uc.level % 3 === 0 && (this.uc.speed += 1, this.etalonUc.speed += 1), this.etalonUc.shotPower <= 10 && this.uc.level % 2 !== 0 && (this.uc.shotPower += 1, this.etalonUc.shotPower += 1))), this.experienceToLevel = this.uc.level * 20;
}
roadEffect(i) {
this.side === "red" ? (i === this.map.backId.hpRegenRed && this.uc.health < this.etalonUc.health && (this.uc.health += 0.1), i === this.map.backId.hpRegenBlue && this.uc.health >= 0 && (this.uc.health -= 0.1)) : (i === this.map.backId.hpRegenBlue && this.uc.health < this.etalonUc.health && (this.uc.health += 0.1), i === this.map.backId.hpRegenRed && this.uc.health >= 0 && (this.uc.health -= 0.1)), i === this.map.backId.cpRegen && this.uc.armor < this.etalonUc.armor && (this.uc.armor += 0.1), i === this.map.backId.sand && (this.uc.speed = 2, this.speedController = 2);
}
checkFrontWay(i) {
let s = !1, h = this.look(i), d = !0;
return h.forEach((a) => {
a === this.map.backId.hpRegenRed || a === this.map.backId.cpRegen || a === this.map.backId.hpRegenBlue || a === this.map.backId.sand ? s = !0 : d = a === this.map.backId.road, s ? this.roadEffect(a) : this.uc.speed = this.etalonUc.speed;
}), d;
}
look(i) {
this.update(this.pos.coords);
let s = [];
switch (this.turn) {
case n.right: {
for (let h = 0; h < this.map.backArray.length; ++h)
this.BRX + i + 1 < this.map.backArray[h].TLX || this.TLX + i + 1 > this.map.backArray[h].BRX || this.BRY < this.map.backArray[h].TLY || this.TLY > this.map.backArray[h].BRY || this.id === this.map.backArray[h].id || this.homeId === this.map.backArray[h].id || s.push(this.map.backArray[h].id);
break;
}
case n.bottom: {
for (let h = 0; h < this.map.backArray.length; ++h)
this.BRX < this.map.backArray[h].TLX || this.TLX > this.map.backArray[h].BRX || this.BRY + i + 1 < this.map.backArray[h].TLY || this.TLY + i + 1 > this.map.backArray[h].BRY || this.id === this.map.backArray[h].id || this.homeId === this.map.backArray[h].id || s.push(this.map.backArray[h].id);
break;
}
case n.left: {
for (let h = 0; h < this.map.backArray.length; ++h)
this.BRX - i - 1 < this.map.backArray[h].TLX || this.TLX - i - 1 > this.map.backArray[h].BRX || this.BRY < this.map.backArray[h].TLY || this.TLY > this.map.backArray[h].BRY || this.id === this.map.backArray[h].id || this.homeId === this.map.backArray[h].id || s.push(this.map.backArray[h].id);
break;
}
case n.top: {
for (let h = 0; h < this.map.backArray.length; ++h)
this.BRX < this.map.backArray[h].TLX || this.TLX > this.map.backArray[h].BRX || this.BRY - i - 1 < this.map.backArray[h].TLY || this.TLY - i - 1 > this.map.backArray[h].BRY || this.id === this.map.backArray[h].id || this.homeId === this.map.backArray[h].id || s.push(this.map.backArray[h].id);
break;
}
}
return s.length === 0 && s.push(this.map.backId.road), s;
}
setPosition(i, s) {
switch (this.turn) {
case n.right: {
this.pos.coords.X = s ? this.pos.coords.X + i : this.pos.coords.X - i;
break;
}
case n.bottom: {
this.pos.coords.Y = s ? this.pos.coords.Y + i : this.pos.coords.Y - i;
break;
}
case n.left: {
this.pos.coords.X = s ? this.pos.coords.X - i : this.pos.coords.X + i;
break;
}
case n.top: {
this.pos.coords.Y = s ? this.pos.coords.Y - i : this.pos.coords.Y + i;
break;
}
}
this.update(this.pos.coords);
}
searchTarget(i) {
let s = i.pos.coords.X < this.pos.coords.X + this.uc.shotDistance && i.pos.coords.X > this.pos.coords.X - this.uc.shotDistance, h = i.pos.coords.Y < this.pos.coords.Y + this.uc.shotDistance && i.pos.coords.Y > this.pos.coords.Y - this.uc.shotDistance;
return s && h && i.uc.health > 0;
}
}
class m extends X {
constructor(i = "Blue", s = "T_2", h = 100, d = 20, a = 5, r = 1, l = 200, u = 100, f = {
model: "gun_2",
degree: 0,
coords: new c(0, 0)
}, W = [
{
model: "bullet_1",
damage: 1,
quantity: 1e4,
shot_model: "bullet_1_shot",
boom_model: "bullet_1_boom",
shot_coords: new c(0, 0),
boom_coords: new c(0, 0)
}
], g = 0) {
super(
new C(s, h, d, a, r, l, u),
f,
W,
g
);
e(this, "directionPriority", !0);
e(this, "turnFlag", !0);
e(this, "counter", 0);
e(this, "target", null);
e(this, "name", "Bot");
this.side = i.toLowerCase();
}
checkTarget1(i) {
switch (this.turn) {
case n.right: {
this.turn = this.directionPriority ? n.top : n.bottom;
let s = this.checkCollision(!1);
return this.turn = n.right, this.pos.coords.X < i.pos.coords.X || s;
}
case n.bottom: {
this.turn = this.directionPriority ? n.right : n.left;
let s = this.checkCollision(!1);
return this.turn = n.bottom, this.pos.coords.Y < i.pos.coords.Y || s;
}
case n.left: {
this.turn = this.directionPriority ? n.bottom : n.top;
let s = this.checkCollision(!1);
return this.turn = n.left, this.pos.coords.X > i.pos.coords.X || s;
}
case n.top: {
this.turn = this.directionPriority ? n.left : n.right;
let s = this.checkCollision(!1);
return this.turn = n.top, this.pos.coords.Y > i.pos.coords.Y || s;
}
}
return !0;
}
checkTarget2(i) {
let s = this.uc.shotDistance - Math.round(this.uc.shotDistance / 4), h = i.id !== this.map.backId.redBase && i.id !== this.map.backId.blueBase ? this.map.unitWidth + 2 : Math.round(this.map.unitWidth / 2);
switch (this.turn) {
case n.right:
return this.pos.coords.X < i.pos.coords.X - s || this.pos.coords.Y > i.pos.coords.Y + h || this.pos.coords.Y < i.pos.coords.Y - h;
case n.bottom:
return this.pos.coords.Y < i.pos.coords.Y - s || this.pos.coords.X > i.pos.coords.X + h || this.pos.coords.X < i.pos.coords.X - h;
case n.left:
return this.pos.coords.X > i.pos.coords.X + s || this.pos.coords.Y > i.pos.coords.Y + h || this.pos.coords.Y < i.pos.coords.Y - h;
case n.top:
return this.pos.coords.Y > i.pos.coords.Y + s || this.pos.coords.X > i.pos.coords.X + h || this.pos.coords.X < i.pos.coords.X - h;
}
return !0;
}
checkCollision(i) {
let s = !1;
if (i)
for (let h = this.uc.speed; h > 0 && (s = !1, this.setPosition(h, !0), this.checkFrontWay(h) || (this.setPosition(h, !1), s = !0), s !== !1); --h)
;
else this.checkFrontWay(this.uc.speed) || (s = !0);
return s;
}
hunt(i) {
this.turnGun(i), i !== null && this.uc.health > 0 && (this.directionPriority ? this.turnFlag === !1 && this.turn === n.top ? this.turn = n.right : this.turnFlag === !1 && (this.turn += 1) : this.turnFlag === !1 && this.turn === n.right ? this.turn = n.top : this.turnFlag === !1 && (this.turn -= 1), this.side === "red" && this.turnFlag ? this.directionPriority = this.pos.coords.Y < Math.round(this.map.frontHeight / 2) : this.turnFlag && (this.directionPriority = this.pos.coords.Y > Math.round(this.map.frontHeight / 2)), this.turnFlag = !0, this.checkTarget1(i) ? this.checkTarget2(i) && this.checkCollision(!0) && this.checkCollision(!1) && (this.turn = this.directionPriority ? this.turn - 1 : this.turn + 1, this.turnClosure(), this.turnFlag = this.checkCollision(!0)) : this.turn = this.directionPriority ? this.turn - 1 : this.turn + 1, this.turnClosure());
}
turnClosure() {
this.turn < n.right && (this.turn = n.top), this.turn > n.top && (this.turn = n.right);
}
turnGun(i) {
let s = Math.round(this.map.unitWidth / 2), h = Math.round(this.map.unitWidth / 2), d = i.pos.coords.X + Math.round(this.map.unitWidth / 2), a = i.pos.coords.Y + Math.round(this.map.unitWidth / 2), r = this.pos.coords.X + s, l = this.pos.coords.Y + h, u = (a - l) / (d - r);
r <= d ? this.gun.degree = Math.atan(u) * 180 / Math.PI : this.gun.degree = Math.atan(u) * 180 / Math.PI + 180;
}
shot() {
this.counter++;
let i = null;
for (let s of this.targets)
if (this.uc.health > 0 && s.uc.health > 0 && this.searchTarget(s)) {
i = s;
break;
}
i !== null && (this.turnGun(i), this.trigger = !0), this.trigger && (this.counter % 2 === 0 && this.reload === this.bullet.speed && this.bullet.move(), this.counter % 2 === 0 && this.reload++, this.kill = this.bullet.fatalHit(), this.kill !== null && (++this.kills, ++this.killsInGame, this.bullet.target = null, this.levelUp(), this.kill = null), this.reload > 10 && (this.trigger = !1, this.bullet.hit = !1, this.bullet.hitMiss = !1, this.reload = 0));
}
}
class H extends x {
constructor(i, s, h) {
super(i, s, h);
e(this, "unitsCount", 8);
e(this, "towersCount", 18);
e(this, "mobsCount", 6);
e(this, "backArray", []);
e(this, "unitsCoords", []);
e(this, "startUnitsTurn", []);
e(this, "baseTowers", []);
e(this, "towers", []);
e(this, "mobs", []);
e(this, "etalonMobs", []);
e(this, "redBase", null);
e(this, "blueBase", null);
e(this, "etalonTower", null);
e(this, "backId", null);
this.backId = new T(this.unitsCount, this.towersCount, this.mobsCount);
const d = { model: "gun_1", degree: 0 }, a = { model: "gun_3", degree: 0 }, r = { model: "gun_5", degree: 0 };
this.redBase = new m("Red", "", 200, 0), this.redBase.tower1 = new m("Red", "tower_1", 100, 0, 0, 3, 350, 0, _.cloneDeep(d)), this.redBase.tower2 = new m("Red", "tower_1", 100, 0, 0, 3, 350, 0, _.cloneDeep(d)), this.blueBase = new m("Blue", "", 200, 0), this.blueBase.tower1 = new m("Blue", "tower_2", 100, 0, 0, 3, 350, 0, _.cloneDeep(a)), this.blueBase.tower2 = new m("Blue", "tower_2", 100, 0, 0, 3, 350, 0, _.cloneDeep(a)), this.etalonTower = new m("", "", 100, 0, 0, 3, 350), Math.round(this.unitWidth * 2 / 3);
const l = Math.round(this.unitWidth / 3), u = Math.round(this.unitWidth / 2);
this.unitsCoords = [
new c(
this.unitWidth * 3 - u,
this.frontHeight - this.unitWidth * 12 - u
),
new c(
this.unitWidth * 3 - u,
this.frontHeight - this.unitWidth * 9 - u
),
new c(
this.unitWidth * 9 - u,
this.frontHeight - this.unitWidth * 3 - u
),
new c(
this.unitWidth * 12 - u,
this.frontHeight - this.unitWidth * 3 - u
),
new c(
this.frontWidth - this.unitWidth * 3 - u,
this.frontHeight - this.unitWidth * 13 + u
),
new c(
this.frontWidth - this.unitWidth * 3 - u,
this.frontHeight - this.unitWidth * 10 + u
),
new c(
this.frontWidth - this.unitWidth * 9 - u,
this.frontHeight - this.unitWidth * 3 - u
),
new c(
this.frontWidth - this.unitWidth * 12 - u,
this.frontHeight - this.unitWidth * 3 - u
)
], this.startUnitsTurn = [
n.right,
n.right,
n.top,
n.top,
n.left,
n.left,
n.top,
n.top
], this.baseTowers = [
this.redBase.tower1,
this.redBase.tower2,
this.blueBase.tower1,
this.blueBase.tower2
], this.redBase.tower1.pos.coords = new c(
this.unitWidth * 9 + u,
this.unitWidth * 10 + u
), this.redBase.tower2.pos.coords = new c(
this.unitWidth * 9 + u,
this.unitWidth * 15 + u
), this.blueBase.tower1.pos.coords = new c(
this.frontWidth - this.unitWidth * 11 + u,
this.unitWidth * 9 + u
), this.blueBase.tower2.pos.coords = new c(
this.frontWidth - this.unitWidth * 11 + u,
this.unitWidth * 14 + u
);
for (let f = 0; f < 9; ++f)
this.towers.push(new m("Red", "tower_1", 100, 0, 0, 3, 350, 0, _.cloneDeep(d)));
for (let f = 0; f < 9; ++f)
this.towers.push(new m("Blue", "tower_2", 100, 0, 0, 3, 350, 0, _.cloneDeep(a)));
this.towersCoords = [
//red towers
new c(this.unitWidth * 16, this.unitWidth * 8),
new c(this.unitWidth * 15, this.unitWidth * 4),
new c(this.unitWidth * 17, this.unitWidth * 14),
new c(this.unitWidth * 17, this.unitWidth * 18),
new c(this.unitWidth * 16, this.unitWidth * 24 + l),
new c(this.unitWidth * 15, this.unitWidth * 28 + l),
new c(this.unitWidth * 27, this.unitWidth * 2),
new c(this.unitWidth * 28, this.unitWidth * 15),
new c(this.unitWidth * 27, this.frontHeight - this.unitWidth * 3),
//blue towers
new c(this.frontWidth - this.unitWidth * 16, this.unitWidth * 4),
new c(this.frontWidth - this.unitWidth * 17, this.unitWidth * 8),
new c(this.frontWidth - this.unitWidth * 18, this.unitWidth * 14),
new c(this.frontWidth - this.unitWidth * 18, this.unitWidth * 18),
new c(this.frontWidth - this.unitWidth * 17, this.unitWidth * 24 + l),
new c(this.frontWidth - this.unitWidth * 16, this.unitWidth * 28 + l),
new c(this.frontWidth - this.unitWidth * 28, this.unitWidth * 2),
new c(this.frontWidth - this.unitWidth * 29, this.unitWidth * 17),
new c(this.frontWidth - this.unitWidth * 28, this.frontHeight - this.unitWidth * 3)
];
for (let f = 0; f < 6; ++f)
this.mobs.push(new m("Green", "tower_3", 15, 0, 0, 3, 250, 1e3, _.cloneDeep(r))), this.etalonMobs.push(new m("Green", "tower_3", 15, 0, 0, 3, 250, 1e3, _.cloneDeep(r)));
this.mobsCoords = [
new c(this.unitWidth * 24 + u, this.unitWidth * 10 + u),
new c(this.unitWidth * 24 + u, this.unitWidth * 21),
new c(this.unitWidth * 23 + u, this.unitWidth * 24 + u),
new c(this.frontWidth - this.unitWidth * 25 - u, this.unitWidth * 9 + u),
new c(this.frontWidth - this.unitWidth * 25 - u, this.unitWidth * 20),
new c(this.frontWidth - this.unitWidth * 24 - u, this.unitWidth * 24)
], this.mapInit();
}
mapInit() {
const i = Math.round(this.unitWidth * 2 / 3), s = Math.round(this.unitWidth / 3);
this.backArray.push(new o(
0,
0,
7 * this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
0,
this.frontHeight - 8 * this.unitWidth,
4 * this.unitWidth,
8 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
4 * this.unitWidth,
this.frontHeight - 6 * this.unitWidth,
this.unitWidth,
6 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
5 * this.unitWidth,
this.frontHeight - 5 * this.unitWidth,
this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
6 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
0,
5 * this.unitWidth,
2 * this.unitWidth,
this.frontHeight - 8 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
2 * this.unitWidth,
this.frontHeight - 11 * this.unitWidth,
2 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
2 * this.unitWidth,
5 * this.unitWidth,
2 * this.unitWidth,
15 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
7 * this.unitWidth,
0,
22 * this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
10 * this.unitWidth,
2 * this.unitWidth,
10 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
10 * this.unitWidth,
3 * this.unitWidth,
8 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
8 * this.unitWidth,
this.frontHeight - 2 * this.unitWidth,
21 * this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
10 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
13 * this.unitWidth,
this.frontHeight - 3 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
13 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
5 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
17 * this.unitWidth,
9 * this.unitWidth,
4 * this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
20 * this.unitWidth,
6 * this.unitWidth,
6 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
23 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
8 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
24 * this.unitWidth,
7 * this.unitWidth,
2 * this.unitWidth,
3 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
24 * this.unitWidth,
12 * this.unitWidth,
2 * this.unitWidth,
3 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
25 * this.unitWidth,
10 * this.unitWidth,
this.unitWidth,
2 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
28 * this.unitWidth,
6 * this.unitWidth,
this.unitWidth,
3 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
28 * this.unitWidth,
11 * this.unitWidth,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
17 * this.unitWidth,
this.frontHeight - 14 * this.unitWidth - s,
4 * this.unitWidth,
5 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
23 * this.unitWidth,
this.frontHeight - 14 * this.unitWidth - s,
3 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
23 * this.unitWidth,
this.frontHeight - 13 * this.unitWidth - s,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
24 * this.unitWidth,
this.frontHeight - 10 * this.unitWidth - s,
2 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
25 * this.unitWidth,
this.frontHeight - 13 * this.unitWidth - s,
this.unitWidth,
3 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
25 * this.unitWidth,
this.frontHeight - 9 * this.unitWidth - s,
this.unitWidth,
3 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
20 * this.unitWidth,
this.frontHeight - 7 * this.unitWidth,
5 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
23 * this.unitWidth,
this.frontHeight - 9 * this.unitWidth - s,
this.unitWidth,
2 * this.unitWidth + s,
this.backId.closeRoad
)), this.backArray.push(new o(
28 * this.unitWidth,
this.frontHeight - 15 * this.unitWidth - s,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
28 * this.unitWidth,
this.frontHeight - 9 * this.unitWidth - s,
this.unitWidth,
3 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 7 * this.unitWidth,
0,
7 * this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 4 * this.unitWidth,
this.frontHeight - 8 * this.unitWidth,
4 * this.unitWidth,
8 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 5 * this.unitWidth,
this.frontHeight - 6 * this.unitWidth,
this.unitWidth,
6 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 6 * this.unitWidth,
this.frontHeight - 5 * this.unitWidth,
this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 8 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 2 * this.unitWidth,
5 * this.unitWidth,
2 * this.unitWidth,
20 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 4 * this.unitWidth,
this.frontHeight - 11 * this.unitWidth,
2 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 4 * this.unitWidth,
5 * this.unitWidth,
2 * this.unitWidth,
15 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
0,
22 * this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 20 * this.unitWidth,
2 * this.unitWidth,
10 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 18 * this.unitWidth,
3 * this.unitWidth,
8 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
this.frontHeight - 2 * this.unitWidth,
21 * this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 21 * this.unitWidth,
this.frontHeight - 3 * this.unitWidth,
8 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 18 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
5 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 11 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 21 * this.unitWidth,
9 * this.unitWidth,
4 * this.unitWidth,
5 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
6 * this.unitWidth,
6 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
7 * this.unitWidth,
3 * this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 24 * this.unitWidth,
9 * this.unitWidth,
this.unitWidth,
2 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
11 * this.unitWidth,
3 * this.unitWidth,
3 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
9 * this.unitWidth,
this.unitWidth,
2 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
6 * this.unitWidth,
this.unitWidth,
3 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
11 * this.unitWidth,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 21 * this.unitWidth,
this.frontHeight - 14 * this.unitWidth - s,
4 * this.unitWidth,
5 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
this.frontHeight - 15 * this.unitWidth - s,
3 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 24 * this.unitWidth,
this.frontHeight - 14 * this.unitWidth - s,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
this.frontHeight - 11 * this.unitWidth - s,
2 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
this.frontHeight - 10 * this.unitWidth - s,
this.unitWidth,
4 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 25 * this.unitWidth,
this.frontHeight - 7 * this.unitWidth,
5 * this.unitWidth,
this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 26 * this.unitWidth,
this.frontHeight - 14 * this.unitWidth - s,
this.unitWidth,
2 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 24 * this.unitWidth,
this.frontHeight - 10 * this.unitWidth - s,
this.unitWidth,
3 * this.unitWidth + s,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
this.frontHeight - 15 * this.unitWidth - s,
this.unitWidth,
4 * this.unitWidth,
this.backId.wall
)), this.backArray.push(new o(
this.frontWidth - 29 * this.unitWidth,
this.frontHeight - 9 * this.unitWidth - s,
this.unitWidth,
3 * this.unitWidth + s,
this.backId.wall
)), this.backArray.push(new o(
29 * this.unitWidth,
0,
8 * this.unitWidth + i,
3 * this.unitWidth,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
6 * this.unitWidth,
8 * this.unitWidth + i,
3 * this.unitWidth,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
11 * this.unitWidth,
8 * this.unitWidth + i,
4 * this.unitWidth,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
18 * this.unitWidth,
8 * this.unitWidth + i,
4 * this.unitWidth,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
24 * this.unitWidth,
8 * this.unitWidth + i,
3 * this.unitWidth + s,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
30 * this.unitWidth + s,
8 * this.unitWidth + i,
3 * this.unitWidth,
this.backId.water
)), this.backArray.push(new o(
29 * this.unitWidth,
9 * this.unitWidth,
9 * this.unitWidth + i,
2 * this.unitWidth,
this.backId.sand
)), this.backArray.push(new o(
29 * this.unitWidth,
22 * this.unitWidth,
9 * this.unitWidth + i,
2 * this.unitWidth,
this.backId.sand
)), this.backArray.push(new o(
2 * this.unitWidth,
this.frontHeight - 13 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[0]
)), this.backArray.push(new o(
2 * this.unitWidth,
this.frontHeight - 10 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[1]
)), this.backArray.push(new o(
8 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[2]
)), this.backArray.push(new o(
11 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[3]
)), this.backArray.push(new o(
this.frontWidth - 4 * this.unitWidth,
this.frontHeight - 13 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[4]
)), this.backArray.push(new o(
this.frontWidth - 4 * this.unitWidth,
this.frontHeight - 10 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[5]
)), this.backArray.push(new o(
this.frontWidth - 10 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[6]
)), this.backArray.push(new o(
this.frontWidth - 13 * this.unitWidth,
this.frontHeight - 4 * this.unitWidth,
2 * this.unitWidth,
2 * this.unitWidth,
this.backId.homes[7]
)), this.backArray.push(new o(
7 * this.unitWidth,
2 * this.unitWidth,
3 * this.unitWidth,
3 * this.unitWidth - 20,
this.backId.hpRegenRed
)), this.backArray.push(new o(
4 * this.unitWidth,
5 * this.unitWidth,
3 * this.unitWidth - 20,
3 * this.unitWidth,
this.backId.cpRegen
)), this.backArray.push(new o(
this.frontWidth - 7 * this.unitWidth + 20,
5 * this.unitWidth,
3 * this.unitWidth - 20,
3 * this.unitWidth,
this.backId.cpRegen
)), this.backArray.push(new o(
this.frontWidth - 10 * this.unitWidth,
2 * this.unitWidth,
3 * this.unitWidth,
3 * this.unitWidth - 20,
this.backId.hpRegenBlue
)), this.backArray.push(new o(
4 * this.unitWidth,
11 * this.unitWidth,
6 * this.unitWidth,
5 * this.unitWidth,
this.backId.redBase
)), this.backArray.push(new o(
4 * this.unitWidth,
10 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
10 * this.unitWidth,
11 * this.unitWidth,
this.unitWidth,
5 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
4 * this.unitWidth,
16 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 10 * this.unitWidth,
10 * this.unitWidth,
6 * this.unitWidth,
5 * this.unitWidth,
this.backId.blueBase
)), this.backArray.push(new o(
this.frontWidth - 11 * this.unitWidth,
9 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 11 * this.unitWidth,
10 * this.unitWidth,
this.unitWidth,
5 * this.unitWidth,
this.backId.closeRoad
)), this.backArray.push(new o(
this.frontWidth - 11 * this.unitWidth,
15 * this.unitWidth,
7 * this.unitWidth,
this.unitWidth,
this.backId.closeRoad
));
}
}
class U {
constructor() {
e(this, "images", /* @__PURE__ */ new Map([
["testGameMap", new Image(4e3, 2e3)],
["bullet_1", new Image(60, 60)],
["bullet_1_shot", new Image(60, 60)],
["bullet_1_boom", new Image(60, 60)],
["T_1", new Image(60, 60)],
["T_2", new Image(60, 60)],
["T_3", new Image(60, 60)],
["T_4", new Image(60, 60)],
["tower_1", new Image(60, 60)],
["tower_2", new Image(60, 60)],
["tower_3", new Image(60, 60)],
["gun_1", new Image(60, 60)],
["gun_2", new Image(60, 60)],
["gun_3", new Image(60, 60)],
["gun_4", new Image(60, 60)],
["gun_5", new Image(60, 60)],
["redCrash", new Image(60, 60)],
["blueCrash", new Image(60, 60)],
["smoke_1", new Image(60, 60)]
]));
e(this, "counter", 0);
const t = k === w.Dev ? "../../" : "";
this.images.get("testGameMap").src = `${t}images/testGame/map_1.png`, this.images.get("bullet_1").src = `${t}images/testGame/bullet_1.png`, this.images.get("bullet_1_shot").src = `${t}images/testGame/bullet_1_shot.png`, this.images.get("bullet_1_boom").src = `${t}images/testGame/bullet_1_boom.png`, this.images.get("T_1").src = `${t}images/testGame/T_1.png`, this.images.get("T_2").src = `${t}images/testGame/T_2.png`, this.images.get("T_3").src = `${t}images/testGame/T_3.png`, this.images.get("T_4").src = `${t}images/testGame/T_4.png`, this.images.get("tower_1").src = `${t}images/testGame/tower_1.png`, this.images.get("tower_2").src = `${t}images/testGame/tower_2.png`, this.images.get("tower_3").src = `${t}images/testGame/tower_3.png`, this.images.get("gun_1").src = `${t}images/testGame/gun_1.png`, this.images.get("gun_2").src = `${t}images/testGame/gun_2.png`, this.images.get("gun_3").src = `${t}images/testGame/gun_3.png`, this.images.get("gun_4").src = `${t}images/testGame/gun_4.png`, this.images.get("gun_5").src = `${t}images/testGame/gun_5.png`, this.images.get("redCrash").src = `${t}images/testGame/redCrash.png`, this.images.get("blueCrash").src = `${t}images/testGame/blueCrash.png`, this.images.get("smoke_1").src = `${t}images/testGame/smoke_1.png`;
}
allUploaded(t) {
let i = () => {
++this.counter === this.images.size && t();
};
this.images.forEach((s) => {
s.onload = i;
});
}
}
class v {
constructor(t, i, s, h, d, a) {
e(this, "sounds", /* @__PURE__ */ new Map());
e(this, "counter", 0);
const r = k === w.Dev ? "../../" : "";
h.forEach((l) => {
l.id === s.id ? this.sounds.set(l.id, new Audio(`${r}sounds/ShotLoud.mp3`)) : this.sounds.set(l.id, new Audio(`${r}sounds/ShotQuit.mp3`));
}), d.forEach((l) => {
this.sounds.set(l.id, new Audio(`${r}sounds/ShotQuit.mp3`));
}), a.forEach((l) => {
this.sounds.set(l.id, new Audio(`${r}sounds/ShotQuit.mp3`));
}), this.sounds.set(t.tower1.id, new Audio(`${r}sounds/ShotQuit.mp3`)), this.sounds.set(t.tower2.id, new Audio(`${r}sounds/ShotQuit.mp3`)), this.sounds.set(i.tower1.id, new Audio(`${r}sounds/ShotQuit.mp3`)), this.sounds.set(i.tower2.id, new Audio(`${r}sounds/ShotQuit.mp3`)), this.sounds.set("Wind", new Audio(`${r}sounds/Wind.mp3`));
}
}
class B {
constructor(t, i, s) {
e(this, "map", null);
e(this, "uI", 0);
e(this, "etalonUnits", []);
e(this, "cloneUnits", []);
this.map = t, this.etalonUnits = i, this.userId = s, this.uI = this.findUser(), this.preparation(), this.counter = 0, this.pause = !1, this.defeat = !1, this.win = !1, this.bonus = 0;
}
findUser() {
for (let t = 0; t < this.etalonUnits.length; ++t)
if (this.userId === this.etalonUnits[t].userId)
return t;
}
preparation() {
this.etalonUnits.forEach((t, i) => {
t.pos.coords.X = this.map.unitsCoords[i].X, t.pos.coords.Y = this.map.unitsCoords[i].Y, t.turn = this.map.startUnitsTurn[i], t.id = this.map.backId.units[i], t.homeId = this.map.backId.homes[i], t.gun.degree = t.turn * 90, this.cloneUnits[i] = _.cloneDeep(t), this.cloneUnits[i].map = t.map = this.map, this.cloneUnits[i].width = this.cloneUnits[i].height = this.map.unitWidth, this.cloneUnits[i].bullet.map = t.bullet.map = this.map, this.cloneUnits[i].bullet.width = this.cloneUnits[i].bullet.height = Math.round(this.map.unitWidth / 5), this.map.backArray.push(this.cloneUnits[i]), this.userId === t.userId && (this.cloneUnits[i].control = t.control, this.cloneUnits[i].control.mouseMove(), this.cloneUnits[i].control.mouseDown(), this.cloneUnits[i].control.mouseUp(), this.cloneUnits[i].control.keyDown(), this.cloneUnits[i].control.keyUp());
}), this.map.towers.forEach((t, i) => {
t.map = this.map, t.bullet.map = this.map, t.id = this.map.backId.towers[i], t.pos.coords = this.map.towersCoords[i], t.turn = t.side === "blue" ? n.left : n.right, t.gun.degree = t.side === "blue" ? 180 : 0, t.targets = this.cloneUnits.filter((s) => t.side !== s.side), t.allies = this.cloneUnits.filter((s) => t.side === s.side), t.width = t.height = this.map.unitWidth, this.map.backArray.push(t), t.update(t.pos.coords);
}), this.map.mobs.forEach((t, i) => {
t.map = this.map, t.bullet.map = this.map, t.id = this.map.backId.mobs[i], t.pos.coords = this.map.mobsCoords[i], t.targets = this.cloneUnits.filter((s) => t.side !== s.side), t.allies = this.cloneUnits.filter((s) => t.side === s.side), t.width = t.height = this.map.unitWidth, this.map.backArray.push(t), t.update(t.pos.coords);
}), this.map.etalonMobs.forEach((t, i) => {
t.map = this.map, t.bullet.map = this.map, t.id = this.map.backId.mobs[i], t.pos.coords = this.map.mobsCoords[i], t.targets = this.cloneUnits.filter((s) => t.side !== s.side), t.allies = this.cloneUnits.filter((s) => t.side === s.side);
}), this.cloneUnits.forEach((t) => {
t.targets = this.cloneUnits.filter((i) => t.side !== i.side), this.map.towers.filter((i) => t.side !== i.side).forEach((i) => {
t.targets.push(i);
}), this.map.mobs.filter((i) => t.side !== i.side).forEach((i) => {
t.targets.push(i);
}), t.targets.push(t.side === "red" ? this.map.blueBase : this.map.redBase), t.allies = this.cloneUnits.filter((i) => t.side === i.side);
}), this.map.baseTowers.forEach((t) => {
t.map = this.map, t.bullet.map = this.map, t.targets = this.cloneUnits.filter((i) => t.side !== i.side), t.allies = this.cloneUnits.filter((i) => t.side === i.side);
}), this.map.redBase.id = this.map.backId.redBase, this.map.blueBase.id = this.map.backId.blueBase, this.map.redBase.tower1.id = 1e3, this.map.blueBase.tower2.id = 1001, this.map.blueBase.tower1.id = 1002, this.map.blueBase.tower2.id = 1003, this.sound = new v(
this.map.redBase,
this.map.blueBase,
this.cloneUnits[this.uI],
this.cloneUnits,
this.map.towers,
this.map.mobs
);
}
unitsBackFill() {
this.cloneUnits.forEach((t) => {
t.pos.pastCoords.X = t.pos.coords.X, t.pos.pastCoords.Y = t.pos.coords.Y, t.update(t.pos.coords), t.checkFrontWay(1);
});
}
run() {
this.cloneUnits[this.uI].control.buttonUp === "Space" && (this.pause = this.pause === !1, this.cloneUnits[this.uI].control.buttonUp = ""), !this.pause && !this.win && !this.defeat && (this.counter++, this.counter > 5400 && (this.counter = 0), this.unitsBackFill(), this.cloneUnits.forEach((t, i) => {
this.uI !== i && (this.botLogic(t), t.target !== null && t.hunt(t.target), t.shot(), this.crash(t, this.etalonUnits[i]), this.rebirth(t, this.etalonUnits[i]));
}), this.map.baseTowers.forEach((t) => {
t.shot();
}), this.map.towers.forEach((t) => {
t.shot();
}), this.map.mobs.forEach((t, i) => {
t.uc.health < t.etalonUc.health && t.shot(), this.crash(t, this.map.etalonMobs[i]), this.rebirth(t, this.map.etalonMobs[i]);
}), this.cloneUnits[this.uI].controlHandling(), this.cloneUnits[this.uI].shot(), this.crash(this.cloneUnits[this.uI], this.etalonUnits[this.uI]), this.rebirth(this.cloneUnits[this.uI], this.etalonUnits[this.uI]), this.gameOver());
}
gameOver() {
this.cloneUnits[this.uI].side === "red" && this.map.blueBase.uc.health <= 0 || this.cloneUnits[this.uI].side === "blue" && this.map.redBase.uc.health <= 0 ? (++this.etalonUnits[this.uI].wins, ++this.etalonUnits[this.uI].battles, this.etalonUnits[this.uI].kills = this.cloneUnits[this.uI].kills, this.bonus = I(500, 1e3), this.etalonUnits[this.uI].money += this.bonus, this.win = !0) : (this.cloneUnits[this.uI].side === "red" && this.map.redBase.uc.health <= 0 || this.cloneUnits[this.uI].side === "blue" && this.map.blueBase.uc.health <= 0) && (++this.etalonUnits[this.uI].defeats, ++this.etalonUnits[this.uI].battles, this.etalonUnits[this.uI].kills = this.cloneUnits[this.uI].kills, this.bonus = I(200, 300), this.etalonUnits[this.uI].money += this.bonus, this.defeat = !0);
}
botLogic(t) {
var i;
if (this.counter % 1200 === 0 || this.counter === 1 || t.target === null || t.target.uc.health <= 0) {
let s = /* @__PURE__ */ new Map();
t.targets.forEach((a, r) => {
let l = Math.abs(a.pos.coords.X - t.pos.coords.X), u = Math.abs(a.pos.coords.Y - t.pos.coords.Y);
s.set(a, Math.round(Math.sqrt(Math.pow(l, 2) + Math.pow(u, 2))));
});
const h = [...s.entries()].sort((a, r) => a[1] - r[1]).map(([a, r]) => a).filter((a) => !t.allies.find((r) => {
var l;
return ((l = r.target) == null ? void 0 : l.id) === a.id;
}));
let d = !1;
for (let a of h) {
for (let r of t.allies) {
if (((i = r.target) == null ? void 0 : i.id) === a.id) break;
if (a.uc.health > 0) {
t.target = a, d = !0;
break;
}
}
if (d) break;
}
}
}
crash(t, i) {
t.uc.health <= 0 && t.uc.respawnTime === t.etalonUc.respawnTime && (t.pos.crashCoords.X = t.pos.coords.X, t.pos.crashCoords.Y = t.pos.coords.Y, t.turn = i.turn, t.gun.degree = i.gun.degree, t.pos.coords.X = i.pos.coords.X, t.pos.coords.Y = i.pos.coords.Y), t.uc.health <= 0 && --t.uc.respawnTime;
}
rebirth(t) {
t.uc.respawnTime <= 0 && (t.uc.respawnTime = t.etalonUc.respawnTime, t.uc.armor = t.etalonUc.armor, t.uc.health = t.etalonUc.health);
}
}
class R extends X {
constructor(i, s, h) {
super();
e(this, "experienceToLevel", 0);
e(this, "money", 0);
e(this, "battles", 0);
e(this, "wins", 0);
e(this, "kills", 0);
e(this, "killsInGame", 0);
e(this, "defeats", 0);
e(this, "counter", 0);
e(this, "control", null);
e(this, "name", "Player");
super.userId = s, super.side = h.team.toLowerCase(), this.control = i, this.uc.model = h.tankBody, this.etalonUc.model = h.tankBody, this.gun.model = h.tankHead;
}
checkCollision(i) {
let s = !1;
for (let a = this.speedController; a > 0 && (s = !1, this.setPosition(a, !0), this.checkFrontWay(a) || (this.setPosition(a, !1), s = !0), s !== !1); a--)
;
let h = this.pos.coords.X - this.pos.pastCoords.X, d = this.pos.coords.Y - this.pos.pastCoords.Y;
if (this.pos.deltaCoords.X = h, this.pos.deltaCoords.Y = d, i && !s) {
let a = this.pos.renderCoords.X + this.pos.deltaCoords.X,