Commit 11d735d8 authored by Manish Kumar's avatar Manish Kumar
Browse files

merge fix

parents a9567179 97dbff02
...@@ -3,41 +3,40 @@ const Partie = require("../models/partie.model.js"); ...@@ -3,41 +3,40 @@ const Partie = require("../models/partie.model.js");
exports.create = (req, res) => { exports.create = (req, res) => {
// Validate request // Validate request
if (!req.body) { if (!req.body) {
res.status(400).send({ res.status(400).send({
message: "Content can not be empty!" message: "Content can not be empty!"
}); });
} }
// add game to db // add game to db
Partie.create(req.session.uid, req.body.pseudo, (err, data) => { Partie.create(req.session.uid, req.body.pseudo, (err, data) => {
if (err) if (err)
res.status(500).send({ res.status(500).send({
message: message: err.message || "Some error occurred while creating the Pokemon."
err.message || "Some error occurred while creating the Pokemon." });
}); else res.send(data);
else res.send(data);
}); });
}; };
exports.getDemandes = (req, res) => { exports.getDemandes = (req, res) => {
console.log("Is logged in: " + req.session.loggedIn); console.log("Is logged in: " + req.session.loggedIn);
if(req.session.loggedIn){ if (req.session.loggedIn) {
Partie.getDemandes(req.session.uid, (err, data) => { Partie.getDemandes(req.session.uid, (err, data) => {
if (err) { if (err) {
if (err.kind === "not_found") { if (err.kind === "not_found") {
res.send({res: true, body: data}); res.send({ res: true, body: data });
} else { } else {
res.status(500).send({ res.status(500).send({
message: "Error retrieving games with id " + req.session.uid message: "Error retrieving games with id " + req.session.uid
}); });
} }
} else{ } else {
res.send({res: true, body: data}); res.send({ res: true, body: data });
} }
}); });
} else{ } else {
res.send({res: false, body:'You must be logged in to see your games !'}); res.send({ res: false, body: 'You must be logged in to see your games !' });
res.end(); res.end();
} }
}; };
...@@ -75,4 +74,16 @@ exports.refuse = (req, res) => { ...@@ -75,4 +74,16 @@ exports.refuse = (req, res) => {
else res.send(data); else res.send(data);
}); });
} }
};
exports.eff = (req, res) => {
if (req.session.loggedIn) {
Partie.efficacite(req.body.typeNous, req.body.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 sql = require("./db.js");
\ No newline at end of file
const Combat = function(combat, joueur) {
this.pseudo = joueur.id_pokemon;
this.email = joueur.courant;
this.password = joueur.password;
};
\ No newline at end of file
...@@ -145,9 +145,20 @@ Partie.refuse = (id_partie, result) => { ...@@ -145,9 +145,20 @@ Partie.refuse = (id_partie, result) => {
} }
console.log("deleted game with id: ", id_partie); console.log("deleted game with id: ", id_partie);
result(null, {res: true, body: res}); result(null, { res: true, body: res });
}); });
}; };
Partie.efficacite = (typeNous, typeEux, result) => {
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; module.exports = Partie;
\ No newline at end of file
module.exports = app => { module.exports = app => {
const partie = require("../controllers/combat.controller.js"); const partie = require("../controllers/combat.controller.js");
//get type efficacité
app.get();
}; };
\ No newline at end of file
module.exports = app => { module.exports = app => {
const partie = require("../controllers/partie.controller.js"); const partie = require("../controllers/partie.controller.js");
// Add request for game // Add request for game
app.post("/addpartie", partie.create); app.post("/addpartie", partie.create);
...@@ -11,5 +11,6 @@ module.exports = app => { ...@@ -11,5 +11,6 @@ module.exports = app => {
app.post("/refusepartie", partie.refuse); app.post("/refusepartie", partie.refuse);
app.post("/getCombatTeam", partie.getCombatTeam); app.post("/getCombatTeam", partie.getCombatTeam);
app.post("/geteff", partie.eff);
}; };
\ No newline at end of file
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
</div> </div>
<div class="actions"> <div class="actions">
<button (click)="toggle()">Water Cannon</button> <button (click)="toggle()">Water Cannon</button>
<button onclick="calculeDmg()">Water Pulse</button> <button (click)="typeAdv()">Water Pulse</button>
<button onclick="surf()">Surf</button> <button onclick="surf()">Surf</button>
<button onclick="tackle()">Tackle</button> <button onclick="tackle()">Tackle</button>
</div> </div>
......
...@@ -13,13 +13,9 @@ export class BattleComponent implements OnInit { ...@@ -13,13 +13,9 @@ export class BattleComponent implements OnInit {
maxHealth = 100; maxHealth = 100;
curHealthSelf = 100; curHealthSelf = 100;
curHealthOpp = 100; curHealthOpp = 100;
damage = 0;
maTeam: any = [];
saTeam: any = [];
pseudo: string; pseudo: string;
uid: any; uid: any;
log: boolean; log: boolean;
dmg: Number;
level = 50; level = 50;
Power = 60; Power = 60;
atk = 100; atk = 100;
...@@ -39,33 +35,22 @@ export class BattleComponent implements OnInit { ...@@ -39,33 +35,22 @@ export class BattleComponent implements OnInit {
constructor(private route: ActivatedRoute, private httpClient: HttpClient) { } constructor(private route: ActivatedRoute, private httpClient: HttpClient) { }
teams(arg, id){
if(id == this.uid){
this.maTeam.push(arg)
} else {
this.saTeam.push(arg)
}
}
getCombatTeam(){ getCombatTeam(){
this.httpClient.post("http://localhost:3000/getCombatTeam", {id_partie: this.id_partie}, { responseType: 'json', withCredentials: true }).subscribe( this.httpClient.post("http://localhost:3000/getCombatTeam", {id_partie: this.id_partie}, { responseType: 'json', withCredentials: true }).subscribe(
(res) => {console.log(res)}); /////////// (res) => {console.log(res)}); ///////////
} }
typeAdv(chiffMoi, chiffToi){ typeAdv(){
if(chiffMoi == chiffToi){ this.httpClient.post("http://localhost:3000/geteff", { typeNous: this.typeMoi, typeEux: this.typeToi}, {responseType: 'json', withCredentials: true}).subscribe((res:any) => (this.calculeDmg(res.body[0].damage_factor)))
return 1
}
} }
calculeDmg(){ calculeDmg(eff){
var reduc = this.typeAdv(this.typeMoi, this.typeToi); let dmg = ((((0.4*this.level+2)*this.atk*this.Power)/(50*this.def))+2)*Math.random()*(eff/100)
this.dmg = ((((((2*this.level)/5)+2)*this.Power*(this.atk/this.def))/50)+2)*Math.random()*reduc console.log(dmg)
} }
ngOnInit(): void { 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.log = res.res;
this.pseudo = res.body; this.pseudo = res.body;
this.uid = res.uid; 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