fix(server): include fishing ticket schedules in charge information

This commit is contained in:
Flechazo committed 2026-10-25 23:04:58 +08:00
1 parent 08cd490861
commit d1711697c1
4 files changed
+107

No files matched your search

@@ -112,3 +112,43 @@ func TestFishingTrapAutoSaleUsesNativeCurrencyAndAtomicSettlement(t *testing.T)
t.Fatal("reopened fishing experience lost")
}
}
func TestFishingChargeScheduleIsIncludedBeforeOpeningHarbor(t *testing.T) {
factory, accounts := newIntegrationFactory(t)
g := newSquareGameplay(t, factory, accounts[0])
login := g.call("/LoginUser", nil)
users := appRows(login, 1)
if len(users) != 1 {
t.Fatal("missing player")
}
// UserDBInfo.fishing_multi_ap=62; EElementType.FishingMultiTicket=55.
tickets := appValue(users[0], 62)
if tickets != 10 {
t.Fatalf("current FishingDefaultTable0 actionPointCount=%d want10", tickets)
}
charge := g.call("/ChargeCostInfo", nil)
matches := 0
for _, info := range appRows(charge, 1) {
items := appRows(info, 2)
if len(items) != 1 {
t.Fatal("invalid cost item")
}
if appValue(items[0], 3) != 55 {
continue
}
matches++
if appValue(items[0], 4) != tickets {
t.Fatal("fishing charge balance disagrees with login")
}
stamp := time.UnixMilli(int64(appValue(info, 1))).UTC()
now := time.Now().UTC()
if stamp.Hour() != 0 || stamp.Minute() != 0 || stamp.Second() != 0 || now.Sub(stamp) < 0 || now.Sub(stamp) >= 24*time.Hour {
t.Fatalf("invalid last charge timestamp %v", stamp)
}
}
if matches != 1 {
t.Fatalf("fishing schedules=%d want1", matches)
}
g.call("/FishingItemInfo", nil)
g.call("/FishingInfo", nil)
}
+1
View File
@@ -103,6 +103,7 @@ func (p *playerAssembly) events(ctx command.Context) error {
return nil, err
}
rows = append(rows, huntingRows...)
rows = append(rows, p.fishingService.ChargeInfo()...)
if p.pvpService != nil {
pvpRows, err := p.pvpService.ChargeInfo(ctx)
if err != nil {
@@ -258,6 +258,14 @@ func (s *Service) Profile() Profile {
p.FishSlots, p.RodSlots, p.ItemSlots = s.state.FishSlots, s.state.RodSlots, s.state.ItemSlots
return p
}
func (s *Service) ChargeInfo() []byte {
profile := s.Profile()
item := wire.AppendVarint(nil, 3, 55)
item = wire.AppendVarint(item, 4, profile.MultiAP)
info := wire.AppendVarint(nil, 1, uint64(profile.ResetTime-86400)*1000)
return wire.AppendBytes(nil, 1, wire.AppendBytes(info, 2, item))
}
func (s *Service) AttachRooms(rooms eventplay.RoomRuntime) { s.rooms = rooms }
func (s *Service) CollectionCount() uint64 { return uint64(len(s.state.Collection)) }
func (s *Service) AttachPublicProfiles(lookup PublicProfileLookup) { s.publicProfile = lookup }
@@ -8,6 +8,7 @@ import (
"bd2server/internal/server/storage/stateio"
"errors"
"testing"
"time"
)
type noEconomy struct{}
@@ -201,3 +202,60 @@ func TestVoyageFallsBackToSoloOnlyWhenNoRoomExists(t *testing.T) {
})
}
}
// The native GameScheduleManager creates cost schedules from ChargeCostInfo.
// FishingMultiTicket is element55; FishingDefaultTable0 grants10 per UTC day.
func TestChargeInfoPreservesSpentFishingTicketsUntilDailyReset(t *testing.T) {
service, ctx, design := fishingFixture(t)
now := time.Date(2026, 10, 25, 15, 0, 0, 0, time.UTC)
service.now = func() time.Time { return now }
service.state.APDay = now.Unix() / 86400
service.state.MultiAP = 0
if _, _, _, err := service.Handle(ctx, "/FishingItemInfo", row(1, 1)); err != nil {
t.Fatal(err)
}
check := func(count uint64, midnight time.Time) {
t.Helper()
raw := service.ChargeInfo()
records := 0
if err := wire.Walk(raw, func(field wire.Field) error {
if field.Number != 1 || field.Type != 2 {
t.Fatal("unexpected charge field")
}
records++
if num(field.Value, 1) != uint64(midnight.UnixMilli()) {
t.Fatal("charge timestamp is not current UTC midnight in milliseconds")
}
item, found, err := wire.Bytes(field.Value, 2)
if err != nil {
return err
}
if !found || num(item, 3) != 55 || num(item, 4) != count {
t.Fatalf("fishing charge item=%x want type55 count%d", item, count)
}
return nil
}); err != nil {
t.Fatal(err)
}
if records != 1 {
t.Fatal("missing or duplicate fishing charge schedule")
}
}
midnight := time.Date(2026, 10, 25, 0, 0, 0, 0, time.UTC)
check(0, midnight)
reopened, err := Open(ctx, design, noEconomy{}, nil)
if err != nil {
t.Fatal(err)
}
reopened.now = service.now
service = reopened
check(0, midnight)
now = now.Add(24 * time.Hour)
check(10, midnight.Add(24*time.Hour))
if _, _, _, err := service.Handle(ctx, "/FishingItemInfo", row(1, 2)); err != nil {
t.Fatal(err)
}
if service.state.MultiAP != 10 || service.state.APDay != now.Unix()/86400 {
t.Fatal("charge view disagrees with persisted daily allowance")
}
}