improve chat
This commit is contained in:
parent
2ae3d43354
commit
61ae57a850
14 changed files with 306 additions and 33 deletions
|
@ -1,17 +1,22 @@
|
|||
'use strict';
|
||||
|
||||
const escapeHtml = require('escape-html');
|
||||
|
||||
const World = require('./world');
|
||||
|
||||
const messages = require('./messages.json');
|
||||
|
||||
class Room {
|
||||
constructor() {
|
||||
constructor(gameServer) {
|
||||
this.players = new Set();
|
||||
this.teamA = new Set();
|
||||
this.teamB = new Set();
|
||||
this.world = new World(this);
|
||||
this.name = (Math.random() * 100000 | 0).toString(36);
|
||||
|
||||
this.gameServer = gameServer;
|
||||
this.io = this.gameServer.net.io;
|
||||
|
||||
this.start();
|
||||
}
|
||||
|
||||
|
@ -37,6 +42,8 @@ class Room {
|
|||
this.stop();
|
||||
wingbase.gameServer.deleteRoom(this.name);
|
||||
}
|
||||
|
||||
this.message('roomLeave', player.name);
|
||||
}
|
||||
|
||||
setTeam(player, team) {
|
||||
|
@ -66,6 +73,17 @@ class Room {
|
|||
this.players.forEach(player => player.send(msg, data));
|
||||
}
|
||||
|
||||
chat(player, message) {
|
||||
wingbase.log(`${this.name}/${player.name}: ${message}`);
|
||||
|
||||
this.chatCooldown++;
|
||||
this.io.to(this.name).emit('chat', {
|
||||
type: 'player',
|
||||
source: player.name,
|
||||
message: escapeHtml(message.slice(0, 100))
|
||||
});
|
||||
}
|
||||
|
||||
message(type, values) {
|
||||
if (!(values instanceof Array)) values = [values];
|
||||
|
||||
|
@ -74,7 +92,7 @@ class Room {
|
|||
|
||||
// TODO: format name to class.
|
||||
|
||||
message = message.replace('@', values[0]);
|
||||
message = message.replace('@', `<b>${values[0]}</b>`);
|
||||
|
||||
this.broadcast('chat', {
|
||||
type: 'server',
|
||||
|
|
|
@ -7,7 +7,11 @@ class Mount {
|
|||
this.ship = ship;
|
||||
|
||||
this.type = data.type || 'turret';
|
||||
this.fixture = false; // TODO: Create fixture.
|
||||
this.fixture = false;
|
||||
this.position = {
|
||||
x: data.pos[0],
|
||||
y: data.pos[1]
|
||||
}
|
||||
|
||||
this.traversal = data.traversal ? {
|
||||
cw: data.bounds[0],
|
||||
|
@ -22,7 +26,7 @@ class Mount {
|
|||
|
||||
packFull() {
|
||||
return {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ class Physics {
|
|||
bodyDef.angularVelocity = body.rvel || 0;
|
||||
bodyDef.bullet = body.type == 'missile';
|
||||
bodyDef.linearDamping = body.type == 'asteroid' ? 0.003 : 0.01;
|
||||
bodyDef.angularDamping = body.type == 'asteroid' ? 0.003 : 0.04;
|
||||
bodyDef.angularDamping = body.type == 'asteroid' ? 0.003 : 0.06;
|
||||
bodyDef.type = body.type == 'structure' ?
|
||||
Box2D.b2BodyType.b2_staticBody : Box2D.b2BodyType.b2_dynamicBody;
|
||||
if (body.player || true) bodyDef.allowSleep = false;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"power": {
|
||||
"forward": 0.015,
|
||||
"back": 0,
|
||||
"rotation": 0.003
|
||||
"rotation": 0.004
|
||||
},
|
||||
"frame": [
|
||||
[
|
||||
|
@ -21,6 +21,19 @@
|
|||
{
|
||||
"pos": [18, 4],
|
||||
"type": "fixed",
|
||||
"size": 0,
|
||||
"traversal": false
|
||||
},
|
||||
{
|
||||
"pos": [18, 28],
|
||||
"type": "fixed",
|
||||
"size": 0,
|
||||
"traversal": false
|
||||
},
|
||||
{
|
||||
"pos": [1, 16],
|
||||
"type": "fixed",
|
||||
"size": 1,
|
||||
"traversal": false
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue