Merge pull request #1 from matthe815/seasons

Feature: Dynamic Seasons
This commit is contained in:
Matthew
2023-07-05 19:35:06 -04:00
committed by GitHub
4 changed files with 53 additions and 11 deletions

View File

@@ -29,6 +29,7 @@
"QuestDebugTools": false, "QuestDebugTools": false,
"EarthStatusOverride": 0, "EarthStatusOverride": 0,
"EarthIDOverride": 0, "EarthIDOverride": 0,
"DynamicSeasons": false,
"EarthMonsterOverride": 0, "EarthMonsterOverride": 0,
"SaveDumps": { "SaveDumps": {
"Enabled": true, "Enabled": true,
@@ -110,9 +111,9 @@
], ],
"Database": { "Database": {
"Host": "localhost", "Host": "localhost",
"Port": 5433, "Port": 5432,
"User": "postgres", "User": "postgres",
"Password": "admin", "Password": "",
"Database": "erupe" "Database": "erupe"
}, },
"Sign": { "Sign": {

View File

@@ -110,6 +110,7 @@ type DevModeOptions struct {
QuestDebugTools bool // Enable various quest debug logs QuestDebugTools bool // Enable various quest debug logs
EarthStatusOverride int32 EarthStatusOverride int32
EarthIDOverride int32 EarthIDOverride int32
DynamicSeasons bool // Enables dynamic seasons
EarthMonsterOverride int32 EarthMonsterOverride int32
SaveDumps SaveDumpOptions SaveDumps SaveDumpOptions
} }

View File

@@ -51,8 +51,19 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
zap.String("Filename", pkt.Filename), zap.String("Filename", pkt.Filename),
) )
} }
// Get quest file.
data, err := os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))) // Get quest file and convert to season if the option is enabled
var data []byte
var err error
if s.server.erupeConfig.DevModeOptions.DynamicSeasons {
data, err = os.ReadFile(filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename)))
} else {
data, err = os.ReadFile(seasonConversion(s, filepath.Join(s.server.erupeConfig.BinPath, fmt.Sprintf("quests/%s.bin", pkt.Filename))))
}
// convert based on season
if err != nil { if err != nil {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename)) s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// This will crash the game. // This will crash the game.
@@ -64,6 +75,39 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
} }
} }
// Convert the file to load based on the season
func seasonConversion(s *Session, questPath string) string {
// remove the last 6 from the quest path
newQuestPath := questPath[:len(questPath)-6]
// Calculate the current day of the season in order to determine time scale
currentDayOfSeason := (time.Now().Unix()/6000)%15 + 1
// Determine if it is day or night based on the current day of the season
timeCycle := uint8(((currentDayOfSeason % 1) * 24)) < 12
// Determine the current season based on a modulus of the current time
season := uint8((int(float64((time.Now().Unix() * int64(s.server.ID)) / (6000 * 15)))) % 3)
var timeSet string
// Determine the letter to append for day / night
if timeCycle {
timeSet = "n"
} else {
timeSet = "d"
}
fileName := fmt.Sprintf("%s%s%d.bin", newQuestPath, timeSet, season)
// Return the original if the season-based file does not exist for some reason
if _, err := os.Stat(fileName); err == nil {
return fileName
} else {
return questPath
}
}
func handleMsgMhfLoadFavoriteQuest(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfLoadFavoriteQuest(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest) pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest)
var data []byte var data []byte

View File

@@ -6,6 +6,7 @@ import (
_config "erupe-ce/config" _config "erupe-ce/config"
"fmt" "fmt"
"net" "net"
"time"
"erupe-ce/common/stringsupport" "erupe-ce/common/stringsupport"
@@ -13,9 +14,6 @@ import (
"erupe-ce/server/channelserver" "erupe-ce/server/channelserver"
) )
// Server Entries
var season uint8
// Server Channels // Server Channels
var currentplayers uint16 var currentplayers uint16
@@ -36,10 +34,8 @@ func encodeServerInfo(config *_config.Config, s *Server, local bool) []byte {
} }
} }
sid := (4096 + serverIdx*256) + 16 sid := (4096 + serverIdx*256) + 16
err := s.db.QueryRow("SELECT season FROM servers WHERE server_id=$1", sid).Scan(&season) //season := (uint8(float64((time.Now().Unix() + int64(sid)) / 1000))) % 3
if err != nil { season := uint8((int(float64((time.Now().Unix() * int64(sid)) / (6000 * 15)))) % 3)
season = 0
}
if si.IP == "" { if si.IP == "" {
si.IP = config.Host si.IP = config.Host
} }