Add score to session save data

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

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

@ -268,9 +268,10 @@ func (s *Server) HandleSavedataClear(w http.ResponseWriter, r *http.Request) {
return
}
session, err := GetSessionSaveData(uuid, slotId)
var session SessionSaveData
err = json.NewDecoder(r.Body).Decode(&session)
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
}
@ -278,9 +279,9 @@ func (s *Server) HandleSavedataClear(w http.ResponseWriter, r *http.Request) {
newCompletion := false
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 {
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
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 {
for range 24 - len(seed) {
seed += "0"
}
}
newCompletion := true
var count int
err := handle.QueryRow("SELECT COUNT(*) FROM seedCompletions WHERE uuid = ? AND seed = ?", uuid, seed).Scan(&count)
if err != nil {
return false, err
} 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 {
return false, err
}
return true, nil
return newCompletion, nil
}

Loading…
Cancel
Save