From 9592bcda28a458a6cb00ba7e78f1d7878fc4ae17 Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Fri, 1 Aug 2014 18:15:17 -0400 Subject: [PATCH] Fixed logic error causing numbering gaps and odd trainer ordering in battle tower. --- library/Data/DataMysql.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/Data/DataMysql.cs b/library/Data/DataMysql.cs index c5d87b7d..e80028bc 100644 --- a/library/Data/DataMysql.cs +++ b/library/Data/DataMysql.cs @@ -459,6 +459,18 @@ namespace PkmnFoundations.Data new MySqlParameter("@rank", record.Rank), new MySqlParameter("@position", position)); + object lastPosition = tran.ExecuteScalar("SELECT MAX(Position) " + + "FROM GtsBattleTower4 WHERE RoomNum = @room AND Rank = @rank", + new MySqlParameter("@room", record.RoomNum), + new MySqlParameter("@rank", record.Rank)); + + // If the room has fewer than 7 trainers, insert this one at the + // end but don't leave any gaps in the numbering. + if (lastPosition is DBNull) + position = 0; + else + position = Math.Min(position, (uint)lastPosition + 1); + // Update the actual record if (pkey != 0) {