Skip to content

Commit

Permalink
Merge pull request #854 from Lucky3028/fix/#174
Browse files Browse the repository at this point in the history
毎年日付が変わる祝日の実績の日付が実際の日付とずれるのを修正
  • Loading branch information
kory33 authored Jul 20, 2021
2 parents 0399571 + 5742c3b commit a51436b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cats.effect.IO
import com.github.unchama.buildassist.BuildAssist
import com.github.unchama.seichiassist.SeichiAssist
import com.github.unchama.seichiassist.data.player.PlayerData
import com.github.unchama.seichiassist.achievement.NamedHoliday._
import com.github.unchama.seichiassist.subsystems.breakcount.domain.level.SeichiExpAmount
import org.bukkit.Material
import org.bukkit.entity.Player
Expand All @@ -13,6 +14,7 @@ import org.bukkit.inventory.meta.SkullMeta
import java.time.temporal.TemporalAdjusters
import java.time.{DayOfWeek, LocalDate, LocalTime, Month}
import scala.concurrent.duration.FiniteDuration
import scala.math.floor

object AchievementConditions {
def playerDataPredicate(predicate: PlayerData => IO[Boolean]): PlayerPredicate = { player =>
Expand Down Expand Up @@ -124,6 +126,18 @@ object AchievementConditions {
AchievementCondition(predicate, _ + "にプレイ", dateSpecification)
}

def playedOn(holiday: NamedHoliday): AchievementCondition[String] = {
val predicate: PlayerPredicate = _ =>
IO{
val now = LocalDate.now()
val target = holiday.dateOn(now.getYear)

now.getMonth == target.getMonth && now.getDayOfMonth == target.getDayOfMonth
}

AchievementCondition(predicate, _ + "にプレイ", holiday.name)
}

object SecretAchievementConditions {
val conditionFor8001: HiddenAchievementCondition[Unit] = {
val shouldDisplay: PlayerPredicate = { _ =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.unchama.seichiassist.achievement

import java.time.{LocalDate, Month}

import enumeratum._

import scala.math.floor

/**
* 年によって日付が変わってしまうので、各年ごとに計算が必要な日の列挙
*/
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("春分の日") {
override def dateOn(year: Int): LocalDate = {
val dayOfMonth = floor(20.8431 + 0.242194 * (year - 1980) - (year - 1980) / 4).toInt

LocalDate.of(year, Month.MARCH, dayOfMonth)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(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, "とある良い子の日"))
Expand All @@ -220,7 +221,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, "七夕"))
Expand Down

0 comments on commit a51436b

Please sign in to comment.