Skip to content

Commit

Permalink
Merge pull request #2122 from GiganticMinecraft/fix/gachaSaveAll
Browse files Browse the repository at this point in the history
ガチャのアイテム設定系不具合の修正
  • Loading branch information
Lucky3028 authored Jun 29, 2023
2 parents b83a9c6 + 8ea9c60 commit ea693a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class GachaCommand[
.beginConfiguration()
.execution { _ =>
val eff = for {
gachaPrizes <- gachaPrizeAPI.listOfNow
gachaPrizes <- gachaPrizeAPI.allGachaPrizeList
_ <- gachaPrizeAPI.replace(gachaPrizes)
} yield MessageEffect("ガチャデータをmysqlに保存しました。")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ object System {
) +: prizes
}
newGachaPrizes <- allGachaPrizesListReference.get
_ <- _gachaPersistence.addGachaPrize(newGachaPrizes.head)
_ <- _gachaPersistence
.addMineStackGachaObject(
newGachaPrizes.head.id,
Expand All @@ -114,7 +115,7 @@ object System {
} yield {
createdEvents.find(_.isHolding) match {
case Some(value) =>
prizes.filter(_.gachaEventName.contains(value.eventName))
prizes.filter(_.gachaEventName.contains(value.eventName)) :+ expBottle
case None =>
prizes.filter(_.gachaEventName.isEmpty)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ trait GachaPrizeListPersistence[F[_], ItemStack] {
*/
def list: F[Vector[GachaPrize[ItemStack]]]

/**
* @return ガチャアイテムを追加する作用
*/
def addGachaPrize(gachaPrize: GachaPrize[ItemStack]): F[Unit]

/**
* @return ガチャリストを更新する作用
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ class JdbcGachaPrizeListPersistence[F[_]: Sync, ItemStack: Cloneable](
}
}

override def addGachaPrize(gachaPrize: GachaPrize[ItemStack]): F[Unit] = Sync[F].delay {
DB.localTx { implicit session =>
val eventId = gachaPrize.gachaEventName.flatMap { eventName =>
sql"SELECT id FROM gacha_events WHERE event_name = ${eventName.name}"
.map(_.int("id"))
.single()
.apply()
}

sql"INSERT INTO gachadata VALUES (${gachaPrize.id.id}, ${gachaPrize.probability.value}, ${serializeAndDeserialize
.serialize(gachaPrize.itemStack)}, $eventId)".execute().apply()
}
}

override def set(gachaPrizesList: Vector[GachaPrize[ItemStack]]): F[Unit] = {
Sync[F].delay {
DB.localTx { implicit session =>
Expand Down

0 comments on commit ea693a8

Please sign in to comment.