diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/gacha/bukkit/GachaCommand.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/gacha/bukkit/GachaCommand.scala index d5f3180580..77f3b17c5b 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/gacha/bukkit/GachaCommand.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/gacha/bukkit/GachaCommand.scala @@ -379,7 +379,7 @@ class GachaCommand[ .beginConfiguration() .execution { _ => val eff = for { - gachaPrizes <- gachaPrizeAPI.listOfNow + gachaPrizes <- gachaPrizeAPI.allGachaPrizeList _ <- gachaPrizeAPI.replace(gachaPrizes) } yield MessageEffect("ガチャデータをmysqlに保存しました。") diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/System.scala index c8998691f2..d55099b213 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/System.scala @@ -100,6 +100,7 @@ object System { ) +: prizes } newGachaPrizes <- allGachaPrizesListReference.get + _ <- _gachaPersistence.addGachaPrize(newGachaPrizes.head) _ <- _gachaPersistence .addMineStackGachaObject( newGachaPrizes.head.id, @@ -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) } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/domain/GachaPrizeListPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/domain/GachaPrizeListPersistence.scala index ed92b13e6f..e74e0f0653 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/domain/GachaPrizeListPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/domain/GachaPrizeListPersistence.scala @@ -12,6 +12,11 @@ trait GachaPrizeListPersistence[F[_], ItemStack] { */ def list: F[Vector[GachaPrize[ItemStack]]] + /** + * @return ガチャアイテムを追加する作用 + */ + def addGachaPrize(gachaPrize: GachaPrize[ItemStack]): F[Unit] + /** * @return ガチャリストを更新する作用 */ diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/infrastructure/JdbcGachaPrizeListPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/infrastructure/JdbcGachaPrizeListPersistence.scala index 2c842c86cd..5dc90cc445 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/infrastructure/JdbcGachaPrizeListPersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/gachaprize/infrastructure/JdbcGachaPrizeListPersistence.scala @@ -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 =>