diff --git a/logic/controller/fight_boss.go b/logic/controller/fight_boss野怪和地图怪.go similarity index 97% rename from logic/controller/fight_boss.go rename to logic/controller/fight_boss野怪和地图怪.go index 40b115552..2686e6265 100644 --- a/logic/controller/fight_boss.go +++ b/logic/controller/fight_boss野怪和地图怪.go @@ -15,7 +15,6 @@ import ( "github.com/gogf/gf/v2/util/gconv" "github.com/gogf/gf/v2/util/grand" - "github.com/samber/lo" ) // processMonID 处理怪物ID字符串,如果是多个ID则随机选择一个 @@ -177,7 +176,7 @@ func (Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInf int(refPet.Lv), refPet.ShinyInfo, -1) if refPet.Ext != 0 { - if grand.Meet(3, 100) { + if grand.Meet(2, 1000) { monster.RandShiny() } } @@ -217,10 +216,11 @@ func (Controller) OnPlayerFightNpcMonster(data1 *fight.FightNpcMonsterInboundInf evs := gconv.Int64s(strings.Split(xmlres.PetMAP[int(monster.ID)].YieldingEV, " ")) foi.Winpet.AddEV(evs) - if leve == 8 { - items.EV = lo.Sum(evs) - 1 - p.Info.EVPool += lo.Sum(evs) //给予累计学习力 - } + //取消累计学习力掉落 + // if leve == 8 { + // items.EV = lo.Sum(evs) - 1 + // p.Info.EVPool += lo.Sum(evs) //给予累计学习力 + // } p.SendPackCmd(8004, items) diff --git a/logic/controller/fight_leitai.go b/logic/controller/fight_擂台.go similarity index 98% rename from logic/controller/fight_leitai.go rename to logic/controller/fight_擂台.go index e94deafa1..2c0ae9064 100644 --- a/logic/controller/fight_leitai.go +++ b/logic/controller/fight_擂台.go @@ -75,12 +75,13 @@ func (h Controller) ArenaFightOwner(data *fight.ARENA_FIGHT_OWENR, c *player.Pla } - if foi.Reason == 0 { //异常退出 + if foi.Reason == 0 { //正常获胜 if foi.WinnerId == c.GetInfo().UserID { c.Info.MaxArenaWins += 1 } else { c.GetSpace().Owner.ARENA_Player.GetInfo().MaxArenaWins += 1 + //这里给经验 } } diff --git a/logic/controller/map.go b/logic/controller/map.go index a3e6c56a1..8cdb1c8ef 100644 --- a/logic/controller/map.go +++ b/logic/controller/map.go @@ -18,7 +18,7 @@ func (h Controller) EnterMap(data *space.InInfo, c *player.Player) (result *info if c.Info.MapID != data.MapId { atomic.StoreUint32(&c.Canmon, 2) - c.MapNPC.Reset(7 * time.Second) + c.MapNPC.Reset(6 * time.Second) } else { atomic.StoreUint32(&c.Canmon, 1) } diff --git a/logic/controller/pet_info.go b/logic/controller/pet_info.go index ee0f27870..c018ff7ee 100644 --- a/logic/controller/pet_info.go +++ b/logic/controller/pet_info.go @@ -125,7 +125,7 @@ func (h Controller) TogglePetBagWarehouse( if ok { // ========== 新增:index合法性校验 ========== if index < 0 || index >= len(player.Info.PetList) { - return result, errorcode.ErrorCodes.ErrSystemError + return result, errorcode.ErrorCodes.ErrPokemonIDMismatch } player.Service.Pet.UPdate(*pet) @@ -142,7 +142,7 @@ func (h Controller) TogglePetBagWarehouse( if !ok { r := player.Service.Pet.PetInfo_One(data.CatchTime) if r == nil { - return result, errorcode.ErrorCodes.ErrSystemError + return result, errorcode.ErrorCodes.ErrPokemonNotExists } player.Info.PetList = append(player.Info.PetList, r.Data) result.PetInfo = r.Data diff --git a/logic/controller/pet_collect.go b/logic/controller/pet_收集计划.go similarity index 100% rename from logic/controller/pet_collect.go rename to logic/controller/pet_收集计划.go diff --git a/logic/controller/user_task.go b/logic/controller/user_task.go index a7a0ce668..c20bf352e 100644 --- a/logic/controller/user_task.go +++ b/logic/controller/user_task.go @@ -79,7 +79,7 @@ func (h Controller) CompleteTask(data1 *task.CompleteTaskInboundInfo, c *player. taskInfo := task.GetTaskInfo(int(data1.TaskId), int(data1.OutState)) if taskInfo == nil { - return result, 0 + return nil, errorcode.ErrorCodes.ErrNeedCompleteTaskForPrize } if taskInfo.Pet != nil { diff --git a/logic/main.go b/logic/main.go index 54088d502..19bbce392 100644 --- a/logic/main.go +++ b/logic/main.go @@ -35,7 +35,7 @@ func PprofWeb() { } func cleanup() { - log.Println("执行优雅清理资源...") + fmt.Println("执行优雅清理资源...") player.Mainplayer.Range(func(key uint32, value *player.Player) bool { value.Kick(true) @@ -43,7 +43,7 @@ func cleanup() { return false }) //fight.Fightpool.ReleaseTimeout(0) - log.Println("资源清理完成,程序即将退出") + fmt.Println("资源清理完成,程序即将退出") } // signalHandlerForMain 主进程信号处理函数 diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index 5d3845e20..1b7ff6165 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -221,7 +221,8 @@ func (our *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) alpaca // 10. PwrDouble: 攻击时,若对方处于异常状态, 则威力翻倍; // 11. DmgBindHpDv: 造成的伤害等于自身剩余体力*1/2+潜力(个体值); 默认: 0 if skill.DmgBindLv != 0 { - skill.Power = int(deftype.CurrentPet.Info.Level) + level := utils.Min(deftype.CurrentPet.Info.Level, 100) + skill.Power = int(level) } if skill.PwrBindDv != 0 { diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index 31652f82d..edf6632c9 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -115,7 +115,7 @@ func (f *FightC) battleLoop() { } // f.Our.Player.(*player.Player).MapNPC.Reset(7 * time.Second) - f.Our.Player.(*player.Player).Info.FightTime = f.Our.Player.(*player.Player).Info.FightTime + time.Now().Unix() - f.StartTime.Unix() + // f.Our.Player.(*player.Player).Info.FightTime = f.Our.Player.(*player.Player).Info.FightTime + time.Now().Unix() - f.StartTime.Unix() } //大乱斗,给个延迟 diff --git a/logic/service/player/Monster.go b/logic/service/player/Monster.go index 21336b1fa..a299a0766 100644 --- a/logic/service/player/Monster.go +++ b/logic/service/player/Monster.go @@ -19,17 +19,6 @@ func RandomStringFromSlice(s []string) string { return s[randomIdx] } -// 刷怪具体实现 - -func (p *Player) Next(time.Time) time.Time { - if atomic.LoadUint32(&p.Canmon) != 1 { - return time.Now().Add(7 * time.Second) - } - - return time.Now().Add(10 * time.Second) - -} - // 应该根据怪物信息决定后端生成 func (p *Player) GenMonster() { @@ -88,7 +77,7 @@ func (p *Player) GenMonster() { if cool.Config.ServerInfo.IsVip != 0 { //测试服,百分百异色 p.OgreInfo.Data[i].FixSHiny() } - if xmlres.PetMAP[int(p.OgreInfo.Data[i].ID)].CatchRate != 0 && grand.Meet(3, 1000) { + if xmlres.PetMAP[int(p.OgreInfo.Data[i].ID)].CatchRate != 0 && grand.Meet(2, 1000) { p.OgreInfo.Data[i].RandSHiny() } if ok { diff --git a/logic/service/player/new.go b/logic/service/player/new.go index 132e41836..8f9424255 100644 --- a/logic/service/player/new.go +++ b/logic/service/player/new.go @@ -9,7 +9,7 @@ import ( // 定义刷野间隔常量(可根据业务调整) const ( - firstEnterInterval = 7 * time.Second // 首次进图/退出战斗后首次 刷新间隔 + //firstEnterInterval = 7 * time.Second // 首次进图/退出战斗后首次 刷新间隔 normalRefreshInterval = 10 * time.Second // 正常循环 刷新间隔 ) diff --git a/logic/service/player/save.go b/logic/service/player/save.go index 1224102c9..2d39d22ce 100644 --- a/logic/service/player/save.go +++ b/logic/service/player/save.go @@ -25,7 +25,7 @@ func (p *Player) Save() { newtime := time.Now().Unix() p.Info.TimeToday = p.Info.TimeToday + newtime - int64(p.Logintime) //保存电池时间 - p.Info.FightTime = p.Info.FightTime + (newtime - int64(p.Logintime)) + // p.Info.FightTime = p.Info.FightTime + (newtime - int64(p.Logintime)) p.Info.OnlineTime = p.Info.OnlineTime + (newtime-int64(p.Logintime))/60 //每次退出时候保存已经在线的分钟数 if p.FightC != nil { @@ -70,12 +70,12 @@ func (p *Player) CanGetExp() int { } islogintime := (int64(time.Now().Unix()) - int64(p.Logintime)) - if p.Info.FightTime > 0 { - return 8 - } + // if p.Info.FightTime > 0 { + // return 8 + // } if islogintime <= (p.Info.TimeLimit - p.Info.TimeToday) { - return 2 + return 1 } else { return 0 } diff --git a/modules/config/model/pet_base.go b/modules/config/model/base_pet.go similarity index 100% rename from modules/config/model/pet_base.go rename to modules/config/model/base_pet.go diff --git a/modules/config/model/cdk.go b/modules/config/model/cdk.go index 1322ccc3c..a62a2d7b4 100644 --- a/modules/config/model/cdk.go +++ b/modules/config/model/cdk.go @@ -28,7 +28,6 @@ type CDKConfig struct { 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"` } // -------------------------- 核心配套方法(遵循项目规范)-------------------------- diff --git a/modules/config/model/egg.go b/modules/config/model/config_egg.go similarity index 64% rename from modules/config/model/egg.go rename to modules/config/model/config_egg.go index 8edc9858b..1d63e0d2c 100644 --- a/modules/config/model/egg.go +++ b/modules/config/model/config_egg.go @@ -8,9 +8,30 @@ const ( TableNameEgg = "config_egg" // 性别配置表(替换原宠物融合表名) ) +type BaseConfig struct { + *cool.Model // 保留通用Model(ID/创建时间/更新时间等) + IsEnable int32 `gorm:"not null;default:0;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"` // 保留原有逻辑 + Remark string `gorm:"type:varchar(255);default:'';comment:'性别配置备注(如:默认性别规则)'" json:"remark"` // 调整注释 +} + +func (m *BaseConfig) TableName() string { + return "this_table_should_not_exist" +} + +// 返回分组名 +func (m *BaseConfig) GroupName() string { + return "default" +} + +func NewBaseConfig() *BaseConfig { + return &BaseConfig{ + Model: cool.NewModel(), + } +} + // Egg 性别配置模型(替换原宠物融合配方模型) type Egg struct { - *cool.Model // 保留通用Model(ID/创建时间/更新时间等) + *BaseConfig //雌性 MalePetIDs []int32 `gorm:"type:int[];comment:'雄性宠物ID列表(如:[1001,1002])'" json:"male_pet_ids"` //雄性 @@ -18,9 +39,6 @@ type Egg struct { //子代指定性别配置表名 OutputMons []int32 `gorm:"type:int[];not null;comment:'宠物类型ID'" json:"pet_type_id"` Probs []int32 `gorm:"type:int[];not null;comment:'对应子代宠物类型的概率(如:[50,50]表示均等概率)'" json:"probs"` - - IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"` // 保留原有逻辑 - Remark string `gorm:"type:varchar(255);default:'';comment:'性别配置备注(如:默认性别规则)'" json:"remark"` // 调整注释 } // TableName 指定性别配置表名(替换原宠物融合表名) @@ -36,7 +54,7 @@ func (*Egg) GroupName() string { // NewEgg 创建性别配置实例(替换原NewPetFusion) func NewEgg() *Egg { return &Egg{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/fusion_material.go b/modules/config/model/fusion_material.go index d10788ba2..c9f539148 100644 --- a/modules/config/model/fusion_material.go +++ b/modules/config/model/fusion_material.go @@ -8,21 +8,17 @@ const ( // PetFusionMaterial 融合材料模型(与配方主表一对一关联) type PetFusionMaterial struct { - *cool.Model // 嵌入通用Model(ID/创建时间/更新时间等) + *BaseConfig - // 4个材料ID(对应XML ItemGroup的Idx=1-4,无材料填0) Material1 uint32 `gorm:"not null;comment:'材料1ID(如400030)'" json:"material1"` Material2 uint32 `gorm:"not null;comment:'材料2ID(如400030)'" json:"material2"` Material3 uint32 `gorm:"not null;comment:'材料3ID(如400028)'" json:"material3"` Material4 uint32 `gorm:"not null;comment:'材料4ID(如400030)'" json:"material4"` - // 4个特性ID(对应XML MaterialGroup的特性索引,4-4对应) Trait1Idx uint32 `gorm:"not null;comment:'特性1索引(如1008)'" json:"trait1_idx"` Trait2Idx uint32 `gorm:"not null;comment:'特性2索引(如1018)'" json:"trait2_idx"` Trait3Idx uint32 `gorm:"not null;comment:'特性3索引(如1023)'" json:"trait3_idx"` Trait4Idx uint32 `gorm:"not null;comment:'特性4索引(如1031)'" json:"trait4_idx"` - - IsEnable int32 `gorm:"not null;default:0;comment:'是否启用该组合(1:启用,0:禁用)'" json:"is_enable"` } // TableName 指定子表名 @@ -38,7 +34,7 @@ func (*PetFusionMaterial) GroupName() string { // NewPetFusionMaterial 创建材料实例 func NewPetFusionMaterial() *PetFusionMaterial { return &PetFusionMaterial{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/fusion_pet.go b/modules/config/model/fusion_pet.go index fd05708b2..2e77cd5a6 100644 --- a/modules/config/model/fusion_pet.go +++ b/modules/config/model/fusion_pet.go @@ -10,16 +10,15 @@ const ( // PetFusion 宠物融合配方主模型(核心配方规则) type PetFusion struct { - *cool.Model // 嵌入通用Model(ID/创建时间/更新时间等) + *BaseConfig MainPetID int32 `gorm:"not null;comment:'主宠物ID(如:尼尔)'" json:"main_pet_id"` - //SubPetID int32 `gorm:"not null;comment:'副宠物ID(如:闪皮)'" json:"sub_pet_id"` + SubPetIDs []int32 `gorm:"type:int[];comment:'副宠物IDs(如:1,2,3)'" json:"sub_pet_ids"` Probability int32 `gorm:"not null;comment:'融合成功率(百分比,如80代表80%)'" json:"probability"` ResultPetID int32 `gorm:"not null;comment:'融合结果宠物ID(如:卡鲁、闪尼)'" json:"result_pet_id"` - Remark string `gorm:"type:varchar(255);default:'';comment:'融合配方备注(如:尼尔+闪皮=闪尼)'" json:"remark"` - IsEnable int32 `gorm:"not null;default:0;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"` - IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"` + + IsDefault int32 `gorm:"not null;default:0;comment:'是否默认配方(1:默认配方,0:非默认;所有配方不匹配时随机选默认配方)'" json:"is_default"` // 关联:一个配方对应多个材料(gorm 一对多关联,查询时可预加载) //Materials []*PetFusionMaterial `gorm:"foreignKey:PetFusionID;references:ID" json:"materials,omitempty"` @@ -38,7 +37,7 @@ func (*PetFusion) GroupName() string { // NewPetFusion 创建主表实例 func NewPetFusion() *PetFusion { return &PetFusion{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/item_gift.go b/modules/config/model/item_gift.go index 6644fc0d7..82ff9507d 100644 --- a/modules/config/model/item_gift.go +++ b/modules/config/model/item_gift.go @@ -11,13 +11,11 @@ const ( // ItemGift 物品奖励基础配置模型(与数据库表 item_gift 字段一一对应,核心存储结构) type ItemGift struct { - *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段,保持与现有模型一致性) - + *BaseConfig // 核心业务字段(按需求实现:物品id、备注、是否启用、是否为扭蛋、物品数量) - ItemID int64 `gorm:"not null;default:0;comment:'物品ID,关联物品配置表主键'" json:"item_id"` - Remark string `gorm:"size:512;default:'';comment:'物品奖励备注说明(如使用场景、特殊说明等)'" json:"remark"` - IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled"` - IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 + ItemID int64 `gorm:"not null;default:0;comment:'物品ID,关联物品配置表主键'" json:"item_id"` + + IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 //ItemCount uint32 `gorm:"not null;default:1;comment:'物品奖励数量'" json:"item_count"` ItemMinCount int64 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"` // ItemMaxCount 单次采集最大产出数量 @@ -37,9 +35,7 @@ func (*ItemGift) GroupName() string { // NewItemGift 创建一个新的ItemGift实例(初始化通用Model字段+默认值,与现有实例创建逻辑一致) func NewItemGift() *ItemGift { return &ItemGift{ - Model: cool.NewModel(), // 初始化通用Model字段(ID/创建时间/更新时间等) - // 字段默认值与gorm tag中default配置保持一致 - IsEnabled: 1, + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/monster_refresh.go b/modules/config/model/monster_refresh.go index cc050a8f2..57a9a610c 100644 --- a/modules/config/model/monster_refresh.go +++ b/modules/config/model/monster_refresh.go @@ -10,7 +10,7 @@ const ( // MonsterRefresh 怪物刷新规则模型(对应前端配置的地图/精灵/等级/脚本配置) type MonsterRefresh struct { - *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段) + *BaseConfig MapID int32 `gorm:"not null;comment:'地图ID'" json:"map_id"` MonsterID string `gorm:"not null;comment:'精灵ID,填0为填充数组'" json:"monster_id"` @@ -21,9 +21,6 @@ type MonsterRefresh struct { // 以下为原模型保留的异色相关字段(前端暂未配置,如需移除可删除) ShinyID string `gorm:"not null;comment:'异色唯一标识ID'" json:"shiny_id"` - // ShinyFilter string `gorm:"type:text;not null;comment:'异色滤镜效果(文本描述或配置参数)'" json:"shiny_filter"` - // ShinyEffect string `gorm:"type:text;not null;comment:'异色光效效果(文本描述或配置参数)'" json:"shiny_effect"` - // TODO: 增加ruffle的显示异色效果(如需保留则完善,无需则删除) } type MonsterRefreshEX struct { @@ -45,7 +42,7 @@ func (*MonsterRefresh) GroupName() string { // NewMonsterRefresh 创建一个新的MonsterRefresh实例(初始化通用Model) func NewMonsterRefresh() *MonsterRefresh { return &MonsterRefresh{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/pet_gift.go b/modules/config/model/pet_gift.go index 600a01d04..5a93b4c1a 100644 --- a/modules/config/model/pet_gift.go +++ b/modules/config/model/pet_gift.go @@ -11,15 +11,15 @@ const ( // PetReward 精灵奖励基础配置模型(核心存储结构,与数据库表字段一一对应) type PetReward struct { - *cool.Model // 嵌入通用Model(包含ID/创建时间/更新时间等通用字段,保持与BossConfig一致) - IsEnabled uint32 `gorm:"not null;default:0;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled"` - MonID int32 `gorm:"not null;comment:'BOSS对应的精灵ID'" json:"mon_id"` - DV int32 `gorm:"not null;default:0;comment:'成长值'" json:"dv"` - Nature int32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"` - Effect int32 `gorm:"not null;comment:'BOSS特性'" json:"effect"` - Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"` - IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 - Desc *string `gorm:"size:512;default:'';comment:'BOSS描述'" json:"desc"` + *BaseConfig + + MonID int32 `gorm:"not null;comment:'BOSS对应的精灵ID'" json:"mon_id"` + DV int32 `gorm:"not null;default:0;comment:'成长值'" json:"dv"` + Nature int32 `gorm:"not null;default:0;comment:'BOSS属性-性格'" json:"nature"` + Effect int32 `gorm:"not null;comment:'BOSS特性'" json:"effect"` + Lv int32 `gorm:"not null;comment:'BOSS等级(LvHpMatchUser非0时此配置无效)'" json:"lv"` + IsEgg uint32 `gorm:"not null;default:0;comment:'是否蛋'" json:"is_egg"` //奖励是否为扭蛋奖励 + IsLight uint32 `gorm:"not null;default:0;comment:'是否擦灯'" json:"is_light"` //奖励是否为光之子`` } // TableName 指定PetReward对应的数据库表名(遵循现有代码规范) @@ -35,9 +35,7 @@ func (*PetReward) GroupName() string { // NewPetReward 创建一个新的PetReward实例(初始化通用Model字段+所有字段默认值,与NewBossConfig保持一致) func NewPetReward() *PetReward { return &PetReward{ - Model: cool.NewModel(), // 初始化通用Model字段(ID/创建时间/更新时间等) - // 可根据需要设置其他字段的默认值,此处保持与gorm tag中default一致 - + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/shiny.go b/modules/config/model/shiny.go index edcd2d219..a6baa20b4 100644 --- a/modules/config/model/shiny.go +++ b/modules/config/model/shiny.go @@ -12,12 +12,11 @@ const ( // ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配) type ColorfulSkin struct { - *cool.Model + *BaseConfig // 核心必填字段 Color data.GlowFilter `gorm:"type:jsonb;not null;;comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"` - IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"` Author string `gorm:"not null;size:64;default:'';comment:'炫彩皮肤配置作者(创建人/配置者名称)'" json:"author" description:"作者"` RefreshCount uint32 `gorm:"not null;default:0;comment:'累计刷新次数(炫彩皮肤外观刷新次数统计)'" json:"refresh_count" description:"刷新次数"` UsageCount uint32 `gorm:"not null;default:0;comment:'累计使用次数(炫彩皮肤使用次数统计)'" json:"usage_count" description:"使用次数"` @@ -26,9 +25,6 @@ type ColorfulSkin struct { ElfProbability uint32 `gorm:"not null;default:0;comment:'野生精灵概率(0-10000)'" json:"elf_probability" description:"野生精灵概率"` //投票 VoteCount uint32 `gorm:"not null;default:0;comment:'投票次数'" json:"vote_count" description:"投票次数"` - - // 辅助备注字段 - Remark string `gorm:"size:512;default:'';comment:'炫彩皮肤备注'" json:"remark" description:"备注信息"` } // -------------------------- 核心配套方法(仅更名适配,逻辑不变)-------------------------- @@ -42,7 +38,7 @@ func (*ColorfulSkin) GroupName() string { func NewColorfulSkin() *ColorfulSkin { return &ColorfulSkin{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/shop.go b/modules/config/model/shop.go index 415e59426..93d4778d7 100644 --- a/modules/config/model/shop.go +++ b/modules/config/model/shop.go @@ -11,16 +11,14 @@ const ( // ShopConfig 商店商品核心配置模型 type ShopConfig struct { - *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) - + *BaseConfig // 核心字段 ProductName string `gorm:"not null;size:128;comment:'商品名称'" json:"product_name" description:"商品名称"` //商品类型 ProductType uint32 `gorm:"not null;default:0;comment:'商品类型(0-普通商品 1-虚拟商品 2-限时商品)'" json:"product_type" description:"商品类型"` //商品ID - ProductID int64 `gorm:"not null;uniqueIndex;comment:'商品ID'" json:"product_id" description:"商品ID"` - Desc string `gorm:"not null;size:512;comment:'商品描述'" json:"desc" description:"商品描述"` + ProductID int64 `gorm:"not null;uniqueIndex;comment:'商品ID'" json:"product_id" description:"商品ID"` // 价格信息 -1代表不允许购买,0表示不支持购买 SeerdouPrice int32 `gorm:"not null;default:0;comment:'骄阳豆价格'" json:"seerdou_price" description:"骄阳豆价格"` @@ -29,9 +27,6 @@ type ShopConfig struct { // 库存信息 Stock uint32 `gorm:"not null;default:0;comment:'商品库存数量(0表示无限库存)'" json:"stock" description:"库存数量"` - // 状态信息 - IsOnSale uint32 `gorm:"not null;default:1;comment:'是否上架(0-下架 1-上架)'" json:"is_on_sale" description:"是否上架"` - // 限购信息 QuotaLimit uint32 `gorm:"not null;default:0;comment:'单位时间内的限购数量(0表示不限购)'" json:"quota_limit" description:"限购数量"` QuotaCycle uint32 `gorm:"not null;default:0;comment:'限购周期(单位:小时,0表示不限购)'" json:"quota_cycle" description:"限购周期(小时)"` @@ -48,7 +43,7 @@ func (*ShopConfig) GroupName() string { func NewShopConfig() *ShopConfig { return &ShopConfig{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/task.go b/modules/config/model/task.go index e3272c0c3..9eb7fefcf 100644 --- a/modules/config/model/task.go +++ b/modules/config/model/task.go @@ -1,11 +1,3 @@ -/* - * @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 ( @@ -19,7 +11,7 @@ const ( // TaskConfig 任务核心配置模型 type TaskConfig struct { - *cool.Model + *BaseConfig // 核心字段 TaskId uint32 `gorm:"not null;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"` @@ -37,10 +29,6 @@ type TaskConfig struct { //绑定奖励 TitleRewardIds uint32 `gorm:"not null;default:0;comment:'绑定奖励称号'" json:"title_reward_ids" description:"绑定奖励称号"` - // 任务状态和周期 - IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该任务(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"` - - Remark string `gorm:"size:512;default:'';comment:'任务备注'" json:"remark" description:"备注信息"` } // -------------------------- 核心配套方法(遵循项目规范)-------------------------- @@ -54,7 +42,7 @@ func (*TaskConfig) GroupName() string { func NewTaskConfig() *TaskConfig { return &TaskConfig{ - Model: cool.NewModel(), + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/model/tower_110.go b/modules/config/model/tower_110.go index 01a0ada0d..a49bbe56c 100644 --- a/modules/config/model/tower_110.go +++ b/modules/config/model/tower_110.go @@ -13,24 +13,19 @@ const ( // -------------------------- 核心基类:所有塔配置的通用结构 -------------------------- type BaseTowerConfig struct { - *cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化) - + *BaseConfig + Name string `gorm:"size:32;default:'';comment:'塔层名称'" json:"name" description:"塔层名称"` + // ItemGift []ItemGift `orm:"with:item_id=id"` // 核心必填字段(所有塔类型通用) TowerLevel uint32 `gorm:"not null;default:0;uniqueIndex;comment:'塔层数(唯一标识每层配置)'" json:"tower_level" description:"塔层数"` BossIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定BOSS ID数组,关联config_pet_boss表主键'" json:"boss_ids" description:"绑定BOSS数组"` TaskIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定任务ID数组,关联config_task表主键'" json:"task_ids" description:"绑定任务数组"` - - // 通用辅助字段(所有塔类型通用) - IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用该层配置(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"` - Remark string `gorm:"size:512;default:'';comment:'塔层备注'" json:"remark" description:"备注信息"` - Name string `gorm:"size:32;default:'';comment:'塔层名称'" json:"name" description:"塔层名称"` - // ItemGift []ItemGift `orm:"with:item_id=id"` } // NewBaseTowerConfig 创建基础塔配置实例(所有塔类型共用) -func NewBaseTowerConfig() BaseTowerConfig { - return BaseTowerConfig{ - Model: cool.NewModel(), +func NewBaseTowerConfig() *BaseTowerConfig { + return &BaseTowerConfig{ + BaseConfig: NewBaseConfig(), } } @@ -38,17 +33,17 @@ func NewBaseTowerConfig() BaseTowerConfig { // Tower110Config 勇者之塔110配置模型 type Tower110Config struct { - BaseTowerConfig + *BaseTowerConfig } // Tower500Config 试炼之塔500配置模型 type Tower500Config struct { - BaseTowerConfig + *BaseTowerConfig } // Tower600Config 勇者之塔600配置模型 type Tower600Config struct { - BaseTowerConfig + *BaseTowerConfig } // -------------------------- 各塔模型的核心配套方法(统一规范)-------------------------- diff --git a/modules/config/model/user_talk.go b/modules/config/model/user_talk.go index 575a54ae9..dcaaf1c64 100644 --- a/modules/config/model/user_talk.go +++ b/modules/config/model/user_talk.go @@ -10,7 +10,7 @@ const TableNameMineralCollectionConfig = "config_talk" // MineralCollectionConfig 挖矿/采集/采摘矿产配置表Model定义 // 字段完全匹配数据表结构,包含最小/最大产出核心字段 type MineralCollectionConfig struct { - *cool.Model // 嵌入基础Model,包含id(主键)、createTime、updateTime等通用字段 + *BaseConfig // MapID 矿产所在地图ID MapID uint32 `gorm:"column:map_id;not null;index:idx_mineral_collection_config_map_id;comment:矿产所在地图ID" json:"map_id"` @@ -21,13 +21,6 @@ type MineralCollectionConfig struct { // ItemID 物品编号(对应道具系统ID) ItemIDS []uint32 `gorm:"column:item_ids;type:jsonb;index:idx_mineral_collection_config_item_id;comment:物品编号(对应道具系统ID)" json:"item_ids"` - // ItemMinCount 单次采集最小产出数量 - // ItemMinCount uint32 `gorm:"column:item_min_count;not null;comment:单次采集最小产出数量" json:"item_min_count"` - // // ItemMaxCount 单次采集最大产出数量 - // ItemMaxCount uint32 `gorm:"column:item_max_count;not null;comment:单次采集最大产出数量" json:"item_max_count"` - // Description 矿产描述 - Description string `gorm:"column:description;type:varchar(128); comment:矿产描述" json:"description"` - // ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"` } // TableName 指定数据表名(必须匹配数据库表名,遵循项目规范) @@ -44,7 +37,7 @@ func (*MineralCollectionConfig) GroupName() string { // 保证通用字段(createTime/updateTime)被正确初始化 func NewMineralCollectionConfig() *MineralCollectionConfig { return &MineralCollectionConfig{ - Model: cool.NewModel(), // 调用基础Model的初始化方法 + BaseConfig: NewBaseConfig(), } } diff --git a/modules/config/service/base.go b/modules/config/service/base.go index 66eb26152..84719d9e9 100644 --- a/modules/config/service/base.go +++ b/modules/config/service/base.go @@ -8,8 +8,35 @@ import ( // /取消redis空节点的强制缓存 func dbm(m cool.IModel) *gdb.Model { - return cool.DBM(m). - Cache(gdb.CacheOption{ - Force: true, + ret := cool.DBM(m) + if cool.Config.ServerInfo.IsVip == 0 { //正式服启动缓存 + ret = ret.Where("is_enable", 1) + } + if cool.Config.ServerInfo.IsDebug == 0 { + + ret = ret.Cache(gdb.CacheOption{ + Force: false, }) + } + return ret +} +func dbm_fix(m cool.IModel) *gdb.Model { + ret := cool.DBM(m).Cache(gdb.CacheOption{ + Force: false, + }) + + return ret +} +func dbm_nocache(m cool.IModel) *gdb.Model { + ret := cool.DBM(m) + if cool.Config.ServerInfo.IsVip == 0 { //正式服启动缓存 + ret = ret.Where("is_enable", 1) + } + // if cool.Config.ServerInfo.IsDebug == 0 { + + // ret = ret.Cache(gdb.CacheOption{ + // Force: false, + // }) + // } + return ret } diff --git a/modules/config/service/boss.go b/modules/config/service/boss.go index f830f8322..462b58b27 100644 --- a/modules/config/service/boss.go +++ b/modules/config/service/boss.go @@ -25,7 +25,7 @@ func (s *BossService) Get(id uint32) *model.BossConfig { return nil } var item *model.BossConfig - dbm(s.Model).Where("id", id).Scan(&item) + dbm_fix(s.Model).Where("id", id).Scan(&item) return item diff --git a/modules/config/service/cdk.go b/modules/config/service/cdk.go index 204b07b39..10f6092a5 100644 --- a/modules/config/service/cdk.go +++ b/modules/config/service/cdk.go @@ -40,7 +40,7 @@ func NewCdkService() *CdkService { } 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) + dbm_fix(s.Model).Where("cdk_code", id).WhereNot("exchange_remain_count", 0).Scan(&item) return item diff --git a/modules/config/service/effect.go b/modules/config/service/effect.go index 885bceca0..0bca4827b 100644 --- a/modules/config/service/effect.go +++ b/modules/config/service/effect.go @@ -10,7 +10,7 @@ type EffectService struct { } func (s *EffectService) Args(id uint32) (int, []int) { - m := dbm(s.Model).Where("se_idx", id) + m := dbm_fix(s.Model).Where("se_idx", id) var tt model.PlayerPetSpecialEffect m.Scan(&tt) diff --git a/modules/config/service/egg.go b/modules/config/service/egg.go index 7acd38c99..3f276166b 100644 --- a/modules/config/service/egg.go +++ b/modules/config/service/egg.go @@ -26,8 +26,7 @@ func (s *EggService) GetData(p1 uint32) []int32 { m := dbm(s.Model) var pet []model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性 - m.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, p1). - Where("is_enable", 1).Scan(&pet) + m.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, p1).Scan(&pet) var petIDs []int32 for _, p := range pet { petIDs = append(petIDs, p.FemalePetIDs...) @@ -42,8 +41,7 @@ func (s *EggService) GetResult(m, f uint32) uint32 { var pet *model.Egg //一个特性应该是唯一的,但是我们要获取默认随机特性 md.Wheref(`male_pet_ids @> ARRAY[?]::integer[]`, m). - Wheref(`female_pet_ids @> ARRAY[?]::integer[]`, f). - Where("is_enable", 1).Scan(&pet) + Wheref(`female_pet_ids @> ARRAY[?]::integer[]`, f).Scan(&pet) if pet != nil { t, _ := utils.RandomByWeight(pet.OutputMons, pet.Probs) diff --git a/modules/config/service/item.go b/modules/config/service/item.go index 33aaa1d09..b0056d5aa 100644 --- a/modules/config/service/item.go +++ b/modules/config/service/item.go @@ -6,7 +6,6 @@ import ( "blazing/cool" "blazing/modules/config/model" - "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/util/grand" ) @@ -19,7 +18,7 @@ type ItemService struct { func (s *ItemService) GetItemCount(id uint32) data.ItemInfo { var item model.ItemGift var res data.ItemInfo - dbm(s.Model).Where("id", id).Where("is_enabled", 1).Scan(&item) + dbm(s.Model).Where("id", id).Scan(&item) if item.ItemID == 0 { @@ -36,11 +35,7 @@ func (s *ItemService) GetItemCount(id uint32) data.ItemInfo { } func (s *ItemService) GetEgg(count int64) []data.ItemInfo { var item []model.ItemGift - cool.DBM(s.Model).Where("is_egg", 1).Where("is_enabled", 1).Cache(gdb.CacheOption{ - // Duration: time.Hour, - - Force: false, - }).Scan(&item) + dbm(s.Model).Where("is_egg", 1).Scan(&item) rr := utils.RandomSlice(item, int(count)) var res = make([]data.ItemInfo, len(rr)) diff --git a/modules/config/service/pet.go b/modules/config/service/pet.go index e23196048..4e9c5c05a 100644 --- a/modules/config/service/pet.go +++ b/modules/config/service/pet.go @@ -18,7 +18,7 @@ func NewPetRewardService() *PetRewardService { } func (s *PetRewardService) GetEgg() model.PetReward { var item model.PetReward - cool.DBM(s.Model).Where("is_egg", 1).Where("is_enabled", 1).OrderRandom().Limit(1).Scan(&item) + dbm_nocache(s.Model).Where("is_egg", 1).OrderRandom().Limit(1).Scan(&item) return item diff --git a/modules/config/service/pet_fusion_service.go b/modules/config/service/pet_fusion_service.go index c74b8727d..c6aead926 100644 --- a/modules/config/service/pet_fusion_service.go +++ b/modules/config/service/pet_fusion_service.go @@ -5,7 +5,6 @@ import ( "blazing/cool" "blazing/modules/config/model" - "github.com/gogf/gf/v2/database/gdb" "github.com/gogf/gf/v2/util/grand" ) @@ -63,12 +62,9 @@ func (s *PetFusionService) Data(p1, p2, rand uint32) uint32 { } func (s *PetFusionService) getData(p1, p2 uint32) []model.PetFusion { - //cacheKey := strings.Join([]string{fmt.Sprintf("%d", p1), fmt.Sprintf("%d", p2)}, ":") - m := dbm(s.Model) var pet []model.PetFusion //一个特性应该是唯一的,但是我们要获取默认随机特性 - m.Where("main_pet_id", p1).Wheref(`sub_pet_ids @> ARRAY[?]::integer[]`, p2). - Where("is_enable", 1).Scan(&pet) + dbm(s.Model).Where("main_pet_id", p1).Wheref(`sub_pet_ids @> ARRAY[?]::integer[]`, p2).Scan(&pet) return pet @@ -77,12 +73,7 @@ func (s *PetFusionService) getData(p1, p2 uint32) []model.PetFusion { func (s *PetFusionService) def() []model.PetFusion { var pets []model.PetFusion - m := cool.DBM(s.Model) - m.Where("is_enable", 1).Where("is_default", 1).Cache(gdb.CacheOption{ - // Duration: time.Hour, - - Force: false, - }).Scan(&pets) + dbm(s.Model).Where("is_default", 1).Scan(&pets) return pets // return ret.Interface().([]model.PetFusion) diff --git a/modules/config/service/shiny.go b/modules/config/service/shiny.go index 759a5b88b..9615f0959 100644 --- a/modules/config/service/shiny.go +++ b/modules/config/service/shiny.go @@ -48,8 +48,7 @@ func (s *ShinyService) RandShiny(id uint32) *model.ColorfulSkin { // 执行 Raw SQL 并扫描返回值 dbm(s.Model). Wheref(`bind_elf_ids @> ?::jsonb`, id). - Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array"). - Where("is_enabled", 1).Scan(&ret) + Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Scan(&ret) for _, v := range ret { //print(v.ID) @@ -76,8 +75,7 @@ func (s *ShinyService) FixShiny(id uint32) *model.ColorfulSkin { // 执行 Raw SQL 并扫描返回值 dbm(s.Model). Wheref(`bind_elf_ids @> ?::jsonb`, id). - Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array"). - Where("is_enabled", 1).Scan(&ret) + Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Scan(&ret) if len(ret) == 0 { return nil } diff --git a/modules/config/service/task.go b/modules/config/service/task.go index 21b5591cc..5416ea373 100644 --- a/modules/config/service/task.go +++ b/modules/config/service/task.go @@ -25,7 +25,7 @@ func NewTaskService() *TaskService { } func (s *TaskService) Get(id, os int) *model.TaskConfig { var item []model.TaskConfig - dbm(s.Model).Where("task_id", id).Where("is_enabled", 1).Scan(&item) + dbm(s.Model).Where("task_id", id).Scan(&item) var res *model.TaskConfig for _, v := range item { if v.OutState == os { diff --git a/modules/config/service/tower.go b/modules/config/service/tower.go index 36ccf860a..ee1c4ac32 100644 --- a/modules/config/service/tower.go +++ b/modules/config/service/tower.go @@ -68,7 +68,7 @@ func (m *UnifiedTowerModel) GroupName() string { // Boss 根据塔等级获取对应的Boss配置(统一入口) func (s *TowerService) Boss(towerLevel uint32) *model.BaseTowerConfig { // 构建基础查询条件 - query := dbm(s.Model).Where("tower_level = ?", towerLevel).Where("is_enabled", 1) + query := dbm(s.Model).Where("tower_level = ?", towerLevel) // 600塔专属的缓存配置 var config model.BaseTowerConfig diff --git a/modules/player/controller/admin/monster_get.go b/modules/player/controller/admin/monster_get.go index 4cf7819da..ef3dacb3d 100644 --- a/modules/player/controller/admin/monster_get.go +++ b/modules/player/controller/admin/monster_get.go @@ -6,7 +6,6 @@ import ( "blazing/modules/player/service" "context" - "github.com/gogf/gf/v2/container/gmap" "github.com/gogf/gf/v2/frame/g" ) @@ -49,19 +48,22 @@ func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res return } -func (c *PetBagController) Level(ctx context.Context, req *PetLevelReq) (res *cool.BaseRes, err error) { - m := gmap.New() - for _, v := range service.NewUserService(0).Pet.Pet_LEVEL_all() { - v.PlayerID -// SELECT -// pp.player_id, -// (pp.data->>'ID')::INT AS id, -// (pp.data->>'Level')::INT AS level -// FROM "player_pet" pp -// WHERE (pp.data->>'Level')::INT > 100 -// ORDER BY level DESC; +func (c *PetBagController) Level(ctx context.Context, req *PetLevelReq) (res *cool.BaseRes, err error) { + // m := gmap.New() + r := service.NewUserService(0).Pet.Pet_LEVEL_all() + + ress := make([]PetLevelRes, 0) + + for _, v := range r { + ress = append(ress, PetLevelRes{ + UserID: int(v.PlayerID), + Level: int(v.Data.Level), + ID: int(v.Data.ID), + }) + } + res.Data = ress return } @@ -70,3 +72,10 @@ type PetLevelReq struct { g.Meta `path:"/getlevel" method:"GET"` // 新增:精灵相关参数(完全对齐自定义表单配置) } +type PetLevelRes struct { + UserID int `json:"user_id"` + //等级PetLevelRes + Level int `json:"level"` + //ID + ID int `json:"id"` +} diff --git a/modules/player/model/info.go b/modules/player/model/info.go index aad8eab0e..6223b2407 100644 --- a/modules/player/model/info.go +++ b/modules/player/model/info.go @@ -122,7 +122,7 @@ type PlayerInfo struct { ExpPool int64 `struc:"skip" json:"exp_pool"` // 累计经验池 OnlineTime int64 `struc:"skip" json:"online_time"` //在线分钟数 - FightTime int64 `struc:"skip" json:"fight_time"` //战斗分钟数 + //FightTime int64 `struc:"skip" json:"fight_time"` //战斗分钟数 // OutInfo 字段 UserID uint32 `struc:"uint32" json:"user_id"` // 米米号 通过sid拿到 RegisterTime uint32 `struc:"uint32" json:"register_time"` // 注册时间(秒时间戳) diff --git a/modules/config/model/user_sign.go b/modules/player/model/user_sign.go similarity index 100% rename from modules/config/model/user_sign.go rename to modules/player/model/user_sign.go diff --git a/modules/player/service/cdk_log.go b/modules/player/service/cdk_log.go index 9b2264037..4e1ab9190 100644 --- a/modules/player/service/cdk_log.go +++ b/modules/player/service/cdk_log.go @@ -12,14 +12,14 @@ type CdkService struct { } func (s *CdkService) CanGet(id uint32) bool { - m1, _ := s.TestModel(s.Model).Where("code_id", id).Exist() + m1, _ := s.dbm(s.Model).Where("code_id", id).Exist() return !m1 } func (s *CdkService) Log(id uint32) { - m := s.TestModel(s.Model) + m := s.dbm(s.Model) data := g.Map{ "player_id": s.userid, "code_id": id, diff --git a/modules/player/service/done.go b/modules/player/service/done.go index 102645d07..ec9ab06ca 100644 --- a/modules/player/service/done.go +++ b/modules/player/service/done.go @@ -50,13 +50,13 @@ func (s *DoneService) UpdatePet(ptye model.PetInfo, res ...uint32) { func (s *DoneService) update(ptye model.EnumMilestone, args []uint32, results []uint32) { if cool.Config.ServerInfo.IsVip != 0 { - + return } ar := gconv.String(args) - if t, _ := s.PModel(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, ar). + if t, _ := s.dbm_fix(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, ar). Wheref(`jsonb_typeof(args) = ?`, "array").Exist(); t { - s.PModel(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, ar). + s.dbm_fix(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, ar). Wheref(`jsonb_typeof(args) = ?`, "array").Data( g.Map{ "results": results, @@ -72,14 +72,14 @@ func (s *DoneService) update(ptye model.EnumMilestone, args []uint32, results [] "results": results, } - s.PModel(s.Model).Data(r).Insert() + s.dbm_fix(s.Model).Data(r).Insert() } } func (s *DoneService) get(ptye model.EnumMilestone, args []uint32) *model.Milestone { var Barges *model.Milestone - s.PModel(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, args). + s.dbm_fix(s.Model).Where("done_type", ptye).Wheref(`args @> ?::jsonb`, args). Wheref(`jsonb_typeof(args) = ?`, "array").Scan(&Barges) return Barges @@ -88,7 +88,7 @@ func (s *DoneService) get(ptye model.EnumMilestone, args []uint32) *model.Milest func (s *DoneService) PetBarge(start, end uint32) []model.Milestone { var Barges []model.Milestone - s.PModel(s.Model).Where("done_type", model.MilestoneMode.Pet). + s.dbm_fix(s.Model).Where("done_type", model.MilestoneMode.Pet). Wheref(`jsonb_typeof(args) = ?`, "array"). Wheref(`jsonb_typeof(args) != ?`, "'[]'::jsonb"). Wheref(`(args->> 0)::int BETWEEN ? AND ?`, start, end). diff --git a/modules/player/service/egg.go b/modules/player/service/egg.go index 3d22c9049..5410d19b0 100644 --- a/modules/player/service/egg.go +++ b/modules/player/service/egg.go @@ -26,7 +26,7 @@ func NewEggService(id uint32) *EggService { } func (s *EggService) Get() (out *model.Egg) { - s.TestModel(s.Model).Scan(&out) + s.dbm_fix(s.Model).Scan(&out) if out != nil { BreedLeftTime := int64(out.Data.StartTime+out.CurEgg.EggID*uint32(time.Hour/1000000000)) - (time.Now().Unix()) if cool.Config.ServerInfo.IsVip != 0 { @@ -38,7 +38,7 @@ func (s *EggService) Get() (out *model.Egg) { } else { out.Data.HatchLeftTime = uint32(BreedLeftTime) } - s.TestModel(s.Model).Save(out) + s.dbm(s.Model).Save(out) } return @@ -58,7 +58,7 @@ func (s *EggService) StartBreed(m, f *model.PetInfo) bool { return false } var tt *model.Egg - s.TestModel(s.Model).Scan(&tt) + s.dbm(s.Model).Scan(&tt) if tt == nil { tt = &model.Egg{} tt.IsVip = cool.Config.ServerInfo.IsVip @@ -83,13 +83,13 @@ func (s *EggService) StartBreed(m, f *model.PetInfo) bool { //tt.CurEgg = cureff tt.EggList = append(tt.EggList, cureff) - s.TestModel(s.Model).Save(tt) + s.dbm(s.Model).Save(tt) return true } func (s *EggService) StartEgg(owner, eggc uint32) bool { var tt *model.Egg - s.TestModel(s.Model).Scan(&tt) + s.dbm(s.Model).Scan(&tt) if tt == nil { return false } @@ -119,14 +119,14 @@ func (s *EggService) StartEgg(owner, eggc uint32) bool { tt.CurEgg = *v tt.Data.Intimacy = 1 - s.TestModel(s.Model).Save(tt) + s.dbm(s.Model).Save(tt) return true } func (s *EggService) EffectHatch() uint32 { var tt *model.Egg - s.TestModel(s.Model).Scan(&tt) + s.dbm(s.Model).Scan(&tt) if tt == nil { return 1 } @@ -138,13 +138,13 @@ func (s *EggService) EffectHatch() uint32 { if tt.Data.Intimacy > 5 { tt.Data.Intimacy = 5 } - s.TestModel(s.Model).Save(tt) + s.dbm(s.Model).Save(tt) return tt.Data.Intimacy } func (s *EggService) GetEgg() *model.PetInfo { var tt *model.Egg - s.TestModel(s.Model).Scan(&tt) + s.dbm(s.Model).Scan(&tt) if tt == nil { return nil } @@ -176,7 +176,7 @@ func (s *EggService) GetEgg() *model.PetInfo { tt.Data.HatchState = 0 p.Generation = uint16(tt.CurEgg.EggID) + 1 tt.CurEgg = model.EggInfo{} - s.TestModel(s.Model).Save(tt) + s.dbm(s.Model).Save(tt) return p } diff --git a/modules/player/service/friend.go b/modules/player/service/friend.go index 1a3ba1405..96a922f98 100644 --- a/modules/player/service/friend.go +++ b/modules/player/service/friend.go @@ -14,7 +14,7 @@ type FriendService struct { } func (s *FriendService) Get() ([]uint32, []uint32) { - m1 := s.TestModel(s.Model) + m1 := s.dbm(s.Model) var talks *model.Friend @@ -26,10 +26,10 @@ func (s *FriendService) Get() ([]uint32, []uint32) { } func (s *FriendService) Add(id uint32) bool { - m1, _ := s.TestModel(s.Model).Exist() + m1, _ := s.dbm(s.Model).Exist() if !m1 { - m := s.TestModel(s.Model) + m := s.dbm(s.Model) data := g.Map{ "player_id": s.userid, "friend": []uint32{}, @@ -40,7 +40,7 @@ func (s *FriendService) Add(id uint32) bool { m.Data(data).Insert() return true } - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Data(g.Map{ "friend": gdb.Raw(fmt.Sprintf("friend|| '%d'::jsonb", id)), @@ -50,7 +50,7 @@ func (s *FriendService) Add(id uint32) bool { } func (s *FriendService) Del(id uint32) bool { - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Data(g.Map{ "friend": gdb.Raw(fmt.Sprintf("jsonb_array_remove(friend, '%d'::jsonb)", id)), diff --git a/modules/player/service/info.go b/modules/player/service/info.go index af0c51224..07d843ad5 100644 --- a/modules/player/service/info.go +++ b/modules/player/service/info.go @@ -19,7 +19,7 @@ import ( func (s *InfoService) IsReg() bool { - m := s.PModel(s.Model) + m := s.dbm_fix(s.Model) record, _ := m.Exist() @@ -31,9 +31,8 @@ func (s *InfoService) IsReg() bool { // 实现注册,id+昵称+颜色 func (s *InfoService) Reg(nick string, color uint32) *model.PlayerInfo { - m := cool.DBM(s.Model).Where("player_id", s.userid) var tt *model.Player - m.Scan(&tt) + s.dbm_fix(s.Model).Scan(&tt) if tt == nil { t := model.NewPlayer() t.PlayerID = uint64(s.userid) @@ -58,7 +57,7 @@ func (s *InfoService) Reg(nick string, color uint32) *model.PlayerInfo { func (s *InfoService) Person(userid uint32) (out *model.Player) { - cool.DBM(s.Model).Where("player_id", userid).Scan(&out) + s.dbm_fix(s.Model).Scan(&out) return @@ -66,9 +65,8 @@ func (s *InfoService) Person(userid uint32) (out *model.Player) { func (s *InfoService) SetLogin() *model.PlayerInfo { - m := cool.DBM(s.Model).Where("player_id", s.userid) var tt *model.Player - m.Scan(&tt) + s.dbm_fix(s.Model).Scan(&tt) if tt == nil { return nil } @@ -110,7 +108,7 @@ func (s *InfoService) SetLogin() *model.PlayerInfo { //每天login时候检查重置时间,然后把电池,任务,挖矿重置 //挖矿需要单独存,因为防止多开挖矿 tt.Data.TimeToday = 0 //重置电池 - tt.Data.FightTime = 60*60*2//重置战斗次数 + //tt.Data.FightTime = 60 * 60 * 2 //重置战斗次数 for _, v := range service.NewTaskService().GetDaily() { @@ -123,7 +121,7 @@ func (s *InfoService) SetLogin() *model.PlayerInfo { } //defer t.Service.Talk_Reset() - _, err := m.Save(tt) + _, err := s.dbm_fix(s.Model).Save(tt) if err != nil { panic(err) } @@ -183,7 +181,7 @@ func (s *InfoService) Save(data model.PlayerInfo) { return } - m := s.PModel(s.Model) + m := s.dbm_fix(s.Model) var tt *model.Player m.Scan(&tt) if tt == nil { diff --git a/modules/player/service/item.go b/modules/player/service/item.go index f369c7862..3d028af51 100644 --- a/modules/player/service/item.go +++ b/modules/player/service/item.go @@ -11,7 +11,7 @@ import ( func (s *ItemService) Exist(itemid uint32) bool { var ttt *model.Item - s.TestModel(s.Model).Where("item_id", itemid).Scan(&ttt) + s.dbm(s.Model).Where("item_id", itemid).Scan(&ttt) return ttt != nil @@ -19,7 +19,7 @@ func (s *ItemService) Exist(itemid uint32) bool { func (s *ItemService) Get(min, max uint32) []model.Item { var ttt []model.Item - s.TestModel(s.Model).Where(g.Map{ + s.dbm(s.Model).Where(g.Map{ "item_id <=": max, "item_id >=": min, }).Scan(&ttt) @@ -32,15 +32,15 @@ func (s *ItemService) UPDATE(id uint32, count int) { return } - m := s.TestModel(s.Model) + m := s.dbm(s.Model) if t, _ := m.Where("item_id", id).Exist(); t { - _, err := s.TestModel(s.Model).Where("item_id", id).Increment("item_cnt", count) + _, err := s.dbm(s.Model).Where("item_id", id).Increment("item_cnt", count) if err != nil { panic(err) } } else { - m := s.TestModel(s.Model) + m := s.dbm(s.Model) data := g.Map{ "player_id": s.userid, "item_id": id, @@ -55,7 +55,7 @@ func (s *ItemService) UPDATE(id uint32, count int) { func (s *ItemService) CheakItem(id uint32) int64 { var ttt model.Item - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Where("item_id", id).Scan(&ttt) return ttt.ItemCnt diff --git a/modules/player/service/pet.go b/modules/player/service/pet.go index 9049380db..9c9abf732 100644 --- a/modules/player/service/pet.go +++ b/modules/player/service/pet.go @@ -11,7 +11,7 @@ import ( // 获取精灵信息 0是仓库,1是放生 func (s *PetService) PetInfo(flag int) []model.Pet { var tt []model.Pet - err := s.TestModel(s.Model).Where("free", flag).Scan(&tt) + err := s.dbm(s.Model).Where("free", flag).Scan(&tt) if err != nil { return []model.Pet{} } @@ -26,7 +26,7 @@ func (s *PetService) PetInfo(flag int) []model.Pet { } func (s *PetService) PetCount(flag int) int { - ret, err := s.TestModel(s.Model).Where("player_id", s.userid).Where("free", flag).Count() + ret, err := s.dbm(s.Model).Where("free", flag).Count() if err != nil { return 0 @@ -38,7 +38,7 @@ func (s *PetService) PetCount(flag int) int { func (s *PetService) UPdateFree(ctime uint32, free uint32) { - s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", ctime).Data( + s.dbm(s.Model).Where("catch_time", ctime).Data( "free", free, ).Update() @@ -46,7 +46,7 @@ func (s *PetService) UPdateFree(ctime uint32, free uint32) { } func (s *PetService) UPdate(t model.PetInfo) { - m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", t.CatchTime) + m := s.dbm(s.Model).Where("catch_time", t.CatchTime) var tt *model.Pet m.Scan(&tt) if tt == nil { @@ -60,7 +60,7 @@ func (s *PetService) UPdate(t model.PetInfo) { } func (s *PetService) PetInfo_One(cachetime uint32) *model.Pet { - m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime) + m := s.dbm(s.Model).Where("catch_time", cachetime) var tt *model.Pet m.Scan(&tt) @@ -73,7 +73,7 @@ func (s *PetService) PetInfo_One(cachetime uint32) *model.Pet { } func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.Pet { - m := s.TestModel(s.Model).Where("player_id", userid).Where("catch_time", cachetime) + m := s.dbm(s.Model).Where("catch_time", cachetime) var tt model.Pet m.Scan(&tt) @@ -82,7 +82,7 @@ func (s *PetService) PetInfo_One_ohter(userid, cachetime uint32) model.Pet { } func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) *model.Pet { - m := s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Unscoped() + m := s.dbm(s.Model).Where("catch_time", cachetime).Unscoped() var tt *model.Pet m.Scan(&tt) @@ -95,13 +95,14 @@ func (s *PetService) PetInfo_One_Unscoped(cachetime uint32) *model.Pet { } func (s *PetService) Pet_del(cachetime uint32) { - s.TestModel(s.Model).Where("player_id", s.userid).Where("catch_time", cachetime).Delete() + s.dbm(s.Model).Where("catch_time", cachetime).Delete() } -func (s *PetService) Pet_LEVEL_all()[]model.Pet { +func (s *PetService) Pet_LEVEL_all() []model.Pet { var tt []model.Pet - s.TestModel(s.Model).Wheref(`(pp.data->>'Level')::INT > 100`, "array").Scan(&tt) -return tt + + s.dbm(s.Model).Fields().Wheref(`(pp.data->>'Level')::INT > 100`, "array").OrderDesc("(pp.data->>'Level')::INT").Scan(&tt) + return tt } // 精灵真正添加后的捕捉时间才是真正的时间 diff --git a/modules/player/service/room.go b/modules/player/service/room.go index 6b79d3347..4ae482ad9 100644 --- a/modules/player/service/room.go +++ b/modules/player/service/room.go @@ -10,9 +10,7 @@ func (s *RoomService) Get(userid uint32) model.BaseHouseEx { //todo待测试 var ttt model.BaseHouseEx - m := s.TestModel(s.Model) - - m.Where("player_id", userid).Scan(&ttt) + s.dbm(s.Model).Scan(&ttt) return ttt @@ -25,7 +23,7 @@ func (s *RoomService) Set(id []model.FitmentShowInfo) { return } var ttt model.BaseHouseEx - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Scan(&ttt) ttt.PlacedItems = id @@ -48,7 +46,7 @@ func (s *RoomService) Show(cactime []uint32) { //todo待测试 var ttt model.BaseHouseEx - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Scan(&ttt) ttt.ShowPokemon = cactime diff --git a/modules/player/service/talk.go b/modules/player/service/talk.go index fb615eb0a..3b0a143b5 100644 --- a/modules/player/service/talk.go +++ b/modules/player/service/talk.go @@ -25,7 +25,7 @@ func NewTalkService(id uint32) *TalkService { func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) { - m1 := s.PModel(s.Model) + m1 := s.dbm(s.Model) var talks *model.Talk m1.Where("talk_id", flag).Scan(&talks) @@ -53,17 +53,17 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) { } func (s *TalkService) Update(flag int) { if cool.Config.ServerInfo.IsVip != 0 { - + return } - m := s.PModel(s.Model).Where("talk_id", flag) + m := s.dbm(s.Model).Where("talk_id", flag) if condition, _ := m.Exist(); !condition { talks := model.NewTalk() talks.PlayerID = uint64(s.userid) talks.TalkID = uint32(flag) - s.PModel(s.Model).Data(talks).FieldsEx("id").Insert() + s.dbm(s.Model).Data(talks).FieldsEx("id").Insert() } - s.PModel(s.Model).Where("talk_id", flag).Increment("count", 1) + s.dbm(s.Model).Where("talk_id", flag).Increment("count", 1) } diff --git a/modules/player/service/task.go b/modules/player/service/task.go index fdf08e31d..0046074d9 100644 --- a/modules/player/service/task.go +++ b/modules/player/service/task.go @@ -12,7 +12,7 @@ import ( func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) { var gg model.TaskEX - m1 := s.PModel(s.Model).Where("task_id", id) + m1 := s.dbm(s.Model).Where("task_id", id) m1.Scan(&gg) tre := t(&gg) diff --git a/modules/player/service/title.go b/modules/player/service/title.go index 08ac772ce..6938adcf6 100644 --- a/modules/player/service/title.go +++ b/modules/player/service/title.go @@ -14,7 +14,7 @@ type TitleService struct { } func (s *TitleService) Get() []uint32 { - m1 := s.TestModel(s.Model) + m1 := s.dbm(s.Model) var talks *model.Title @@ -26,7 +26,7 @@ func (s *TitleService) Get() []uint32 { } func (s *TitleService) Can(id uint32) bool { - m1 := s.TestModel(s.Model) + m1 := s.dbm(s.Model) ok, _ := m1.Wheref(`available_title @> ?::jsonb`, id).Exist() @@ -34,10 +34,10 @@ func (s *TitleService) Can(id uint32) bool { } func (s *TitleService) Give(id uint32) bool { - m1, _ := s.TestModel(s.Model).Exist() + m1, _ := s.dbm(s.Model).Exist() if !m1 { - m := s.TestModel(s.Model) + m := s.dbm(s.Model) data := g.Map{ "player_id": s.userid, "available_title": []uint32{id}, @@ -47,7 +47,7 @@ func (s *TitleService) Give(id uint32) bool { m.Data(data).Insert() return true } - m := s.TestModel(s.Model) + m := s.dbm(s.Model) m.Data(g.Map{ "available_title": gdb.Raw(fmt.Sprintf("available_title|| '%d'::jsonb", id)), diff --git a/modules/player/service/user.go b/modules/player/service/user.go index 8e12f8730..ca757b68f 100644 --- a/modules/player/service/user.go +++ b/modules/player/service/user.go @@ -11,17 +11,17 @@ type BaseService struct { *cool.Service } type UserService struct { - Talk *TalkService //挖矿 - Task *TaskService //任务 - Info *InfoService //信息 - Pet *PetService //精灵 - Item *ItemService //物品 - Done *DoneService //完成 - Room *RoomService - Title *TitleService - Cdk *CdkService - Friend *FriendService - Egg *EggService + Talk *TalkService //挖矿 + Task *TaskService //任务 + Info *InfoService //信息 + Pet *PetService //精灵 + Item *ItemService //物品 + Done *DoneService //完成 + Room *RoomService //基地 + Title *TitleService //标题 + Cdk *CdkService //cdk + Friend *FriendService //好友 + Egg *EggService //孵化 } func NewUserService(id uint32) *UserService { @@ -43,7 +43,7 @@ func NewUserService(id uint32) *UserService { } -func (s *BaseService) TestModel(m cool.IModel) *gdb.Model { +func (s *BaseService) dbm(m cool.IModel) *gdb.Model { m1 := cool.DBM(m) if s.userid != 0 { m1.Where("player_id", s.userid) @@ -53,7 +53,7 @@ func (s *BaseService) TestModel(m cool.IModel) *gdb.Model { return m1 } -func (s *BaseService) PModel(m cool.IModel) *gdb.Model { +func (s *BaseService) dbm_fix(m cool.IModel) *gdb.Model { m1 := cool.DBM(m) if s.userid != 0 { m1.Where("player_id", s.userid)