mirror of
https://git.rezel.net/LudoTech/traque.git
synced 2026-02-09 10:20:16 +01:00
backend for team capture
This commit is contained in:
@@ -51,6 +51,7 @@ export default class Game {
|
|||||||
sockets: [],
|
sockets: [],
|
||||||
startingArea: null,
|
startingArea: null,
|
||||||
ready: false,
|
ready: false,
|
||||||
|
captured: false,
|
||||||
});
|
});
|
||||||
this.updateTeamChasing();
|
this.updateTeamChasing();
|
||||||
return true;
|
return true;
|
||||||
@@ -60,13 +61,21 @@ export default class Game {
|
|||||||
if(this.teams.length <= 1) {
|
if(this.teams.length <= 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
this.teams[0].chased = this.teams[this.teams.length - 1].id;
|
let firstTeam = null;
|
||||||
this.teams[this.teams.length - 1].chasing = this.teams[0].id;
|
let previousTeam = null
|
||||||
|
for(let i = 0; i < this.teams.length; i++ ) {
|
||||||
for(let i = 0; i < this.teams.length - 1; i++) {
|
if(!this.teams[i].captured) {
|
||||||
this.teams[i].chasing = this.teams[i + 1].id;
|
if(previousTeam != null) {
|
||||||
this.teams[i+1].chased = this.teams[i].id;
|
this.teams[i].chased = previousTeam;
|
||||||
|
this.getTeam(previousTeam).chasing = this.teams[i].id;
|
||||||
|
}else {
|
||||||
|
firstTeam = this.teams[i].id;
|
||||||
|
}
|
||||||
|
previousTeam = this.teams[i].id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.getTeam(firstTeam).chased = previousTeam;
|
||||||
|
this.getTeam(previousTeam).chasing =firstTeam;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +96,7 @@ export default class Game {
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
this.updateTeamChasing();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,4 +140,14 @@ export default class Game {
|
|||||||
this.updateTeamChasing();
|
this.updateTeamChasing();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
capture(teamId, captureCode) {
|
||||||
|
let enemyTeam = this.getTeam(this.getTeam(teamId).chasing)
|
||||||
|
if(enemyTeam.captureCode == captureCode) {
|
||||||
|
enemyTeam.captured = true;
|
||||||
|
this.updateTeamChasing();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +184,8 @@ function sendUpdatedTeamInformations(teamId) {
|
|||||||
lastSentLocation: team.lastSentLocation,
|
lastSentLocation: team.lastSentLocation,
|
||||||
captureCode: team.captureCode,
|
captureCode: team.captureCode,
|
||||||
startingArea: team.startingArea,
|
startingArea: team.startingArea,
|
||||||
ready: team.ready
|
ready: team.ready,
|
||||||
|
captured: team.captured
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -228,6 +229,7 @@ io.of("player").on("connection", (socket) => {
|
|||||||
if (team.sockets.indexOf(socket.id) == 0) {
|
if (team.sockets.indexOf(socket.id) == 0) {
|
||||||
game.updateLocation(teamId, position);
|
game.updateLocation(teamId, position);
|
||||||
teamBroadcast(teamId, "update_team", { currentLocation: team.currentLocation, ready: team.ready });
|
teamBroadcast(teamId, "update_team", { currentLocation: team.currentLocation, ready: team.ready });
|
||||||
|
secureBroadcast("teams", game.teams);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -241,4 +243,14 @@ io.of("player").on("connection", (socket) => {
|
|||||||
game.updateTeamChasing();
|
game.updateTeamChasing();
|
||||||
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation });
|
teamBroadcast(teamId, "update_team", { enemyLocation: team.enemyLocation });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('capture', (captureCode) => {
|
||||||
|
if(game.capture(teamId, captureCode)) {
|
||||||
|
sendUpdatedTeamInformations(teamId)
|
||||||
|
sendUpdatedTeamInformations(game.getTeam(teamId).chasing)
|
||||||
|
secureBroadcast("teams", game.teams);
|
||||||
|
}else {
|
||||||
|
socket.emit("error", "Incorrect code")
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user