fix-weaponstatsession-error

This commit is contained in:
ScrawnyRonnie 2025-06-17 14:16:54 -04:00
parent 42fb0d692d
commit 8f04b634c5

View file

@ -10,6 +10,8 @@ import net.psforever.types.Vector3
import net.psforever.util.Database.ctx import net.psforever.util.Database.ctx
import net.psforever.util.Database.ctx._ import net.psforever.util.Database.ctx._
import scala.concurrent.Future
object ToDatabase { object ToDatabase {
/** /**
* Insert an entry into the database's `killactivity` table. * Insert an entry into the database's `killactivity` table.
@ -101,22 +103,27 @@ object ToDatabase {
* insert a new entry into the table. * insert a new entry into the table.
* Shots fired. * Shots fired.
*/ */
def reportToolDischarge(avatarId: Long, stats: EquipmentStat): Unit = { def reportToolDischarge(avatarId: Long, stats: EquipmentStat): Future[Unit] = {
ctx.run(query[persistence.Weaponstatsession] import ctx._
.insert( import scala.concurrent.ExecutionContext.Implicits.global
_.avatarId -> lift(avatarId), ctx.transaction { implicit ec =>
_.weaponId -> lift(stats.objectId), ctx.run(
_.shotsFired -> lift(stats.shotsFired), query[persistence.Weaponstatsession]
_.shotsLanded -> lift(stats.shotsLanded), .insert(
_.kills -> lift(0), _.avatarId -> lift(avatarId),
_.assists -> lift(0), _.weaponId -> lift(stats.objectId),
_.sessionId -> lift(-1L) _.shotsFired -> lift(stats.shotsFired),
) _.shotsLanded -> lift(stats.shotsLanded),
.onConflictUpdate(_.avatarId, _.weaponId, _.sessionId)( _.kills -> lift(0),
(t, e) => t.shotsFired -> (t.shotsFired + e.shotsFired), _.assists -> lift(0),
(t, e) => t.shotsLanded -> (t.shotsLanded + e.shotsLanded) _.sessionId -> lift(-1L)
) )
) .onConflictUpdate(_.avatarId, _.weaponId, _.sessionId)(
(t, e) => t.shotsFired -> (t.shotsFired + e.shotsFired),
(t, e) => t.shotsLanded -> (t.shotsLanded + e.shotsLanded)
)
).map(_ => ())
}
} }
/** /**