correção do bug do inventario '-'
This commit is contained in:
Binary file not shown.
@@ -460,6 +460,36 @@ func player_updateInputs(c echo.Context) error {
|
||||
}
|
||||
|
||||
if inv != "" {
|
||||
row, err := db.Query(fmt.Sprintf("SELECT id, item_peso FROM inv_%s ORDER BY id DESC;", userSession["playerName"]))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Println("Erro ao consultar inventario do inventario.")
|
||||
return c.JSON(http.StatusInternalServerError, resp_json{
|
||||
Status: "Error",
|
||||
Message: "Erro ao consultar inventario do inventario.",
|
||||
})
|
||||
}
|
||||
var peso_total int = 0
|
||||
|
||||
for row.Next() {
|
||||
var id int
|
||||
var peso int
|
||||
if err := row.Scan(&id, &peso); err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, resp_json{
|
||||
Status: "Error",
|
||||
Message: "algo deu errado ao inventario",
|
||||
})
|
||||
}
|
||||
peso_total = peso_total + peso
|
||||
}
|
||||
valorInv, _ := strconv.Atoi(inv)
|
||||
if peso_total > valorInv {
|
||||
return c.JSON(http.StatusUnauthorized, resp_json{
|
||||
Status: "Error",
|
||||
Message: "você não pode ter um inventario com menos capacidade do que esta carregando.",
|
||||
})
|
||||
}
|
||||
|
||||
_, err = db.Exec("UPDATE players SET inventario=? WHERE id=?;", inv, userSession["user_id"])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user