mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
feat: Cycle simulation (simulate cycles if beyond a single set)
This commit is contained in:
@@ -119,9 +119,9 @@
|
|||||||
],
|
],
|
||||||
"Database": {
|
"Database": {
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
"Port": 5432,
|
"Port": 5433,
|
||||||
"User": "postgres",
|
"User": "postgres",
|
||||||
"Password": "",
|
"Password": "admin",
|
||||||
"Database": "erupe"
|
"Database": "erupe"
|
||||||
},
|
},
|
||||||
"Sign": {
|
"Sign": {
|
||||||
|
|||||||
@@ -190,6 +190,14 @@ func makeEventQuest(s *Session, rows *sql.Rows) ([]byte, error) {
|
|||||||
return bf.Data(), nil
|
return bf.Data(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func calculateNumberOfCycles(duration time.Duration, lastStartTime time.Time) int {
|
||||||
|
timeDifference := time.Now().Sub(lastStartTime)
|
||||||
|
println(timeDifference.String())
|
||||||
|
println(float64(duration))
|
||||||
|
numberOfCycles := int(timeDifference.Nanoseconds() / int64(duration))
|
||||||
|
return numberOfCycles
|
||||||
|
}
|
||||||
|
|
||||||
func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
|
func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
|
||||||
pkt := p.(*mhfpacket.MsgMhfEnumerateQuest)
|
pkt := p.(*mhfpacket.MsgMhfEnumerateQuest)
|
||||||
var totalCount, returnedCount uint16
|
var totalCount, returnedCount uint16
|
||||||
@@ -219,14 +227,22 @@ func handleMsgMhfEnumerateQuest(s *Session, p mhfpacket.MHFPacket) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Count the number of cycles necessary to align quest with actual time.
|
||||||
|
cycleCount := calculateNumberOfCycles(time.Duration(activeDuration+inactiveDuration)*24*time.Hour, startTime)
|
||||||
|
|
||||||
// Calculate the rotation time based on start time, active duration, and inactive duration
|
// Calculate the rotation time based on start time, active duration, and inactive duration
|
||||||
rotationTime := startTime.Add((time.Duration(activeDuration+inactiveDuration) * 24) * time.Hour)
|
rotationTime := startTime.Add(time.Duration(activeDuration+inactiveDuration) * 24 * time.Duration(cycleCount) * time.Hour)
|
||||||
if currentTime.After(rotationTime) {
|
if currentTime.After(rotationTime) {
|
||||||
// The rotation time has passed, update the start time and reset the rotation
|
// take the rotationTime and normalize it to midnight
|
||||||
_, err := transaction.Exec("UPDATE event_quests SET start_time = $1 WHERE id = $2", rotationTime, id)
|
newRotationTime := time.Date(rotationTime.Year(), rotationTime.Month(), rotationTime.Day(), 0, 0, 0, 0, rotationTime.Location())
|
||||||
|
newRotationTime = newRotationTime.Add(time.Duration(TimeMidnight().Add(13 * time.Hour).Nanosecond()))
|
||||||
|
|
||||||
|
_, err := transaction.Exec("UPDATE event_quests SET start_time = $1 WHERE id = $2", newRotationTime, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
transaction.Rollback() // Rollback if an error occurs
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
startTime = newRotationTime // Set the new start time so the quest can be used immediatelyw
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the quest is currently active
|
// Check if the quest is currently active
|
||||||
|
|||||||
Reference in New Issue
Block a user