feature: Season implementation

This commit is contained in:
Matthe815
2023-07-05 19:29:39 -04:00
parent e9d151be33
commit 35f9d5ac18
3 changed files with 50 additions and 9 deletions

View File

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

View File

@@ -51,8 +51,19 @@ func handleMsgSysGetFile(s *Session, p mhfpacket.MHFPacket) {
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 {
s.logger.Error(fmt.Sprintf("Failed to open file: %s/quests/%s.bin", s.server.erupeConfig.BinPath, pkt.Filename))
// 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) {
pkt := p.(*mhfpacket.MsgMhfLoadFavoriteQuest)
var data []byte

View File

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