Skip to content

Commit 33c9a29

Browse files
committed
fix: add missing region specific mob_channel_status reset to previous commit feature
1 parent b15a0e7 commit 33c9a29

2 files changed

Lines changed: 31 additions & 14 deletions

File tree

apps/pocketbase/pb_go/crons.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func handleMobRespawn(app core.App) {
5757

5858
// Group mobs by topic (topic -> []mobIds)
5959
mobsByTopic := make(map[string][]string)
60-
var resetMobIds []string
60+
var mobResets []MobReset
6161

6262
for _, mob := range respawningMobs {
6363
mobName := mob.GetString("name")
@@ -66,10 +66,12 @@ func handleMobRespawn(app core.App) {
6666
monsterID := mob.GetInt("monster_id")
6767

6868
var topics []string
69+
var regions []string
6970

7071
if mobType == "boss" {
7172
// Bosses reset for all regions
7273
topics = []string{SSE_TOPIC_RESETS, SSE_TOPIC_RESETS_SEA}
74+
regions = []string{"NA", "SEA"}
7375
} else if mobType == "magical_creature" {
7476
// Check if current hour matches any reset hour for any region
7577
if regionHours, exists := MagicalCreatureResetHours[monsterID]; exists {
@@ -79,8 +81,10 @@ func handleMobRespawn(app core.App) {
7981
switch region {
8082
case "NA":
8183
topics = append(topics, SSE_TOPIC_RESETS)
84+
regions = append(regions, "NA")
8285
case "SEA":
8386
topics = append(topics, SSE_TOPIC_RESETS_SEA)
87+
regions = append(regions, "SEA")
8488
}
8589
break
8690
}
@@ -90,7 +94,12 @@ func handleMobRespawn(app core.App) {
9094
}
9195

9296
if len(topics) > 0 {
93-
resetMobIds = append(resetMobIds, mobId)
97+
for _, region := range regions {
98+
mobResets = append(mobResets, MobReset{
99+
MobID: mobId,
100+
Region: region,
101+
})
102+
}
94103
for _, topic := range topics {
95104
mobsByTopic[topic] = append(mobsByTopic[topic], mobId)
96105
}
@@ -99,17 +108,17 @@ func handleMobRespawn(app core.App) {
99108
}
100109
}
101110

102-
if len(resetMobIds) == 0 {
111+
if len(mobResets) == 0 {
103112
log.Printf("[MOB_RESPAWN] no mobs to reset")
104113
return
105114
}
106115

107-
if err := batchUpdateMobChannelStatus(app, resetMobIds); err != nil {
116+
if err := batchUpdateMobChannelStatus(app, mobResets); err != nil {
108117
log.Printf("[MOB_RESPAWN] reset error=%v", err)
109118
return
110119
}
111120

112-
log.Printf("[MOB_RESPAWN] reset mobs=%d time=%02d:%02d", len(resetMobIds), currentHour, currentMinute)
121+
log.Printf("[MOB_RESPAWN] reset mobs=%d time=%02d:%02d", len(mobResets), currentHour, currentMinute)
113122

114123
// Broadcast each topic with its mobs
115124
for topic, mobIds := range mobsByTopic {
@@ -119,24 +128,27 @@ func handleMobRespawn(app core.App) {
119128
}
120129
}
121130

122-
func batchUpdateMobChannelStatus(app core.App, mobIds []string) error {
123-
if len(mobIds) == 0 {
131+
func batchUpdateMobChannelStatus(app core.App, mobResets []MobReset) error {
132+
if len(mobResets) == 0 {
124133
return nil
125134
}
126135

127-
placeholders := make([]string, len(mobIds))
136+
// Build conditions for (mob, region) pairs
137+
conditions := make([]string, 0, len(mobResets))
128138
params := dbx.Params{"timestamp": time.Now().Format("2006-01-02 15:04:05")}
129139

130-
for i, mobId := range mobIds {
131-
key := fmt.Sprintf("mob%d", i)
132-
placeholders[i] = fmt.Sprintf("{:%s}", key)
133-
params[key] = mobId
140+
for i, reset := range mobResets {
141+
mobKey := fmt.Sprintf("mob%d", i)
142+
regionKey := fmt.Sprintf("region%d", i)
143+
conditions = append(conditions, fmt.Sprintf("(mob = {:%s} AND region = {:%s})", mobKey, regionKey))
144+
params[mobKey] = reset.MobID
145+
params[regionKey] = reset.Region
134146
}
135147

136148
query := fmt.Sprintf(
137-
"UPDATE %s SET last_hp = 100, last_update = {:timestamp} WHERE mob IN (%s)",
149+
"UPDATE %s SET last_hp = 100, last_update = {:timestamp} WHERE %s",
138150
COLLECTION_MOB_CHANNEL_STATUS,
139-
strings.Join(placeholders, ","),
151+
strings.Join(conditions, " OR "),
140152
)
141153

142154
_, err := app.DB().NewQuery(query).Bind(params).Execute()

apps/pocketbase/pb_go/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ type RegionInfo struct {
5151
Name string // Region code
5252
Enabled bool // Whether to handle this region's reports
5353
}
54+
55+
type MobReset struct {
56+
MobID string // PocketBase mob record ID
57+
Region string // Region code (NA, SEA, etc.)
58+
}

0 commit comments

Comments
 (0)