From 32a915c0c7692dd6974ec4fe423332a867c28c2f Mon Sep 17 00:00:00 2001 From: Lucky3028 Date: Fri, 25 Dec 2020 11:22:37 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[Fix]=20=E7=88=B6=E3=81=AE=E6=97=A5?= =?UTF-8?q?=E3=81=AF=E6=AF=8E=E5=B9=B46=E6=9C=88=E3=81=AE=E7=AC=AC3?= =?UTF-8?q?=E6=97=A5=E6=9B=9C=E6=97=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unchama/seichiassist/achievement/SeichiAchievement.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala index 7da99dc4a5..f6f5ccf642 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala @@ -220,7 +220,7 @@ object SeichiAchievement extends Enum[SeichiAchievement] { case object No_9020 extends NormalManual(9020, playedOn(Month.MAY, 2, DayOfWeek.SUNDAY, "母の日")) case object No_9021 extends NormalManual(9021, playedIn(Month.JUNE)) case object No_9022 extends NormalManual(9022, playedOn(Month.JUNE, 12, "とある日記の日")) - case object No_9023 extends NormalManual(9023, playedOn(Month.JUNE, 17, "父の日")) + case object No_9023 extends NormalManual(9023, playedOn(Month.JUNE, 3, DayOfWeek.SUNDAY, "父の日")) case object No_9024 extends NormalManual(9024, playedOn(Month.JUNE, 29, "とある生誕の日")) case object No_9025 extends NormalManual(9025, playedIn(Month.JULY)) case object No_9026 extends NormalManual(9026, playedOn(Month.JULY, 7, "七夕")) From 3473b429d4fe319360625b773fa9b1313091d427 Mon Sep 17 00:00:00 2001 From: Lucky3028 Date: Fri, 25 Dec 2020 13:50:12 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[Fix]=20=E6=98=A5=E5=88=86=E3=81=AE?= =?UTF-8?q?=E6=97=A5=E3=82=92=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=AB=E8=A8=88?= =?UTF-8?q?=E7=AE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../achievement/AchievementConditions.scala | 20 +++++++++++++++++++ .../NeedToBeCalculatedOfWhen.scala | 5 +++++ .../achievement/SeichiAchievement.scala | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala index e4c3ae9bbe..0ef61b69be 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.SkullMeta import scala.concurrent.duration.FiniteDuration +import scala.math.floor object AchievementConditions { def playerDataPredicate(predicate: PlayerData => IO[Boolean]): PlayerPredicate = { player => @@ -101,6 +102,25 @@ object AchievementConditions { AchievementCondition(predicate, _ + "にプレイ", dateSpecification) } + def playedOn(day: NeedToBeCalculatedOfWhen, dateSpecification: String): AchievementCondition[String] = { + val predicate: PlayerPredicate = _ => + IO{ + val now = LocalDate.now() + + val dayOfMonth = floor(day match { + case SpringEquinoxDay => 20.8431 + 0.242194 * (now.getYear - 1980) - (now.getYear - 1980) / 4 + }).toInt + + val month = day match { + case SpringEquinoxDay => Month.MARCH + } + + now.getMonth == month && now.getDayOfMonth == dayOfMonth + } + + AchievementCondition(predicate, _ + "にプレイ", dateSpecification) + } + object SecretAchievementConditions { val conditionFor8001: HiddenAchievementCondition[Unit] = { val shouldDisplay: PlayerPredicate = { _ => diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala new file mode 100644 index 0000000000..6d88ba23ba --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala @@ -0,0 +1,5 @@ +package com.github.unchama.seichiassist.achievement + +sealed trait NeedToBeCalculatedOfWhen + +case object SpringEquinoxDay extends NeedToBeCalculatedOfWhen diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala index f6f5ccf642..5abfa50e60 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala @@ -209,7 +209,7 @@ object SeichiAchievement extends Enum[SeichiAchievement] { case object No_9009 extends NormalManual(9009, playedIn(Month.MARCH)) case object No_9010 extends NormalManual(9010, playedOn(Month.MARCH, 3, "とある女の子の日")) case object No_9011 extends NormalManual(9011, playedOn(Month.MARCH, 14, "燃え尽きたカカオだらけの日")) - case object No_9012 extends NormalManual(9012, playedOn(Month.MARCH, 20, "春分の日")) + case object No_9012 extends NormalManual(9012, playedOn(SpringEquinoxDay, "春分の日")) case object No_9013 extends NormalManual(9013, playedIn(Month.APRIL)) case object No_9014 extends NormalManual(9014, playedOn(Month.APRIL, 1, "とある嘘の日")) case object No_9015 extends NormalManual(9015, playedOn(Month.APRIL, 15, "とある良い子の日")) From 1538b3787d759ea8f50f5ed9610634d552b98001 Mon Sep 17 00:00:00 2001 From: Lucky3028 Date: Wed, 30 Dec 2020 15:43:34 +0900 Subject: [PATCH 3/5] [Change] NeedToBeCalculatedOfWhen -> NamedHoliday --- .../seichiassist/achievement/AchievementConditions.scala | 2 +- .../unchama/seichiassist/achievement/NamedHoliday.scala | 8 ++++++++ .../achievement/NeedToBeCalculatedOfWhen.scala | 5 ----- 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala delete mode 100644 src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala index 0ef61b69be..3dc3100ad1 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala @@ -102,7 +102,7 @@ object AchievementConditions { AchievementCondition(predicate, _ + "にプレイ", dateSpecification) } - def playedOn(day: NeedToBeCalculatedOfWhen, dateSpecification: String): AchievementCondition[String] = { + def playedOn(day: NamedHoliday, dateSpecification: String): AchievementCondition[String] = { val predicate: PlayerPredicate = _ => IO{ val now = LocalDate.now() diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala new file mode 100644 index 0000000000..47e06404a7 --- /dev/null +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala @@ -0,0 +1,8 @@ +package com.github.unchama.seichiassist.achievement + +/** + * 年によって日付が変わってしまうので、各年ごとに計算が必要な日の列挙 + */ +sealed trait NamedHoliday + +case object SpringEquinoxDay extends NamedHoliday diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala deleted file mode 100644 index 6d88ba23ba..0000000000 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/NeedToBeCalculatedOfWhen.scala +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.unchama.seichiassist.achievement - -sealed trait NeedToBeCalculatedOfWhen - -case object SpringEquinoxDay extends NeedToBeCalculatedOfWhen From 73485fdda7928498a19e55c3ff747056d3a4cca9 Mon Sep 17 00:00:00 2001 From: Lucky3028 Date: Wed, 30 Dec 2020 16:39:22 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[Move]=20Enum=E3=81=AB=E5=AF=BE=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=9D=E3=81=AE=E6=97=A5=E3=81=8C=E3=81=84=E3=81=A4?= =?UTF-8?q?=E3=81=8B=E3=81=AA=E3=81=A9=E3=81=AE=E8=A8=88=E7=AE=97=E3=82=92?= =?UTF-8?q?=E7=A7=BB=E5=8B=95=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../achievement/AchievementConditions.scala | 15 +++-------- .../achievement/NamedHoliday.scala | 25 +++++++++++++++++-- .../achievement/SeichiAchievement.scala | 3 ++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala index 3dc3100ad1..8db2160cbe 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala @@ -6,6 +6,7 @@ import java.time.{DayOfWeek, LocalDate, LocalTime, Month} import cats.effect.IO import com.github.unchama.seichiassist.SeichiAssist import com.github.unchama.seichiassist.data.player.PlayerData +import com.github.unchama.seichiassist.achievement.NamedHoliday._ import org.bukkit.Material import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.SkullMeta @@ -102,23 +103,15 @@ object AchievementConditions { AchievementCondition(predicate, _ + "にプレイ", dateSpecification) } - def playedOn(day: NamedHoliday, dateSpecification: String): AchievementCondition[String] = { + def playedOn(day: NamedHoliday): AchievementCondition[String] = { val predicate: PlayerPredicate = _ => IO{ val now = LocalDate.now() - val dayOfMonth = floor(day match { - case SpringEquinoxDay => 20.8431 + 0.242194 * (now.getYear - 1980) - (now.getYear - 1980) / 4 - }).toInt - - val month = day match { - case SpringEquinoxDay => Month.MARCH - } - - now.getMonth == month && now.getDayOfMonth == dayOfMonth + now.getMonth == day.month && now.getDayOfMonth == day.getDayOfMonth() } - AchievementCondition(predicate, _ + "にプレイ", dateSpecification) + AchievementCondition(predicate, _ + "にプレイ", day.name) } object SecretAchievementConditions { diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala index 47e06404a7..b07ea26a7d 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala @@ -1,8 +1,29 @@ package com.github.unchama.seichiassist.achievement +import java.time.{LocalDate, Month} + +import enumeratum._ + +import scala.math.floor + /** * 年によって日付が変わってしまうので、各年ごとに計算が必要な日の列挙 */ -sealed trait NamedHoliday +sealed class NamedHoliday(val month: Month, val name: String) extends EnumEntry + +case object NamedHoliday extends Enum[NamedHoliday] { + val values: IndexedSeq[NamedHoliday] = findValues + + case object SpringEquinoxDay extends NamedHoliday(Month.MARCH, "春分の日") + + implicit class NamedHolidayOps(val holiday: NamedHoliday) extends AnyVal { + def getDayOfMonth(): Int = { + val year = LocalDate.now().getYear -case object SpringEquinoxDay extends NamedHoliday + floor(holiday match { + // 春分の日の計算方法:[[http://hp.vector.co.jp/authors/VA006522/zatugaku/syunbun.txt]] + case SpringEquinoxDay => 20.8431 + 0.242194 * (year - 1980) - (year - 1980) / 4 + }).toInt + } + } +} diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala index 5abfa50e60..acc38dc5fb 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/SeichiAchievement.scala @@ -3,6 +3,7 @@ package com.github.unchama.seichiassist.achievement import java.time.{DayOfWeek, Month} import cats.effect.IO +import com.github.unchama.seichiassist.achievement.NamedHoliday.SpringEquinoxDay import enumeratum.{Enum, EnumEntry} import org.bukkit.entity.Player @@ -209,7 +210,7 @@ object SeichiAchievement extends Enum[SeichiAchievement] { case object No_9009 extends NormalManual(9009, playedIn(Month.MARCH)) case object No_9010 extends NormalManual(9010, playedOn(Month.MARCH, 3, "とある女の子の日")) case object No_9011 extends NormalManual(9011, playedOn(Month.MARCH, 14, "燃え尽きたカカオだらけの日")) - case object No_9012 extends NormalManual(9012, playedOn(SpringEquinoxDay, "春分の日")) + case object No_9012 extends NormalManual(9012, playedOn(SpringEquinoxDay)) case object No_9013 extends NormalManual(9013, playedIn(Month.APRIL)) case object No_9014 extends NormalManual(9014, playedOn(Month.APRIL, 1, "とある嘘の日")) case object No_9015 extends NormalManual(9015, playedOn(Month.APRIL, 15, "とある良い子の日")) From 5742c3bc41fe998877027114957155b4c3e93b4b Mon Sep 17 00:00:00 2001 From: Kory <6561358+kory33@users.noreply.github.com> Date: Wed, 21 Jul 2021 04:40:04 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[clean]=20NamedHoliday=E3=82=92=E7=B4=94?= =?UTF-8?q?=E7=B2=8B=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../achievement/AchievementConditions.scala | 7 ++++--- .../seichiassist/achievement/NamedHoliday.scala | 17 +++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala index ac34237c16..03bbce54cf 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/AchievementConditions.scala @@ -125,15 +125,16 @@ object AchievementConditions { AchievementCondition(predicate, _ + "にプレイ", dateSpecification) } - def playedOn(day: NamedHoliday): AchievementCondition[String] = { + def playedOn(holiday: NamedHoliday): AchievementCondition[String] = { val predicate: PlayerPredicate = _ => IO{ val now = LocalDate.now() + val target = holiday.dateOn(now.getYear) - now.getMonth == day.month && now.getDayOfMonth == day.getDayOfMonth() + now.getMonth == target.getMonth && now.getDayOfMonth == target.getDayOfMonth } - AchievementCondition(predicate, _ + "にプレイ", day.name) + AchievementCondition(predicate, _ + "にプレイ", holiday.name) } object SecretAchievementConditions { diff --git a/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala index b07ea26a7d..aa5caba30f 100644 --- a/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala +++ b/src/main/scala/com/github/unchama/seichiassist/achievement/NamedHoliday.scala @@ -9,21 +9,18 @@ import scala.math.floor /** * 年によって日付が変わってしまうので、各年ごとに計算が必要な日の列挙 */ -sealed class NamedHoliday(val month: Month, val name: String) extends EnumEntry +sealed abstract class NamedHoliday(val name: String) extends EnumEntry { + def dateOn(year: Int): LocalDate +} case object NamedHoliday extends Enum[NamedHoliday] { val values: IndexedSeq[NamedHoliday] = findValues - case object SpringEquinoxDay extends NamedHoliday(Month.MARCH, "春分の日") - - implicit class NamedHolidayOps(val holiday: NamedHoliday) extends AnyVal { - def getDayOfMonth(): Int = { - val year = LocalDate.now().getYear + case object SpringEquinoxDay extends NamedHoliday("春分の日") { + override def dateOn(year: Int): LocalDate = { + val dayOfMonth = floor(20.8431 + 0.242194 * (year - 1980) - (year - 1980) / 4).toInt - floor(holiday match { - // 春分の日の計算方法:[[http://hp.vector.co.jp/authors/VA006522/zatugaku/syunbun.txt]] - case SpringEquinoxDay => 20.8431 + 0.242194 * (year - 1980) - (year - 1980) / 4 - }).toInt + LocalDate.of(year, Month.MARCH, dayOfMonth) } } }