Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions docs/api/player.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
```

## Players
Выдает список игркоов.
Выдает список игроков.

**Имя события**: `players`

Expand All @@ -58,7 +58,9 @@
y: 0
},
dimensions: 30,
nickname: 'unnamed'
nickname: 'unnamed',
deaths: 0,
kills: 0
},
// ...
]
Expand Down Expand Up @@ -86,6 +88,8 @@
```

## PlayerDied
NOTE: В поле Damager.kills прийдёт новое кол-во убийств убийцы или -1, если убийца не игрок (Damager.entityClass соответственно будет не 'player').

**Имя события**: `playerDied`

**Broadcast**: `+`
Expand All @@ -94,12 +98,14 @@
```
{
Player: {
id: 1
id: 1,
deaths: 0
},
Damage: 10,
Damager: {
id: 1,
entityClass: entity
entityClass: entity,
kills: 1
}
}
```
Expand All @@ -113,7 +119,9 @@
```
{
Player: {
id: 1
id: 1,
deaths: 0,
kills: 0
},
// Новая позиция игрока
Vector: {
Expand Down
2 changes: 1 addition & 1 deletion server/core/damage-spell.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ module.exports = class DamageSpell extends Missile {
* @param {Entity} damagedEntity - сущность, которой будет нанесён урон
*/
hurt(damagedEntity) {
damagedEntity.onDamaged(this, DAMAGE);
damagedEntity.onDamaged(this.creator, DAMAGE);
}
}
10 changes: 10 additions & 0 deletions server/core/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ module.exports = class Entity {
*/
onDeath(killer) {
this.__isDead = true;
killer.iKilled(this);
}

/**
Expand All @@ -191,4 +192,13 @@ module.exports = class Entity {
this.randomPosition();
this.__isDead = false;
}

/**
* Действия при убийстве другой сущности
*
* @param {Entity} prey - жертва, сущность, которая была убита этой сущностью
*/
iKilled(prey) {

}
};
9 changes: 9 additions & 0 deletions server/core/missile.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ module.exports = class Missile extends Entity {
.send();
}

/**
* Действия при убийстве другой сущности
*
* @param {Entity} prey - жертва, сущность, которая была убита этой сущностью
*/
iKilled(prey) {
this.creator.iKilled(prey);
}

/**
* Действия при смерти сущности
*
Expand Down
25 changes: 24 additions & 1 deletion server/entities/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module.exports = class Player extends Entity {
this.__health = PLAYER_START_HEALTH;
this.speed = PLAYER_MOVE_SPEED;
this.__nickname = nick;
this.__countOfDeaths = 0;
this.__countOfkills = 0;

(new PlayerMessages.Connected())
.withPlayer(this)
Expand Down Expand Up @@ -83,6 +85,8 @@ module.exports = class Player extends Entity {
onDeath(killer, damage) {
super.onDeath(killer);

this.__countOfDeaths++;

this.__reSpawnTimeout = setTimeout(() => {
this.reSpawn();
}, PLAYER_RESPAWN_TIME * 1000);
Expand Down Expand Up @@ -111,13 +115,32 @@ module.exports = class Player extends Entity {
* @param {Entity} collidedWithEntity - Сущность, с которой произошло столкновение
*/
onCollide(collidedWithEntity) {
// переписать этот говнокод
// переписать
if (!(collidedWithEntity instanceof Player)) {
collidedWithEntity.onCollide(this);
}
}

/**
* Действия при убийстве другой сущности
*
* @param {Entity} prey - жертва, сущность, которая была убита этой сущностью
*/
iKilled(prey) {
if(prey instanceof Player) {
this.__countOfkills++;
}
}

get nickname() {
return this.__nickname;
}

get countOfDeaths() {
return this.__countOfDeaths;
}

get countOfKills() {
return this.__countOfkills;
}
};
22 changes: 21 additions & 1 deletion server/messages/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ module.exports = {
constructor() {
super('playerDied');
}

withPlayer(player) {
super.withPlayer(player);

this.DTO.Player.deaths = player.countOfDeaths;

return this;
}

withDamage(damage, damager) {
super.withDamage(damage, damager);

this.DTO.Damager.kills = damager.countOfKills || -1;

return this;
}
},

Respawn: class ReSpawnMessage extends Message {
Expand All @@ -57,6 +73,8 @@ module.exports = {
super.withPlayer(player);

super.DTO.Player.nickname = player.nickname;
this.DTO.Player.deaths = player.countOfDeaths;
this.DTO.Player.kills = player.countOfKills;

return this;
}
Expand Down Expand Up @@ -86,7 +104,9 @@ module.exports = {
y: player.y
},
dimensions: player.dimensions,
nickname: player.nickname
nickname: player.nickname,
deaths: player.countOfDeaths,
kills: player.countOfKills
});
});
}
Expand Down