Skip to content

Commit

Permalink
Merge pull request #1848 from GiganticMinecraft/fix/canNotGetSignedGa…
Browse files Browse the repository at this point in the history
…chaPrize

マインスタックから取り出したGT等の名義品アイテムに名義がない不具合を修正
  • Loading branch information
Lucky3028 authored Jan 31, 2023
2 parents aaf18e5 + 7a901da commit 66fbeba
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ class BlockLineUpTriggerListener[

val mineStackObjectToBeUsed =
if (buildAssistData.line_up_minestack_flg == 1) {
mineStackAPI.mineStackObjectList.findByItemStack(mainHandItem, player).unsafeRunSync()
mineStackAPI
.mineStackObjectList
.findBySignedItemStack(mainHandItem, player)
.unsafeRunSync()
} else None

val maxBlockUsage = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TilingSkillTriggerListener[G[_]: ConcurrentEffect, F[
val minestackObjectToUse =
mineStackAPI
.mineStackObjectList
.findByItemStack(offHandItem, player)
.findBySignedItemStack(offHandItem, player)
.toIO
.unsafeRunSync()
.filter(_ => buildAssistPlayerData.zs_minestack_flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,22 @@ trait GachaPrizeReadAPI[F[_], ItemStack] {
def staticGachaPrizeFactory: StaticGachaPrizeFactory[ItemStack]

/**
* @param itemStack 記名されている[[ItemStack]]
* @return 通常排出ガチャ景品の中から`name`が記名された`itemStack`に一致する[[GachaPrize]]を取得する作用
*/
def findOfRegularPrizesByItemStack(
def findOfRegularPrizesBySignedItemStack(
itemStack: ItemStack,
name: String
): F[Option[GachaPrize[ItemStack]]]

/**
* @param itemStack 記名されていない[[ItemStack]]
* @return 通常排出ガチャ景品の中から、記名されてない`itemStack`に一致する[[GachaPrize]]を取得する作用
*/
def findOfRegularGachaPrizesByNotSignedItemStack(
itemStack: ItemStack
): F[Option[GachaPrize[ItemStack]]]

/**
* @return [[CanBeSignedAsGachaPrize]]を返す
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,27 @@ object System {
override def canBeSignedAsGachaPrize: CanBeSignedAsGachaPrize[ItemStack] =
_canBeSignedAsGachaPrize

override def findOfRegularPrizesByItemStack(
override def findOfRegularPrizesBySignedItemStack(
itemStack: ItemStack,
name: String
): F[Option[GachaPrize[ItemStack]]] = for {
prizes <- allGachaPrizesListReference.get
defaultGachaPrizes = prizes.filter(_.gachaEventName.isEmpty)
} yield defaultGachaPrizes.find { gachaPrize =>
if (gachaPrize.signOwner)
if (gachaPrize.signOwner) {
gachaPrize.materializeWithOwnerSignature(name).isSimilar(itemStack)
else
} else {
gachaPrize.itemStack.isSimilar(itemStack)
}
}

override def findOfRegularGachaPrizesByNotSignedItemStack(
itemStack: ItemStack
): F[Option[GachaPrize[ItemStack]]] = for {
prizes <- allGachaPrizesListReference.get
defaultGachaPrizes = prizes.filter(_.gachaEventName.isEmpty)
} yield defaultGachaPrizes.find { gachaPrize =>
gachaPrize.itemStack.isSimilar(itemStack)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,11 @@ class BukkitMineStackObjectList[F[_]: Sync](
allMineStackGroups.map(_.filter { group => categoryOf(group) == category })
}

override def findByItemStack(
override def findBySignedItemStack(
itemStack: ItemStack,
player: Player
): F[Option[MineStackObject[ItemStack]]] = for {
foundGachaPrizeOpt <- gachaPrizeAPI.findOfRegularPrizesByItemStack(
foundGachaPrizeOpt <- gachaPrizeAPI.findOfRegularPrizesBySignedItemStack(
itemStack,
player.getName
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BukkitMineStackRepository[F[_]: Sync](

override def tryIntoMineStack(player: Player, itemStack: ItemStack, amount: Int): F[Boolean] =
for {
foundMineStackObject <- mineStackObjectList.findByItemStack(itemStack, player)
foundMineStackObject <- mineStackObjectList.findBySignedItemStack(itemStack, player)
_ <- foundMineStackObject.traverse(addStackedAmountOf(player, _, amount))
} yield foundMineStackObject.isDefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ case class MineStackObject[ItemStack: Cloneable](
name: String
)(implicit gachaPrizeAPI: GachaPrizeAPI[F, ItemStack, Player]): F[Option[ItemStack]] = {
if (category != MineStackObjectCategory.GACHA_PRIZES) return Sync[F].pure(None)
println("gachaPrize")

implicit val canBeSignedAsGachaPrize: CanBeSignedAsGachaPrize[ItemStack] =
gachaPrizeAPI.canBeSignedAsGachaPrize

for {
foundGachaPrize <- gachaPrizeAPI.findOfRegularPrizesByItemStack(itemStack, name)
} yield foundGachaPrize.map { gachaPrize => gachaPrize.materializeWithOwnerSignature(name) }
foundGachaPrize <- gachaPrizeAPI.findOfRegularGachaPrizesByNotSignedItemStack(itemStack)
} yield {
println(s"foundGachaPrize: ${foundGachaPrize.isDefined}")
foundGachaPrize.map { gachaPrize => gachaPrize.materializeWithOwnerSignature(name) }
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ trait MineStackObjectList[F[_], ItemStack, Player] {
def allMineStackObjects: F[Vector[MineStackObject[ItemStack]]]

/**
* @param itemStack 記名することのできるアイテムは、既に記名されていることを想定している
* @return [[ItemStack]]から[[MineStackObject]]を取得しようとする作用
*/
def findByItemStack(
def findBySignedItemStack(
itemStack: ItemStack,
player: Player
): F[Option[MineStackObject[ItemStack]]]
Expand Down

0 comments on commit 66fbeba

Please sign in to comment.