From 0ae65cee45b067952d687294772b3c2d8bf528af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Fri, 24 Apr 2026 17:22:25 +0800 Subject: [PATCH] 1 --- common/cool/coolconfig/config.go | 17 +++++- common/cool/initdb.go | 8 ++- logic/controller/pet_barge.go | 4 +- logic/controller/room_info.go | 3 + logic/service/fight/fightc.go | 9 +-- logic/service/space/boss_time.go | 59 +------------------ login/internal/cmd/cmd.go | 1 + manifest/config/config.yaml | 1 - .../config/controller/admin/collect_plan.go | 20 +++++++ modules/config/model/collect_plan.go | 35 +++++++++++ modules/config/service/collect_plan.go | 36 +++++++++++ modules/player/service/pet.go | 14 +++-- 12 files changed, 132 insertions(+), 75 deletions(-) create mode 100644 modules/config/controller/admin/collect_plan.go create mode 100644 modules/config/model/collect_plan.go create mode 100644 modules/config/service/collect_plan.go diff --git a/common/cool/coolconfig/config.go b/common/cool/coolconfig/config.go index 60ad4e7f..031b474f 100644 --- a/common/cool/coolconfig/config.go +++ b/common/cool/coolconfig/config.go @@ -1,6 +1,8 @@ package coolconfig import ( + "os" + "strings" "time" "github.com/gogf/gf/v2/frame/g" @@ -72,7 +74,7 @@ type file struct { func newConfig() *sConfig { var ctx g.Ctx config := &sConfig{ - AutoMigrate: GetCfgWithDefault(ctx, "blazing.autoMigrate", g.NewVar(false)).Bool(), + AutoMigrate: hasDebugArg(), Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(), Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(), @@ -97,6 +99,19 @@ func newConfig() *sConfig { return config } +func hasDebugArg() bool { + for _, arg := range os.Args[1:] { + if arg == "-debug" || arg == "--debug" { + return true + } + if strings.HasPrefix(arg, "-debug=") || strings.HasPrefix(arg, "--debug=") { + value := strings.TrimSpace(strings.SplitN(arg, "=", 2)[1]) + return value != "" && value != "0" && !strings.EqualFold(value, "false") + } + } + return false +} + // qiniu 七牛云配置 type qiniu struct { AccessKey string `json:"ak"` diff --git a/common/cool/initdb.go b/common/cool/initdb.go index 7ce4307b..c850ff92 100644 --- a/common/cool/initdb.go +++ b/common/cool/initdb.go @@ -63,7 +63,13 @@ func CreateTable(model IModel) error { autoMigrateMu.Lock() autoMigrateModels = append(autoMigrateModels, model) autoMigrateMu.Unlock() - return nil + + if !Config.AutoMigrate { + return nil + } + + db := getDBbyModel(model) + return db.AutoMigrate(model) } // RunAutoMigrate 显式执行已注册模型的建表/迁移。 diff --git a/logic/controller/pet_barge.go b/logic/controller/pet_barge.go index 9a7bc9a5..e9930d5e 100644 --- a/logic/controller/pet_barge.go +++ b/logic/controller/pet_barge.go @@ -18,8 +18,8 @@ func (h Controller) GetPetBargeList(data *PetBargeListInboundInfo, player *playe ret.PetBargeList = append(ret.PetBargeList, pet.PetBargeListInfo{ PetId: uint32(v.Args[0]), EnCntCnt: 1, - IsCatched: uint32(v.Results[0]), - IsKilled: uint32(v.Results[1]), + IsCatched: uint32(v.Results[1]), + IsKilled: uint32(v.Results[0]), }) } diff --git a/logic/controller/room_info.go b/logic/controller/room_info.go index d5fc6db2..43652269 100644 --- a/logic/controller/room_info.go +++ b/logic/controller/room_info.go @@ -106,6 +106,9 @@ func (h Controller) GetAllFurniture(data *FitmentAllInboundEmpty, c *player.Play // 返回: 精灵详细信息和错误码 func (h Controller) GetRoomPetInfo(data *C2S_RoomPetInfo, c *player.Player) (result *pet.RoomPetInfo, err errorcode.ErrorCode) { petInfo := c.Service.Pet.PetInfoOneOther(data.UserID, data.CatchTime) + if petInfo == nil { + return nil, errorcode.ErrorCodes.ErrPokemonNotExists + } result = &pet.RoomPetInfo{} copier.CopyWithOption(result, &petInfo.Data, copier.Option{DeepCopy: true}) result.OwnerId = data.UserID diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index e0368b2e..5dc681ad 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -10,7 +10,6 @@ import ( _ "blazing/logic/service/fight/itemover" _ "blazing/logic/service/fight/rule" "blazing/modules/player/model" - "fmt" "reflect" "github.com/alpacahq/alpacadecimal" @@ -69,15 +68,12 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info //还原属性 attacker.Prop, defender.Prop = originalProps[0], originalProps[1] attackerPet.Info, defenderPet.Info = originalPetInfo[0], originalPetInfo[1] - fmt.Printf("[processSkillAttack] After restore: attacker.Prop=%v, defender.Prop=%v\n", attacker.Prop, defender.Prop) if attacker.IsCritical == 1 { //命中了才有暴击 //暴击破防 if skill.Category() == info.Category.PHYSICAL && defender.Prop[1] > 0 { - fmt.Printf("[processSkillAttack] Crit break DEF: defender.Prop[1] %d -> 0\n", defender.Prop[1]) defender.Prop[1] = 0 } else if skill.Category() == info.Category.SPECIAL && defender.Prop[3] > 0 { - fmt.Printf("[processSkillAttack] Crit break SPDEF: defender.Prop[3] %d -> 0\n", defender.Prop[3]) defender.Prop[3] = 0 } //暴击翻倍 @@ -105,7 +101,6 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, skill *info effect.OnSkill() //调用伤害计算 return true }) - fmt.Printf("[processSkillAttack] After OnSkill: attacker.Prop=%v, defender.Prop=%v, attacker.SkillID=%d\n", attacker.Prop, defender.Prop, attacker.SkillID) defender.Damage(attacker, &info.DamageZone{ Damage: SumDamage, @@ -443,7 +438,6 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) return true }) } - fmt.Printf("[enterturn] After Skill_Use: attacker.Prop=%v, defender.Prop=%v\n", attacker.Prop, defender.Prop) //技能使用后 defender.ExecWithOpponent(attacker, func(effect input.Effect) bool { //技能使用后的我方效果 f.setEffectSkillContext(effect, currentSkill, defender) @@ -456,7 +450,6 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) effect.Action_end() return true }) - fmt.Printf("[enterturn] After Action_end: attacker.Prop=%v, defender.Prop=%v\n", attacker.Prop, defender.Prop) if defenderPet != nil && attackerPet != nil && defenderPet.Info.Hp <= 0 && attackerPet.Info.Hp <= 0 { //先手方死亡,触发反同归于尽 attackerPet.Info.Hp = 1 @@ -495,7 +488,6 @@ func (f *FightC) enterturn(firstAttack, secondAttack *action.SelectSkillAction) } attackValueResult := f.buildNoteUseSkillOutboundInfo() - fmt.Printf("[enterturn] Broadcast: First.Prop=%v, Second.Prop=%v\n", attackValueResult.FirstAttackInfo.Prop, attackValueResult.SecondAttackInfo.Prop) //因为切完才能广播,所以必须和回合结束分开结算 f.BroadcastPlayers(func(p common.PlayerI) { for _, switchAction := range f.Switch { @@ -566,3 +558,4 @@ func (f *FightC) TURNOVER(cur *input.Input) { // break } } + diff --git a/logic/service/space/boss_time.go b/logic/service/space/boss_time.go index 808b5310..8b2f854d 100644 --- a/logic/service/space/boss_time.go +++ b/logic/service/space/boss_time.go @@ -21,64 +21,7 @@ type TimeBossRule struct { } // Timed boss schedule config. -var timeBossRules = []TimeBossRule{ - { - PetID: 261, - Week: 1, - ShowHours: []int{12, 17, 18, 24}, - ShowMinute: 35, - LastTime: 40, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 2, - ShowHours: []int{17, 18, 24}, - ShowMinute: 0, - LastTime: 5, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 3, - ShowHours: []int{17, 18, 24}, - ShowMinute: 0, - LastTime: 5, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 4, - ShowHours: []int{12, 17, 18, 24}, - ShowMinute: 35, - LastTime: 40, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 5, - ShowHours: []int{17, 18, 24}, - ShowMinute: 0, - LastTime: 5, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 6, - ShowHours: []int{17, 18, 24}, - ShowMinute: 0, - LastTime: 5, - MapIDs: []uint32{15, 105, 54}, - }, - { - PetID: 261, - Week: 7, - ShowHours: generateHourRange(0, 23), - ShowMinute: 0, - LastTime: 10, - MapIDs: []uint32{15, 105, 54}, - }, -} +var timeBossRules = []TimeBossRule{} var ( registeredCronIDs = make(map[string]bool) diff --git a/login/internal/cmd/cmd.go b/login/internal/cmd/cmd.go index 84ec9c1d..2921e320 100644 --- a/login/internal/cmd/cmd.go +++ b/login/internal/cmd/cmd.go @@ -29,6 +29,7 @@ var ( g.DB().SetDebug(true) // service.NewServerService().SetServerScreen(0, "sss") cool.Config.ServerInfo.IsDebug = 1 + cool.Config.AutoMigrate = true } if err = cool.RunAutoMigrate(); err != nil { return err diff --git a/manifest/config/config.yaml b/manifest/config/config.yaml index 088f40e9..be2c6c78 100644 --- a/manifest/config/config.yaml +++ b/manifest/config/config.yaml @@ -56,7 +56,6 @@ redis: pass: "redis_TxYnSy" blazing: - autoMigrate: true eps: true file: mode: "local" # local | minio | oss diff --git a/modules/config/controller/admin/collect_plan.go b/modules/config/controller/admin/collect_plan.go new file mode 100644 index 00000000..6febaee5 --- /dev/null +++ b/modules/config/controller/admin/collect_plan.go @@ -0,0 +1,20 @@ +package admin + +import ( + "blazing/cool" + "blazing/modules/config/service" +) + +type CollectPlanController struct { + *cool.Controller +} + +func init() { + cool.RegisterController(&CollectPlanController{ + &cool.Controller{ + Prefix: "/admin/config/collectPlan", + Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"}, + Service: service.NewCollectPlanService(), + }, + }) +} diff --git a/modules/config/model/collect_plan.go b/modules/config/model/collect_plan.go new file mode 100644 index 00000000..d251641b --- /dev/null +++ b/modules/config/model/collect_plan.go @@ -0,0 +1,35 @@ +package model + +import "blazing/cool" + +const ( + TableNameCollectPlanConfig = "config_collect_plan" +) + +// CollectPlanConfig 精灵收集计划配置。 +type CollectPlanConfig struct { + *BaseConfig + + Title string `gorm:"type:varchar(64);not null;default:'';comment:'计划标题'" json:"title" description:"计划标题"` + Description string `gorm:"type:text;not null;default:'';comment:'计划描述'" json:"description" description:"计划描述"` + RewardGroups []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'奖励精灵组'" json:"reward_groups" description:"奖励精灵组"` + TargetGroups []uint32 `gorm:"type:jsonb;not null;default:'[]';comment:'目标精灵列表'" json:"target_groups" description:"目标精灵列表"` +} + +func (*CollectPlanConfig) TableName() string { + return TableNameCollectPlanConfig +} + +func (*CollectPlanConfig) GroupName() string { + return "default" +} + +func NewCollectPlanConfig() *CollectPlanConfig { + return &CollectPlanConfig{ + BaseConfig: NewBaseConfig(), + } +} + +func init() { + cool.CreateTable(&CollectPlanConfig{}) +} diff --git a/modules/config/service/collect_plan.go b/modules/config/service/collect_plan.go new file mode 100644 index 00000000..9e8c8eca --- /dev/null +++ b/modules/config/service/collect_plan.go @@ -0,0 +1,36 @@ +package service + +import ( + "blazing/cool" + "blazing/modules/config/model" + + "github.com/gogf/gf/v2/frame/g" +) + +type CollectPlanService struct { + *cool.Service +} + +func NewCollectPlanService() *CollectPlanService { + return &CollectPlanService{ + &cool.Service{ + Model: model.NewCollectPlanConfig(), + ListQueryOp: &cool.QueryOp{ + FieldEQ: []string{"is_enable", "id"}, + AddOrderby: map[string]string{ + "id": "asc", + }, + }, + PageQueryOp: &cool.QueryOp{ + FieldEQ: []string{"is_enable", "id"}, + KeyWordField: []string{"title", "description", "remark"}, + AddOrderby: map[string]string{ + "id": "asc", + }, + ModifyResult: func(ctx g.Ctx, data interface{}) interface{} { + return data + }, + }, + }, + } +} diff --git a/modules/player/service/pet.go b/modules/player/service/pet.go index f466829d..759e5b13 100644 --- a/modules/player/service/pet.go +++ b/modules/player/service/pet.go @@ -260,10 +260,16 @@ func (s *PetService) PetInfoOneByID(id uint32) *model.Pet { return tt } -func (s *PetService) PetInfoOneOther(userid, catchTime uint32) model.Pet { - var tt model.Pet - s.dbm(s.Model).Where("catch_time", catchTime).Scan(&tt) - tt.Data.CatchTime = tt.CatchTime +func (s *PetService) PetInfoOneOther(userid, catchTime uint32) *model.Pet { + var tt *model.Pet + if err := s.dbm_fix(s.Model). + Where("player_id", userid). + Where("catch_time", catchTime). + Where("is_vip", cool.Config.ServerInfo.IsVip). + Scan(&tt); err != nil || tt == nil { + return nil + } + setCatchTime(tt) return tt }