Skip to content

Commit 66c7f9f

Browse files
committed
More support for custom gamemodes
1 parent 23b8564 commit 66c7f9f

8 files changed

+54
-15
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ build/Release
2929
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
3030
node_modules
3131
*.project
32+
src/.settings/.jsdtscope
33+
src/.settings/org.eclipse.wst.jsdt.ui.superType.container
34+
src/.settings/org.eclipse.wst.jsdt.ui.superType.name

src/GameServer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ GameServer.prototype.addNode = function(node) {
178178

179179
// Adds to the owning player's screen
180180
if (node.owner){
181-
node.owner.socket.sendPacket(new Packet.AddNodes(node));
181+
node.owner.socket.sendPacket(new Packet.AddNode(node));
182182
}
183183

184184
// Add to visible nodes
@@ -251,6 +251,9 @@ GameServer.prototype.mainLoop = function() {
251251
// Update leaderboard with the gamemode's method
252252
this.leaderboard = [];
253253
this.gameMode.updateLB(this);
254+
255+
// Update - Gamemode
256+
this.gameMode.onServerUpdate(this);
254257

255258
this.tickMain = 0; // Reset
256259
}

src/PacketHandler.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ function PacketHandler(gameServer, socket) {
44
this.gameServer = gameServer;
55
this.socket = socket;
66

7+
this.pressQ = false;
78
this.pressW = false;
89
this.pressSpace = false;
910
}
@@ -57,6 +58,13 @@ PacketHandler.prototype.handleMessage = function(message) {
5758
case 17:
5859
// Space Press - Split cell
5960
this.pressSpace = true;
61+
break;
62+
case 18:
63+
// Q Key Pressed
64+
this.pressQ = true;
65+
break;
66+
case 19:
67+
// Q Key Released
6068
break;
6169
case 21:
6270
// W Press - Eject mass
@@ -76,7 +84,7 @@ PacketHandler.prototype.setNickname = function(newNick) {
7684
var client = this.socket.playerTracker;
7785
if (client.cells.length < 1) {
7886
// If client has no cells... then spawn a player
79-
this.gameServer.spawnPlayer(client);
87+
this.gameServer.gameMode.onPlayerSpawn(this.gameServer,client);
8088

8189
// Turn off spectate mode
8290
client.spectate = false;

src/PlayerTracker.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ PlayerTracker.prototype.getTeam = function() {
8181
// Functions
8282

8383
PlayerTracker.prototype.update = function() {
84-
// Actions buffer
85-
if (this.socket.packetHandler.pressSpace) {
86-
// Split cell
87-
this.gameServer.splitCells(this);
84+
// Actions buffer (So that people cant spam packets)
85+
if (this.socket.packetHandler.pressSpace) { // Split cell
86+
this.gameServer.gameMode.pressSpace(this.gameServer,this);
8887
this.socket.packetHandler.pressSpace = false;
89-
}
90-
if (this.socket.packetHandler.pressW) {
91-
// Eject mass
92-
this.gameServer.ejectMass(this);
88+
} if (this.socket.packetHandler.pressW) { // Eject mass
89+
this.gameServer.gameMode.pressW(this.gameServer,this);
9390
this.socket.packetHandler.pressW = false;
91+
} if (this.socket.packetHandler.pressQ) { // Q Press
92+
this.gameServer.gameMode.pressQ(this.gameServer,this);
93+
this.socket.packetHandler.pressQ = false;
9494
}
9595

9696
// Remove nodes from visible nodes if possible

src/gamemodes/Mode.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function Mode() {
22
this.ID = -1;
33
this.name = "Blank";
44
this.decayMod = 1.0; // Modifier for decay rate (Multiplier)
5-
this.packetLB = 49; // Packet id for leaderboard packet (49 = List, 50 = Pie chart)
5+
this.packetLB = 49; // Packet id for leaderboard packet (48 = Text List, 49 = List, 50 = Pie chart)
66
this.haveTeams = false; // True = gamemode uses teams, false = gamemode doesnt use teams
77

88
this.rankOne; // Current player that has the highest score
@@ -16,10 +16,33 @@ Mode.prototype.onServerInit = function(gameServer) {
1616
// Called when the server starts
1717
}
1818

19+
Mode.prototype.onServerUpdate = function(gameServer) {
20+
// Called during each server update tick
21+
}
22+
1923
Mode.prototype.onPlayerInit = function(player) {
2024
// Called after a player object is constructed
2125
}
2226

27+
Mode.prototype.onPlayerSpawn = function(gameServer,player) {
28+
// Called when a player is spawned
29+
gameServer.spawnPlayer(player);
30+
}
31+
32+
Mode.prototype.pressQ = function(gameServer,player) {
33+
// Called when the Q key is pressed
34+
}
35+
36+
Mode.prototype.pressW = function(gameServer,player) {
37+
// Called when the W key is pressed
38+
gameServer.ejectMass(player);
39+
}
40+
41+
Mode.prototype.pressSpace = function(gameServer,player) {
42+
// Called when the Space bar is pressed
43+
gameServer.splitCells(player);
44+
}
45+
2346
Mode.prototype.onCellAdd = function(cell) {
2447
// Called when a player cell is added
2548
}

src/packet/AddNodes.js src/packet/AddNode.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function AddNodes(item) {
1+
function AddNode(item) {
22
this.item = item;
33
}
44

5-
module.exports = AddNodes;
5+
module.exports = AddNode;
66

7-
AddNodes.prototype.build = function() {
7+
AddNode.prototype.build = function() {
88
// Only add player controlled cells with this packet or it will bug the camera
99
var buf = new ArrayBuffer(5);
1010
var view = new DataView(buf);

src/packet/UpdateLeaderboard.js

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ UpdateLeaderboard.prototype.build = function() {
1212
var validElements = 0;
1313

1414
switch (this.packetLB) {
15+
case 48: // Custom Text List
16+
break;
1517
case 49: // FFA-type Packet (List)
1618
// Get size of packet
1719
for (var i = 0; i < lb.length; i++) {

src/packet/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
AddNodes: require('./AddNodes'),
2+
AddNode: require('./AddNode'),
33
ClearNodes: require('./ClearNodes'),
44
UpdatePosition: require('./UpdatePosition'),
55
SetBorder: require('./SetBorder'),

0 commit comments

Comments
 (0)