Add score to session save data

pull/1/head
Flashfyre 10 months ago
parent 5214c4aff4
commit 71889f7daa

@ -63,6 +63,7 @@ type SessionSaveData struct {
Arena ArenaData `json:"arena"` Arena ArenaData `json:"arena"`
PokeballCounts PokeballCounts `json:"pokeballCounts"` PokeballCounts PokeballCounts `json:"pokeballCounts"`
Money int `json:"money"` Money int `json:"money"`
Score int `json:"score"`
WaveIndex int `json:"waveIndex"` WaveIndex int `json:"waveIndex"`
BattleType BattleType `json:"battleType"` BattleType BattleType `json:"battleType"`
Trainer TrainerData `json:"trainer"` Trainer TrainerData `json:"trainer"`
@ -92,6 +93,7 @@ type SessionHistoryData struct {
Party []PokemonData `json:"party"` Party []PokemonData `json:"party"`
Modifiers []PersistentModifierData `json:"modifiers"` Modifiers []PersistentModifierData `json:"modifiers"`
Money int `json:"money"` Money int `json:"money"`
Score int `json:"score"`
WaveIndex int `json:"waveIndex"` WaveIndex int `json:"waveIndex"`
BattleType BattleType `json:"battleType"` BattleType BattleType `json:"battleType"`
GameVersion string `json:"gameVersion"` GameVersion string `json:"gameVersion"`

@ -268,9 +268,10 @@ func (s *Server) HandleSavedataClear(w http.ResponseWriter, r *http.Request) {
return return
} }
session, err := GetSessionSaveData(uuid, slotId) var session SessionSaveData
err = json.NewDecoder(r.Body).Decode(&session)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, fmt.Sprintf("failed to decode request body: %s", err), http.StatusBadRequest)
return return
} }
@ -278,9 +279,9 @@ func (s *Server) HandleSavedataClear(w http.ResponseWriter, r *http.Request) {
newCompletion := false newCompletion := false
if sessionCompleted { if sessionCompleted {
newCompletion, err = db.TryAddSeedCompletion(uuid, session.Seed, int(session.GameMode)) newCompletion, err = db.TryAddSeedCompletion(uuid, session.Seed, int(session.GameMode), session.Score)
if err != nil { if err != nil {
log.Print("failed to mark seed as completed") log.Printf("failed to mark seed as completed: %s", err.Error())
} }
} }

@ -1,24 +1,26 @@
package db package db
func TryAddSeedCompletion(uuid []byte, seed string, mode int) (bool, error) { func TryAddSeedCompletion(uuid []byte, seed string, mode int, score int) (bool, error) {
if len(seed) < 24 { if len(seed) < 24 {
for range 24 - len(seed) { for range 24 - len(seed) {
seed += "0" seed += "0"
} }
} }
newCompletion := true
var count int var count int
err := handle.QueryRow("SELECT COUNT(*) FROM seedCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count) err := handle.QueryRow("SELECT COUNT(*) FROM seedCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
if err != nil { if err != nil {
return false, err return false, err
} else if count > 0 { } else if count > 0 {
return false, nil newCompletion = false
} }
_, err = handle.Exec("INSERT INTO seedCompletions (uuid, seed, mode, timestamp) VALUES (?, ?, ?, UTC_TIMESTAMP())", uuid, seed, mode) _, err = handle.Exec("INSERT INTO seedCompletions (uuid, seed, mode, score, timestamp) VALUES (?, ?, ?, ?, UTC_TIMESTAMP()) ON DUPLICATE KEY UPDATE score = ?, timestamp = IF(score < ?, UTC_TIMESTAMP(), timestamp)", uuid, seed, mode, score, score, score)
if err != nil { if err != nil {
return false, err return false, err
} }
return true, nil return newCompletion, nil
} }

Loading…
Cancel
Save