```
feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"blazing/modules/base/service"
|
||||
|
||||
blazing "blazing/modules/blazing/service"
|
||||
blazing "blazing/modules/player/service"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
@@ -63,11 +63,16 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq)
|
||||
|
||||
}
|
||||
|
||||
if cool.Config.ServerInfo.IsDebug != 0 {
|
||||
res.IsDebug = 1
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type SessionRes struct {
|
||||
UserID int `json:"userid"`
|
||||
Session string `json:"session"`
|
||||
IsDebug int `json:"isDebug"`
|
||||
//Server model.ServerList `json:"server"`
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package blazing
|
||||
|
||||
import (
|
||||
_ "blazing/modules/blazing/controller"
|
||||
_ "blazing/modules/blazing/model"
|
||||
_ "blazing/modules/blazing/service"
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
_ "blazing/modules/blazing/controller/admin"
|
||||
_ "blazing/modules/blazing/controller/app"
|
||||
)
|
||||
@@ -3,6 +3,9 @@ package admin
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type ServerController struct {
|
||||
@@ -20,3 +23,22 @@ func init() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// quit 退出
|
||||
type QuitSReq struct {
|
||||
g.Meta `path:"/quit" method:"POST"`
|
||||
ID uint32 `json:"id" v:"required#请选择要退出的服务器"`
|
||||
//code 0是非强制,1是强制QuitReq
|
||||
Code int `json:"code" v:"required#请选择退出类型"`
|
||||
}
|
||||
|
||||
func (this *ServerController) Quit(ctx context.Context, req *QuitSReq) (res *cool.BaseRes, err error) {
|
||||
res = &cool.BaseRes{}
|
||||
serv := service.NewServerService().GetServerID(uint16(req.ID))
|
||||
|
||||
aa, ok := cool.GetClient(serv.Port)
|
||||
if ok && aa != nil { //如果已经存在且这个端口已经被存过
|
||||
aa.QuitSelf(req.Code)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
module blazing/modules/config
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require github.com/aidarkhanov/nanoid/v2 v2.0.0-20210915221554-84fce99176fc // indirect
|
||||
|
||||
2
modules/config/go.sum
Normal file
2
modules/config/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/aidarkhanov/nanoid/v2 v2.0.0-20210915221554-84fce99176fc h1:t/xPF/DMrr51WHT8rpHwMj5Xvle5xceEuRaxIY5kMOs=
|
||||
github.com/aidarkhanov/nanoid/v2 v2.0.0-20210915221554-84fce99176fc/go.mod h1:YF/U48D1yA3AoGGUdRrCV95J/KJBShvR9TyLqQwdtlI=
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 表名常量(遵循现有命名规范)
|
||||
const TableNamePlayerPetSpecialEffect = "player_pet_special_effect"
|
||||
const TableNamePlayerPetSpecialEffect = "config_boss_effect"
|
||||
|
||||
// PlayerPetSpecialEffect 精灵特效表(仅包含XML中指定的4个核心字段)
|
||||
// 对应XML中的<NewSeIdx>节点:Idx、Stat、Eid、Args
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TableNameBossConfig = "config_pet_boss" // BOSS配置表(全量包含基础/奖励/护盾/捕捉/特效/世界野怪/地图费用/战斗通用逻辑)
|
||||
TableNameBossConfig = "config_boss" // BOSS配置表(全量包含基础/奖励/护盾/捕捉/特效/世界野怪/地图费用/战斗通用逻辑)
|
||||
)
|
||||
|
||||
// BossConfig BOSS配置模型(覆盖所有补充的配置项:GBTL/非VIP费用/首场景/战斗通用逻辑)
|
||||
|
||||
@@ -7,26 +7,25 @@ import (
|
||||
|
||||
// 表名常量定义:CDK配置表
|
||||
const (
|
||||
TableNameCDKConfig = "cdk_config" // CDK配置表(记录CDK编号、可兑换次数、奖励配置等核心信息)
|
||||
TableNameCDKConfig = "config_gift_cdk" // CDK配置表(记录CDK编号、可兑换次数、奖励配置等核心信息)
|
||||
)
|
||||
|
||||
// CDKConfig CDK核心配置模型(含可兑换次数,满足查询`where 可兑换次数 != 0`需求)
|
||||
type CDKConfig struct {
|
||||
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化)
|
||||
*cool.Model
|
||||
|
||||
// 核心字段
|
||||
CDKCode string `gorm:"not null;size:64;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"`
|
||||
CDKCode string `gorm:"not null;size:16;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"`
|
||||
|
||||
//cdk可兑换次数,where不等于0
|
||||
ExchangeRemainCount uint32 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
||||
ExchangeRemainCount int64 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
ElfRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励精灵ID数组,关联config_pet_boss表主键'" json:"elf_reward_ids" description:"奖励精灵数组"`
|
||||
TitleRewardIds uint32 `gorm:"not null;default:0;comment:'绑定奖励称号'" json:"title_reward_ids" description:"绑定奖励称号"`
|
||||
|
||||
// 辅助配置字段
|
||||
ValidStartTime time.Time `gorm:"not null;comment:'CDK有效开始时间'" json:"valid_start_time" description:"有效开始时间"`
|
||||
ValidEndTime time.Time `gorm:"not null;comment:'CDK有效结束时间'" json:"valid_end_time" description:"有效结束时间"`
|
||||
IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该CDK(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"`
|
||||
Remark string `gorm:"size:512;default:'';comment:'CDK备注'" json:"remark" description:"备注信息"`
|
||||
ValidEndTime time.Time `gorm:"not null;comment:'CDK有效结束时间'" json:"valid_end_time" description:"有效结束时间"`
|
||||
|
||||
Remark string `gorm:"size:512;default:'';comment:'CDK备注'" json:"remark" description:"备注信息"`
|
||||
//ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"`
|
||||
}
|
||||
|
||||
@@ -41,16 +40,7 @@ func (*CDKConfig) GroupName() string {
|
||||
|
||||
func NewCDKConfig() *CDKConfig {
|
||||
return &CDKConfig{
|
||||
Model: cool.NewModel(),
|
||||
CDKCode: "",
|
||||
|
||||
ExchangeRemainCount: 1, // 剩余可兑换次数默认1,确保不为0
|
||||
ItemRewardIds: []uint32{},
|
||||
ElfRewardIds: []uint32{},
|
||||
ValidStartTime: time.Now(),
|
||||
ValidEndTime: time.Now().AddDate(1, 0, 0), // 默认有效期1年
|
||||
IsEnabled: 1,
|
||||
Remark: "",
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package model
|
||||
import "blazing/cool"
|
||||
|
||||
const (
|
||||
TableNamePetFusionMaterial = "pet_fusion_material" // 宠物融合材料表(子表)
|
||||
TableNamePetFusionMaterial = "config_fusion_material" // 宠物融合材料表(子表)
|
||||
)
|
||||
|
||||
// PetFusionMaterial 融合材料模型(与配方主表一对一关联)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TableNamePetFusion = "pet_fusion" // 宠物融合配方表(主表)
|
||||
TableNamePetFusion = "config_fusion_pet" // 宠物融合配方表(主表)
|
||||
)
|
||||
|
||||
// PetFusion 宠物融合配方主模型(核心配方规则)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 表名常量定义:物品奖励表(存储物品奖励的核心配置信息)
|
||||
const (
|
||||
TableNameItemGift = "item_gift" // 物品奖励配置表(包含物品关联、数量、启用状态、扭蛋标识及备注信息)
|
||||
TableNameItemGift = "config_gift_item" // 物品奖励配置表(包含物品关联、数量、启用状态、扭蛋标识及备注信息)
|
||||
)
|
||||
|
||||
// ItemGift 物品奖励基础配置模型(与数据库表 item_gift 字段一一对应,核心存储结构)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TableNameMonsterRefresh = "monster_refresh" // 怪物刷新规则表(地图-精灵等级-刷新脚本配置)
|
||||
TableNameMonsterRefresh = "config_monster_refresh" // 怪物刷新规则表(地图-精灵等级-刷新脚本配置)
|
||||
)
|
||||
|
||||
// MonsterRefresh 怪物刷新规则模型(对应前端配置的地图/精灵/等级/脚本配置)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TableNameMeleeConfig = "config_pet_melee" // BOSS配置表(全量包含基础/奖励/护盾/捕捉/特效/世界野怪/地图费用/战斗通用逻辑)
|
||||
TableNameMeleeConfig = "config_boss_melee" // BOSS配置表(全量包含基础/奖励/护盾/捕捉/特效/世界野怪/地图费用/战斗通用逻辑)
|
||||
)
|
||||
|
||||
// PetBaseConfig BOSS配置模型(覆盖所有补充的配置项:GBTL/非VIP费用/首场景/战斗通用逻辑)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 表名常量定义:精灵奖励表(存储精灵BOSS/普通精灵对应的奖励配置:掉落物品/数量/概率/获取条件等)
|
||||
const (
|
||||
TableNamePetReward = "config_pet_reward" // 精灵奖励配置表(包含基础掉落/稀有奖励/VIP专属奖励/保底机制)
|
||||
TableNamePetReward = "config_gift_pet" // 精灵奖励配置表(包含基础掉落/稀有奖励/VIP专属奖励/保底机制)
|
||||
)
|
||||
|
||||
// PetReward 精灵奖励基础配置模型(核心存储结构,与数据库表字段一一对应)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 表名常量定义:炫彩皮肤表
|
||||
const (
|
||||
TableNameColorfulSkin = "colorful_skin" // 炫彩皮肤表(记录炫彩皮肤颜色、光环、绑定精灵等核心配置)
|
||||
TableNameColorfulSkin = "config_shiny" // 炫彩皮肤表(记录炫彩皮肤颜色、光环、绑定精灵等核心配置)
|
||||
)
|
||||
|
||||
// ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 表名常量定义:商店配置表
|
||||
const (
|
||||
TableNameShopConfig = "shop_config" // 商店配置表(记录商品信息、价格、库存、分类等)
|
||||
TableNameShopConfig = "config_shop" // 商店配置表(记录商品信息、价格、库存、分类等)
|
||||
)
|
||||
|
||||
// ShopConfig 商店商品核心配置模型
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/*
|
||||
* @Author: 昔念 12574910+72wo@users.noreply.github.com
|
||||
* @Date: 2025-12-31 02:42:41
|
||||
* @LastEditors: 昔念 12574910+72wo@users.noreply.github.com
|
||||
* @LastEditTime: 2026-01-18 11:37:05
|
||||
* @FilePath: \sun\modules\config\model\task.go
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
package model
|
||||
|
||||
import (
|
||||
@@ -15,11 +23,13 @@ type TaskConfig struct {
|
||||
|
||||
// 核心字段
|
||||
TaskId uint32 `gorm:"not null;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"`
|
||||
OutState uint32 `gorm:"not null;default:0;comment:'任务分支'" json:"out_state" description:"任务分支"`
|
||||
OutState int `gorm:"not null;default:0;comment:'任务分支'" json:"out_state" description:"任务分支"`
|
||||
//父级任务
|
||||
ParentTaskId uint32 `gorm:"not null;default:0;comment:'父级任务ID'" json:"parent_task_id" description:"父级任务ID"`
|
||||
// type(任务类型,0为常规任务,1为日常任务),
|
||||
TaskType uint32 `gorm:"not null;default:0;comment:'任务类型'" json:"task_type" description:"任务类型"`
|
||||
//是否可以被接受TaskConfig
|
||||
IsAcceptable uint32 `gorm:"not null;default:1;comment:'是否可以被接受'" json:"is_acceptable" description:"是否可以被接受"`
|
||||
|
||||
// 奖励配置
|
||||
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组,关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
|
||||
// -------------------------- 表名常量定义(统一管理所有塔配置表名)--------------------------
|
||||
const (
|
||||
TableNamedARKTowerConfig = "tower_110_config" // 勇者之塔110配置表
|
||||
TableNameTrialTowerConfig = "trial_tower_config" // 试炼之塔500配置表
|
||||
TableNameBraveTowerConfig = "brave_tower_config" // 勇者之塔600配置表
|
||||
TableNamedARKTowerConfig = "config_tower_110" // 勇者之塔110配置表
|
||||
TableNameTrialTowerConfig = "config_tower_500" // 试炼之塔500配置表
|
||||
TableNameBraveTowerConfig = "config_tower_600" // 勇者之塔600配置表
|
||||
)
|
||||
|
||||
// -------------------------- 核心基类:所有塔配置的通用结构 --------------------------
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 表名常量(遵循现有命名规范:小写+下划线)
|
||||
const TableNameSignIn = "player_sign_in"
|
||||
const TableNameSignIn = "config_sign_in"
|
||||
|
||||
// SignIn 签到记录表
|
||||
// 核心字段:签到完成状态、状压签到进度、签到奖励脚本
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 表名常量(遵循项目现有命名规范)
|
||||
const TableNameMineralCollectionConfig = "mineral_collection_config"
|
||||
const TableNameMineralCollectionConfig = "config_talk"
|
||||
|
||||
// MineralCollectionConfig 挖矿/采集/采摘矿产配置表Model定义
|
||||
// 字段完全匹配数据表结构,包含最小/最大产出核心字段
|
||||
|
||||
@@ -3,7 +3,23 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
)
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"github.com/google/uuid"
|
||||
) // 1. 扩展字符集:数字+大小写字母+安全符号(避开URL/输入易冲突的符号,如/、?、&)
|
||||
|
||||
const charsetWithSymbol = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz"
|
||||
|
||||
func Generate16CharSecure() string {
|
||||
result := make([]byte, 16)
|
||||
for i := 0; i < 16; i++ {
|
||||
|
||||
result[i] = charsetWithSymbol[grand.N(0, len(charsetWithSymbol)-1)]
|
||||
}
|
||||
return string(result)
|
||||
}
|
||||
|
||||
type CdkService struct {
|
||||
*cool.Service
|
||||
@@ -13,6 +29,33 @@ func NewCdkService() *CdkService {
|
||||
return &CdkService{
|
||||
&cool.Service{
|
||||
Model: model.NewCDKConfig(),
|
||||
InsertParam: func(ctx context.Context) g.MapStrAny {
|
||||
uuid.NewV7()
|
||||
return g.MapStrAny{
|
||||
"cdk_code": Generate16CharSecure(),
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
func (s *CdkService) Get(id string) *model.CDKConfig {
|
||||
var item *model.CDKConfig
|
||||
dbm(s.Model).Where("cdk_code", id).WhereNot("exchange_remain_count", 0).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *CdkService) Set(id string) bool {
|
||||
|
||||
res, err := cool.DBM(s.Model).Where("cdk_code", id).WhereNot("exchange_remain_count", 0).Decrement("exchange_remain_count", 1)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
rows, _ := res.RowsAffected()
|
||||
if rows == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
@@ -23,26 +23,13 @@ func NewTaskService() *TaskService {
|
||||
},
|
||||
}
|
||||
}
|
||||
func (s *TaskService) Get(id, os uint32) *model.TaskConfig {
|
||||
func (s *TaskService) Get(id, os int) *model.TaskConfig {
|
||||
var item []model.TaskConfig
|
||||
dbm(s.Model).Where("task_id", id).Scan(&item)
|
||||
var res *model.TaskConfig
|
||||
if len(item) == 1 { //只有一个直接默认
|
||||
if item[0].OutState == os {
|
||||
res = &item[0]
|
||||
}
|
||||
if item[0].OutState < 10 {
|
||||
res = &item[0]
|
||||
}
|
||||
|
||||
}
|
||||
if len(item) > 1 { //
|
||||
|
||||
for _, v := range item {
|
||||
if v.OutState == os {
|
||||
res = &item[os]
|
||||
return res
|
||||
}
|
||||
for _, v := range item {
|
||||
if v.OutState == os {
|
||||
res = &v
|
||||
|
||||
}
|
||||
|
||||
@@ -53,13 +40,20 @@ func (s *TaskService) Get(id, os uint32) *model.TaskConfig {
|
||||
}
|
||||
func (s *TaskService) GetDaily() []model.TaskConfig {
|
||||
var item []model.TaskConfig
|
||||
cool.DBM(s.Model).Where("task_type", 1).
|
||||
Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&item)
|
||||
dbm(s.Model).Where("task_type", 1).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
func (s *TaskService) IsAcceptable(taskid uint32) bool {
|
||||
|
||||
con, _ := cool.DBM(s.Model).Where("is_acceptable", 1).Where("task_id", taskid).
|
||||
Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Count()
|
||||
|
||||
return con > 0
|
||||
|
||||
}
|
||||
|
||||
@@ -68,28 +68,15 @@ func (m *UnifiedTowerModel) GroupName() string {
|
||||
// Boss 根据塔等级获取对应的Boss配置(统一入口)
|
||||
func (s *TowerService) Boss(towerLevel uint32) *model.BaseTowerConfig {
|
||||
// 构建基础查询条件
|
||||
query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel)
|
||||
query := cool.DBM(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1)
|
||||
|
||||
// 根据塔类型处理不同的缓存逻辑
|
||||
switch s.towerType {
|
||||
case TowerType110, TowerType500:
|
||||
// 110塔和500塔使用普通查询
|
||||
var config model.BaseTowerConfig
|
||||
query.Scan(&config)
|
||||
return &config
|
||||
|
||||
case TowerType600:
|
||||
// 600塔专属的缓存配置
|
||||
var config model.BaseTowerConfig
|
||||
query.Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour, // 可根据需要开启缓存时长
|
||||
Force: false,
|
||||
}).Scan(&config)
|
||||
return &config
|
||||
|
||||
default:
|
||||
return nil // 非支持类型返回nil,也可根据业务需求调整
|
||||
}
|
||||
// 600塔专属的缓存配置
|
||||
var config model.BaseTowerConfig
|
||||
query.Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour, // 可根据需要开启缓存时长
|
||||
Force: false,
|
||||
}).Scan(&config)
|
||||
return &config
|
||||
}
|
||||
|
||||
// 兼容原有调用方式的快捷构造函数(可选,保证代码平滑迁移)
|
||||
@@ -103,4 +90,4 @@ func NewTower500Service() *TowerService {
|
||||
|
||||
func NewTower600Service() *TowerService {
|
||||
return NewTowerService(TowerType600)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ package modules
|
||||
|
||||
import (
|
||||
_ "blazing/modules/base"
|
||||
_ "blazing/modules/blazing"
|
||||
_ "blazing/modules/config"
|
||||
_ "blazing/modules/dict"
|
||||
_ "blazing/modules/player"
|
||||
_ "blazing/modules/space"
|
||||
_ "blazing/modules/task"
|
||||
)
|
||||
|
||||
7
modules/player/blazing.go
Normal file
7
modules/player/blazing.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package blazing
|
||||
|
||||
import (
|
||||
_ "blazing/modules/player/controller"
|
||||
_ "blazing/modules/player/model"
|
||||
_ "blazing/modules/player/service"
|
||||
)
|
||||
@@ -2,7 +2,7 @@ package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/service"
|
||||
"blazing/modules/player/service"
|
||||
)
|
||||
|
||||
type ItemBagController struct {
|
||||
@@ -2,8 +2,8 @@ package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/blazing/service"
|
||||
"blazing/modules/player/model"
|
||||
"blazing/modules/player/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -2,7 +2,7 @@ package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/service"
|
||||
"blazing/modules/player/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
50
modules/player/controller/admin/title.go
Normal file
50
modules/player/controller/admin/title.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* @Author: 昔念 12574910+72wo@users.noreply.github.com
|
||||
* @Date: 2026-01-18 11:55:13
|
||||
* @LastEditors: 昔念 12574910+72wo@users.noreply.github.com
|
||||
* @LastEditTime: 2026-01-18 11:59:32
|
||||
* @FilePath: \sun\modules\blazing\controller\admin\title.go
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type TitleController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
var task_info_controller = &TitleController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/game/title",
|
||||
Api: []string{"Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewItemService(0), //因为page已经过滤,所以这里需要改成0
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(task_info_controller)
|
||||
}
|
||||
|
||||
type GetReq struct {
|
||||
g.Meta `path:"/get" method:"POST"`
|
||||
ID uint32 `json:"id"`
|
||||
}
|
||||
|
||||
func (c *TitleController) Get(ctx context.Context, req *GetReq) (res *cool.BaseRes, err error) {
|
||||
res = &cool.BaseRes{}
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
//r = g.RequestFromCtx(ctx)
|
||||
)
|
||||
|
||||
res.Data = service.NewUserService(uint32(admin.UserId)).Title.Get()
|
||||
return
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@ package app
|
||||
import (
|
||||
"blazing/cool"
|
||||
baseservice "blazing/modules/base/service"
|
||||
blazing "blazing/modules/blazing/service"
|
||||
"blazing/modules/config/service"
|
||||
blazing "blazing/modules/player/service"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
6
modules/player/controller/controller.go
Normal file
6
modules/player/controller/controller.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
_ "blazing/modules/player/controller/admin"
|
||||
_ "blazing/modules/player/controller/app"
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
module blazing/modules/blazing
|
||||
module blazing/modules/player
|
||||
|
||||
go 1.20
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
// 表名常量定义:精灵捕捉击杀数量记录表
|
||||
const (
|
||||
TableNamePetCatchKillCount = "pet_catch_kill_count" // 精灵捕捉击杀数量表(记录每个精灵的捕捉总数量、击杀总数量)
|
||||
TableNamePetCatchKillCount = "player_catch_kill_count" // 精灵捕捉击杀数量表(记录每个精灵的捕捉总数量、击杀总数量)
|
||||
)
|
||||
|
||||
// PetBargeListInfo 精灵捕捉击杀数量核心模型(简化版,直接记录数量,摒弃状态判断)
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// 表名常量定义:金豆消费记录表
|
||||
const (
|
||||
TableNameGoldBeanConsume = "gold_bean_consume_record" // 金豆消费记录表(记录用户金豆消耗的明细、类型、关联业务等信息)
|
||||
TableNameGoldBeanConsume = "player_gold_log" // 金豆消费记录表(记录用户金豆消耗的明细、类型、关联业务等信息)
|
||||
)
|
||||
|
||||
// 通过金豆消费时间来确认金豆物品的购买重置周期
|
||||
37
modules/player/model/cdk.go
Normal file
37
modules/player/model/cdk.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量
|
||||
const TableNamePlayerCdkLog = "player_cdk_log"
|
||||
|
||||
// CdkLog 对应数据库表 player_cdk_log,用于记录CDK兑换日志
|
||||
type CdkLog struct {
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_cdk_log_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
CodeID uint32 `gorm:"not null;comment:'CDK编号'" json:"code_id"`
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
func (*CdkLog) TableName() string {
|
||||
return TableNamePlayerCdkLog
|
||||
}
|
||||
|
||||
// GroupName 返回表组名
|
||||
func (*CdkLog) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewCdkLog 创建一个新的CDK记录
|
||||
func NewCdkLog() *CdkLog {
|
||||
return &CdkLog{
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 程序启动时自动创建表
|
||||
func init() {
|
||||
cool.CreateTable(&CdkLog{})
|
||||
}
|
||||
@@ -17,16 +17,7 @@ var MilestoneMode = enum.New[struct {
|
||||
Task EnumMilestone
|
||||
}]()
|
||||
|
||||
// 里程碑数据结构,与DoneEvent对应,记录单条里程碑的详细信息
|
||||
// type MilestoneData struct {
|
||||
// DoneType EnumMilestone `json:"done_type"` // 里程碑类型(如:0-地图解锁,1-BOSS击杀,2-物品收集等)
|
||||
// Args []uint32 `json:"args"` // 关联ID列表(如地图ID、BOSSID、物品ID等)
|
||||
// Results []uint32 `json:"results"` // 完成情况参数(如:击杀次数、收集数量阈值等)
|
||||
// Count uint32 `json:"count"` // 累计完成次数(如:某BOSS累计击杀3次)
|
||||
// //IsCompleted bool `json:"is_completed"` // 是否完全达成(用于区分阶段性里程碑)
|
||||
// }
|
||||
|
||||
const TableNameMilestone = "milestone"
|
||||
const TableNameMilestone = "player_milestone"
|
||||
|
||||
// Milestone 数据库存储结构体,映射milestone表
|
||||
type Milestone struct {
|
||||
@@ -1,51 +1,51 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const TableNamePlayerBagItem = "player_bag_item"
|
||||
|
||||
// PlayerBagItem mapped from table <player_bag_item>
|
||||
type Item struct {
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_bag_item_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
// 物品Id,
|
||||
ItemId uint32 `json:"item_id"`
|
||||
|
||||
// 物品数量,
|
||||
ItemCnt uint32 `json:"item_cnt"`
|
||||
}
|
||||
|
||||
type SingleItemInfo struct {
|
||||
// 物品Id,
|
||||
ItemId uint32 `json:"itemId"`
|
||||
// 物品数量,
|
||||
ItemCnt uint32 `json:"itemCnt"`
|
||||
// 固定值360000,
|
||||
LeftTime uint32 `json:"leftTime"`
|
||||
// 固定值0,
|
||||
ItemLevel uint32 `json:"itemLevel"`
|
||||
}
|
||||
|
||||
// TableName PlayerBagItem's table name
|
||||
func (*Item) TableName() string {
|
||||
return TableNamePlayerBagItem
|
||||
}
|
||||
|
||||
// GroupName PlayerBagItem's table group
|
||||
func (*Item) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPlayerBagItem create a new PlayerBagItem
|
||||
func NewPlayerBag() *Item {
|
||||
return &Item{
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
cool.CreateTable(&Item{})
|
||||
}
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
const TableNamePlayerBagItem = "player_item"
|
||||
|
||||
// PlayerBagItem mapped from table <player_bag_item>
|
||||
type Item struct {
|
||||
Base
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_bag_item_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
// 物品Id,
|
||||
ItemId uint32 `json:"item_id"`
|
||||
|
||||
// 物品数量,
|
||||
ItemCnt uint32 `json:"item_cnt"`
|
||||
}
|
||||
|
||||
type SingleItemInfo struct {
|
||||
// 物品Id,
|
||||
ItemId uint32 `json:"itemId"`
|
||||
// 物品数量,
|
||||
ItemCnt uint32 `json:"itemCnt"`
|
||||
// 固定值360000,
|
||||
LeftTime uint32 `json:"leftTime"`
|
||||
// 固定值0,
|
||||
ItemLevel uint32 `json:"itemLevel"`
|
||||
}
|
||||
|
||||
// TableName PlayerBagItem's table name
|
||||
func (*Item) TableName() string {
|
||||
return TableNamePlayerBagItem
|
||||
}
|
||||
|
||||
// GroupName PlayerBagItem's table group
|
||||
func (*Item) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPlayerBagItem create a new PlayerBagItem
|
||||
func NewPlayerBag() *Item {
|
||||
return &Item{
|
||||
Base: *NewBase(),
|
||||
}
|
||||
}
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
cool.CreateTable(&Item{})
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const TableNamePet = "pet"
|
||||
const TableNamePet = "player_pet"
|
||||
|
||||
// Pet mapped from table <pet>
|
||||
type Pet struct {
|
||||
@@ -54,6 +54,8 @@ type PetInfo struct {
|
||||
|
||||
// 名字:默认为全0,补齐到16字节(固定长度 → [16]byte)
|
||||
Name string `struc:"[16]byte" json:"Name,omitempty"`
|
||||
//generation
|
||||
Generation uint32 `fieldDesc:"世代" `
|
||||
|
||||
// 个体值(@UInt long → uint32)
|
||||
Dv uint32 `struc:"uint32" `
|
||||
@@ -128,10 +130,10 @@ const (
|
||||
// 功能:为宠物6个EV值增加增量,保证单个≤255、总和≤510
|
||||
// 参数:evadd - 6个EV字段的增量数组(长度必须为6)
|
||||
// 返回:error - 参数非法/逻辑异常时返回错误;bool - 是否触发了超额削减(方便业务监控)
|
||||
func (pet *PetInfo) AddEV(evadd []uint32) (bool, error) {
|
||||
func (pet *PetInfo) AddEV(ev_add []uint32) (bool, error) {
|
||||
// 1. 参数安全校验:避免数组越界panic
|
||||
if len(evadd) != evFieldCount {
|
||||
return false, fmt.Errorf("evadd长度必须为%d,当前为%d", evFieldCount, len(evadd))
|
||||
if len(ev_add) != evFieldCount {
|
||||
return false, fmt.Errorf("evadd长度必须为%d,当前为%d", evFieldCount, len(ev_add))
|
||||
}
|
||||
if len(pet.Ev) != evFieldCount {
|
||||
return false, errors.New("pet.Ev未初始化或长度不为6")
|
||||
@@ -141,7 +143,7 @@ func (pet *PetInfo) AddEV(evadd []uint32) (bool, error) {
|
||||
var tempEV [evFieldCount]uint32
|
||||
for i := 0; i < evFieldCount; i++ {
|
||||
// 直接累加增量
|
||||
tempEV[i] = pet.Ev[i] + evadd[i]
|
||||
tempEV[i] = pet.Ev[i] + ev_add[i]
|
||||
// 单项不超过255
|
||||
if tempEV[i] > maxSingleEV {
|
||||
tempEV[i] = maxSingleEV
|
||||
@@ -1,230 +1,230 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
const TableNamePlayerInfo = "player_info"
|
||||
|
||||
type Player struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
||||
Data string `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||
}
|
||||
type PlayerEX struct {
|
||||
Player
|
||||
Data PlayerInfo `orm:"data" json:"data"`
|
||||
}
|
||||
type Pos struct {
|
||||
X uint32 `struc:"uint32" default:"0"`
|
||||
Y uint32 `struc:"uint32" default:"0"`
|
||||
}
|
||||
|
||||
// 计算两个uint32的差值绝对值(转为int64避免溢出)
|
||||
func absDiff(a, b uint32) int64 {
|
||||
return int64(math.Abs(float64(int64(a) - int64(b))))
|
||||
}
|
||||
|
||||
// 判断两个Pos的X和Y差值的绝对值是否均小于50
|
||||
func bothDiffsLessThan50(pos1, pos2 Pos) bool {
|
||||
xDiff := absDiff(pos1.X, pos2.X)
|
||||
yDiff := absDiff(pos1.Y, pos2.Y)
|
||||
return xDiff < 50 && yDiff < 50
|
||||
}
|
||||
|
||||
func (p Pos) BothLessThan50(t Pos) bool {
|
||||
|
||||
return bothDiffsLessThan50(p, t)
|
||||
}
|
||||
|
||||
// PeopleItemInfo 穿戴装备信息结构(PeopleItemInfo)
|
||||
type PeopleItemInfo struct {
|
||||
ID uint32 `struc:"uint32"` // 装备id
|
||||
Level uint32 `struc:"uint32" default:"1"` // 未知字段(默认值1,@Builder.Default)
|
||||
}
|
||||
|
||||
// InitDefaults 初始化默认值(确保默认值正确赋值)
|
||||
func (p *PeopleItemInfo) InitDefaults() {
|
||||
p.Level = 1 // 未知字段默认值1,与Java的@Builder.Default保持一致
|
||||
}
|
||||
func NewPlayerInfo() PlayerInfo {
|
||||
l := PlayerInfo{
|
||||
|
||||
Clothes: make([]PeopleItemInfo, 0),
|
||||
PetList: make([]PetInfo, 0),
|
||||
}
|
||||
|
||||
// 自动填充 struct tag 里的 default 值
|
||||
if err := defaults.Set(&l); err != nil {
|
||||
panic(err) // 方便发现 default 设置错误
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// TaskStatus 任务状态(与 AS3 对应)
|
||||
type TaskStatus uint8
|
||||
|
||||
const (
|
||||
Unaccepted TaskStatus = 0 // 未接受(AS3 中 0 或 2 映射至此)
|
||||
Accepted TaskStatus = 1 // 已接受
|
||||
Completed TaskStatus = 3 // 已完成
|
||||
Reserved TaskStatus = 2 // 预留(AS3 中映射为未接受)
|
||||
)
|
||||
|
||||
// SetTask 设置第 i 个任务的状态(0 ≤ i < 2000)
|
||||
func (m *PlayerInfo) SetTask(i int, status TaskStatus) error {
|
||||
i-- //下标减1
|
||||
if i < 0 || i >= 4000 {
|
||||
return fmt.Errorf("index out of range: %d (must be 0-1999)", i)
|
||||
}
|
||||
|
||||
byteIdx := i / 4
|
||||
bitOffset := (i % 4) * 2
|
||||
|
||||
// 清除原有 2 位
|
||||
m.TaskList[byteIdx] &^= 0x3 << bitOffset
|
||||
|
||||
// 设置新状态(确保只取低 2 位)
|
||||
m.TaskList[byteIdx] |= byte(status&0x3) << bitOffset
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTask 获取第 i 个任务的状态
|
||||
func (m *PlayerInfo) GetTask(i int) TaskStatus {
|
||||
i-- //下标减1
|
||||
// if i < 0 || i >= 2000 {
|
||||
// return 0, fmt.Errorf("index out of range: %d", i)
|
||||
// }
|
||||
|
||||
byteIdx := i / 4
|
||||
bitOffset := (i % 4) * 2
|
||||
|
||||
return TaskStatus((m.TaskList[byteIdx] >> bitOffset) & 0x3)
|
||||
}
|
||||
|
||||
type PlayerInfo struct {
|
||||
ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池
|
||||
|
||||
OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数
|
||||
// OutInfo 字段
|
||||
UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到
|
||||
RegisterTime uint32 `struc:"uint32" json:"register_time"` // 注册时间(秒时间戳)
|
||||
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
|
||||
Title uint32 `struc:"uint32" json:"title"` // 称号
|
||||
Vip uint16 `struc:"uint16" json:"vip"` // 固定0
|
||||
Viped uint16 `struc:"uint16" default:"15" json:"viped"` // 固定15
|
||||
DSFlag uint32 `struc:"uint32" json:"ds_flag"` // 固定0
|
||||
Color uint32 `struc:"uint32" json:"color"` // 机器人颜色RGB颜色值(uint32,实际为3个uint8)
|
||||
Texture uint32 `struc:"uint32" json:"texture"` // 固定0
|
||||
Energy uint32 `struc:"uint32" default:"3000" json:"energy"` // 固定3000
|
||||
Coins uint32 `struc:"uint32" json:"coins"` // 赛尔豆
|
||||
EVPool uint32 `struc:"uint32" json:"ev_pool"` //累计学习力
|
||||
FightBadge uint32 `struc:"uint32" json:"fight_badge"` // 固定0
|
||||
MapID uint32 `struc:"uint32" default:"1" json:"map_id"` // 上线地图ID
|
||||
Pos Pos `json:"pos"` // 坐标
|
||||
TimeToday uint32 `struc:"uint32" default:"0" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit uint32 `struc:"uint32" default:"43200" json:"time_limit"` // 总电池限制(秒)
|
||||
IsClothHalfDay byte `struc:"byte" json:"is_cloth_half_day"` // 活动标志0/1
|
||||
IsRoomHalfDay byte `struc:"byte" json:"is_room_half_day"` // 活动标志0/1
|
||||
IFortressHalfDay byte `struc:"byte" json:"i_fortress_half_day"` // 活动标志0/1
|
||||
IsHQHalfDay byte `struc:"byte" json:"is_hq_half_day"` // 活动标志0/1
|
||||
LoginCount uint32 `struc:"uint32" json:"login_count"` // 固定0
|
||||
Inviter uint32 `struc:"uint32" json:"inviter"` // 固定0
|
||||
NewInviteeCount uint32 `struc:"uint32" json:"new_invitee_count"` // 固定0
|
||||
VipLevel uint32 `struc:"uint32" default:"8" json:"vip_level"` // 固定8
|
||||
VipValue uint32 `struc:"uint32" default:"80000" json:"vip_value"` // 固定80000
|
||||
VipStage uint32 `struc:"uint32" default:"1" json:"vip_stage"` // 超no的外形等级建议固定1
|
||||
AutoCharge uint32 `struc:"uint32" default:"1" json:"auto_charge"` // nono是否自动充电
|
||||
VipEndTime uint32 `struc:"uint32" default:"4294967295" json:"vip_end_time"` // 超no的结束时间建议尽可能大
|
||||
FreshManBonus uint32 `struc:"uint32" json:"fresh_man_bonus"` // 邀请活动建议先给固定值0
|
||||
//NonoChipList [80]byte `struc:"[80]byte" json:"-"` // 超no芯片列表
|
||||
DailyResArr [50]byte `struc:"[50]byte" default:"0" json:"daily_res_arr"` // 每日任务状态 40+是谱尼的
|
||||
Study struct {
|
||||
TeacherID uint32 `struc:"uint32" json:"teacher_id"` // 教官id
|
||||
|
||||
StudentID uint32 `struc:"uint32" json:"student_id"` // 学员id
|
||||
GraduationCount uint32 `struc:"uint32" default:"0" json:"graduation_count"` // 毕业人数
|
||||
}
|
||||
|
||||
MaxPuniLv uint32 `struc:"uint32" default:"0" json:"max_puni_lv"` // 默认0, 虚无 元素 能量 生命 轮回 永恒 圣洁 最高为8
|
||||
PetMaxLevel uint32 `struc:"uint32" json:"pet_max_level"` // 精灵最高等级
|
||||
AllPetNumber uint32 `struc:"uint32" json:"all_pet_number"` // 精灵数量
|
||||
MonKingWin uint32 `struc:"uint32" json:"mon_king_win"` // 精灵王胜场
|
||||
MessWin uint32 `struc:"skip" json:"mess_win"` // 大乱斗胜场
|
||||
CurrentStage uint32 `struc:"uint32" default:"1" json:"current_stage"` // 勇者之塔层数
|
||||
MaxStage uint32 `struc:"uint32" json:"max_stage"` // 试炼之塔最高层
|
||||
CurrentFreshStage uint32 `struc:"uint32" default:"1" json:"current_fresh_stage"` // 当前试炼层数
|
||||
MaxFreshStage uint32 `struc:"uint32" json:"max_fresh_stage"` // 最高试炼层
|
||||
MaxArenaWins uint32 `struc:"uint32" json:"max_arena_wins"` // 星际擂台连胜
|
||||
TwoTimes uint32 `struc:"uint32" default:"0" json:"two_times"` // 双倍经验加速器剩余使用次数
|
||||
ThreeTimes uint32 `struc:"uint32" default:"0" json:"three_times"` // 三倍经验加速器剩余使用次数
|
||||
AutoFight uint32 `struc:"uint32" default:"0" json:"auto_fight"` // 是否自动战斗
|
||||
AutoFightTime uint32 `struc:"uint32" default:"0" json:"auto_fight_time"` // 自动战斗剩余的场次
|
||||
EnergyTime uint32 `struc:"uint32" default:"0" json:"energy_time"` // 能量吸收仪剩余次数
|
||||
LearnTimes uint32 `struc:"uint32" default:"0" json:"learn_times"` // 学习力吸收仪剩余次数
|
||||
MonBattleMedal uint32 `struc:"uint32" default:"0" json:"mon_battle_medal"` // 默认0
|
||||
RecordCount uint32 `struc:"uint32" default:"0" json:"record_count"` // 默认0
|
||||
ObtainTm uint32 `struc:"uint32" default:"0" json:"obtain_tm"` // 默认0
|
||||
SoulBeadItemID uint32 `struc:"uint32" json:"soul_bead_item_id"` // 当前元神珠id
|
||||
ExpireTm uint32 `struc:"uint32" default:"0" json:"expire_tm"` // 默认0
|
||||
FuseTimes uint32 `struc:"uint32" default:"0" json:"fuse_times"` // 默认0
|
||||
|
||||
NONO struct {
|
||||
//fieldDescription:"1为跟随 0为收回 且如果为收回 那么后续结构不需要发送, 不序列化"
|
||||
Flag uint32 `struc:"skip" json:"nono_flag"`
|
||||
|
||||
HasNono uint32 `struc:"uint32" default:"1" json:"has_nono"` // 玩家是否有nono
|
||||
SuperNono uint32 `struc:"uint32" default:"1" json:"super_nono"` // 玩家是否有超能nono
|
||||
NonoState uint32 `struc:"uint32" default:"4294967295" json:"nono_state"` // 默认-1
|
||||
NonoColor uint32 `struc:"uint32" json:"nono_color"` // nono颜色
|
||||
Nick string `struc:"[16]byte" default:"nono" json:"nono_nick"` // nono名字(16字节)
|
||||
}
|
||||
|
||||
TeamInfo TeamInfo `struc:"struct" json:"team_info"` // 战队信息24字节
|
||||
TeamPkInfo TeamPKInfo `struc:"struct" json:"team_pk_info"` // 8字节
|
||||
Reserved byte `struc:"byte" json:"reserved"` // 1字节无内容
|
||||
Badge uint32 `struc:"uint32" default:"0" json:"badge"` // 默认0
|
||||
Reserved1 [27]byte `struc:"[27]byte" default:"3" json:"reserved1"` // 27字节默认3
|
||||
TaskList [1000]byte `struc:"[1000]byte" default:"0" json:"task_list"` // 任务状态数组500字节,默认3
|
||||
PetListCount uint32 `struc:"sizeof=PetList" json:"pet_list_count"` // 精灵列表长度
|
||||
PetList []PetInfo ` json:"pet_list"` // 精灵背包内信息
|
||||
ClothesCount uint32 `struc:"sizeof=Clothes" json:"clothes_count"` // 穿戴装备数量
|
||||
Clothes []PeopleItemInfo ` json:"clothes"` // 穿戴装备
|
||||
}
|
||||
|
||||
// trace("个人装扮是否半价:",MainManager.isClothHalfDay);
|
||||
// trace("小屋装扮是否半价:",MainManager.isRoomHalfDay);
|
||||
// trace("要塞装扮是否半价:",MainManager.iFortressHalfDay);
|
||||
// trace("总部装扮是否半价:",MainManager.isHQHalfDay);
|
||||
//
|
||||
// TableName PlayerInfo's table name
|
||||
func (*Player) TableName() string {
|
||||
return TableNamePlayerInfo
|
||||
}
|
||||
|
||||
// GroupName PlayerInfo's table group
|
||||
func (*Player) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPlayerInfo create a new PlayerInfo
|
||||
func NewPlayer() *PlayerEX {
|
||||
return &PlayerEX{
|
||||
Player: Player{
|
||||
Model: cool.NewModel(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
cool.CreateTable(&Player{})
|
||||
}
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
const TableNamePlayerInfo = "player_info"
|
||||
|
||||
type Player struct {
|
||||
*cool.Model
|
||||
PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务
|
||||
Data string `gorm:"type:jsonb;not null;comment:'全部数据'" json:"data"`
|
||||
}
|
||||
type PlayerEX struct {
|
||||
Player
|
||||
Data PlayerInfo `orm:"data" json:"data"`
|
||||
}
|
||||
type Pos struct {
|
||||
X uint32 `struc:"uint32" default:"0"`
|
||||
Y uint32 `struc:"uint32" default:"0"`
|
||||
}
|
||||
|
||||
// 计算两个uint32的差值绝对值(转为int64避免溢出)
|
||||
func absDiff(a, b uint32) int64 {
|
||||
return int64(math.Abs(float64(int64(a) - int64(b))))
|
||||
}
|
||||
|
||||
// 判断两个Pos的X和Y差值的绝对值是否均小于50
|
||||
func bothDiffsLessThan50(pos1, pos2 Pos) bool {
|
||||
xDiff := absDiff(pos1.X, pos2.X)
|
||||
yDiff := absDiff(pos1.Y, pos2.Y)
|
||||
return xDiff < 50 && yDiff < 50
|
||||
}
|
||||
|
||||
func (p Pos) BothLessThan50(t Pos) bool {
|
||||
|
||||
return bothDiffsLessThan50(p, t)
|
||||
}
|
||||
|
||||
// PeopleItemInfo 穿戴装备信息结构(PeopleItemInfo)
|
||||
type PeopleItemInfo struct {
|
||||
ID uint32 `struc:"uint32"` // 装备id
|
||||
Level uint32 `struc:"uint32" default:"1"` // 未知字段(默认值1,@Builder.Default)
|
||||
}
|
||||
|
||||
// InitDefaults 初始化默认值(确保默认值正确赋值)
|
||||
func (p *PeopleItemInfo) InitDefaults() {
|
||||
p.Level = 1 // 未知字段默认值1,与Java的@Builder.Default保持一致
|
||||
}
|
||||
func NewPlayerInfo() PlayerInfo {
|
||||
l := PlayerInfo{
|
||||
|
||||
Clothes: make([]PeopleItemInfo, 0),
|
||||
PetList: make([]PetInfo, 0),
|
||||
}
|
||||
|
||||
// 自动填充 struct tag 里的 default 值
|
||||
if err := defaults.Set(&l); err != nil {
|
||||
panic(err) // 方便发现 default 设置错误
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// TaskStatus 任务状态(与 AS3 对应)
|
||||
type TaskStatus uint8
|
||||
|
||||
const (
|
||||
Unaccepted TaskStatus = 0 // 未接受(AS3 中 0 或 2 映射至此)
|
||||
Accepted TaskStatus = 1 // 已接受
|
||||
Completed TaskStatus = 3 // 已完成
|
||||
Reserved TaskStatus = 2 // 预留(AS3 中映射为未接受)
|
||||
)
|
||||
|
||||
// SetTask 设置第 i 个任务的状态(0 ≤ i < 2000)
|
||||
func (m *PlayerInfo) SetTask(i int, status TaskStatus) error {
|
||||
i-- //下标减1
|
||||
if i < 0 || i >= 4000 {
|
||||
return fmt.Errorf("index out of range: %d (must be 0-1999)", i)
|
||||
}
|
||||
|
||||
byteIdx := i / 4
|
||||
bitOffset := (i % 4) * 2
|
||||
|
||||
// 清除原有 2 位
|
||||
m.TaskList[byteIdx] &^= 0x3 << bitOffset
|
||||
|
||||
// 设置新状态(确保只取低 2 位)
|
||||
m.TaskList[byteIdx] |= byte(status&0x3) << bitOffset
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTask 获取第 i 个任务的状态
|
||||
func (m *PlayerInfo) GetTask(i int) TaskStatus {
|
||||
i-- //下标减1
|
||||
// if i < 0 || i >= 2000 {
|
||||
// return 0, fmt.Errorf("index out of range: %d", i)
|
||||
// }
|
||||
|
||||
byteIdx := i / 4
|
||||
bitOffset := (i % 4) * 2
|
||||
|
||||
return TaskStatus((m.TaskList[byteIdx] >> bitOffset) & 0x3)
|
||||
}
|
||||
|
||||
type PlayerInfo struct {
|
||||
ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池
|
||||
|
||||
OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数
|
||||
// OutInfo 字段
|
||||
UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到
|
||||
RegisterTime uint32 `struc:"uint32" json:"register_time"` // 注册时间(秒时间戳)
|
||||
Nick string `struc:"[16]byte" default:"seer" json:"nick"` // 16字节昵称
|
||||
Title uint32 `struc:"uint32" json:"title"` // 称号
|
||||
Vip uint16 `struc:"uint16" json:"vip"` // 固定0
|
||||
Viped uint16 `struc:"uint16" default:"15" json:"viped"` // 固定15
|
||||
DSFlag uint32 `struc:"uint32" json:"ds_flag"` // 固定0
|
||||
Color uint32 `struc:"uint32" json:"color"` // 机器人颜色RGB颜色值(uint32,实际为3个uint8)
|
||||
Texture uint32 `struc:"uint32" json:"texture"` // 固定0
|
||||
Energy uint32 `struc:"uint32" default:"3000" json:"energy"` // 固定3000
|
||||
Coins uint32 `struc:"uint32" json:"coins"` // 赛尔豆
|
||||
EVPool uint32 `struc:"uint32" json:"ev_pool"` //累计学习力
|
||||
FightBadge uint32 `struc:"uint32" json:"fight_badge"` // 固定0
|
||||
MapID uint32 `struc:"uint32" default:"1" json:"map_id"` // 上线地图ID
|
||||
Pos Pos `json:"pos"` // 坐标
|
||||
TimeToday uint32 `struc:"uint32" default:"0" json:"time_today"` // 已消耗时间(秒)
|
||||
TimeLimit uint32 `struc:"uint32" default:"43200" json:"time_limit"` // 总电池限制(秒)
|
||||
IsClothHalfDay byte `struc:"byte" json:"is_cloth_half_day"` // 活动标志0/1
|
||||
IsRoomHalfDay byte `struc:"byte" json:"is_room_half_day"` // 活动标志0/1
|
||||
IFortressHalfDay byte `struc:"byte" json:"i_fortress_half_day"` // 活动标志0/1
|
||||
IsHQHalfDay byte `struc:"byte" json:"is_hq_half_day"` // 活动标志0/1
|
||||
LoginCount uint32 `struc:"uint32" json:"login_count"` // 固定0
|
||||
Inviter uint32 `struc:"uint32" json:"inviter"` // 固定0
|
||||
NewInviteeCount uint32 `struc:"uint32" json:"new_invitee_count"` // 固定0
|
||||
VipLevel uint32 `struc:"uint32" default:"8" json:"vip_level"` // 固定8
|
||||
VipValue uint32 `struc:"uint32" default:"80000" json:"vip_value"` // 固定80000
|
||||
VipStage uint32 `struc:"uint32" default:"1" json:"vip_stage"` // 超no的外形等级建议固定1
|
||||
AutoCharge uint32 `struc:"uint32" default:"1" json:"auto_charge"` // nono是否自动充电
|
||||
VipEndTime uint32 `struc:"uint32" default:"4294967295" json:"vip_end_time"` // 超no的结束时间建议尽可能大
|
||||
FreshManBonus uint32 `struc:"uint32" json:"fresh_man_bonus"` // 邀请活动建议先给固定值0
|
||||
//NonoChipList [80]byte `struc:"[80]byte" json:"-"` // 超no芯片列表
|
||||
DailyResArr [50]byte `struc:"[50]byte" default:"0" json:"daily_res_arr"` // 每日任务状态 40+是谱尼的
|
||||
Study struct {
|
||||
TeacherID uint32 `struc:"uint32" json:"teacher_id"` // 教官id
|
||||
|
||||
StudentID uint32 `struc:"uint32" json:"student_id"` // 学员id
|
||||
GraduationCount uint32 `struc:"uint32" default:"0" json:"graduation_count"` // 毕业人数
|
||||
}
|
||||
|
||||
MaxPuniLv uint32 `struc:"uint32" default:"0" json:"max_puni_lv"` // 默认0, 虚无 元素 能量 生命 轮回 永恒 圣洁 最高为8
|
||||
PetMaxLevel uint32 `struc:"uint32" json:"pet_max_level"` // 精灵最高等级
|
||||
AllPetNumber uint32 `struc:"uint32" json:"all_pet_number"` // 精灵数量
|
||||
MonKingWin uint32 `struc:"uint32" json:"mon_king_win"` // 精灵王胜场
|
||||
MessWin uint32 `struc:"skip" json:"mess_win"` // 大乱斗胜场
|
||||
CurrentStage uint32 `struc:"uint32" default:"1" json:"current_stage"` // 勇者之塔层数
|
||||
MaxStage uint32 `struc:"uint32" json:"max_stage"` // 试炼之塔最高层
|
||||
CurrentFreshStage uint32 `struc:"uint32" default:"1" json:"current_fresh_stage"` // 当前试炼层数
|
||||
MaxFreshStage uint32 `struc:"uint32" json:"max_fresh_stage"` // 最高试炼层
|
||||
MaxArenaWins uint32 `struc:"uint32" json:"max_arena_wins"` // 星际擂台连胜
|
||||
TwoTimes uint32 `struc:"uint32" default:"0" json:"two_times"` // 双倍经验加速器剩余使用次数
|
||||
ThreeTimes uint32 `struc:"uint32" default:"0" json:"three_times"` // 三倍经验加速器剩余使用次数
|
||||
AutoFight uint32 `struc:"uint32" default:"0" json:"auto_fight"` // 是否自动战斗
|
||||
AutoFightTime uint32 `struc:"uint32" default:"0" json:"auto_fight_time"` // 自动战斗剩余的场次
|
||||
EnergyTime uint32 `struc:"uint32" default:"0" json:"energy_time"` // 能量吸收仪剩余次数
|
||||
LearnTimes uint32 `struc:"uint32" default:"0" json:"learn_times"` // 学习力吸收仪剩余次数
|
||||
MonBattleMedal uint32 `struc:"uint32" default:"0" json:"mon_battle_medal"` // 默认0
|
||||
RecordCount uint32 `struc:"uint32" default:"0" json:"record_count"` // 默认0
|
||||
ObtainTm uint32 `struc:"uint32" default:"0" json:"obtain_tm"` // 默认0
|
||||
SoulBeadItemID uint32 `struc:"uint32" json:"soul_bead_item_id"` // 当前元神珠id
|
||||
ExpireTm uint32 `struc:"uint32" default:"0" json:"expire_tm"` // 默认0
|
||||
FuseTimes uint32 `struc:"uint32" default:"0" json:"fuse_times"` // 默认0
|
||||
|
||||
NONO struct {
|
||||
//fieldDescription:"1为跟随 0为收回 且如果为收回 那么后续结构不需要发送, 不序列化"
|
||||
Flag uint32 `struc:"skip" json:"nono_flag"`
|
||||
|
||||
HasNono uint32 `struc:"uint32" default:"1" json:"has_nono"` // 玩家是否有nono
|
||||
SuperNono uint32 `struc:"uint32" default:"1" json:"super_nono"` // 玩家是否有超能nono
|
||||
NonoState uint32 `struc:"uint32" default:"4294967295" json:"nono_state"` // 默认-1
|
||||
NonoColor uint32 `struc:"uint32" json:"nono_color"` // nono颜色
|
||||
Nick string `struc:"[16]byte" default:"nono" json:"nono_nick"` // nono名字(16字节)
|
||||
}
|
||||
|
||||
TeamInfo TeamInfo `struc:"struct" json:"team_info"` // 战队信息24字节
|
||||
TeamPkInfo TeamPKInfo `struc:"struct" json:"team_pk_info"` // 8字节
|
||||
Reserved byte `struc:"byte" json:"reserved"` // 1字节无内容
|
||||
Badge uint32 `struc:"uint32" default:"0" json:"badge"` // 默认0
|
||||
Reserved1 [27]byte `struc:"[27]byte" default:"3" json:"reserved1"` // 27字节默认3
|
||||
TaskList [1000]byte `struc:"[1000]byte" default:"0" json:"task_list"` // 任务状态数组500字节,默认3
|
||||
PetListCount uint32 `struc:"sizeof=PetList" json:"pet_list_count"` // 精灵列表长度
|
||||
PetList []PetInfo ` json:"pet_list"` // 精灵背包内信息
|
||||
ClothesCount uint32 `struc:"sizeof=Clothes" json:"clothes_count"` // 穿戴装备数量
|
||||
Clothes []PeopleItemInfo ` json:"clothes"` // 穿戴装备
|
||||
}
|
||||
|
||||
// trace("个人装扮是否半价:",MainManager.isClothHalfDay);
|
||||
// trace("小屋装扮是否半价:",MainManager.isRoomHalfDay);
|
||||
// trace("要塞装扮是否半价:",MainManager.iFortressHalfDay);
|
||||
// trace("总部装扮是否半价:",MainManager.isHQHalfDay);
|
||||
//
|
||||
// TableName PlayerInfo's table name
|
||||
func (*Player) TableName() string {
|
||||
return TableNamePlayerInfo
|
||||
}
|
||||
|
||||
// GroupName PlayerInfo's table group
|
||||
func (*Player) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewPlayerInfo create a new PlayerInfo
|
||||
func NewPlayer() *PlayerEX {
|
||||
return &PlayerEX{
|
||||
Player: Player{
|
||||
Model: cool.NewModel(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// init 创建表
|
||||
func init() {
|
||||
cool.CreateTable(&Player{})
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 基地房型表名
|
||||
const TableNameBaseHouse = "room_house"
|
||||
const TableNameBaseHouse = "player_room_house"
|
||||
|
||||
// NewBaseHouse 构造函数:创建基地房型实例
|
||||
func NewBaseHouse() *BaseHouse {
|
||||
@@ -24,14 +24,12 @@ type BaseHouse struct {
|
||||
|
||||
// 核心业务字段
|
||||
// ShowPokemon 基地展示精灵ID列表(支持展示多个精灵)
|
||||
ShowPokemon []uint32 `gorm:"type:json;not null;default:'[]';comment:'基地展示精灵ID列表'" json:"show_pokemon"`
|
||||
ShowPokemon []uint32 `gorm:"type:jsonb;default:'[]';comment:'基地展示精灵ID列表'" json:"show_pokemon"`
|
||||
|
||||
// OwnedItems 基地拥有物品(key=物品ID,value=物品数量,JSON格式存储)
|
||||
OwnedItems string `gorm:"type:json;not null;default:'{}';comment:'基地拥有物品(物品ID:数量)'" json:"owned_items"`
|
||||
UserItems string `gorm:"type:json;not null;default:'{}';comment:'用户物品列表(物品ID:数量)'" json:"user_items"`
|
||||
UsedItems string `gorm:"type:jsonb;default:'{}';comment:'用户物品列表(物品ID:数量)'" json:"used_items"`
|
||||
|
||||
// PlacedItems 基地摆放物品(包含物品ID、摆放坐标、朝向等信息)
|
||||
PlacedItems string `gorm:"type:json;not null;default:'[]';comment:'基地摆放物品列表(含位置/朝向)'" json:"placed_items"`
|
||||
PlacedItems string `gorm:"type:jsonb;default:'[]';comment:'基地摆放物品列表(含位置/朝向)'" json:"placed_items"`
|
||||
}
|
||||
|
||||
func (*BaseHouse) TableName() string {
|
||||
@@ -41,8 +39,8 @@ func (*BaseHouse) TableName() string {
|
||||
type BaseHouseEx struct {
|
||||
BaseHouse
|
||||
PlacedItems []FitmentShowInfo `json:"placed_items"`
|
||||
OwnedItems map[uint32]uint32 `json:"owned_items"`
|
||||
UserItems map[uint32]uint32 `json:"user_items"`
|
||||
//OwnedItems map[uint32]uint32 `json:"owned_items"`
|
||||
UsedItems map[uint32]uint32 `json:"used_items"`
|
||||
}
|
||||
|
||||
// FitmentShowInfo 表示家具展示信息
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 表名常量(遵循小写+下划线的命名规范)
|
||||
const TableNameSignInRecord = "player_sign_in_record"
|
||||
const TableNameSignInRecord = "player_sign_in_log"
|
||||
|
||||
// SignInRecord 玩家签到明细记录表
|
||||
// 记录玩家每一次的签到行为,关联签到活动表
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// 资源采集计数表名
|
||||
const TableNameResourceCollection = "talk"
|
||||
const TableNameResourceCollection = "player_talk"
|
||||
|
||||
func NewTalk() *Talk {
|
||||
return &Talk{
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// todo 还需要做一个记录任务奖励的表
|
||||
const TableNameTask = "task"
|
||||
const TableNameTask = "player_task"
|
||||
|
||||
// Task mapped from table <task>
|
||||
type Task struct {
|
||||
@@ -16,14 +16,6 @@ type Title struct {
|
||||
AvailableTitle []uint32 `gorm:"type:json; comment:'可用称号'" json:"available_title"`
|
||||
}
|
||||
|
||||
// TitleInfo 用于前端返回的称号信息
|
||||
type TitleInfo struct {
|
||||
TitleId uint32 `json:"titleId"` // 称号ID
|
||||
LeftTime uint32 `json:"leftTime"` // 剩余时间(秒),永久称号可设为 0
|
||||
ItemLevel uint32 `json:"itemLevel"` // 称号等级,可固定为 0
|
||||
IsActive bool `json:"isActive"` // 是否当前使用
|
||||
}
|
||||
|
||||
// TableName 返回表名
|
||||
func (*Title) TableName() string {
|
||||
return TableNamePlayerTitle
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
42
modules/player/service/cdk_log.go
Normal file
42
modules/player/service/cdk_log.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type CdkService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (s *CdkService) CanGet(id uint32) bool {
|
||||
m1, _ := s.TestModel(s.Model).Where("code_id", id).Exist()
|
||||
|
||||
return !m1
|
||||
|
||||
}
|
||||
|
||||
func (s *CdkService) Log(id uint32) {
|
||||
m := s.TestModel(s.Model)
|
||||
data := g.Map{
|
||||
"player_id": s.userid,
|
||||
"code_id": id,
|
||||
"is_vip": cool.Config.ServerInfo.IsVip,
|
||||
}
|
||||
|
||||
m.Data(data).Insert()
|
||||
|
||||
}
|
||||
|
||||
func NewCdkService(id uint32) *CdkService {
|
||||
return &CdkService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewCdkLog()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
@@ -3,11 +3,13 @@ package service
|
||||
import (
|
||||
"blazing/common/data/share"
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -15,6 +17,7 @@ import (
|
||||
"github.com/gogf/gf/v2/os/glog"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
"github.com/google/uuid"
|
||||
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
||||
)
|
||||
|
||||
// 是否注册,如果注册过,那么就会产生用户player信息
|
||||
@@ -68,11 +71,23 @@ func (s *InfoService) Person(userid uint32) *model.PlayerInfo {
|
||||
return &ret
|
||||
|
||||
}
|
||||
func (s *InfoService) Personself() *model.PlayerInfo {
|
||||
func (s *InfoService) GetCache() *model.PlayerInfo {
|
||||
|
||||
ret, _ := cool.CacheManager.Get(context.TODO(), fmt.Sprintf("player: %d", s.userid))
|
||||
if ret == nil {
|
||||
return nil
|
||||
}
|
||||
var rets *model.PlayerInfo
|
||||
ret.Struct(&rets)
|
||||
return rets
|
||||
|
||||
}
|
||||
func (s *InfoService) SetLogin() *model.PlayerInfo {
|
||||
|
||||
m := cool.DBM(s.Model).Where("player_id", s.userid)
|
||||
var tt model.PlayerEX
|
||||
err := m.Scan(&tt)
|
||||
if err != nil {
|
||||
var tt *model.PlayerEX
|
||||
m.Scan(&tt)
|
||||
if tt == nil {
|
||||
return nil
|
||||
}
|
||||
tt.Data.AllPetNumber = uint32(NewPetService(s.userid).PetCount(0))
|
||||
@@ -104,10 +119,19 @@ func (s *InfoService) Personself() *model.PlayerInfo {
|
||||
|
||||
}
|
||||
ret := tt.Data
|
||||
|
||||
return &ret
|
||||
|
||||
}
|
||||
|
||||
var User = csmap.New[string, uint32](
|
||||
// set the number of map shards. the default value is 32.
|
||||
csmap.WithShardCount[string, uint32](32),
|
||||
|
||||
// set the total capacity, every shard map has total capacity/shard count capacity. the default value is 0.
|
||||
// csmap.WithSize[string, int](1000),
|
||||
)
|
||||
|
||||
// 生成session
|
||||
// GetSessionId 生成并返回会话ID、UUID字符串及可能的错误
|
||||
// 会话ID由accountID(4字节) + UUID(16字节) + 随机数(4字节)组成,最终编码为十六进制字符串
|
||||
@@ -132,27 +156,28 @@ func (s *InfoService) Gensession() string {
|
||||
|
||||
// 编码为十六进制字符串作为最终会话ID
|
||||
sessionID := hex.EncodeToString(sessionBytes)
|
||||
share.ShareManager.SaveSession(string(uuidStr), uint32(s.userid))
|
||||
User.Store(string(uuidStr), uint32(s.userid))
|
||||
//share.ShareManager.SaveSession(string(uuidStr), uint32(s.userid))
|
||||
return sessionID
|
||||
}
|
||||
|
||||
func (s *InfoService) Kick(id uint32) {
|
||||
func (s *InfoService) Kick(id uint32) error {
|
||||
|
||||
cool.Logger.Info(context.TODO(), "服务器收到踢人")
|
||||
useid1, err := share.ShareManager.GetUserOnline(id)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
cl, ok := cool.GetClient(useid1)
|
||||
if ok {
|
||||
err := cl.KickPerson(id) //实现指定服务器踢人
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *InfoService) Save(data model.PlayerInfo) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -3,7 +3,7 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/base/service"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
)
|
||||
|
||||
@@ -17,26 +17,27 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx {
|
||||
return ttt
|
||||
|
||||
}
|
||||
func (s *RoomService) Add(id, count uint32) {
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Scan(&ttt)
|
||||
if ttt.OwnedItems == nil {
|
||||
ttt.OwnedItems = make(map[uint32]uint32)
|
||||
// func (s *RoomService) Add(id, count uint32) {
|
||||
// //todo待测试
|
||||
// var ttt model.BaseHouseEx
|
||||
// m := s.TestModel(s.Model)
|
||||
|
||||
}
|
||||
t, ok := ttt.OwnedItems[id]
|
||||
if ok {
|
||||
ttt.OwnedItems[id] = t + count
|
||||
} else {
|
||||
ttt.OwnedItems[id] = count
|
||||
}
|
||||
ttt.PlayerID = uint64(s.userid)
|
||||
m.Save(ttt)
|
||||
// m.Scan(&ttt)
|
||||
// if ttt.OwnedItems == nil {
|
||||
// ttt.OwnedItems = make(map[uint32]uint32)
|
||||
|
||||
}
|
||||
// }
|
||||
// t, ok := ttt.OwnedItems[id]
|
||||
// if ok {
|
||||
// ttt.OwnedItems[id] = t + count
|
||||
// } else {
|
||||
// ttt.OwnedItems[id] = count
|
||||
// }
|
||||
// ttt.PlayerID = uint64(s.userid)
|
||||
// m.Save(ttt)
|
||||
|
||||
// }
|
||||
func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
@@ -44,6 +45,16 @@ func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
|
||||
m.Scan(&ttt)
|
||||
ttt.PlacedItems = id
|
||||
ttt.UsedItems = make(map[uint32]uint32)
|
||||
for _, ids := range id {
|
||||
_, ok := ttt.UsedItems[ids.Id]
|
||||
if !ok {
|
||||
ttt.UsedItems[ids.Id] = 1
|
||||
} else {
|
||||
ttt.UsedItems[ids.Id] = ttt.UsedItems[ids.Id] + 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ttt.PlayerID = uint64(s.userid)
|
||||
m.Save(ttt)
|
||||
@@ -2,8 +2,8 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
config "blazing/modules/config/service"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/player/model"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
75
modules/player/service/title.go
Normal file
75
modules/player/service/title.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type TitleService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (s *TitleService) Get() []uint32 {
|
||||
m1 := s.TestModel(s.Model)
|
||||
|
||||
var talks *model.Title
|
||||
|
||||
m1.Scan(&talks)
|
||||
if talks == nil {
|
||||
return []uint32{}
|
||||
}
|
||||
return talks.AvailableTitle
|
||||
}
|
||||
|
||||
func (s *TitleService) Can(id uint32) bool {
|
||||
m1 := s.TestModel(s.Model)
|
||||
|
||||
var talks *model.Title
|
||||
|
||||
m1.Scan(&talks)
|
||||
if talks == nil {
|
||||
return false
|
||||
}
|
||||
_, ok := lo.Find(talks.AvailableTitle, func(item uint32) bool {
|
||||
return item == id
|
||||
|
||||
})
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s *TitleService) Give(id uint32) bool {
|
||||
m1 := s.TestModel(s.Model)
|
||||
|
||||
var talks *model.Title
|
||||
|
||||
m1.Scan(&talks)
|
||||
|
||||
if talks == nil {
|
||||
m := s.TestModel(s.Model)
|
||||
data := g.Map{
|
||||
"player_id": s.userid,
|
||||
"available_title": []uint32{id},
|
||||
"is_vip": cool.Config.ServerInfo.IsVip,
|
||||
}
|
||||
|
||||
m.Data(data).Insert()
|
||||
return true
|
||||
}
|
||||
talks.AvailableTitle = append(talks.AvailableTitle, id)
|
||||
m1.Save()
|
||||
return true
|
||||
}
|
||||
|
||||
func NewTitleService(id uint32) *TitleService {
|
||||
return &TitleService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewPlayerTitle()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,6 +19,8 @@ type UserService struct {
|
||||
Done *DoneService //完成
|
||||
Room *RoomService
|
||||
Barge *BargeService
|
||||
Title *TitleService
|
||||
Cdk *CdkService
|
||||
}
|
||||
|
||||
func NewUserService(id uint32) *UserService {
|
||||
@@ -32,6 +34,8 @@ func NewUserService(id uint32) *UserService {
|
||||
Done: NewDoneService(id),
|
||||
Room: NewRoomService(id),
|
||||
Barge: NewBargeService(id),
|
||||
Title: NewTitleService(id),
|
||||
Cdk: NewCdkService(id),
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user