Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 整地報酬ガチャ券受取ボタンに右クリックして1スタックだけ引き出せるようにする機能を追加 #2371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fd03f11
feat: 整地報酬ガチャ券受取について右クリック用の受取バッチ処理を追加
kuroma6666 Sep 1, 2024
73249fc
feat: 整地報酬ガチャ券受取ボタンの右クリック対応
kuroma6666 Sep 1, 2024
a2298a5
update: 整地報酬ガチャ券受取ボタンのガチャ券受取枚数について説明を追加
kuroma6666 Sep 1, 2024
6feb27c
chore: コメント微修正
kuroma6666 Sep 1, 2024
47dfbe2
fix: バッチ命名の修正 RightClick->OneStack
kuroma6666 Sep 1, 2024
33f852c
fix: 引数名省略
kuroma6666 Sep 1, 2024
7143d2f
chore: ボタンlore微修正
kuroma6666 Sep 1, 2024
bfafc88
fix: Batchで扱うガチャポイントの数を明確にするよう修正
kuroma6666 Sep 2, 2024
ac1ba33
fix: 整地報酬ガチャ券受取変数名について省略をしないよう修正 recv->receive
kuroma6666 Sep 2, 2024
5316bd6
fix: 引数名の省略
kuroma6666 Sep 3, 2024
bba87bd
docs: BatchSizeのコメントを変更
kuroma6666 Sep 3, 2024
7c3fa7b
add: ガチャ券へのポイント交換にて一度に得られるガチャ券の上限変数を追加
kuroma6666 Sep 3, 2024
4d6cb2a
docs: 使うバッチ名をコメントへ明記した
kuroma6666 Sep 3, 2024
2b6abc6
fix: useInBatch関数を定義し、`useInLargeBatch` と `useInSmallBatch`について書き換え
kuroma6666 Sep 3, 2024
65b83ae
fix; `BatchSize`型の定義とLarge/SmallBatchSizeを`BatchSize`型とする
kuroma6666 Sep 3, 2024
2823cb8
fix: コンパイルエラー修正
kuroma6666 Sep 3, 2024
9ca46ed
fix: コンパイルエラー修正
kuroma6666 Sep 3, 2024
fe735f9
fix: effect名の修正
kuroma6666 Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import com.github.unchama.menuinventory.router.CanOpen
import com.github.unchama.menuinventory.slot.button.action.{
ClickEventFilter,
FilteredButtonEffect,
LeftClickButtonEffect
LeftClickButtonEffect,
RightClickButtonEffect
}
import com.github.unchama.menuinventory.slot.button.{Button, RecomputedButton, action}
import com.github.unchama.seichiassist.data.descrptions.PlayerStatsLoreGenerator
Expand Down Expand Up @@ -519,8 +520,11 @@ object FirstPage extends Menu {
}

