Commit 3f45b4ef authored by Manish Kumar's avatar Manish Kumar
Browse files

update pokemon state

parent 6df214e5
......@@ -64,6 +64,19 @@ exports.getCombatTeam = (req, res) => {
}
};
exports.updatePartie = (req, res) => {
console.log(req.body);
if (req.session.loggedIn) {
Partie.updatePartie(req.body.id_etat, req.body.active, req.body.stats, req.body.moves, (err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while updating pokemon state."
});
else res.send(data);
});
}
};
exports.refuse = (req, res) => {
if (req.session.loggedIn) {
Partie.refuse(req.body.id_partie, (err, data) => {
......
......@@ -112,7 +112,7 @@ Partie.accept = (id_partie, result) => {
};
Partie.getCombatTeam = (id_partie, id_joueur, result) => {
sql.query("SELECT DISTINCT p.id_pokemon, p.pokeName, ep.active, typePoke.id_type, typePoke.nomType as typeNom, gs.id, gs.identifier as statName, es.stat_value, es.effort, s.stat_id as baseStat_id, gsBase.identifier as baseStatName, s.base_stat, m.id_move, m.identifier, m.power, m.accuracy, typeMove.id_type as m_id_type, typeMove.nomType, em.pp FROM etatPoke as ep, etatStats as es, etatMove as em, team as t, joueur as j, pokemon as p, move as m, genState as gs, type as typePoke, type as typeMove, pokemon_type as pty, stats as s, genState as gsBase WHERE ep.id_partie=? AND ep.id_team=t.id_team AND t.id_joueur=? AND ep.id_etat=es.id_etat AND ep.id_etat=em.id_etat AND t.id_pokemon=p.id_pokemon AND m.id_move=em.id_move AND gs.id=es.stat_id AND p.id_pokemon=pty.pokemon_id AND pty.type_id=typePoke.id_type AND m.type_id=typeMove.id_type AND p.id_pokemon=s.pokemon_id AND gsBase.id=s.stat_id ORDER BY p.id_pokemon", [id_partie, id_joueur], (err, res) => {
sql.query("SELECT DISTINCT p.id_pokemon, p.pokeName, ep.id_etat, ep.active, typePoke.id_type, typePoke.nomType as typeNom, gs.id, gs.identifier as statName, es.stat_value, es.effort, s.stat_id as baseStat_id, gsBase.identifier as baseStatName, s.base_stat, m.id_move, m.identifier, m.power, m.accuracy, typeMove.id_type as m_id_type, typeMove.nomType, em.pp, dc.id_dmg_classe, dc.identifier as dmg_classe FROM etatPoke as ep, etatStats as es, etatMove as em, team as t, joueur as j, pokemon as p, move as m, genState as gs, type as typePoke, type as typeMove, pokemon_type as pty, stats as s, genState as gsBase, damage_classe as dc WHERE ep.id_partie=? AND ep.id_team=t.id_team AND t.id_joueur=? AND ep.id_etat=es.id_etat AND ep.id_etat=em.id_etat AND t.id_pokemon=p.id_pokemon AND m.id_move=em.id_move AND gs.id=es.stat_id AND p.id_pokemon=pty.pokemon_id AND pty.type_id=typePoke.id_type AND m.type_id=typeMove.id_type AND p.id_pokemon=s.pokemon_id AND gsBase.id=s.stat_id AND m.damage_class_id=dc.id_dmg_classe ORDER BY p.id_pokemon, gs.id, s.stat_id", [id_partie, id_joueur], (err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
......@@ -130,6 +130,56 @@ Partie.getCombatTeam = (id_partie, id_joueur, result) => {
});
}
Partie.updatePartie = (id_etat, active, stats, moves, result) => {
sql.beginTransaction(function(errTransaction) {
if (errTransaction) { throw err; }
sql.query('UPDATE etatPoke SET active=? WHERE id_etat=?', [active, id_etat], function(err, res) {
if (err) {
console.log("error: ", err);
sql.rollback(function() {
throw err;
});
result(err, null);
return;
}
var sqlStats = [];
stats.forEach(stat => {
sqlStats.push(id_etat, stat.id, stat.stat_value);
});
sql.query('INSERT INTO etatStats (id_etat, stat_id, stat_value, effort) VALUES (?, ?, ?, 0), (?, ?, ?, 0), (?, ?, ?, 0), (?, ?, ?, 0), (?, ?, ?, 0), (?, ?, ?, 0) ON DUPLICATE KEY UPDATE id_etat=VALUES(id_etat), stat_id=VALUES(stat_id), stat_value=VALUES(stat_value), effort=VALUES(effort);', sqlStats, function(err, res) {
if (err) {
console.log("error: ", err);
sql.rollback(function() {
throw err;
});
result(err, null);
return;
}
var sqlMoves = [];
moves.forEach(move => {
sqlMoves.push(id_etat, move.id_move, move.pp);
});
sql.query('INSERT INTO etatMove (id_etat, id_move, pp) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?), (?, ?, ?) ON DUPLICATE KEY UPDATE id_etat=VALUES(id_etat), id_move=VALUES(id_move), pp=VALUES(pp);', sqlMoves, function(err, res) {
if (err) {
console.log("error: ", err);
sql.rollback(function() {
throw err;
});
result(err, null);
return;
}
});
});
result(null, { res: true, id: res.insertId });
});
});
}
Partie.refuse = (id_partie, result) => {
sql.query("DELETE FROM partie WHERE id_partie=?", [id_partie], (err, res) => {
if (err) {
......
......@@ -11,6 +11,9 @@ module.exports = app => {
app.post("/refusepartie", partie.refuse);
app.post("/getCombatTeam", partie.getCombatTeam);
app.post("/geteff", partie.eff);
app.post("/updatepartie", partie.updatePartie);
};
\ No newline at end of file
......@@ -37,7 +37,7 @@
50
</span>
</div>
<div id="apHP" class="hp-count">{{affichageHp}}</div>
<div id="apHP" class="hp-count">{{curHealthSelf}}</div>
</div>
<div class="health-box">
<div class="health-bar-red" [style.width.%]="affichageHp"></div>
......@@ -56,7 +56,7 @@
What should {{curPoke.pokeName}} do?
</div>
<div class="actions">
<button (click)="typeAdv(move.m_id_type)" *ngFor="let move of curPoke.moves">{{move.identifier}}</button>
<button (click)="typeAdv(move)" *ngFor="let move of curPoke.moves">{{move.identifier}}</button>
</div>
<div class="continue">
</div>
......
......@@ -66,8 +66,12 @@ export class BattleComponent implements OnInit {
(res) => {this.selfTeam = res; this.getPokemon(), console.log(res)});
}
typeAdv(type){
this.httpClient.post("http://localhost:3000/geteff", { typeNous: type, typeEux: this.typeToi}, {responseType: 'json', withCredentials: true}).subscribe((res:any) => (this.calculeDmg(res.body[0].damage_factor)))
typeAdv(move){
this.httpClient.post("http://localhost:3000/geteff", { typeNous: move.m_id_type, typeEux: this.typeToi}, {responseType: 'json', withCredentials: true}).subscribe((res:any) => {this.calculeDmg(res.body[0].damage_factor); move.pp--; console.log(this.curPoke.moves); this.updateDBPokemon()});
}
updateDBPokemon(){
this.httpClient.post("http://localhost:3000/updatepartie", this.curPoke, {responseType: 'json', withCredentials: true}).subscribe((res:any) => (console.log(res)));
}
calculeDmg(eff){
......
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