服务端(Go): - GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面 - GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新 - 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新) - 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍 - 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0) - 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算 启动器(Python/JS): - 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭 - GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐) - 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
111 lines
3.4 KiB
Go
111 lines
3.4 KiB
Go
package adventuregroup
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"math"
|
|
"testing"
|
|
"time"
|
|
|
|
dnfrepo "longheng.io/server/internal/modules/dnf/repository"
|
|
dnfrepomemory "longheng.io/server/internal/modules/dnf/repository/memory"
|
|
)
|
|
|
|
func TestOwnerObserveDailyLoginStartsAdvancesAndResetsStreak(t *testing.T) {
|
|
ctx := context.Background()
|
|
repositories := dnfrepomemory.NewMemoryGroup()
|
|
if err := repositories.Account.Save(ctx, dnfrepo.AccountRecord{
|
|
AccountID: "account-1",
|
|
Metadata: map[string]string{"account_cera": "123"},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
owner, err := NewOwner(repositories)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
location := time.FixedZone("test", 8*60*60)
|
|
observe := func(at time.Time) ObserveDailyLoginResult {
|
|
t.Helper()
|
|
result, observeErr := owner.ObserveDailyLogin(ctx, ObserveDailyLoginCommand{
|
|
AccountID: "account-1",
|
|
ObservedAt: at,
|
|
})
|
|
if observeErr != nil {
|
|
t.Fatal(observeErr)
|
|
}
|
|
return result
|
|
}
|
|
|
|
first := observe(time.Date(2026, 7, 28, 8, 0, 0, 0, location))
|
|
if !first.Changed || first.ConsecutiveDays != 1 || first.CalendarDate != "2026-07-28" {
|
|
t.Fatalf("first=%+v", first)
|
|
}
|
|
same := observe(time.Date(2026, 7, 28, 23, 59, 0, 0, location))
|
|
if same.Changed || same.ConsecutiveDays != 1 {
|
|
t.Fatalf("same=%+v", same)
|
|
}
|
|
next := observe(time.Date(2026, 7, 29, 0, 1, 0, 0, location))
|
|
if !next.Changed || next.ConsecutiveDays != 2 {
|
|
t.Fatalf("next=%+v", next)
|
|
}
|
|
gap := observe(time.Date(2026, 7, 31, 0, 1, 0, 0, location))
|
|
if !gap.Changed || gap.ConsecutiveDays != 1 {
|
|
t.Fatalf("gap=%+v", gap)
|
|
}
|
|
account, found, err := repositories.Account.Load(ctx, "account-1")
|
|
if err != nil || !found {
|
|
t.Fatalf("load found=%t err=%v", found, err)
|
|
}
|
|
if account.Metadata[DailyLoginStateMetadataKey] != "2026-07-31|1" ||
|
|
account.Metadata["account_cera"] != "123" {
|
|
t.Fatalf("account metadata=%v", account.Metadata)
|
|
}
|
|
}
|
|
|
|
func TestOwnerObserveDailyLoginPreservesFutureAndSaturates(t *testing.T) {
|
|
ctx := context.Background()
|
|
repositories := dnfrepomemory.NewMemoryGroup()
|
|
if err := repositories.Account.Save(ctx, dnfrepo.AccountRecord{
|
|
AccountID: "account-1",
|
|
Metadata: map[string]string{
|
|
DailyLoginStateMetadataKey: "2026-07-29|4294967295",
|
|
},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
owner, _ := NewOwner(repositories)
|
|
result, err := owner.ObserveDailyLogin(ctx, ObserveDailyLoginCommand{
|
|
AccountID: "account-1",
|
|
ObservedAt: time.Date(2026, 7, 28, 12, 0, 0, 0, time.UTC),
|
|
})
|
|
if err != nil || result.Changed || result.ConsecutiveDays != math.MaxUint32 {
|
|
t.Fatalf("future result=%+v err=%v", result, err)
|
|
}
|
|
result, err = owner.ObserveDailyLogin(ctx, ObserveDailyLoginCommand{
|
|
AccountID: "account-1",
|
|
ObservedAt: time.Date(2026, 7, 30, 12, 0, 0, 0, time.UTC),
|
|
})
|
|
if err != nil || !result.Changed || result.ConsecutiveDays != math.MaxUint32 {
|
|
t.Fatalf("saturated result=%+v err=%v", result, err)
|
|
}
|
|
}
|
|
|
|
func TestOwnerObserveDailyLoginRejectsCorruptState(t *testing.T) {
|
|
ctx := context.Background()
|
|
repositories := dnfrepomemory.NewMemoryGroup()
|
|
if err := repositories.Account.Save(ctx, dnfrepo.AccountRecord{
|
|
AccountID: "account-1",
|
|
Metadata: map[string]string{DailyLoginStateMetadataKey: "bad"},
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
owner, _ := NewOwner(repositories)
|
|
if _, err := owner.ObserveDailyLogin(ctx, ObserveDailyLoginCommand{
|
|
AccountID: "account-1",
|
|
ObservedAt: time.Now(),
|
|
}); !errors.Is(err, ErrDailyLoginStateInvalid) {
|
|
t.Fatalf("error=%v", err)
|
|
}
|
|
}
|