Files
hanfuit 645b64fe21 DNF90 服务端与启动器完整源码(含 GM 工具功能增强)
服务端(Go):
- GM 塞背包/带属性装备发放:在线角色推送 op14 增量物品行,背包实时刷新,无需回角色选择界面
- GM 改金币/改等级:去掉在线拒绝,落库后推送 op14 钱包/op37 等级状态,在线实时刷新
- 等级端点统一切换到新版 GMSetCharacterLevel(自带在线刷新)
- 无限/锁死疲劳模式 + 燃烧疲劳:每房间消耗 2 点、打怪与通关经验双倍
- 燃烧疲劳开关时给所有在线角色推送系统提示(op12 mode 0)
- 深渊史诗掉率:GM 全局倍率 + 城镇增益药剂窗口倍率,真实接入掉落结算

启动器(Python/JS):
- 标题栏自绘、窗口 1204x717、禁止拖拽改大小、仅最小化/关闭
- GM 工具:疲劳与燃烧、深渊史诗掉率、拍卖行上架(单一定价对齐)
- 拍卖行上架前端对齐服务端单一价格语义,修复 400 报错
2026-11-04 14:31:55 +08:00

120 lines
3.6 KiB
Go

package player
import (
"context"
"fmt"
"strings"
"time"
)
// Record 是兼容旧玩家模块调用方的 Profile 别名。
type Record = Profile
func (m *Module) mutateLoadedProfile(ctx context.Context, accountID string, mutate func(*Profile) []ProfileField) (Profile, error) {
accountID = strings.TrimSpace(accountID)
if accountID == "" {
return Profile{}, fmt.Errorf("account id is required")
}
if mutate == nil {
return Profile{}, fmt.Errorf("profile mutation is required")
}
if _, err := m.LoadOrCreate(ctx, accountID); err != nil {
return Profile{}, err
}
before, profile, err := m.profiles.MutateLoaded(ctx, accountID, func(profile *Profile, _ time.Time) ([]ProfileField, error) {
return mutate(profile), nil
})
if err != nil {
return Profile{}, err
}
m.observeSummaryChange(ctx, before, profile)
return cloneProfile(profile), nil
}
func (m *Module) mutateCritProfile(ctx context.Context, accountID string, operation ProfileOperation, reason string, mutate func(*Profile, time.Time) (map[string]any, error)) (Profile, error) {
if m == nil {
return Profile{}, fmt.Errorf("profile module is nil")
}
accountID = strings.TrimSpace(accountID)
if accountID == "" {
return Profile{}, fmt.Errorf("account id is required")
}
if mutate == nil {
return Profile{}, fmt.Errorf("profile mutation is required")
}
dirtyFields := dirtyFieldsByOp(operation)
if len(dirtyFields) == 0 {
return Profile{}, fmt.Errorf("unsupported profile operation %s", operation)
}
before, profile, err := m.profiles.MutateLoaded(ctx, accountID, func(profile *Profile, now time.Time) ([]ProfileField, error) {
mutation, err := mutate(profile, now)
if err != nil {
return nil, err
}
eventProfile := cloneProfile(*profile)
eventProfile.UpdatedAt = now
eventProfile.Version++
if err := m.emitProfileMutation(ctx, eventProfile, string(operation), reason, dirtyFields, mutation); err != nil {
return nil, err
}
return dirtyFields, nil
})
if err != nil {
return Profile{}, err
}
m.observeSummaryChange(ctx, before, profile)
return cloneProfile(profile), nil
}
func newProfile(accountID string, now time.Time) Profile {
profile := Profile{
AccountID: accountID,
RoleID: "role-" + accountID,
State: "online",
LoadedAt: now,
UpdatedAt: now,
Version: 1,
}
applyProfileDefaults(&profile, now)
return profile
}
func prepareLoadedProfile(profile Profile, accountID string, now time.Time, existed bool) (Profile, []ProfileField, error) {
dirtyFields := newProfileFieldSet(dirtyFieldsByModule(ProfileModuleRuntime)...)
if existed {
profile = normAccountID(profile, accountID)
dirtyFields.Merge(ensureProfileModules(&profile, now))
}
profile.State = "online"
profile.LoadedAt = now
profile.UpdatedAt = now
profile.Version++
return profile, dirtyFields.List(), nil
}
func prepareSavedProfile(profile Profile, now time.Time) (Profile, []ProfileField, error) {
profile.State = "offline"
profile.SavedAt = now
profile.UpdatedAt = now
profile.Version++
return profile, dirtyFieldsByModule(ProfileModuleRuntime), nil
}
func touchProfileRecord(profile Profile, now time.Time) (Profile, []ProfileField, error) {
profile.UpdatedAt = now
profile.Version++
return profile, nil, nil
}
func sameProfileVersion(current, snapshot Profile) bool {
return current.Version == snapshot.Version && current.UpdatedAt.Equal(snapshot.UpdatedAt)
}
func ensureProfileModules(profile *Profile, now time.Time) profileFieldSet {
return newProfileFieldSet(backfillModules(profile, now)...)
}
func cloneProfile(profile Profile) Profile {
return cloneProfileModules(profile)
}