val computeGachaTicketButton: IO[Button] = {
val effect: FilteredButtonEffect = LeftClickButtonEffect(
environment.gachaPointApi.receiveBatch
val leftClickEffect: FilteredButtonEffect = LeftClickButtonEffect(
environment.gachaPointApi.receiveLargeBatch
)
val rightClickEffect: FilteredButtonEffect = RightClickButtonEffect(
environment.gachaPointApi.receiveSmallBatch
)

val computeItemStack: IO[ItemStack] =
Expand All @@ -534,8 +538,10 @@ object FirstPage extends Menu {

val requiredToNextTicket =
s"$RESET${AQUA}次のガチャ券まで:${point.amountUntilNextGachaTicket.amount}ブロック"
val receiveGachaTicketDescription =
s"$RESET${GRAY}左クリックで最大9st、右クリックで最大1stのガチャ券を受け取ります"

List(gachaTicketStatus, requiredToNextTicket)
List(gachaTicketStatus, requiredToNextTicket, receiveGachaTicketDescription)
}

new SkullItemStackBuilder(SkullOwners.unchama)
Expand All @@ -545,7 +551,7 @@ object FirstPage extends Menu {
}

val computeButton: IO[Button] = computeItemStack.map { itemStack =>
Button(itemStack, effect)
Button(itemStack, leftClickEffect, rightClickEffect)
}

RecomputedButton(computeButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ trait GachaPointApi[F[_], G[_], Player] {
/**
* プレーヤーのガチャポイントをガチャ券に変換して一括で受け取る作用。
*/
val receiveBatch: Kleisli[F, Player, Unit]
val receiveLargeBatch: Kleisli[F, Player, Unit]

/**
* プレーヤーのガチャポイントをガチャ券に変換して一括で受け取る作用。
*/
val receiveSmallBatch: Kleisli[F, Player, Unit]

/**
* プレーヤーのガチャポイントを増やす作用。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ object System {
ReadOnlyRef.fromRef(value.pointRef)
)

override val receiveBatch: Kleisli[F, Player, Unit] = Kleisli { player =>
override val receiveLargeBatch: Kleisli[F, Player, Unit] = Kleisli { player =>
gachaPointRepositoryControlsRepository
.lift(player)
.traverse { value => value.semaphore.tryBatchTransaction }
.as(())
.traverse { _.semaphore.tryLargeBatchTransaction }
.void
}

override val receiveSmallBatch: Kleisli[F, Player, Unit] = Kleisli { player =>
gachaPointRepositoryControlsRepository
.lift(player)
.traverse { _.semaphore.trySmallBatchTransaction }
.void
}

override def addGachaPoint(point: GachaPoint): Kleisli[F, Player, Unit] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ class BatchUsageSemaphore[F[_]: FlatMap, G[_]: ContextCoercion[*[_], F]](
import cats.implicits._

/**
* バッチでのガチャポイント変換を行い、 [[BatchUsageSemaphore.usageInterval]]の間使用不可にする作用。
* 576個(= 64 * 9スタック)のバッチでガチャポイント変換を行い、 [[BatchUsageSemaphore.usageInterval]]の間使用不可にする作用。
*/
def tryBatchTransaction: F[Unit] =
def tryLargeBatchTransaction: F[Unit] =
recoveringSemaphore.tryUse {
ContextCoercion {
gachaPointRef.modify { point => point.useInBatch.asTuple }
gachaPointRef.modify { _.useInLargeBatch.asTuple }
}.flatTap(grantAction.give)
}(BatchUsageSemaphore.usageInterval)

/**
* 64個(= 64 * 1スタック)のバッチでガチャポイント変換を行い、 [[BatchUsageSemaphore.usageInterval]]の間使用不可にする作用。
*/
def trySmallBatchTransaction: F[Unit] =
kuroma6666 marked this conversation as resolved.
Show resolved Hide resolved
recoveringSemaphore.tryUse {
ContextCoercion {
gachaPointRef.modify { _.useInSmallBatch.asTuple }
}.flatTap(grantAction.give)
}(BatchUsageSemaphore.usageInterval)

}

object BatchUsageSemaphore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.Seichi
/**
* ガチャポイントとはプレーヤーが持つ「消費可能な整地経験量」である。
*
* プレーヤーは576個(= 64 * 9スタック)のバッチにてガチャポイントをガチャ券に交換できる。
* プレーヤーは576個(= 64 * 9スタック)のバッチもしくは、64個(1スタック)のバッチにてガチャポイントをガチャ券に交換できる。
*/
case class GachaPoint(exp: SeichiExpAmount) {

Expand All @@ -18,15 +18,25 @@ case class GachaPoint(exp: SeichiExpAmount) {
/**
* ガチャポイントをバッチでガチャ券に変換した際のポイントの変化を計算する。
*/
lazy val useInBatch: GachaPoint.Usage = {
val ticketCount = availableTickets.min(GachaPoint.batchSize).toInt
private def useInBatch(batchSize: BatchSize): GachaPoint.Usage = {
val ticketCount = availableTickets.min(batchSize.value).toInt

val expToUse = GachaPoint.perGachaTicket.exp.amount * ticketCount
val remaining = GachaPoint.ofNonNegative(exp.amount - expToUse)

GachaPoint.Usage(remaining, ticketCount)
}

/**
* ガチャポイントを576個(= 64 * 9スタック)のバッチでガチャ券に変換した際のポイントの変化を計算する。
*/
lazy val useInLargeBatch: GachaPoint.Usage = useInBatch(GachaPoint.largeBatchSize)

/**
* ガチャポイントを64個(= 64 * 1スタック)のバッチでガチャ券に変換した際のポイントの変化を計算する。
*/
lazy val useInSmallBatch: GachaPoint.Usage = useInBatch(GachaPoint.smallBatchSize)

/**
* 次にガチャ券を利用できるようになるまでに必要な整地経験値量
*/
Expand All @@ -42,6 +52,10 @@ case class GachaPoint(exp: SeichiExpAmount) {
def subtract(point: GachaPoint): GachaPoint = GachaPoint(exp.subtract(point.exp))
}

case class BatchSize(value: Int) {
require(value > 0, "batch size must be positive")
}

object GachaPoint {

def ofNonNegative(x: BigDecimal): GachaPoint = GachaPoint(SeichiExpAmount.ofNonNegative(x))
Expand All @@ -54,15 +68,25 @@ object GachaPoint {
* 変換にて得られるガチャ券の総数
*/
case class Usage(remainingGachaPoint: GachaPoint, gachaTicketCount: Int) {
require(gachaTicketCount <= GachaPoint.batchSize, "usage must not exceed batch size")
require(gachaTicketCount <= GachaPoint.maxBatchSize.value, "usage must not exceed max batch size")

def asTuple: (GachaPoint, Int) = (remainingGachaPoint, gachaTicketCount)
}

/**
* ガチャ券を576個(= 64 * 9スタック)のバッチでガチャポイントに変換する際のバッチサイズ
*/
final val largeBatchSize = BatchSize(9 * 64)

/**
* ガチャ券を64個(= 64 * 1スタック)のバッチでガチャポイントに変換する際のバッチサイズ
*/
final val smallBatchSize = BatchSize(64)

/**
* ガチャ券へのポイント交換にて一度に得られるガチャ券の上限
*/
final val batchSize = 9 * 64
final val maxBatchSize = largeBatchSize

/**
* ガチャポイントの初期値
Expand All @@ -86,3 +110,4 @@ object GachaPoint {
ofNonNegative(perGachaTicketPoint * gachaTicketAmount)

}