4 Commits

Author SHA1 Message Date
stratic-dev
9a8186ae2a Merge branch 'main' of https://github.com/ZeruLight/Erupe into feature/enum-event 2025-04-30 15:59:23 +00:00
stratic-dev
4a7668549c add in sql and nil pointer fix 2024-05-11 03:06:51 +01:00
stratic-dev
eebb9510e8 event system init integration 2024-05-10 23:31:30 +01:00
stratic-dev
9ee132eb41 Exposed EnumEvent 2024-05-08 20:19:40 +01:00
4 changed files with 59 additions and 6 deletions

View File

@@ -103,7 +103,14 @@
"EnableHiganjimaEvent": false, "EnableHiganjimaEvent": false,
"EnableNierEvent": false, "EnableNierEvent": false,
"DisableRoad": false, "DisableRoad": false,
"SeasonOverride": false "SeasonOverride": false,
"EnumerateEvent": {
"Enabled":false,
"EventID":2,
"Duration":172800,
"RestartAfter":2977200,
"QuestIDs": [20001, 20004, 20005, 20006, 20011, 20012, 20013, 20018, 20019, 20020, 20021, 20022, 20023, 20024, 20025, 20026, 20027, 20028, 20029]
}
}, },
"Discord": { "Discord": {
"Enabled": false, "Enabled": false,

View File

@@ -140,6 +140,14 @@ type CapLinkOptions struct {
Port int Port int
} }
type EnumerateEventOptions struct {
QuestIDs []uint16
EventID uint16
Enabled bool
Duration int
RestartAfter int
}
// GameplayOptions has various gameplay modifiers // GameplayOptions has various gameplay modifiers
type GameplayOptions struct { type GameplayOptions struct {
MinFeatureWeapons int // Minimum number of Active Feature weapons to generate daily MinFeatureWeapons int // Minimum number of Active Feature weapons to generate daily
@@ -194,6 +202,7 @@ type GameplayOptions struct {
EnableNierEvent bool // Enables the Nier event in the Rasta Bar EnableNierEvent bool // Enables the Nier event in the Rasta Bar
DisableRoad bool // Disables the Hunting Road DisableRoad bool // Disables the Hunting Road
SeasonOverride bool // Overrides the Quest Season with the current Mezeporta Season SeasonOverride bool // Overrides the Quest Season with the current Mezeporta Season
EnumerateEvent EnumerateEventOptions
} }
// Discord holds the discord integration config. // Discord holds the discord integration config.

View File

@@ -0,0 +1,5 @@
BEGIN;
ALTER TYPE event_type ADD VALUE 'ancientdragon';
END;

View File

@@ -11,22 +11,54 @@ import (
) )
type Event struct { type Event struct {
EventType uint16 EventType uint16 //0 Nothing //1 or 2 "An Acient Dragon has attacked the fort"
Unk1 uint16 Unk1 uint16
Unk2 uint16 Unk2 uint16
Unk3 uint16 Unk3 uint16
Unk4 uint16 Unk4 uint16
Unk5 uint32 StartTime uint32
Unk6 uint32 EndTime uint32
QuestFileIDs []uint16 QuestFileIDs []uint16
} }
func cleanupEnumEvent(s *Session) {
s.server.db.Exec("DELETE FROM events WHERE event_type='ancientdragon'")
}
func generateEnumEventTimestamps(s *Session, start uint32) []uint32 {
timestamps := make([]uint32, 2)
midnight := TimeMidnight()
//if start is 0 or start is after a duration
if start == 0 || TimeAdjusted().Unix() > int64(start)+int64(s.server.erupeConfig.GameplayOptions.EnumerateEvent.RestartAfter) {
cleanupEnumEvent(s)
// Generate a new diva defense, starting midnight tomorrow
start = uint32(midnight.Add(24 * time.Hour).Unix())
s.server.db.Exec("INSERT INTO events (event_type, start_time) VALUES ('ancientdragon', to_timestamp($1)::timestamp without time zone)", start)
}
timestamps[0] = start
timestamps[1] = timestamps[0] + uint32(s.server.erupeConfig.GameplayOptions.EnumerateEvent.Duration)
return timestamps
}
func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) { func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
pkt := p.(*mhfpacket.MsgMhfEnumerateEvent) pkt := p.(*mhfpacket.MsgMhfEnumerateEvent)
bf := byteframe.NewByteFrame() bf := byteframe.NewByteFrame()
id, start := uint32(0xCAFEBEEF), uint32(0)
rows, _ := s.server.db.Queryx("SELECT id, (EXTRACT(epoch FROM start_time)::int) as start_time FROM events WHERE event_type='ancientdragon'")
if !rows.Next() {
for rows.Next() {
rows.Scan(&id, &start)
}
}
var timestamps []uint32
events := []Event{} events := []Event{}
if s.server.erupeConfig.GameplayOptions.EnumerateEvent.Enabled {
timestamps = generateEnumEventTimestamps(s, start)
events = append(events, Event{s.server.erupeConfig.GameplayOptions.EnumerateEvent.EventID, 0, 0, 0, 0, timestamps[0], timestamps[1], s.server.erupeConfig.GameplayOptions.EnumerateEvent.QuestIDs})
}
bf.WriteUint8(uint8(len(events))) bf.WriteUint8(uint8(len(events)))
for _, event := range events { for _, event := range events {
bf.WriteUint16(event.EventType) bf.WriteUint16(event.EventType)
@@ -34,8 +66,8 @@ func handleMsgMhfEnumerateEvent(s *Session, p mhfpacket.MHFPacket) {
bf.WriteUint16(event.Unk2) bf.WriteUint16(event.Unk2)
bf.WriteUint16(event.Unk3) bf.WriteUint16(event.Unk3)
bf.WriteUint16(event.Unk4) bf.WriteUint16(event.Unk4)
bf.WriteUint32(event.Unk5) bf.WriteUint32(event.StartTime)
bf.WriteUint32(event.Unk6) bf.WriteUint32(event.EndTime)
if event.EventType == 2 { if event.EventType == 2 {
bf.WriteUint8(uint8(len(event.QuestFileIDs))) bf.WriteUint8(uint8(len(event.QuestFileIDs)))
for _, qf := range event.QuestFileIDs { for _, qf := range event.QuestFileIDs {