From 1fc70ab8b2b54ba8a04500d9bdff71714e3c6192 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 15 Sep 2024 15:42:31 +0900 Subject: [PATCH 01/26] =?UTF-8?q?feat:=20=E3=83=91=E3=83=83=E3=82=B7?= =?UTF-8?q?=E3=83=96=E3=82=B9=E3=82=AD=E3=83=AB=E3=83=A1=E3=83=8B=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E3=83=9E=E3=83=8A=E3=81=8C=E7=84=A1=E3=81=8F?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=9F=E3=82=89=E6=8E=98=E3=82=8C=E3=81=AA?= =?UTF-8?q?=E3=81=8F=E3=81=99=E3=82=8B=E3=82=B9=E3=82=AD=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E3=83=88=E3=82=B0=E3=83=AB=E3=83=9C=E3=82=BF=E3=83=B3=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menus/skill/PassiveSkillMenu.scala | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala index 9def38cd0f..a463c0a50e 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala @@ -62,6 +62,7 @@ object PassiveSkillMenu extends Menu { val dynamicPartComputation = List( ChestSlotRef(0, 0) -> computeToggleMultipleBlockTypeDestructionButton, ChestSlotRef(0, 1) -> computeToggleChestBreakButton, + ChestSlotRef(0, 2) -> computeToggleManaFullyConsumedBreakStopButton, ChestSlotRef(1, 0) -> computeGiganticBerserkButton, ChestSlotRef(1, 1) -> computeToggleNetherQuartzBlockButton ).traverse(_.sequence) @@ -231,6 +232,49 @@ object PassiveSkillMenu extends Menu { ) }) + val computeToggleManaFullyConsumedBreakStopButton: IO[Button] = RecomputedButton(for { + originalBreakStopConfig <- breakSkillTriggerConfigAPI + .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + } yield { + val baseLore = List(s"${YELLOW}マナ切れでブロック破壊を止めるスキル") + val statusLore = if (originalBreakStopConfig) { + List(s"${GREEN}ON (マナが切れるとブロック破壊を止めます。)", s"${DARK_RED}クリックでOFF") + } else { + List(s"${RED}OFF (マナが切れてもブロック破壊を続けます。)", s"${DARK_GREEN}クリックでON") + } + + Button( + new IconItemStackBuilder(Material.LAPIS_LAZULI) + .tap { builder => + if (originalBreakStopConfig) + builder.enchanted() + } + .title(s"$WHITE$UNDERLINE${BOLD}マナ切れでブロック破壊を止めるスキル切り替え") + .lore(baseLore ++ statusLore) + .build(), + LeftClickButtonEffect { + SequentialEffect( + breakSkillTriggerConfigAPI.toggleBreakSkillTriggerConfig( + BreakSkillTriggerConfigKey.ManaFullyConsumed + ), + DeferredEffect(IO { + if (!originalBreakStopConfig) { + SequentialEffect( + MessageEffect(s"${GREEN}マナが切れたらブロック破壊を止めるスキルを有効化しました。"), + FocusedSoundEffect(Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1f, 1f) + ) + } else { + SequentialEffect( + MessageEffect(s"${RED}マナが切れたらブロック破壊を止めるスキルを無効化しました。"), + FocusedSoundEffect(Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1f, 0.5f) + ) + } + }) + ) + } + ) + }) + val computeGiganticBerserkButton: IO[Button] = RecomputedButton { environment .breakCountApi From 09a17d6a21f6ee0a5161a30bc5f58f98d363084d Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 15 Sep 2024 15:43:10 +0900 Subject: [PATCH 02/26] =?UTF-8?q?feat:=20=E3=83=9E=E3=83=8A=E3=82=92?= =?UTF-8?q?=E6=B6=88=E8=B2=BB=E3=81=97=E3=81=8D=E3=81=A3=E3=81=9F=E9=9A=9B?= =?UTF-8?q?=E3=81=AE=E5=88=86=E5=B2=90=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seichiassist/listener/PlayerBlockBreakListener.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index ebc784fff2..85ff76009c 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -181,7 +181,14 @@ class PlayerBlockBreakListener( .tryAcquire(manaToConsumeOnThisChunk) .unsafeRunSync() match { case Some(value) => reservedMana.addOne(value) - case None => b.break() + case None => + // マナを消費しきっていたら処理を終了する + if (BreakUtil.isBreakBlockManaFullyConsumed(player)) + { + event.setCancelled(true) + return + } + b.break() } // 減る耐久値の計算(溶岩及び水を破壊するとブロック10個分の耐久値減少判定を行う) From 924113e43cc7f2311cc8c14a185dcc3d10544e15 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 15 Sep 2024 15:43:55 +0900 Subject: [PATCH 03/26] =?UTF-8?q?chore:=20V1.19.0=20=E3=83=96=E3=83=AD?= =?UTF-8?q?=E3=83=83=E3=82=AF=E7=A0=B4=E5=A3=8A=E3=81=AE=E6=8A=91=E5=88=B6?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=82=AC=E3=83=BC=E8=A8=AD=E5=AE=9A=E3=82=92?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E3=81=99=E3=82=8B=E3=83=9E=E3=82=A4=E3=82=B0?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1.19.0__Create_break_trigger_preference_table.sql | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql diff --git a/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql b/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql new file mode 100644 index 0000000000..9ef12523e0 --- /dev/null +++ b/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql @@ -0,0 +1,9 @@ +USE seichiassist; + +CREATE TABLE player_break_trigger_preference( + uuid CHAR(36) NOT NULL, + trigger_category ENUM('ManaFullyConsumed') NOT NULL, + do_not_break BOOL NOT NULL DEFAULT FALSE, + PRIMARY KEY(uuid, trigger_category), + INDEX index_player_break_trigger_preference_on_uuid (uuid) +); From 9f45f4234a6761b3512b75874ca5c2cf0da543d3 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 15 Sep 2024 15:45:02 +0900 Subject: [PATCH 04/26] =?UTF-8?q?feat:=20breakskilltriggerconfig=E3=82=B5?= =?UTF-8?q?=E3=83=96=E3=82=B7=E3=82=B9=E3=83=86=E3=83=A0=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=20`breakskilltargetconfig`=E3=81=A7=E6=89=B1=E3=81=88?= =?UTF-8?q?=E3=81=AA=E3=81=84=E4=BA=8B=E6=9F=84=E3=82=92=E6=89=B1=E3=81=86?= =?UTF-8?q?=E7=82=BA=E3=81=AE=E3=82=B5=E3=83=96=E3=82=B7=E3=82=B9=E3=83=86?= =?UTF-8?q?=E3=83=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unchama/seichiassist/SeichiAssist.scala | 7 ++ .../seichiassist/menus/TopLevelRouter.scala | 2 + .../menus/skill/PassiveSkillMenu.scala | 3 + .../BreakSkillTriggerConfigAPI.scala | 28 ++++++++ .../breakskilltriggerconfig/System.scala | 66 +++++++++++++++++++ ...illTriggerConfigRepositoryDefinition.scala | 23 +++++++ .../domain/BreakSkillTriggerConfig.scala | 28 ++++++++ .../domain/BreakSkillTriggerConfigKey.scala | 21 ++++++ .../BreakSkillTriggerConfigPersistence.scala | 7 ++ ...bcBreakSkillTriggerConfigPersistence.scala | 52 +++++++++++++++ 10 files changed, 237 insertions(+) create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala index f7359a6b8b..6840a95ae9 100644 --- a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala +++ b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala @@ -63,6 +63,7 @@ import com.github.unchama.seichiassist.subsystems.autosave.application.SystemCon import com.github.unchama.seichiassist.subsystems.breakcount.{BreakCountAPI, BreakCountReadAPI} import com.github.unchama.seichiassist.subsystems.breakcountbar.BreakCountBarAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI import com.github.unchama.seichiassist.subsystems.buildcount.BuildCountAPI import com.github.unchama.seichiassist.subsystems.discordnotification.DiscordNotificationAPI import com.github.unchama.seichiassist.subsystems.donate.DonatePremiumPointAPI @@ -495,6 +496,9 @@ class SeichiAssist extends JavaPlugin() { lazy val breakSkillTargetConfigSystem: subsystems.breakskilltargetconfig.System[IO, Player] = subsystems.breakskilltargetconfig.System.wired[IO, SyncIO].unsafeRunSync() + lazy val breakSkillTriggerConfigSystem: subsystems.breakskilltriggerconfig.System[IO, Player] = + subsystems.breakskilltriggerconfig.System.wired[IO, SyncIO].unsafeRunSync() + /* TODO: mineStackSystemは本来privateであるべきだが、mineStackにアイテムを格納するAPIが現状の BreakUtilの実装から呼び出されている都合上やむを得ずpublicになっている。*/ lazy val mineStackSystem: subsystems.minestack.System[IO, Player, ItemStack] = @@ -562,6 +566,7 @@ class SeichiAssist extends JavaPlugin() { openirontrapdoor.System.wired, gridRegionSystem, breakSkillTargetConfigSystem, + breakSkillTriggerConfigSystem, joinAndQuitMessenger, elevatorSystem, blockLiquidStreamSystem, @@ -746,6 +751,8 @@ class SeichiAssist extends JavaPlugin() { implicit val gridRegionAPI: GridRegionAPI[IO, Player, Location] = gridRegionSystem.api implicit val breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player] = breakSkillTargetConfigSystem.api + implicit val breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player] = + breakSkillTriggerConfigSystem.api implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] = playerHeadSkinSystem.api val menuRouter = TopLevelRouter.apply diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala b/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala index c7b44baa6c..7856db1575 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala @@ -31,6 +31,7 @@ import com.github.unchama.seichiassist.subsystems.breakcount.BreakCountAPI import com.github.unchama.seichiassist.subsystems.breakcount.domain.SeichiAmountData import com.github.unchama.seichiassist.subsystems.breakcountbar.BreakCountBarAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI import com.github.unchama.seichiassist.subsystems.buildcount.domain.playerdata.BuildAmountData import com.github.unchama.seichiassist.subsystems.discordnotification.DiscordNotificationAPI import com.github.unchama.seichiassist.subsystems.donate.DonatePremiumPointAPI @@ -104,6 +105,7 @@ object TopLevelRouter { fairySpeechAPI: FairySpeechAPI[IO, Player], gridRegionAPI: GridRegionAPI[IO, Player, Location], breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player], + breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player], playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] ): TopLevelRouter[IO] = new TopLevelRouter[IO] { import assortedRankingApi._ diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala index a463c0a50e..2bdb75b292 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala @@ -13,6 +13,8 @@ import com.github.unchama.seichiassist.menus.stickmenu.FirstPage import com.github.unchama.seichiassist.subsystems.breakcount.BreakCountAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.BreakSkillTargetConfigKey +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey import com.github.unchama.seichiassist.subsystems.playerheadskin.PlayerHeadSkinAPI import com.github.unchama.targetedeffect._ import com.github.unchama.targetedeffect.commandsender.MessageEffect @@ -34,6 +36,7 @@ object PassiveSkillMenu extends Menu { class Environment( implicit val breakCountApi: BreakCountAPI[IO, SyncIO, Player], implicit val breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player], + implicit val breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player], val ioCanOpenFirstPage: IO CanOpen FirstPage.type, implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] ) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala new file mode 100644 index 0000000000..1df97cf935 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala @@ -0,0 +1,28 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig + +import cats.data.Kleisli +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey + +trait BreakSkillTriggerConfigAPI[F[_], Player] { + + /** + * @return 破壊トリガをトグルする作用 + */ + def toggleBreakSkillTriggerConfig( + configKey: BreakSkillTriggerConfigKey + ): Kleisli[F, Player, Unit] + + /** + * @return 現在の破壊トリガを取得する作用 + */ + def breakSkillTriggerConfig(player: Player, configKey: BreakSkillTriggerConfigKey): F[Boolean] + +} + +object BreakSkillTriggerConfigAPI { + + def apply[F[_], Player]( + implicit ev: BreakSkillTriggerConfigAPI[F, Player] + ): BreakSkillTriggerConfigAPI[F, Player] = ev + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala new file mode 100644 index 0000000000..4b13276b9c --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala @@ -0,0 +1,66 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig + +import cats.data.Kleisli +import cats.effect.SyncEffect +import com.github.unchama.datarepository.bukkit.player.BukkitRepositoryControls +import com.github.unchama.generic.ContextCoercion +import com.github.unchama.seichiassist.meta.subsystem.Subsystem +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.repository.BreakSkillTriggerConfigRepositoryDefinition +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ + BreakSkillTriggerConfigKey, + BreakSkillTriggerConfigPersistence +} +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.persistence.JdbcBreakSkillTriggerConfigPersistence +import org.bukkit.entity.Player + +trait System[F[_], Player] extends Subsystem[F] { + val api: BreakSkillTriggerConfigAPI[F, Player] +} + +object System { + + import cats.implicits._ + + def wired[F[_], G[_]: SyncEffect: ContextCoercion[*[_], F]]: G[System[F, Player]] = { + implicit val breakSkillTriggerConfigPersistence: BreakSkillTriggerConfigPersistence[G] = + new JdbcBreakSkillTriggerConfigPersistence[G] + + for { + breakSkillTriggerConfigRepositoryControls <- BukkitRepositoryControls.createHandles( + BreakSkillTriggerConfigRepositoryDefinition.withContext[G, Player] + ) + } yield { + val breakSkillTriggerConfigRepository = breakSkillTriggerConfigRepositoryControls.repository + + new System[F, Player] { + override val api: BreakSkillTriggerConfigAPI[F, Player] = + new BreakSkillTriggerConfigAPI[F, Player] { + override def toggleBreakSkillTriggerConfig( + configKey: BreakSkillTriggerConfigKey + ): Kleisli[F, Player, Unit] = + Kleisli { player => + ContextCoercion( + breakSkillTriggerConfigRepository(player) + .update(_.toggleBreakSkillTriggerConfig(configKey)) + ) + } + + override def breakSkillTriggerConfig( + player: Player, + configKey: BreakSkillTriggerConfigKey + ): F[Boolean] = + ContextCoercion( + breakSkillTriggerConfigRepository(player) + .get + .map(_.breakSkillTriggerConfig(configKey)) + ) + } + + override val managedRepositoryControls: Seq[BukkitRepositoryControls[F, _]] = Seq( + breakSkillTriggerConfigRepositoryControls.coerceFinalizationContextTo[F] + ) + } + } + } + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala new file mode 100644 index 0000000000..89339ce26d --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala @@ -0,0 +1,23 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.repository + +import cats.effect.Sync +import cats.effect.concurrent.Ref +import com.github.unchama.datarepository.definitions.RefDictBackedRepositoryDefinition +import com.github.unchama.datarepository.template.RepositoryDefinition +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ + BreakSkillTriggerConfig, + BreakSkillTriggerConfigPersistence +} + +object BreakSkillTriggerConfigRepositoryDefinition { + + def withContext[F[_]: Sync, Player]( + implicit persistence: BreakSkillTriggerConfigPersistence[F] + ): RepositoryDefinition[F, Player, Ref[F, BreakSkillTriggerConfig]] = + RefDictBackedRepositoryDefinition + .usingUuidRefDict[F, Player, BreakSkillTriggerConfig](persistence)( + BreakSkillTriggerConfig.initial + ) + .toRefRepository + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala new file mode 100644 index 0000000000..8111bc8286 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala @@ -0,0 +1,28 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain + +case class BreakSkillTriggerConfig(config: Map[BreakSkillTriggerConfigKey, Boolean]) { + + /** + * @return `configKey`の破壊トリガをトグルする + */ + def toggleBreakSkillTriggerConfig( + configKey: BreakSkillTriggerConfigKey + ): BreakSkillTriggerConfig = + this.copy(this.config + (configKey -> !this.config.getOrElse(configKey, false))) + + /** + * @return 現在の破壊トリガを取得する + */ + def breakSkillTriggerConfig(configKey: BreakSkillTriggerConfigKey): Boolean = + this.config.getOrElse(configKey, false) + +} + +object BreakSkillTriggerConfig { + + /** + * [[BreakSkillTriggerConfig]]の初期値 + */ + val initial: BreakSkillTriggerConfig = BreakSkillTriggerConfig(Map.empty) + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala new file mode 100644 index 0000000000..293979b2d0 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala @@ -0,0 +1,21 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain + +import enumeratum.{Enum, EnumEntry} + +/** + * トリガ条件の集合を表現する。 + * これらの値は整地スキルでブロックを破壊する際に、 + * プレイヤーの設定に応じて使われる。 + */ +sealed trait BreakSkillTriggerConfigKey extends EnumEntry + +object BreakSkillTriggerConfigKey extends Enum[BreakSkillTriggerConfigKey] { + + val values: IndexedSeq[BreakSkillTriggerConfigKey] = findValues + + /** + * マナを消費しきった場合にブロックを破壊するかどうか + */ + case object ManaFullyConsumed extends BreakSkillTriggerConfigKey + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala new file mode 100644 index 0000000000..938ba6b70f --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala @@ -0,0 +1,7 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain + +import com.github.unchama.generic.RefDict + +import java.util.UUID + +trait BreakSkillTriggerConfigPersistence[F[_]] extends RefDict[F, UUID, BreakSkillTriggerConfig] diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala new file mode 100644 index 0000000000..1b656ca440 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala @@ -0,0 +1,52 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.persistence + +import cats.effect.Sync +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ + BreakSkillTriggerConfig, + BreakSkillTriggerConfigKey, + BreakSkillTriggerConfigPersistence +} +import scalikejdbc.{DB, scalikejdbcSQLInterpolationImplicitDef} + +import java.util.UUID + +class JdbcBreakSkillTriggerConfigPersistence[F[_]: Sync] + extends BreakSkillTriggerConfigPersistence[F] { + + override def read(key: UUID): F[Option[BreakSkillTriggerConfig]] = Sync[F].delay { + val config = DB.readOnly { implicit session => + sql"SELECT trigger_category, do_not_break FROM player_break_trigger_preference WHERE uuid = ${key.toString}" + .map { rs => + BreakSkillTriggerConfigKey.withNameOption(rs.string("trigger_category")).map { + flagName => flagName -> rs.boolean("do_not_break") + } + } + .toList() + .flatten + .toMap + } + + Some(BreakSkillTriggerConfig(config)) + } + + override def write(key: UUID, value: BreakSkillTriggerConfig): F[Unit] = Sync[F].delay { + DB.localTx { implicit session => + val uuid = key.toString + val batchParams = + value + .config + .map { + case (triggerCategory, doNotBreak) => + Seq(uuid, triggerCategory.entryName, doNotBreak) + } + .toSeq + + sql"""INSERT INTO player_break_trigger_preference (uuid, trigger_category, do_not_break) + | VALUES (?, ?, ?) + | ON DUPLICATE KEY UPDATE + | do_not_break = VALUE(do_not_break) + """.stripMargin.batch(batchParams: _*).apply[List]() + } + } + +} From e7c7cd31c4c44e4d8882335e8fc65db51f94ff1d Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 15 Sep 2024 15:45:58 +0900 Subject: [PATCH 05/26] =?UTF-8?q?feat:=20=E3=83=96=E3=83=AD=E3=83=83?= =?UTF-8?q?=E3=82=AF=E7=A0=B4=E5=A3=8A=E6=99=82=E3=80=81=E3=80=8C=E3=83=9E?= =?UTF-8?q?=E3=83=8A=E5=88=87=E3=82=8C=E3=80=8D=E3=81=8B=E3=81=A9=E3=81=86?= =?UTF-8?q?=E3=81=8B=E5=88=A4=E5=AE=9A=E3=81=99=E3=82=8B=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unchama/seichiassist/util/BreakUtil.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala index 29edc3a824..7ce6fe6cbc 100644 --- a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala +++ b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala @@ -16,6 +16,7 @@ import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.{Active, import com.github.unchama.seichiassist.subsystems.breakcount.domain.CardinalDirection import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.SeichiExpAmount import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.BreakSkillTargetConfigKey +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey import com.github.unchama.targetedeffect.player.ActionBarMessageEffect import com.github.unchama.util.bukkit.ItemStackUtil import com.github.unchama.util.external.{ExternalPlugins, WorldGuardWrapper} @@ -174,6 +175,27 @@ object BreakUtil { canBreakBlockMadeFromQuartz } + /** + * ブロック破壊時、「マナ切れ」かどうか判定する。 + * @param player マナ切れブロック破壊停止設定を取得するプレイヤー + */ + def isBreakBlockManaFullyConsumed( + player: Player, + ): Boolean = { + + val isBreakBlockManaFullyConsumed = SeichiAssist + .instance + .breakSkillTriggerConfigSystem + .api + .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + .unsafeRunSync() + + if(isBreakBlockManaFullyConsumed){ + ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() + } + isBreakBlockManaFullyConsumed + } + private def equalsIgnoreNameCaseWorld(name: String): Boolean = { val world = ManagedWorld.fromName(name).getOrElse(return false) From 67257369c4072946320a389cca2a25aa8b735d9e Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Mon, 16 Sep 2024 12:56:36 +0900 Subject: [PATCH 06/26] =?UTF-8?q?fix:=20`isBreakBlockManaFullyConsumed`?= =?UTF-8?q?=E3=82=92`breakskilltriggerconfig`=E3=82=B5=E3=83=96=E3=82=B7?= =?UTF-8?q?=E3=82=B9=E3=83=86=E3=83=A0=E3=81=AB=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/BreakSkillTriggerSettings.scala | 31 +++++++++++++++++++ .../unchama/seichiassist/util/BreakUtil.scala | 22 ------------- 2 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala new file mode 100644 index 0000000000..326ee2f141 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala @@ -0,0 +1,31 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.actions + +import com.github.unchama.seichiassist._ +import com.github.unchama.targetedeffect.player.ActionBarMessageEffect +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey +import org.bukkit.ChatColor.RED +import org.bukkit.entity.Player + +object BreakSkillTriggerSettings{ + + /** + * ブロック破壊時、「マナ切れブロック破壊停止設定」を取得する。 + * @param player マナ切れブロック破壊停止設定を取得するプレイヤー + */ + def isBreakBlockManaFullyConsumed( + player: Player, + ): Boolean = { + + val isBreakBlockManaFullyConsumed = SeichiAssist + .instance + .breakSkillTriggerConfigSystem + .api + .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + .unsafeRunSync() + + if(isBreakBlockManaFullyConsumed){ + ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() + } + isBreakBlockManaFullyConsumed + } +} \ No newline at end of file diff --git a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala index 7ce6fe6cbc..29edc3a824 100644 --- a/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala +++ b/src/main/scala/com/github/unchama/seichiassist/util/BreakUtil.scala @@ -16,7 +16,6 @@ import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.{Active, import com.github.unchama.seichiassist.subsystems.breakcount.domain.CardinalDirection import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.SeichiExpAmount import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.BreakSkillTargetConfigKey -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey import com.github.unchama.targetedeffect.player.ActionBarMessageEffect import com.github.unchama.util.bukkit.ItemStackUtil import com.github.unchama.util.external.{ExternalPlugins, WorldGuardWrapper} @@ -175,27 +174,6 @@ object BreakUtil { canBreakBlockMadeFromQuartz } - /** - * ブロック破壊時、「マナ切れ」かどうか判定する。 - * @param player マナ切れブロック破壊停止設定を取得するプレイヤー - */ - def isBreakBlockManaFullyConsumed( - player: Player, - ): Boolean = { - - val isBreakBlockManaFullyConsumed = SeichiAssist - .instance - .breakSkillTriggerConfigSystem - .api - .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) - .unsafeRunSync() - - if(isBreakBlockManaFullyConsumed){ - ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() - } - isBreakBlockManaFullyConsumed - } - private def equalsIgnoreNameCaseWorld(name: String): Boolean = { val world = ManagedWorld.fromName(name).getOrElse(return false) From c043e8de8d553a544298a6193a5ad262d9cf881a Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 21 Sep 2024 15:21:35 +0900 Subject: [PATCH 07/26] =?UTF-8?q?fix:=20=E3=82=B9=E3=82=AD=E3=83=AB?= =?UTF-8?q?=E7=99=BA=E5=8B=95=E5=88=86=E3=81=AE=E3=83=9E=E3=83=8A=E4=B8=8D?= =?UTF-8?q?=E8=B6=B3=E3=81=AE=E3=81=A8=E3=81=8D=E3=80=81=E3=83=96=E3=83=AD?= =?UTF-8?q?=E3=83=83=E3=82=AF=E7=A0=B4=E5=A3=8A=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E7=B5=82=E4=BA=86=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 65 ++++++++++++++++--- .../BreakSkillTriggerSettings.scala | 0 .../mana/domain/LevelCappedManaAmount.scala | 6 ++ .../subsystems/mana/domain/ManaAmount.scala | 5 ++ .../mana/domain/ManaManipulation.scala | 15 +++++ 5 files changed, 82 insertions(+), 9 deletions(-) rename src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/{action => actions}/BreakSkillTriggerSettings.scala (100%) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 85ff76009c..6936880f3d 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -14,6 +14,7 @@ import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.Seichi import com.github.unchama.seichiassist.subsystems.mana.ManaApi import com.github.unchama.seichiassist.subsystems.mana.domain.ManaAmount import com.github.unchama.seichiassist.subsystems.minestack.MineStackAPI +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.actions.BreakSkillTriggerSettings import com.github.unchama.seichiassist.util.BreakUtil import com.github.unchama.seichiassist.{MaterialSets, SeichiAssist} import com.github.unchama.targetedeffect.player.FocusedSoundEffect @@ -101,18 +102,71 @@ class PlayerBlockBreakListener( return } + val selectedSkill = skillState + .activeSkill + .getOrElse( + return + ) + if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return + + // マナを消費しきっていたら処理を終了 + val playerLocY = player.getLocation.getBlockY - 1 + val skillArea = BreakArea(selectedSkill, skillState.usageMode) + val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() + val isMultiTypeBreakingSkillEnabled = + BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() + // 破壊範囲のブロック計算 + val totalBreakRangeVolume = { + val breakLength = skillArea.breakLength + breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum + } + + import com.github.unchama.seichiassist.data.syntax._ + breakAreaList.foreach { breakArea => + val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = + BlockSearching + .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) + .unsafeRunSync() + .filterSolids(targetBlock => + isMultiTypeBreakingSkillEnabled || BlockSearching + .multiTypeBreakingFilterPredicate(block)(targetBlock) + ) + .filterAll(targetBlock => + player.isSneaking || targetBlock + .getLocation + .getBlockY > playerLocY || targetBlock == block + ) + +// このチャンクで消費されるマナ計算 + val manaToConsumeOnThisChunk = ManaAmount { + (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume + } + // 消費マナが不足している場合は処理を終了 + manaApi + .manaAmount(player) + .skillUsageAmount(manaToConsumeOnThisChunk) + .unsafeRunSync() match { + case Some(value) => event.setCancelled(false) + case None => + if (BreakSkillTriggerSettings.isBreakBlockManaFullyConsumed(player)) { + event.setCancelled(true) + return + } + } +} + // 追加マナ獲得 manaApi .manaAmount(player) .restoreAbsolute(ManaAmount(BreakUtil.calcManaDrop(player))) .unsafeRunSync() - +/* val selectedSkill = skillState .activeSkill .getOrElse( return ) - +*/ if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return // 破壊不可能ブロックの時処理を終了 @@ -181,13 +235,6 @@ class PlayerBlockBreakListener( .tryAcquire(manaToConsumeOnThisChunk) .unsafeRunSync() match { case Some(value) => reservedMana.addOne(value) - case None => - // マナを消費しきっていたら処理を終了する - if (BreakUtil.isBreakBlockManaFullyConsumed(player)) - { - event.setCancelled(true) - return - } b.break() } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala similarity index 100% rename from src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/action/BreakSkillTriggerSettings.scala rename to src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala index 7c75a89e4e..6681b5ea90 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala @@ -22,6 +22,12 @@ case class LevelCappedManaAmount private (manaAmount: ManaAmount, level: SeichiL manaAmount.tryUse(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) } + def tryConsume( + amount: ManaAmount + )(manaMultiplier: ManaMultiplier): Option[LevelCappedManaAmount] = { + manaAmount.tryConsume(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) + } + def withHigherLevelOption(newLevel: SeichiLevel): Option[LevelCappedManaAmount] = Option.when(newLevel > level)(LevelCappedManaAmount(manaAmount, newLevel).fillToCap) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala index 4744ed8501..cddc7885c6 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala @@ -12,6 +12,11 @@ case class ManaAmount(value: Double) { Option.when(resultingAmount >= 0.0)(ManaAmount(resultingAmount)) } + def tryConsume(amount: ManaAmount)(manaMultiplier: ManaMultiplier): Option[ManaAmount] = { + val resultingAmount = value + Option.when(resultingAmount >= amount.multiply(manaMultiplier.value).value)(ManaAmount(resultingAmount)) + } + def multiply(rate: Double): ManaAmount = { require(rate >= 0.0, "マナ量乗算の倍率は非負である必要があります") ManaAmount(rate * value) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala index ded6a9a728..c1414ac17b 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala @@ -28,6 +28,11 @@ trait ManaManipulation[F[_]] { */ def tryAcquire(amount: ManaAmount): F[Option[ManaAmount]] + /** + * スキル発動分のマナが足りない場合は `None` を返す作用。 + */ + def skillUsageAmount(amount: ManaAmount): F[Option[ManaAmount]] + } object ManaManipulation { @@ -54,6 +59,16 @@ object ManaManipulation { } } } + override def skillUsageAmount(amount: ManaAmount): F[Option[ManaAmount]] = { + dragonNightTimeMultiplierRef.get.flatMap { multiplier => + ref.modify { original => + original.tryConsume(amount)(multiplier) match { + case Some(reduced) => (reduced,Some(amount)) + case None => (original, None) + } + } + } + } } } From f1e05997c0ec77f04ffc9b2909093c40c281f154 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 21 Sep 2024 16:47:23 +0900 Subject: [PATCH 08/26] =?UTF-8?q?fix:=20=E6=B6=88=E8=B2=BB=E3=83=9E?= =?UTF-8?q?=E3=83=8A=E4=B8=8D=E8=B6=B3=E5=87=A6=E7=90=86=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 6936880f3d..72b2956886 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -107,9 +107,10 @@ class PlayerBlockBreakListener( .getOrElse( return ) + if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return - // マナを消費しきっていたら処理を終了 + val playerLocY = player.getLocation.getBlockY - 1 val skillArea = BreakArea(selectedSkill, skillState.usageMode) val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() @@ -123,7 +124,7 @@ class PlayerBlockBreakListener( import com.github.unchama.seichiassist.data.syntax._ breakAreaList.foreach { breakArea => - val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = + val BlockSearching.Result(breakBlocks, _, _) = BlockSearching .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) .unsafeRunSync() @@ -137,36 +138,30 @@ class PlayerBlockBreakListener( .getBlockY > playerLocY || targetBlock == block ) -// このチャンクで消費されるマナ計算 - val manaToConsumeOnThisChunk = ManaAmount { - (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume - } - // 消費マナが不足している場合は処理を終了 - manaApi - .manaAmount(player) - .skillUsageAmount(manaToConsumeOnThisChunk) - .unsafeRunSync() match { - case Some(value) => event.setCancelled(false) - case None => - if (BreakSkillTriggerSettings.isBreakBlockManaFullyConsumed(player)) { - event.setCancelled(true) - return - } - } -} + // このチャンクで消費されるマナ計算 + val manaToConsumeOnThisChunk = ManaAmount { + (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume + } + // 消費マナが不足している場合は処理を終了 + manaApi + .manaAmount(player) + .skillUsageAmount(manaToConsumeOnThisChunk) + .unsafeRunSync() match { + case Some(_) => + case None => + if (BreakSkillTriggerSettings.isBreakBlockManaFullyConsumed(player)) { + event.setCancelled(true) + return + } + } + } // 追加マナ獲得 manaApi .manaAmount(player) .restoreAbsolute(ManaAmount(BreakUtil.calcManaDrop(player))) .unsafeRunSync() -/* - val selectedSkill = skillState - .activeSkill - .getOrElse( - return - ) -*/ + if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return // 破壊不可能ブロックの時処理を終了 @@ -235,7 +230,7 @@ class PlayerBlockBreakListener( .tryAcquire(manaToConsumeOnThisChunk) .unsafeRunSync() match { case Some(value) => reservedMana.addOne(value) - b.break() + case None => b.break() } // 減る耐久値の計算(溶岩及び水を破壊するとブロック10個分の耐久値減少判定を行う) From 66d94e19b7b5ba739d419dea930af2b47feb5bb1 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 01:59:35 +0900 Subject: [PATCH 09/26] =?UTF-8?q?fix:=20`PlayerBlockBreakListener`?= =?UTF-8?q?=E3=81=B8=E3=83=9E=E3=83=8A=E5=88=87=E3=82=8C=E3=83=96=E3=83=AD?= =?UTF-8?q?=E3=83=83=E3=82=AF=E7=A0=B4=E5=A3=8A=E5=81=9C=E6=AD=A2=E8=A8=AD?= =?UTF-8?q?=E5=AE=9A=E5=8F=96=E5=BE=97=E5=87=A6=E7=90=86=E3=82=92=E7=A7=BB?= =?UTF-8?q?=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 21 +++++++++++++ .../actions/BreakSkillTriggerSettings.scala | 31 ------------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 72b2956886..13791e140c 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -422,4 +422,25 @@ class PlayerBlockBreakListener( event.setCancelled(true) player.sendMessage(s"${RED}Y-59以下に敷かれたハーフブロックは破壊不可能です。") } + + /** + * ブロック破壊時、「マナ切れブロック破壊停止設定」を取得する。 + * @param player マナ切れブロック破壊停止設定を取得するプレイヤー + */ + def isBreakBlockManaFullyConsumed( + player: Player, + ): Boolean = { + + val isBreakBlockManaFullyConsumed = SeichiAssist + .instance + .breakSkillTriggerConfigSystem + .api + .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + .unsafeRunSync() + + if(isBreakBlockManaFullyConsumed){ + ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() + } + isBreakBlockManaFullyConsumed + } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala index 326ee2f141..e69de29bb2 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala @@ -1,31 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.actions - -import com.github.unchama.seichiassist._ -import com.github.unchama.targetedeffect.player.ActionBarMessageEffect -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey -import org.bukkit.ChatColor.RED -import org.bukkit.entity.Player - -object BreakSkillTriggerSettings{ - - /** - * ブロック破壊時、「マナ切れブロック破壊停止設定」を取得する。 - * @param player マナ切れブロック破壊停止設定を取得するプレイヤー - */ - def isBreakBlockManaFullyConsumed( - player: Player, - ): Boolean = { - - val isBreakBlockManaFullyConsumed = SeichiAssist - .instance - .breakSkillTriggerConfigSystem - .api - .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) - .unsafeRunSync() - - if(isBreakBlockManaFullyConsumed){ - ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() - } - isBreakBlockManaFullyConsumed - } -} \ No newline at end of file From acb3cf86a367ca17d3d496fc4c9e54edcf8669fb Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 02:01:18 +0900 Subject: [PATCH 10/26] =?UTF-8?q?fix:=20=E3=83=9E=E3=83=8A=E6=B6=88?= =?UTF-8?q?=E8=B2=BB=E3=81=A7=E3=81=8D=E3=82=8B=E3=81=8B=E3=81=A9=E3=81=86?= =?UTF-8?q?=E3=81=8B=E5=88=A4=E6=96=AD=E3=81=99=E3=82=8B=E9=96=A2=E6=95=B0?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 12 +++++------- .../subsystems/mana/domain/ManaManipulation.scala | 10 +++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 13791e140c..46de69b7d5 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -145,14 +145,12 @@ class PlayerBlockBreakListener( // 消費マナが不足している場合は処理を終了 manaApi .manaAmount(player) - .skillUsageAmount(manaToConsumeOnThisChunk) + .canAcquire(manaToConsumeOnThisChunk) .unsafeRunSync() match { - case Some(_) => - case None => - if (BreakSkillTriggerSettings.isBreakBlockManaFullyConsumed(player)) { - event.setCancelled(true) - return - } + case false if isBreakBlockManaFullyConsumed(player) => + event.setCancelled(true) + return + case _ => } } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala index c1414ac17b..cec06030f4 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala @@ -29,9 +29,9 @@ trait ManaManipulation[F[_]] { def tryAcquire(amount: ManaAmount): F[Option[ManaAmount]] /** - * スキル発動分のマナが足りない場合は `None` を返す作用。 + * `amount` だけマナを消費することができれば `true`、消費できなければ `false` を返す作用 */ - def skillUsageAmount(amount: ManaAmount): F[Option[ManaAmount]] + def canAcquire(amount: ManaAmount): F[Boolean] } @@ -59,12 +59,12 @@ object ManaManipulation { } } } - override def skillUsageAmount(amount: ManaAmount): F[Option[ManaAmount]] = { + override def canAcquire(amount: ManaAmount): F[Boolean] = { dragonNightTimeMultiplierRef.get.flatMap { multiplier => ref.modify { original => original.tryConsume(amount)(multiplier) match { - case Some(reduced) => (reduced,Some(amount)) - case None => (original, None) + case Some(reduced) => (reduced, true) + case None => (original, false) } } } From 9753a7ac4478d182575f52baf3a1c9a2fc82212d Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 15:05:13 +0900 Subject: [PATCH 11/26] =?UTF-8?q?fix:=20`isBreakBlockManaFullyConsumed`?= =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=82=92`PlayerBlockBreakListener`=E3=81=B8?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 46de69b7d5..307c54255a 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -420,14 +420,12 @@ class PlayerBlockBreakListener( event.setCancelled(true) player.sendMessage(s"${RED}Y-59以下に敷かれたハーフブロックは破壊不可能です。") } - + /** * ブロック破壊時、「マナ切れブロック破壊停止設定」を取得する。 * @param player マナ切れブロック破壊停止設定を取得するプレイヤー */ - def isBreakBlockManaFullyConsumed( - player: Player, - ): Boolean = { + def isBreakBlockManaFullyConsumed(player: Player): Boolean = { val isBreakBlockManaFullyConsumed = SeichiAssist .instance @@ -435,10 +433,10 @@ class PlayerBlockBreakListener( .api .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) .unsafeRunSync() - - if(isBreakBlockManaFullyConsumed){ - ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() - } - isBreakBlockManaFullyConsumed + + if (isBreakBlockManaFullyConsumed) { + ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() + } + isBreakBlockManaFullyConsumed } } From 05c80c11b04e3b600f11f9e7dfe3f70604b7f436 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 15:05:59 +0900 Subject: [PATCH 12/26] =?UTF-8?q?chore:=20import=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC=E3=82=B8=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seichiassist/listener/PlayerBlockBreakListener.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 307c54255a..9e3d364b09 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -11,13 +11,14 @@ import com.github.unchama.seichiassist.seichiskill.ActiveSkillRange.MultiArea import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.Disabled import com.github.unchama.seichiassist.seichiskill.{BlockSearching, BreakArea} import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.SeichiExpAmount +import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey import com.github.unchama.seichiassist.subsystems.mana.ManaApi import com.github.unchama.seichiassist.subsystems.mana.domain.ManaAmount import com.github.unchama.seichiassist.subsystems.minestack.MineStackAPI -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.actions.BreakSkillTriggerSettings import com.github.unchama.seichiassist.util.BreakUtil import com.github.unchama.seichiassist.{MaterialSets, SeichiAssist} import com.github.unchama.targetedeffect.player.FocusedSoundEffect +import com.github.unchama.targetedeffect.player.ActionBarMessageEffect import com.github.unchama.util.bukkit.ItemStackUtil import com.github.unchama.util.effect.BukkitResources import com.github.unchama.util.external.WorldGuardWrapper From d79bad16f674d790dfe3b089bcc693782747dd2b Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 20:48:23 +0900 Subject: [PATCH 13/26] =?UTF-8?q?fix:=20=E6=B6=88=E8=B2=BB=E3=83=9E?= =?UTF-8?q?=E3=83=8A=E4=B8=8D=E8=B6=B3=E5=88=A4=E5=AE=9A=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=A8=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF=E7=A0=B4=E5=A3=8A?= =?UTF-8?q?=E6=99=82=E5=87=A6=E7=90=86=E3=82=92=E6=98=8E=E7=A2=BA=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 104 +++++++----------- 1 file changed, 41 insertions(+), 63 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 9e3d364b09..bff56e6e89 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -7,6 +7,8 @@ import com.github.unchama.minecraft.actions.OnMinecraftServerThread import com.github.unchama.seichiassist.ManagedWorld._ import com.github.unchama.seichiassist.MaterialSets.{BlockBreakableBySkill, BreakTool} import com.github.unchama.seichiassist.concurrent.PluginExecutionContexts +import com.github.unchama.seichiassist.data.{AxisAlignedCuboid} +import com.github.unchama.seichiassist.data.syntax._ import com.github.unchama.seichiassist.seichiskill.ActiveSkillRange.MultiArea import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.Disabled import com.github.unchama.seichiassist.seichiskill.{BlockSearching, BreakArea} @@ -103,18 +105,21 @@ class PlayerBlockBreakListener( return } + // 選択したスキル val selectedSkill = skillState .activeSkill .getOrElse( return ) - if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return - + // プレイヤーのY座標 val playerLocY = player.getLocation.getBlockY - 1 + // スキル破壊範囲 val skillArea = BreakArea(selectedSkill, skillState.usageMode) + // 破壊エリアリスト val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() + // 複数種類ブロック同時破壊設定 val isMultiTypeBreakingSkillEnabled = BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() // 破壊範囲のブロック計算 @@ -122,37 +127,39 @@ class PlayerBlockBreakListener( val breakLength = skillArea.breakLength breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum } + // ブロック探索結果 + val blockSearchResult: AxisAlignedCuboid => (List[BlockBreakableBySkill], List[Block], List[Block]) = { + breakArea: AxisAlignedCuboid => + val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = + BlockSearching + .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) + .unsafeRunSync() + .filterSolids(targetBlock => + isMultiTypeBreakingSkillEnabled || BlockSearching + .multiTypeBreakingFilterPredicate(block)(targetBlock) + ) + .filterAll(targetBlock => + player.isSneaking || targetBlock + .getLocation + .getBlockY > playerLocY || targetBlock == block + ) + (breakBlocks, waterBlocks, lavaBlocks) + } - import com.github.unchama.seichiassist.data.syntax._ + // 消費マナが不足しているか判定 breakAreaList.foreach { breakArea => - val BlockSearching.Result(breakBlocks, _, _) = - BlockSearching - .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) - .unsafeRunSync() - .filterSolids(targetBlock => - isMultiTypeBreakingSkillEnabled || BlockSearching - .multiTypeBreakingFilterPredicate(block)(targetBlock) - ) - .filterAll(targetBlock => - player.isSneaking || targetBlock - .getLocation - .getBlockY > playerLocY || targetBlock == block - ) - - // このチャンクで消費されるマナ計算 - val manaToConsumeOnThisChunk = ManaAmount { - (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume - } - // 消費マナが不足している場合は処理を終了 - manaApi - .manaAmount(player) - .canAcquire(manaToConsumeOnThisChunk) - .unsafeRunSync() match { - case false if isBreakBlockManaFullyConsumed(player) => - event.setCancelled(true) - return - case _ => - } + val (breakBlocks, _, _) = blockSearchResult(breakArea) + // 破壊範囲で消費されるマナ計算 + val manaToConsumeOnBreakArea = ManaAmount { + (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume + } + // 消費マナが不足している場合は処理を終了 + manaApi.manaAmount(player).canAcquire(manaToConsumeOnBreakArea).unsafeRunSync() match { + case false if isBreakBlockManaFullyConsumed(player) => + event.setCancelled(true) + return + case _ => + } } // 追加マナ獲得 @@ -161,8 +168,6 @@ class PlayerBlockBreakListener( .restoreAbsolute(ManaAmount(BreakUtil.calcManaDrop(player))) .unsafeRunSync() - if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return - // 破壊不可能ブロックの時処理を終了 if (!BreakUtil.canBreakWithSkill(player, block)) { event.setCancelled(true) @@ -171,21 +176,8 @@ class PlayerBlockBreakListener( event.setCancelled(true) + // ブロック破壊時に行う処理 { - // プレイヤーの足のy座標を取得 - val playerLocY = player.getLocation.getBlockY - 1 - - val skillArea = BreakArea(selectedSkill, skillState.usageMode) - val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() - - val isMultiTypeBreakingSkillEnabled = - BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() - - val totalBreakRangeVolume = { - val breakLength = skillArea.breakLength - breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum - } - // エフェクト用に壊されるブロック全てのリストデータ val multiBreakList = new ArrayBuffer[Set[BlockBreakableBySkill]] // 壊される溶岩の全てのリストデータ @@ -202,22 +194,7 @@ class PlayerBlockBreakListener( val b = new Breaks b.breakable { breakAreaList.foreach { breakArea => - import com.github.unchama.seichiassist.data.syntax._ - - val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = - BlockSearching - .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) - .unsafeRunSync() - .filterSolids(targetBlock => - isMultiTypeBreakingSkillEnabled || BlockSearching - .multiTypeBreakingFilterPredicate(block)(targetBlock) - ) - .filterAll(targetBlock => - player.isSneaking || targetBlock - .getLocation - .getBlockY > playerLocY || targetBlock == block - ) - + val (breakBlocks, waterBlocks, lavaBlocks) = blockSearchResult(breakArea) // このチャンクで消費されるマナ val manaToConsumeOnThisChunk = ManaAmount { (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume @@ -424,6 +401,7 @@ class PlayerBlockBreakListener( /** * ブロック破壊時、「マナ切れブロック破壊停止設定」を取得する。 + * マナ切れブロック破壊設定が `true` になっている場合、プレイヤーに破壊抑制メッセージを送信する。 * @param player マナ切れブロック破壊停止設定を取得するプレイヤー */ def isBreakBlockManaFullyConsumed(player: Player): Boolean = { From ad5b883f31e5a2a16f730b595294907a8c8adadc Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 21:20:21 +0900 Subject: [PATCH 14/26] chore: scalafmt --- .../com/github/unchama/seichiassist/SeichiAssist.scala | 3 ++- .../seichiassist/listener/PlayerBlockBreakListener.scala | 3 ++- .../subsystems/breakskilltriggerconfig/System.scala | 3 ++- .../subsystems/mana/domain/LevelCappedManaAmount.scala | 8 ++++---- .../seichiassist/subsystems/mana/domain/ManaAmount.scala | 4 +++- .../subsystems/mana/domain/ManaManipulation.scala | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala index 6840a95ae9..2d6d7ed128 100644 --- a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala +++ b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala @@ -496,7 +496,8 @@ class SeichiAssist extends JavaPlugin() { lazy val breakSkillTargetConfigSystem: subsystems.breakskilltargetconfig.System[IO, Player] = subsystems.breakskilltargetconfig.System.wired[IO, SyncIO].unsafeRunSync() - lazy val breakSkillTriggerConfigSystem: subsystems.breakskilltriggerconfig.System[IO, Player] = + lazy val breakSkillTriggerConfigSystem + : subsystems.breakskilltriggerconfig.System[IO, Player] = subsystems.breakskilltriggerconfig.System.wired[IO, SyncIO].unsafeRunSync() /* TODO: mineStackSystemは本来privateであるべきだが、mineStackにアイテムを格納するAPIが現状の diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index bff56e6e89..87798882e8 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -128,7 +128,8 @@ class PlayerBlockBreakListener( breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum } // ブロック探索結果 - val blockSearchResult: AxisAlignedCuboid => (List[BlockBreakableBySkill], List[Block], List[Block]) = { + val blockSearchResult + : AxisAlignedCuboid => (List[BlockBreakableBySkill], List[Block], List[Block]) = { breakArea: AxisAlignedCuboid => val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = BlockSearching diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala index 4b13276b9c..4a86270d70 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala @@ -30,7 +30,8 @@ object System { BreakSkillTriggerConfigRepositoryDefinition.withContext[G, Player] ) } yield { - val breakSkillTriggerConfigRepository = breakSkillTriggerConfigRepositoryControls.repository + val breakSkillTriggerConfigRepository = + breakSkillTriggerConfigRepositoryControls.repository new System[F, Player] { override val api: BreakSkillTriggerConfigAPI[F, Player] = diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala index 6681b5ea90..5abd116b5a 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala @@ -23,10 +23,10 @@ case class LevelCappedManaAmount private (manaAmount: ManaAmount, level: SeichiL } def tryConsume( - amount: ManaAmount - )(manaMultiplier: ManaMultiplier): Option[LevelCappedManaAmount] = { - manaAmount.tryConsume(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) - } + amount: ManaAmount + )(manaMultiplier: ManaMultiplier): Option[LevelCappedManaAmount] = { + manaAmount.tryConsume(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) + } def withHigherLevelOption(newLevel: SeichiLevel): Option[LevelCappedManaAmount] = Option.when(newLevel > level)(LevelCappedManaAmount(manaAmount, newLevel).fillToCap) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala index cddc7885c6..d86abdd3f6 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala @@ -14,7 +14,9 @@ case class ManaAmount(value: Double) { def tryConsume(amount: ManaAmount)(manaMultiplier: ManaMultiplier): Option[ManaAmount] = { val resultingAmount = value - Option.when(resultingAmount >= amount.multiply(manaMultiplier.value).value)(ManaAmount(resultingAmount)) + Option.when(resultingAmount >= amount.multiply(manaMultiplier.value).value)( + ManaAmount(resultingAmount) + ) } def multiply(rate: Double): ManaAmount = { diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala index cec06030f4..0ea196c1a3 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala @@ -29,7 +29,7 @@ trait ManaManipulation[F[_]] { def tryAcquire(amount: ManaAmount): F[Option[ManaAmount]] /** - * `amount` だけマナを消費することができれば `true`、消費できなければ `false` を返す作用 + * `amount` だけマナを消費することができれば `true`、消費できなければ `false` を返す作用 */ def canAcquire(amount: ManaAmount): F[Boolean] From 02c93680dce55c860dc66c47cb785eee471fa79f Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sun, 22 Sep 2024 21:20:42 +0900 Subject: [PATCH 15/26] =?UTF-8?q?chore:=20`BreakSkillTriggerSettings`?= =?UTF-8?q?=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/actions/BreakSkillTriggerSettings.scala | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/actions/BreakSkillTriggerSettings.scala deleted file mode 100644 index e69de29bb2..0000000000 From ae8d4c24487d2def375b79fd64cfa071db19cf7f Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 12 Oct 2024 16:09:53 +0900 Subject: [PATCH 16/26] =?UTF-8?q?chore:=20`canAcquire`=E3=81=AE=E3=82=B3?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seichiassist/subsystems/mana/domain/ManaManipulation.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala index 0ea196c1a3..020a0efc81 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala @@ -29,7 +29,7 @@ trait ManaManipulation[F[_]] { def tryAcquire(amount: ManaAmount): F[Option[ManaAmount]] /** - * `amount` だけマナを消費することができれば `true`、消費できなければ `false` を返す作用 + * `amount` だけマナを消費することが可能ならば `true`、そうでないなら `false` を返す作用 */ def canAcquire(amount: ManaAmount): F[Boolean] From 914bf47782b676e8f8a5a2ff54b888536bf040a3 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 12 Oct 2024 16:11:40 +0900 Subject: [PATCH 17/26] =?UTF-8?q?fix:=20=E3=80=8C=E3=83=9E=E3=83=8A?= =?UTF-8?q?=E3=81=8C=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AB=E3=82=B9?= =?UTF-8?q?=E3=82=AD=E3=83=AB=E3=81=AE=E7=99=BA=E5=8B=95=E3=82=92=E6=8A=91?= =?UTF-8?q?=E5=88=B6=E3=81=99=E3=82=8B=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B?= =?UTF-8?q?=E3=80=8D=E3=81=AE=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E6=A7=8B?= =?UTF-8?q?=E9=80=A0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1.19.0__Create_break_trigger_preference_table.sql | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql b/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql index 9ef12523e0..3ced2c8f23 100644 --- a/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql +++ b/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql @@ -1,9 +1,7 @@ USE seichiassist; -CREATE TABLE player_break_trigger_preference( +CREATE TABLE player_break_suppression_preference( uuid CHAR(36) NOT NULL, - trigger_category ENUM('ManaFullyConsumed') NOT NULL, - do_not_break BOOL NOT NULL DEFAULT FALSE, - PRIMARY KEY(uuid, trigger_category), - INDEX index_player_break_trigger_preference_on_uuid (uuid) + do_break_suppression_due_to_mana BOOL NOT NULL DEFAULT FALSE, + FOREIGN KEY fk_player_break_suppression_preference_uuid REFERENCES playerdata(uuid) ); From eaec16e889d1da0f6d5cfe8ffbad20955390fa0b Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 12 Oct 2024 16:16:26 +0900 Subject: [PATCH 18/26] =?UTF-8?q?fix=20`isBreakBlockManaFullyConsumed`?= =?UTF-8?q?=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index 87798882e8..ea3381b85e 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -405,18 +405,16 @@ class PlayerBlockBreakListener( * マナ切れブロック破壊設定が `true` になっている場合、プレイヤーに破壊抑制メッセージを送信する。 * @param player マナ切れブロック破壊停止設定を取得するプレイヤー */ - def isBreakBlockManaFullyConsumed(player: Player): Boolean = { - - val isBreakBlockManaFullyConsumed = SeichiAssist - .instance - .breakSkillTriggerConfigSystem - .api - .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) - .unsafeRunSync() - - if (isBreakBlockManaFullyConsumed) { - ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています").run(player).unsafeRunSync() - } - isBreakBlockManaFullyConsumed + def isBreakBlockManaFullyConsumed(player: Player): IO[Boolean] = { + for { + isBreakBlockManaFullyConsumed <- SeichiAssist + .instance + .breakSkillTriggerConfigSystem + .api + .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + _ <- ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています") + .run(player) + .whenA(isBreakBlockManaFullyConsumed) + } yield isBreakBlockManaFullyConsumed } } From df86061d736db1385b3cdc9b5f5fb3f7359436c5 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 12 Oct 2024 16:54:50 +0900 Subject: [PATCH 19/26] =?UTF-8?q?fix:=20=E6=8C=87=E6=91=98=E5=86=85?= =?UTF-8?q?=E5=AE=B9(*)=E3=82=92=E5=8F=8D=E6=98=A0=E3=81=97=E3=80=81`onPla?= =?UTF-8?q?yerActiveSkillEvent`=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20*https://github.com/GiganticMinecraft/Seic?= =?UTF-8?q?hiAssist/pull/2370#discussion=5Fr1770582819?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../listener/PlayerBlockBreakListener.scala | 93 ++++++++++++------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index ea3381b85e..bf09b7cf13 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -8,7 +8,6 @@ import com.github.unchama.seichiassist.ManagedWorld._ import com.github.unchama.seichiassist.MaterialSets.{BlockBreakableBySkill, BreakTool} import com.github.unchama.seichiassist.concurrent.PluginExecutionContexts import com.github.unchama.seichiassist.data.{AxisAlignedCuboid} -import com.github.unchama.seichiassist.data.syntax._ import com.github.unchama.seichiassist.seichiskill.ActiveSkillRange.MultiArea import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.Disabled import com.github.unchama.seichiassist.seichiskill.{BlockSearching, BreakArea} @@ -113,24 +112,24 @@ class PlayerBlockBreakListener( ) if (!selectedSkill.range.isInstanceOf[MultiArea] || skillState.usageMode == Disabled) return - // プレイヤーのY座標 - val playerLocY = player.getLocation.getBlockY - 1 - // スキル破壊範囲 - val skillArea = BreakArea(selectedSkill, skillState.usageMode) - // 破壊エリアリスト - val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() - // 複数種類ブロック同時破壊設定 - val isMultiTypeBreakingSkillEnabled = - BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() - // 破壊範囲のブロック計算 - val totalBreakRangeVolume = { - val breakLength = skillArea.breakLength - breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum - } - // ブロック探索結果 - val blockSearchResult - : AxisAlignedCuboid => (List[BlockBreakableBySkill], List[Block], List[Block]) = { - breakArea: AxisAlignedCuboid => + // 消費するマナが不足しているか判定 + { + // プレイヤーのY座標 + val playerLocY = player.getLocation.getBlockY - 1 + // スキル破壊範囲 + val skillArea = BreakArea(selectedSkill, skillState.usageMode) + // 破壊エリアリスト + val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() + // 複数種類ブロック同時破壊設定 + val isMultiTypeBreakingSkillEnabled = + BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() + // 破壊範囲のブロック計算 + val totalBreakRangeVolume = { + val breakLength = skillArea.breakLength + breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum + } + breakAreaList.foreach { breakArea => + import com.github.unchama.seichiassist.data.syntax._ val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = BlockSearching .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) @@ -144,22 +143,18 @@ class PlayerBlockBreakListener( .getLocation .getBlockY > playerLocY || targetBlock == block ) - (breakBlocks, waterBlocks, lavaBlocks) - } - // 消費マナが不足しているか判定 - breakAreaList.foreach { breakArea => - val (breakBlocks, _, _) = blockSearchResult(breakArea) - // 破壊範囲で消費されるマナ計算 - val manaToConsumeOnBreakArea = ManaAmount { - (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume - } - // 消費マナが不足している場合は処理を終了 - manaApi.manaAmount(player).canAcquire(manaToConsumeOnBreakArea).unsafeRunSync() match { - case false if isBreakBlockManaFullyConsumed(player) => - event.setCancelled(true) - return - case _ => + // 破壊範囲で消費されるマナ計算 + val manaToConsumeOnBreakArea = ManaAmount { + (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume + } + // 消費マナが不足している場合は処理を終了 + manaApi.manaAmount(player).canAcquire(manaToConsumeOnBreakArea).unsafeRunSync() match { + case false if isBreakBlockManaFullyConsumed(player).unsafeRunSync() => + event.setCancelled(true) + return + case _ => + } } } @@ -179,6 +174,20 @@ class PlayerBlockBreakListener( // ブロック破壊時に行う処理 { + // プレイヤーのY座標 + val playerLocY = player.getLocation.getBlockY - 1 + // スキル破壊範囲 + val skillArea = BreakArea(selectedSkill, skillState.usageMode) + // 破壊エリアリスト + val breakAreaList = skillArea.makeBreakArea(player).unsafeRunSync() + // 複数種類ブロック同時破壊設定 + val isMultiTypeBreakingSkillEnabled = + BreakUtil.performsMultipleIDBlockBreakWhenUsingSkills(player).unsafeRunSync() + // 破壊範囲のブロック計算 + val totalBreakRangeVolume = { + val breakLength = skillArea.breakLength + breakLength.x * breakLength.y * breakLength.z * skillArea.breakNum + } // エフェクト用に壊されるブロック全てのリストデータ val multiBreakList = new ArrayBuffer[Set[BlockBreakableBySkill]] // 壊される溶岩の全てのリストデータ @@ -195,7 +204,21 @@ class PlayerBlockBreakListener( val b = new Breaks b.breakable { breakAreaList.foreach { breakArea => - val (breakBlocks, waterBlocks, lavaBlocks) = blockSearchResult(breakArea) + import com.github.unchama.seichiassist.data.syntax._ + + val BlockSearching.Result(breakBlocks, waterBlocks, lavaBlocks) = + BlockSearching + .searchForBlocksBreakableWithSkill(player, breakArea.gridPoints(), block) + .unsafeRunSync() + .filterSolids(targetBlock => + isMultiTypeBreakingSkillEnabled || BlockSearching + .multiTypeBreakingFilterPredicate(block)(targetBlock) + ) + .filterAll(targetBlock => + player.isSneaking || targetBlock + .getLocation + .getBlockY > playerLocY || targetBlock == block + ) // このチャンクで消費されるマナ val manaToConsumeOnThisChunk = ManaAmount { (gravity + 1) * selectedSkill.manaCost * (breakBlocks.size + 1).toDouble / totalBreakRangeVolume From 5d5bcd02caef3c0ad80efd31008416a59ead56af Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 15:35:37 +0900 Subject: [PATCH 20/26] =?UTF-8?q?fix:=20BreakSkillTriggerConfigKey->BreakS?= =?UTF-8?q?uppressionPreference=E3=81=B8case=20class=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/BreakSkillTriggerConfig.scala | 28 ------------------- .../domain/BreakSuppressionPreference.scala | 23 +++++++++++++++ 2 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala deleted file mode 100644 index 8111bc8286..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfig.scala +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain - -case class BreakSkillTriggerConfig(config: Map[BreakSkillTriggerConfigKey, Boolean]) { - - /** - * @return `configKey`の破壊トリガをトグルする - */ - def toggleBreakSkillTriggerConfig( - configKey: BreakSkillTriggerConfigKey - ): BreakSkillTriggerConfig = - this.copy(this.config + (configKey -> !this.config.getOrElse(configKey, false))) - - /** - * @return 現在の破壊トリガを取得する - */ - def breakSkillTriggerConfig(configKey: BreakSkillTriggerConfigKey): Boolean = - this.config.getOrElse(configKey, false) - -} - -object BreakSkillTriggerConfig { - - /** - * [[BreakSkillTriggerConfig]]の初期値 - */ - val initial: BreakSkillTriggerConfig = BreakSkillTriggerConfig(Map.empty) - -} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala new file mode 100644 index 0000000000..e512fd69d6 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala @@ -0,0 +1,23 @@ +package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain + +case class BreakSuppressionPreference(doBreakSuppression: Boolean) { + + /** + * @return 破壊抑制の設定をトグルする + */ + def toggleBreakSuppression(): BreakSuppressionPreference = + this.copy(doBreakSuppression = !this.doBreakSuppression) + + /** + * @return 現在の破壊抑制の設定を取得する + */ + def isBreakSuppressionEnabled: Boolean = doBreakSuppression +} + +object BreakSuppressionPreference { + + /** + * [[BreakSuppressionPreference]]の初期値 + */ + val initial: BreakSuppressionPreference = BreakSuppressionPreference(doBreakSuppression = false) +} From a4451d07869e24c1292b245a6313aa1c5b1b7f6a Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 15:58:28 +0900 Subject: [PATCH 21/26] =?UTF-8?q?fix:=20`BreakSkillTriggerConfigKey`?= =?UTF-8?q?=E5=AE=9A=E7=BE=A9=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/BreakSkillTriggerConfigKey.scala | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala deleted file mode 100644 index 293979b2d0..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigKey.scala +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain - -import enumeratum.{Enum, EnumEntry} - -/** - * トリガ条件の集合を表現する。 - * これらの値は整地スキルでブロックを破壊する際に、 - * プレイヤーの設定に応じて使われる。 - */ -sealed trait BreakSkillTriggerConfigKey extends EnumEntry - -object BreakSkillTriggerConfigKey extends Enum[BreakSkillTriggerConfigKey] { - - val values: IndexedSeq[BreakSkillTriggerConfigKey] = findValues - - /** - * マナを消費しきった場合にブロックを破壊するかどうか - */ - case object ManaFullyConsumed extends BreakSkillTriggerConfigKey - -} From 38c29da4f4b422bbac130a9ada157f6b4d057b95 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 16:13:53 +0900 Subject: [PATCH 22/26] =?UTF-8?q?fix:=20`BreakSkillTrigger`->`BreakSuppres?= =?UTF-8?q?sionPreference`=E3=81=B8=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=AB?= =?UTF-8?q?=E4=BC=B4=E3=81=86subsystem=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BreakSkillTriggerConfigAPI.scala | 28 -------- .../breakskilltriggerconfig/System.scala | 67 ------------------- ...illTriggerConfigRepositoryDefinition.scala | 23 ------- .../BreakSkillTriggerConfigPersistence.scala | 7 -- ...bcBreakSkillTriggerConfigPersistence.scala | 52 -------------- .../BreakSuppressionPreferenceAPI.scala | 25 +++++++ .../breaksuppressionpreference/System.scala | 62 +++++++++++++++++ ...essionPreferenceRepositoryDefinition.scala | 23 +++++++ .../domain/BreakSuppressionPreference.scala | 2 +- ...reakSuppressionPreferencePersistence.scala | 7 ++ ...reakSuppressionPreferencePersistence.scala | 35 ++++++++++ 11 files changed, 153 insertions(+), 178 deletions(-) delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala delete mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/BreakSuppressionPreferenceAPI.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/application/BreakSuppressionPreferenceRepositoryDefinition.scala rename src/main/scala/com/github/unchama/seichiassist/subsystems/{breakskilltriggerconfig => breaksuppressionpreference}/domain/BreakSuppressionPreference.scala (87%) create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala create mode 100644 src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala deleted file mode 100644 index 1df97cf935..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/BreakSkillTriggerConfigAPI.scala +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig - -import cats.data.Kleisli -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey - -trait BreakSkillTriggerConfigAPI[F[_], Player] { - - /** - * @return 破壊トリガをトグルする作用 - */ - def toggleBreakSkillTriggerConfig( - configKey: BreakSkillTriggerConfigKey - ): Kleisli[F, Player, Unit] - - /** - * @return 現在の破壊トリガを取得する作用 - */ - def breakSkillTriggerConfig(player: Player, configKey: BreakSkillTriggerConfigKey): F[Boolean] - -} - -object BreakSkillTriggerConfigAPI { - - def apply[F[_], Player]( - implicit ev: BreakSkillTriggerConfigAPI[F, Player] - ): BreakSkillTriggerConfigAPI[F, Player] = ev - -} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala deleted file mode 100644 index 4a86270d70..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/System.scala +++ /dev/null @@ -1,67 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig - -import cats.data.Kleisli -import cats.effect.SyncEffect -import com.github.unchama.datarepository.bukkit.player.BukkitRepositoryControls -import com.github.unchama.generic.ContextCoercion -import com.github.unchama.seichiassist.meta.subsystem.Subsystem -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.repository.BreakSkillTriggerConfigRepositoryDefinition -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ - BreakSkillTriggerConfigKey, - BreakSkillTriggerConfigPersistence -} -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.persistence.JdbcBreakSkillTriggerConfigPersistence -import org.bukkit.entity.Player - -trait System[F[_], Player] extends Subsystem[F] { - val api: BreakSkillTriggerConfigAPI[F, Player] -} - -object System { - - import cats.implicits._ - - def wired[F[_], G[_]: SyncEffect: ContextCoercion[*[_], F]]: G[System[F, Player]] = { - implicit val breakSkillTriggerConfigPersistence: BreakSkillTriggerConfigPersistence[G] = - new JdbcBreakSkillTriggerConfigPersistence[G] - - for { - breakSkillTriggerConfigRepositoryControls <- BukkitRepositoryControls.createHandles( - BreakSkillTriggerConfigRepositoryDefinition.withContext[G, Player] - ) - } yield { - val breakSkillTriggerConfigRepository = - breakSkillTriggerConfigRepositoryControls.repository - - new System[F, Player] { - override val api: BreakSkillTriggerConfigAPI[F, Player] = - new BreakSkillTriggerConfigAPI[F, Player] { - override def toggleBreakSkillTriggerConfig( - configKey: BreakSkillTriggerConfigKey - ): Kleisli[F, Player, Unit] = - Kleisli { player => - ContextCoercion( - breakSkillTriggerConfigRepository(player) - .update(_.toggleBreakSkillTriggerConfig(configKey)) - ) - } - - override def breakSkillTriggerConfig( - player: Player, - configKey: BreakSkillTriggerConfigKey - ): F[Boolean] = - ContextCoercion( - breakSkillTriggerConfigRepository(player) - .get - .map(_.breakSkillTriggerConfig(configKey)) - ) - } - - override val managedRepositoryControls: Seq[BukkitRepositoryControls[F, _]] = Seq( - breakSkillTriggerConfigRepositoryControls.coerceFinalizationContextTo[F] - ) - } - } - } - -} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala deleted file mode 100644 index 89339ce26d..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/application/BreakSkillTriggerConfigRepositoryDefinition.scala +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.application.repository - -import cats.effect.Sync -import cats.effect.concurrent.Ref -import com.github.unchama.datarepository.definitions.RefDictBackedRepositoryDefinition -import com.github.unchama.datarepository.template.RepositoryDefinition -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ - BreakSkillTriggerConfig, - BreakSkillTriggerConfigPersistence -} - -object BreakSkillTriggerConfigRepositoryDefinition { - - def withContext[F[_]: Sync, Player]( - implicit persistence: BreakSkillTriggerConfigPersistence[F] - ): RepositoryDefinition[F, Player, Ref[F, BreakSkillTriggerConfig]] = - RefDictBackedRepositoryDefinition - .usingUuidRefDict[F, Player, BreakSkillTriggerConfig](persistence)( - BreakSkillTriggerConfig.initial - ) - .toRefRepository - -} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala deleted file mode 100644 index 938ba6b70f..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSkillTriggerConfigPersistence.scala +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain - -import com.github.unchama.generic.RefDict - -import java.util.UUID - -trait BreakSkillTriggerConfigPersistence[F[_]] extends RefDict[F, UUID, BreakSkillTriggerConfig] diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala deleted file mode 100644 index 1b656ca440..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/infrastructure/JdbcBreakSkillTriggerConfigPersistence.scala +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.persistence - -import cats.effect.Sync -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.{ - BreakSkillTriggerConfig, - BreakSkillTriggerConfigKey, - BreakSkillTriggerConfigPersistence -} -import scalikejdbc.{DB, scalikejdbcSQLInterpolationImplicitDef} - -import java.util.UUID - -class JdbcBreakSkillTriggerConfigPersistence[F[_]: Sync] - extends BreakSkillTriggerConfigPersistence[F] { - - override def read(key: UUID): F[Option[BreakSkillTriggerConfig]] = Sync[F].delay { - val config = DB.readOnly { implicit session => - sql"SELECT trigger_category, do_not_break FROM player_break_trigger_preference WHERE uuid = ${key.toString}" - .map { rs => - BreakSkillTriggerConfigKey.withNameOption(rs.string("trigger_category")).map { - flagName => flagName -> rs.boolean("do_not_break") - } - } - .toList() - .flatten - .toMap - } - - Some(BreakSkillTriggerConfig(config)) - } - - override def write(key: UUID, value: BreakSkillTriggerConfig): F[Unit] = Sync[F].delay { - DB.localTx { implicit session => - val uuid = key.toString - val batchParams = - value - .config - .map { - case (triggerCategory, doNotBreak) => - Seq(uuid, triggerCategory.entryName, doNotBreak) - } - .toSeq - - sql"""INSERT INTO player_break_trigger_preference (uuid, trigger_category, do_not_break) - | VALUES (?, ?, ?) - | ON DUPLICATE KEY UPDATE - | do_not_break = VALUE(do_not_break) - """.stripMargin.batch(batchParams: _*).apply[List]() - } - } - -} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/BreakSuppressionPreferenceAPI.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/BreakSuppressionPreferenceAPI.scala new file mode 100644 index 0000000000..9e18059cf1 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/BreakSuppressionPreferenceAPI.scala @@ -0,0 +1,25 @@ +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference + +import cats.data.Kleisli + +trait BreakSuppressionPreferenceAPI[F[_], Player] { + + /** + * @return 破壊抑制の設定をトグルする作用 + */ + def toggleBreakSuppression: Kleisli[F, Player, Unit] + + /** + * @return 現在の破壊抑制の設定を取得する作用 + */ + def isBreakSuppressionEnabled(player: Player): F[Boolean] + +} + +object BreakSkillTriggerConfigAPI { + + def apply[F[_], Player]( + implicit ev: BreakSuppressionPreferenceAPI[F, Player] + ): BreakSuppressionPreferenceAPI[F, Player] = ev + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala new file mode 100644 index 0000000000..84b327807e --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala @@ -0,0 +1,62 @@ +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference + +import cats.data.Kleisli +import cats.effect.SyncEffect +import com.github.unchama.datarepository.bukkit.player.BukkitRepositoryControls +import com.github.unchama.generic.ContextCoercion +import com.github.unchama.seichiassist.meta.subsystem.Subsystem +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.application.repository.BreakSuppressionPreferenceRepositoryDefinition +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain.{ + BreakSuppressionPreference, + BreakSuppressionPreferencePersistence +} +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.persistence.JdbcBreakSuppressionPreferencePersistence +import org.bukkit.entity.Player + +trait System[F[_], Player] extends Subsystem[F] { + val api: BreakSuppressionPreferenceAPI[F, Player] +} + +object System { + + import cats.implicits._ + + def wired[F[_], G[_]: SyncEffect: ContextCoercion[*[_], F]]: G[System[F, Player]] = { + implicit val breakSuppressionPreferencePersistence + : BreakSuppressionPreferencePersistence[G] = + new JdbcBreakSuppressionPreferencePersistence[G] + + for { + breakSuppressionPreferenceRepositoryControls <- BukkitRepositoryControls.createHandles( + BreakSuppressionPreferenceRepositoryDefinition.withContext[G, Player] + ) + } yield { + val breakSuppressionPreferenceRepository = + breakSuppressionPreferenceRepositoryControls.repository + + new System[F, Player] { + override val api: BreakSuppressionPreferenceAPI[F, Player] = + new BreakSuppressionPreferenceAPI[F, Player] { + override def toggleBreakSuppressionPreference: Kleisli[F, Player, Unit] = + Kleisli { player => + ContextCoercion( + breakSuppressionPreferenceRepository(player).update(pref => + pref.copy(doBreakSuppression = !pref.doBreakSuppression) + ) + ) + } + + override def getBreakSuppressionPreference(player: Player): F[Boolean] = + ContextCoercion( + breakSuppressionPreferenceRepository(player).get.map(_.doBreakSuppression) + ) + } + + override val managedRepositoryControls: Seq[BukkitRepositoryControls[F, _]] = Seq( + breakSuppressionPreferenceRepositoryControls.coerceFinalizationContextTo[F] + ) + } + } + } + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/application/BreakSuppressionPreferenceRepositoryDefinition.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/application/BreakSuppressionPreferenceRepositoryDefinition.scala new file mode 100644 index 0000000000..5a5703c82a --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/application/BreakSuppressionPreferenceRepositoryDefinition.scala @@ -0,0 +1,23 @@ +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.application.repository + +import cats.effect.Sync +import cats.effect.concurrent.Ref +import com.github.unchama.datarepository.definitions.RefDictBackedRepositoryDefinition +import com.github.unchama.datarepository.template.RepositoryDefinition +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain.{ + BreakSuppressionPreference, + BreakSuppressionPreferencePersistence +} + +object BreakSuppressionPreferenceRepositoryDefinition { + + def withContext[F[_]: Sync, Player]( + implicit persistence: BreakSuppressionPreferencePersistence[F] + ): RepositoryDefinition[F, Player, Ref[F, BreakSuppressionPreference]] = + RefDictBackedRepositoryDefinition + .usingUuidRefDict[F, Player, BreakSuppressionPreference](persistence)( + BreakSuppressionPreference(doBreakSuppression = false) + ) + .toRefRepository + +} diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala similarity index 87% rename from src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala rename to src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala index e512fd69d6..7f2f9fe95f 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breakskilltriggerconfig/domain/BreakSuppressionPreference.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala @@ -1,4 +1,4 @@ -package com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain case class BreakSuppressionPreference(doBreakSuppression: Boolean) { diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala new file mode 100644 index 0000000000..b3df65533e --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala @@ -0,0 +1,7 @@ +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain + +import com.github.unchama.generic.RefDict + +import java.util.UUID + +trait BreakSuppressionPreferenceConfigPersistence[F[_]] extends RefDict[F, UUID, BreakSuppressionPreference] diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala new file mode 100644 index 0000000000..1136424f26 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala @@ -0,0 +1,35 @@ +package com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.persistence + +import cats.effect.Sync +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain.{ + BreakSuppressionPreference, + BreakSuppressionPreferencePersistence +} +import scalikejdbc.{DB, scalikejdbcSQLInterpolationImplicitDef} + +import java.util.UUID + +class JdbcBreakSuppressionPreferencePersistence[F[_]: Sync] + extends BreakSuppressionPreferencePersistence[F] { + + override def read(key: UUID): F[Option[BreakSuppressionPreference]] = Sync[F].delay { + val doBreakSuppression = DB.readOnly { implicit session => + sql"SELECT do_break_suppression FROM player_break_suppression_preference WHERE uuid = ${key.toString}" + .map(rs => rs.boolean("do_break_suppression")) + .single() + } + + doBreakSuppression.map(BreakSuppressionPreference) + } + + override def write(key: UUID, value: BreakSuppressionPreference): F[Unit] = Sync[F].delay { + DB.localTx { implicit session => + val uuid = key.toString + sql"""INSERT INTO player_break_suppression_preference (uuid, player_break_suppression_preference) + | VALUES ($uuid, ${value.doBreakSuppression}) + | ON DUPLICATE KEY UPDATE + | do_break_suppression = VALUE(do_break_suppression) + """.stripMargin.update().apply() + } + } +} From 7b3c3c719a405ee3c56ff721c7aa6984a3d97b99 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 21:59:41 +0900 Subject: [PATCH 23/26] =?UTF-8?q?fix:=20`BreakSkillTrigger`->`BreakSuppres?= =?UTF-8?q?sionPreference`=E3=81=B8=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=AB?= =?UTF-8?q?=E4=BC=B4=E3=81=86=E3=83=93=E3=83=AB=E3=83=89=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/unchama/seichiassist/SeichiAssist.scala | 14 +++++++------- .../listener/PlayerBlockBreakListener.scala | 11 +++++------ .../seichiassist/menus/TopLevelRouter.scala | 4 ++-- .../menus/skill/PassiveSkillMenu.scala | 14 ++++++-------- .../breaksuppressionpreference/System.scala | 4 ++-- .../domain/BreakSuppressionPreference.scala | 3 ++- .../BreakSuppressionPreferencePersistence.scala | 3 ++- ...JdbcBreakSuppressionPreferencePersistence.scala | 10 +++++----- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala index 2d6d7ed128..f0bd4e3822 100644 --- a/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala +++ b/src/main/scala/com/github/unchama/seichiassist/SeichiAssist.scala @@ -63,7 +63,7 @@ import com.github.unchama.seichiassist.subsystems.autosave.application.SystemCon import com.github.unchama.seichiassist.subsystems.breakcount.{BreakCountAPI, BreakCountReadAPI} import com.github.unchama.seichiassist.subsystems.breakcountbar.BreakCountBarAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.BreakSuppressionPreferenceAPI import com.github.unchama.seichiassist.subsystems.buildcount.BuildCountAPI import com.github.unchama.seichiassist.subsystems.discordnotification.DiscordNotificationAPI import com.github.unchama.seichiassist.subsystems.donate.DonatePremiumPointAPI @@ -496,9 +496,9 @@ class SeichiAssist extends JavaPlugin() { lazy val breakSkillTargetConfigSystem: subsystems.breakskilltargetconfig.System[IO, Player] = subsystems.breakskilltargetconfig.System.wired[IO, SyncIO].unsafeRunSync() - lazy val breakSkillTriggerConfigSystem - : subsystems.breakskilltriggerconfig.System[IO, Player] = - subsystems.breakskilltriggerconfig.System.wired[IO, SyncIO].unsafeRunSync() + lazy val breakSuppressionPreferenceSystem + : subsystems.breaksuppressionpreference.System[IO, Player] = + subsystems.breaksuppressionpreference.System.wired[IO, SyncIO].unsafeRunSync() /* TODO: mineStackSystemは本来privateであるべきだが、mineStackにアイテムを格納するAPIが現状の BreakUtilの実装から呼び出されている都合上やむを得ずpublicになっている。*/ @@ -567,7 +567,7 @@ class SeichiAssist extends JavaPlugin() { openirontrapdoor.System.wired, gridRegionSystem, breakSkillTargetConfigSystem, - breakSkillTriggerConfigSystem, + breakSuppressionPreferenceSystem, joinAndQuitMessenger, elevatorSystem, blockLiquidStreamSystem, @@ -752,8 +752,8 @@ class SeichiAssist extends JavaPlugin() { implicit val gridRegionAPI: GridRegionAPI[IO, Player, Location] = gridRegionSystem.api implicit val breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player] = breakSkillTargetConfigSystem.api - implicit val breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player] = - breakSkillTriggerConfigSystem.api + implicit val breakSuppressionPreferenceAPI: BreakSuppressionPreferenceAPI[IO, Player] = + breakSuppressionPreferenceSystem.api implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] = playerHeadSkinSystem.api val menuRouter = TopLevelRouter.apply diff --git a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala index bf09b7cf13..18ed69bfbb 100644 --- a/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala +++ b/src/main/scala/com/github/unchama/seichiassist/listener/PlayerBlockBreakListener.scala @@ -12,7 +12,6 @@ import com.github.unchama.seichiassist.seichiskill.ActiveSkillRange.MultiArea import com.github.unchama.seichiassist.seichiskill.SeichiSkillUsageMode.Disabled import com.github.unchama.seichiassist.seichiskill.{BlockSearching, BreakArea} import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.SeichiExpAmount -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey import com.github.unchama.seichiassist.subsystems.mana.ManaApi import com.github.unchama.seichiassist.subsystems.mana.domain.ManaAmount import com.github.unchama.seichiassist.subsystems.minestack.MineStackAPI @@ -430,14 +429,14 @@ class PlayerBlockBreakListener( */ def isBreakBlockManaFullyConsumed(player: Player): IO[Boolean] = { for { - isBreakBlockManaFullyConsumed <- SeichiAssist + breakSuppressionPreference <- SeichiAssist .instance - .breakSkillTriggerConfigSystem + .breakSuppressionPreferenceSystem .api - .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + .isBreakSuppressionEnabled(player) _ <- ActionBarMessageEffect(s"${RED}マナ切れでブロック破壊を止めるスキルは有効化されています") .run(player) - .whenA(isBreakBlockManaFullyConsumed) - } yield isBreakBlockManaFullyConsumed + .whenA(breakSuppressionPreference) + } yield breakSuppressionPreference } } diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala b/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala index 7856db1575..d3180f98b2 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/TopLevelRouter.scala @@ -31,7 +31,7 @@ import com.github.unchama.seichiassist.subsystems.breakcount.BreakCountAPI import com.github.unchama.seichiassist.subsystems.breakcount.domain.SeichiAmountData import com.github.unchama.seichiassist.subsystems.breakcountbar.BreakCountBarAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.BreakSuppressionPreferenceAPI import com.github.unchama.seichiassist.subsystems.buildcount.domain.playerdata.BuildAmountData import com.github.unchama.seichiassist.subsystems.discordnotification.DiscordNotificationAPI import com.github.unchama.seichiassist.subsystems.donate.DonatePremiumPointAPI @@ -105,7 +105,7 @@ object TopLevelRouter { fairySpeechAPI: FairySpeechAPI[IO, Player], gridRegionAPI: GridRegionAPI[IO, Player, Location], breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player], - breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player], + breakSuppressionPreferenceAPI: BreakSuppressionPreferenceAPI[IO, Player], playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] ): TopLevelRouter[IO] = new TopLevelRouter[IO] { import assortedRankingApi._ diff --git a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala index 2bdb75b292..94aedca3d5 100644 --- a/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala +++ b/src/main/scala/com/github/unchama/seichiassist/menus/skill/PassiveSkillMenu.scala @@ -13,8 +13,8 @@ import com.github.unchama.seichiassist.menus.stickmenu.FirstPage import com.github.unchama.seichiassist.subsystems.breakcount.BreakCountAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.BreakSkillTargetConfigAPI import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.BreakSkillTargetConfigKey -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.BreakSkillTriggerConfigAPI -import com.github.unchama.seichiassist.subsystems.breakskilltriggerconfig.domain.BreakSkillTriggerConfigKey +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.BreakSuppressionPreferenceAPI +import com.github.unchama.seichiassist.subsystems.breaksuppressionpreference.domain.BreakSuppressionPreference import com.github.unchama.seichiassist.subsystems.playerheadskin.PlayerHeadSkinAPI import com.github.unchama.targetedeffect._ import com.github.unchama.targetedeffect.commandsender.MessageEffect @@ -36,7 +36,7 @@ object PassiveSkillMenu extends Menu { class Environment( implicit val breakCountApi: BreakCountAPI[IO, SyncIO, Player], implicit val breakSkillTargetConfigAPI: BreakSkillTargetConfigAPI[IO, Player], - implicit val breakSkillTriggerConfigAPI: BreakSkillTriggerConfigAPI[IO, Player], + implicit val breakSuppressionPreferenceAPI: BreakSuppressionPreferenceAPI[IO, Player], val ioCanOpenFirstPage: IO CanOpen FirstPage.type, implicit val playerHeadSkinAPI: PlayerHeadSkinAPI[IO, Player] ) @@ -236,8 +236,8 @@ object PassiveSkillMenu extends Menu { }) val computeToggleManaFullyConsumedBreakStopButton: IO[Button] = RecomputedButton(for { - originalBreakStopConfig <- breakSkillTriggerConfigAPI - .breakSkillTriggerConfig(player, BreakSkillTriggerConfigKey.ManaFullyConsumed) + originalBreakStopConfig <- breakSuppressionPreferenceAPI.isBreakSuppressionEnabled(player) + } yield { val baseLore = List(s"${YELLOW}マナ切れでブロック破壊を止めるスキル") val statusLore = if (originalBreakStopConfig) { @@ -257,9 +257,7 @@ object PassiveSkillMenu extends Menu { .build(), LeftClickButtonEffect { SequentialEffect( - breakSkillTriggerConfigAPI.toggleBreakSkillTriggerConfig( - BreakSkillTriggerConfigKey.ManaFullyConsumed - ), + breakSuppressionPreferenceAPI.toggleBreakSuppression, DeferredEffect(IO { if (!originalBreakStopConfig) { SequentialEffect( diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala index 84b327807e..f7b3016909 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/System.scala @@ -37,7 +37,7 @@ object System { new System[F, Player] { override val api: BreakSuppressionPreferenceAPI[F, Player] = new BreakSuppressionPreferenceAPI[F, Player] { - override def toggleBreakSuppressionPreference: Kleisli[F, Player, Unit] = + override def toggleBreakSuppression: Kleisli[F, Player, Unit] = Kleisli { player => ContextCoercion( breakSuppressionPreferenceRepository(player).update(pref => @@ -46,7 +46,7 @@ object System { ) } - override def getBreakSuppressionPreference(player: Player): F[Boolean] = + override def isBreakSuppressionEnabled(player: Player): F[Boolean] = ContextCoercion( breakSuppressionPreferenceRepository(player).get.map(_.doBreakSuppression) ) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala index 7f2f9fe95f..d0725622f4 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreference.scala @@ -19,5 +19,6 @@ object BreakSuppressionPreference { /** * [[BreakSuppressionPreference]]の初期値 */ - val initial: BreakSuppressionPreference = BreakSuppressionPreference(doBreakSuppression = false) + val initial: BreakSuppressionPreference = + BreakSuppressionPreference(doBreakSuppression = false) } diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala index b3df65533e..1b2810b0b2 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/domain/BreakSuppressionPreferencePersistence.scala @@ -4,4 +4,5 @@ import com.github.unchama.generic.RefDict import java.util.UUID -trait BreakSuppressionPreferenceConfigPersistence[F[_]] extends RefDict[F, UUID, BreakSuppressionPreference] +trait BreakSuppressionPreferencePersistence[F[_]] + extends RefDict[F, UUID, BreakSuppressionPreference] diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala index 1136424f26..e0d2bc9a0f 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/breaksuppressionpreference/infrastructure/JdbcBreakSuppressionPreferencePersistence.scala @@ -14,8 +14,8 @@ class JdbcBreakSuppressionPreferencePersistence[F[_]: Sync] override def read(key: UUID): F[Option[BreakSuppressionPreference]] = Sync[F].delay { val doBreakSuppression = DB.readOnly { implicit session => - sql"SELECT do_break_suppression FROM player_break_suppression_preference WHERE uuid = ${key.toString}" - .map(rs => rs.boolean("do_break_suppression")) + sql"SELECT do_break_suppression_due_to_mana FROM player_break_suppression_preference WHERE uuid = ${key.toString}" + .map(rs => rs.boolean("do_break_suppression_due_to_mana")) .single() } @@ -25,11 +25,11 @@ class JdbcBreakSuppressionPreferencePersistence[F[_]: Sync] override def write(key: UUID, value: BreakSuppressionPreference): F[Unit] = Sync[F].delay { DB.localTx { implicit session => val uuid = key.toString - sql"""INSERT INTO player_break_suppression_preference (uuid, player_break_suppression_preference) + sql"""INSERT INTO player_break_suppression_preference (uuid, do_break_suppression_due_to_mana) | VALUES ($uuid, ${value.doBreakSuppression}) | ON DUPLICATE KEY UPDATE - | do_break_suppression = VALUE(do_break_suppression) - """.stripMargin.update().apply() + | do_break_suppression_due_to_mana = VALUES(do_break_suppression_due_to_mana) + """.stripMargin.update() } } } From a10401e3899c64ec749a574e517c88211ff796db Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 22:01:28 +0900 Subject: [PATCH 24/26] =?UTF-8?q?fix:=20DB=E3=83=9E=E3=82=A4=E3=82=B0?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3SQL=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... => V1.19.0__Create_break_suppression_preference_table.sql} | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename src/main/resources/db/migration/{V1.19.0__Create_break_trigger_preference_table.sql => V1.19.0__Create_break_suppression_preference_table.sql} (56%) diff --git a/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql b/src/main/resources/db/migration/V1.19.0__Create_break_suppression_preference_table.sql similarity index 56% rename from src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql rename to src/main/resources/db/migration/V1.19.0__Create_break_suppression_preference_table.sql index 3ced2c8f23..6154fc19c8 100644 --- a/src/main/resources/db/migration/V1.19.0__Create_break_trigger_preference_table.sql +++ b/src/main/resources/db/migration/V1.19.0__Create_break_suppression_preference_table.sql @@ -3,5 +3,6 @@ USE seichiassist; CREATE TABLE player_break_suppression_preference( uuid CHAR(36) NOT NULL, do_break_suppression_due_to_mana BOOL NOT NULL DEFAULT FALSE, - FOREIGN KEY fk_player_break_suppression_preference_uuid REFERENCES playerdata(uuid) + PRIMARY KEY (uuid), + CONSTRAINT fk_player_break_suppression_preference_uuid FOREIGN KEY (uuid) REFERENCES playerdata(uuid) ); From 1680ffe2819412b79288e195a3bbc4057abe7206 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 22:36:28 +0900 Subject: [PATCH 25/26] =?UTF-8?q?fix:=20`tryConsume`=E3=81=AE=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subsystems/mana/domain/LevelCappedManaAmount.scala | 7 ------- .../seichiassist/subsystems/mana/domain/ManaAmount.scala | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala index 5abd116b5a..9e56b4d153 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/LevelCappedManaAmount.scala @@ -21,13 +21,6 @@ case class LevelCappedManaAmount private (manaAmount: ManaAmount, level: SeichiL )(manaMultiplier: ManaMultiplier): Option[LevelCappedManaAmount] = { manaAmount.tryUse(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) } - - def tryConsume( - amount: ManaAmount - )(manaMultiplier: ManaMultiplier): Option[LevelCappedManaAmount] = { - manaAmount.tryConsume(amount)(manaMultiplier).map(LevelCappedManaAmount(_, level)) - } - def withHigherLevelOption(newLevel: SeichiLevel): Option[LevelCappedManaAmount] = Option.when(newLevel > level)(LevelCappedManaAmount(manaAmount, newLevel).fillToCap) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala index d86abdd3f6..4744ed8501 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaAmount.scala @@ -12,13 +12,6 @@ case class ManaAmount(value: Double) { Option.when(resultingAmount >= 0.0)(ManaAmount(resultingAmount)) } - def tryConsume(amount: ManaAmount)(manaMultiplier: ManaMultiplier): Option[ManaAmount] = { - val resultingAmount = value - Option.when(resultingAmount >= amount.multiply(manaMultiplier.value).value)( - ManaAmount(resultingAmount) - ) - } - def multiply(rate: Double): ManaAmount = { require(rate >= 0.0, "マナ量乗算の倍率は非負である必要があります") ManaAmount(rate * value) From 95d772f6f1dd1796704302d10974cc68605d7317 Mon Sep 17 00:00:00 2001 From: kuroma6666 Date: Sat, 14 Dec 2024 22:36:49 +0900 Subject: [PATCH 26/26] =?UTF-8?q?fix:=20`canAcuire`=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subsystems/mana/domain/ManaManipulation.scala | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala index 020a0efc81..67e818eb29 100644 --- a/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala +++ b/src/main/scala/com/github/unchama/seichiassist/subsystems/mana/domain/ManaManipulation.scala @@ -60,14 +60,10 @@ object ManaManipulation { } } override def canAcquire(amount: ManaAmount): F[Boolean] = { - dragonNightTimeMultiplierRef.get.flatMap { multiplier => - ref.modify { original => - original.tryConsume(amount)(multiplier) match { - case Some(reduced) => (reduced, true) - case None => (original, false) - } - } - } + for { + multiplier <- dragonNightTimeMultiplierRef.get + original <- ref.get + } yield original.tryUse(amount)(multiplier).isDefined } }