Commit a4e7e479 authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

push the combat bc ordi bugs

parent c13a4311
......@@ -3,41 +3,40 @@ const Partie = require("../models/partie.model.js");
exports.create = (req, res) => {
// Validate request
if (!req.body) {
res.status(400).send({
message: "Content can not be empty!"
});
res.status(400).send({
message: "Content can not be empty!"
});
}
// add game to db
Partie.create(req.session.uid, req.body.pseudo, (err, data) => {
if (err)
res.status(500).send({
message:
err.message || "Some error occurred while creating the Pokemon."
});
else res.send(data);
if (err)
res.status(500).send({
message: err.message || "Some error occurred while creating the Pokemon."
});
else res.send(data);
});
};
exports.getDemandes = (req, res) => {
console.log("Is logged in: " + req.session.loggedIn);
if(req.session.loggedIn){
Partie.getDemandes(req.session.uid, (err, data) => {
if (err) {
if (err.kind === "not_found") {
res.send({res: true, body: data});
} else {
res.status(500).send({
message: "Error retrieving games with id " + req.session.uid
});
}
} else{
res.send({res: true, body: data});
}
});
} else{
res.send({res: false, body:'You must be logged in to see your games !'});
res.end();
if (req.session.loggedIn) {
Partie.getDemandes(req.session.uid, (err, data) => {
if (err) {
if (err.kind === "not_found") {
res.send({ res: true, body: data });
} else {
res.status(500).send({
message: "Error retrieving games with id " + req.session.uid
});
}
} else {
res.send({ res: true, body: data });
}
});
} else {
res.send({ res: false, body: 'You must be logged in to see your games !' });
res.end();
}
};
......@@ -63,4 +62,16 @@ exports.refuse = (req, res) => {
else res.send(data);
});
}
};
exports.eff = (req, res) => {
if (req.session.loggedIn) {
Partie.efficacite(typeNous, typeEux, (err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while deleting the challenge."
});
else res.send(data);
});
}
};
\ No newline at end of file
const sql = require("./db.js");
const Combat = function(combat, joueur) {
this.pseudo = joueur.id_pokemon;
this.email = joueur.courant;
this.password = joueur.password;
};
\ No newline at end of file
const sql = require("./db.js");
\ No newline at end of file
......@@ -48,7 +48,7 @@ Partie.accept = (id_partie, result) => {
result(err, null);
return;
}
result(null, {res: true, id: res.insertId});
result(null, { res: true, id: res.insertId });
});
};
......@@ -65,9 +65,20 @@ Partie.refuse = (id_partie, result) => {
}
console.log("deleted game with id: ", id_partie);
result(null, {res: true, body: res});
result(null, { res: true, body: res });
});
};
Partie.efficacite = (typeNous, typeEux, res) => {
sql.query("SELECT damage_factor from efficacite WHERE damage_type_id = ? AND target_type_id = ?", [typeNous, typeEux], (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
return;
}
result(null, { body: res })
});
};
module.exports = Partie;
\ No newline at end of file
module.exports = app => {
const partie = require("../controllers/combat.controller.js");
//get type efficacité
app.get();
};
\ No newline at end of file
module.exports = app => {
const partie = require("../controllers/partie.controller.js");
// Add request for game
app.post("/addpartie", partie.create);
......@@ -10,4 +10,6 @@ module.exports = app => {
app.post("/refusepartie", partie.refuse);
app.post("/geteff", partie.eff);
};
\ No newline at end of file
......@@ -65,7 +65,7 @@
</div>
<div class="actions">
<button (click)="toggle()">Water Cannon</button>
<button onclick="calculeDmg()">Water Pulse</button>
<button (click)="calculeDmg()">Water Pulse</button>
<button onclick="surf()">Surf</button>
<button onclick="tackle()">Tackle</button>
</div>
......
......@@ -43,24 +43,23 @@ export class BattleComponent implements OnInit {
}
lesTeams(id){
this.httpClient.post("http://localhost:3000/getteam", {uid: id}, { responseType: 'json', withCredentials: true }).subscribe(
(res) => {this.teams(res, id)})
//this.httpClient.post("http://localhost:3000/getcombatteam", {uid: id}, { responseType: 'json', withCredentials: true }).subscribe(
// (res) => {this.teams(res, id)})
}
typeAdv(chiffMoi, chiffToi){
if(chiffMoi == chiffToi){
return 1
}
this.httpClient.post("http://localhost:3000/geteff", { typeNous: chiffMoi, typeEux: chiffToi}, {responseType: 'json', withCredentials: true}).subscribe(res => (this.effet = res , console.log(res)))
return this.effet;
}
calculeDmg(){
var reduc = this.typeAdv(this.typeMoi, this.typeToi);
this.dmg = ((((((2*this.level)/5)+2)*this.Power*(this.atk/this.def))/50)+2)*Math.random()*reduc
console.log(this.dmg)
}
ngOnInit(): void {
this.httpClient.get("http://localHost:3000/checkLogin", { responseType: 'json', withCredentials: true}).subscribe( (res: any) => {
this.httpClient.get("http://localhost:3000/checkLogin", { responseType: 'json', withCredentials: true}).subscribe( (res: any) => {
this.log = res.res;
this.pseudo = res.body;
this.uid = res.uid;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment