From 40ec8273425f105ba9cb9bdf40fb8aa69c27f694 Mon Sep 17 00:00:00 2001 From: xinian Date: Mon, 6 Apr 2026 03:11:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E6=88=98?= =?UTF-8?q?=E6=96=97=E5=B1=9E=E6=80=A7=E5=92=8C=E7=89=B9=E6=95=88=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/fight_boss野怪和地图怪.go | 2 +- logic/service/fight/info/BattlePetEntity.go | 29 +++++++++++++ logic/service/fight/input/input.go | 24 +---------- logic/service/fight/new.go | 2 +- logic/service/item/petuse.go | 16 +------ logic/service/player/base.go | 21 +++++++++ modules/player/controller/admin/sign.go | 16 +++++++ modules/player/model/pet.go | 48 +++++++++++++++++++++ modules/player/service/sign.go | 47 ++++++++++++++++++++ 9 files changed, 166 insertions(+), 39 deletions(-) diff --git a/logic/controller/fight_boss野怪和地图怪.go b/logic/controller/fight_boss野怪和地图怪.go index 6a648852f..191679c50 100644 --- a/logic/controller/fight_boss野怪和地图怪.go +++ b/logic/controller/fight_boss野怪和地图怪.go @@ -44,7 +44,7 @@ func (Controller) PlayerFightBoss(req *ChallengeBossInboundInfo, p *player.Playe ai := player.NewAI_player(monsterInfo) ai.CanCapture = resolveBossCaptureRate(bossConfigs[0].IsCapture, leadMonsterID) ai.BossScript = bossConfigs[0].Script - ai.Prop[0] = 2 + ai.AddBattleProp(0, 2) var fightC *fight.FightC fightC, err = fight.NewFight(p, ai, p.GetPetInfo(100), ai.GetPetInfo(0), func(foi model.FightOverInfo) { diff --git a/logic/service/fight/info/BattlePetEntity.go b/logic/service/fight/info/BattlePetEntity.go index fb26494c9..cbe2b98b0 100644 --- a/logic/service/fight/info/BattlePetEntity.go +++ b/logic/service/fight/info/BattlePetEntity.go @@ -41,6 +41,35 @@ func (t *BattlePetEntity) Alive() bool { } +func (t *BattlePetEntity) AddBattleAttr(attr int, value uint32) { + if t == nil || value == 0 { + return + } + + switch attr { + case 0: + t.Info.MaxHp += value + t.Info.Hp += value + case 1, 2, 3, 4, 5: + t.Info.Prop[attr-1] += value + } +} + +func (t *BattlePetEntity) ApplyInitEffectBonus(effect model.PetEffectInfo) { + if t == nil || effect.EID != 26 || len(effect.Args) < 2 { + return + } + + for i := 0; i+1 < len(effect.Args); i += 2 { + attr := effect.Args[i] + value := effect.Args[i+1] + if value <= 0 { + continue + } + t.AddBattleAttr(attr, uint32(value)) + } +} + // 创建精灵实例 func CreateBattlePetEntity(info model.PetInfo) *BattlePetEntity { ret := &BattlePetEntity{} diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 472bfa1ee..7f19a2508 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -145,28 +145,6 @@ func (our *Input) SetCurPetAt(index int, pet *info.BattlePetEntity) { our.CurPet[index] = pet } -func applyInitPetEffectBonus(pet *info.BattlePetEntity, effect model.PetEffectInfo) { - if pet == nil || effect.EID != 26 || len(effect.Args) < 2 { - return - } - - for i := 0; i+1 < len(effect.Args); i += 2 { - attr := effect.Args[i] - value := effect.Args[i+1] - if value <= 0 { - continue - } - - switch attr { - case 0: - pet.Info.MaxHp += uint32(value) - pet.Info.Hp += uint32(value) - case 1, 2, 3, 4, 5: - pet.Info.Prop[attr-1] += uint32(value) - } - } -} - // 非原地交换:收集非0血量精灵 + 0血量精灵,拼接后返回 func (our *Input) SortPet() { var nonZeroHP []*info.BattlePetEntity // 收集血量>0的精灵(保持原顺序) @@ -189,7 +167,7 @@ func (our *Input) SortPet() { t.Duration(-1) - applyInitPetEffectBonus(s, e1) + s.ApplyInitEffectBonus(e1) our.AddEffect(our, t) } diff --git a/logic/service/fight/new.go b/logic/service/fight/new.go index 8b58c2b4b..b0ac43047 100644 --- a/logic/service/fight/new.go +++ b/logic/service/fight/new.go @@ -154,7 +154,7 @@ func buildFight(opts *fightBuildOptions) (*FightC, errorcode.ErrorCode) { if ai.CanCapture > 0 { opp.CanCapture = ai.CanCapture } - opp.AttackValue.Prop = ai.Prop + ai.ApplyBattleProps(opp.AttackValue) } } } diff --git a/logic/service/item/petuse.go b/logic/service/item/petuse.go index 518841510..f97ba2d35 100644 --- a/logic/service/item/petuse.go +++ b/logic/service/item/petuse.go @@ -14,8 +14,6 @@ import ( type PetItemHandler func(itemid uint32, ctx *model.PetInfo) bool -const maxHPUpEffectIdx uint16 = 60000 - // RangeHandler 范围ID处理器(用于ID区间匹配) type RangeHandler struct { Start uint32 @@ -121,19 +119,9 @@ func handleNewSeIdxPetItem(itemid uint32, onpet *model.PetInfo) errorcode.ErrorC } if itemCfg.NewSeIdx == 0 { if itemCfg.MaxHPUp > 0 { - for _, eff := range onpet.EffectInfo { - if eff.Status == 8 { - return errorcode.ErrorCodes.ErrCannotInjectPillAgain - } + if !onpet.AddMaxHPUpEffect(itemid, itemCfg.MaxHPUp) { + return errorcode.ErrorCodes.ErrCannotInjectPillAgain } - - onpet.EffectInfo = append(onpet.EffectInfo, model.PetEffectInfo{ - ItemID: itemid, - Idx: maxHPUpEffectIdx, - Status: 8, - EID: 26, - Args: []int{0, itemCfg.MaxHPUp}, - }) return 0 } return errorcode.ErrorCodes.ErrItemUnusable diff --git a/logic/service/player/base.go b/logic/service/player/base.go index f74a82233..abb577e7f 100644 --- a/logic/service/player/base.go +++ b/logic/service/player/base.go @@ -44,6 +44,27 @@ func (p *baseplayer) GetPetInfo(limitlevel uint32) []model.PetInfo { } return ret } + +func (p *baseplayer) AddBattleProp(index int, level int8) { + if p == nil || index < 0 || index >= len(p.Prop) || level == 0 { + return + } + + p.Prop[index] += level + if p.Prop[index] > 6 { + p.Prop[index] = 6 + } + if p.Prop[index] < -6 { + p.Prop[index] = -6 + } +} + +func (p *baseplayer) ApplyBattleProps(target *model.AttackValue) { + if p == nil || target == nil { + return + } + target.Prop = p.Prop +} func (f *baseplayer) InvitePlayer(ff common.PlayerI) { } diff --git a/modules/player/controller/admin/sign.go b/modules/player/controller/admin/sign.go index 8a69323f9..3b09cd65d 100644 --- a/modules/player/controller/admin/sign.go +++ b/modules/player/controller/admin/sign.go @@ -3,6 +3,9 @@ package admin import ( "blazing/cool" "blazing/modules/player/service" + "context" + + "github.com/gogf/gf/v2/frame/g" ) type SignRecordController struct { @@ -18,3 +21,16 @@ func init() { }, }) } + +type ResetAllReq struct { + g.Meta `path:"/resetAll" method:"POST"` + Authorization string `json:"Authorization" in:"header"` +} + +func (c *SignRecordController) ResetAll(ctx context.Context, req *ResetAllReq) (res *cool.BaseRes, err error) { + result, err := service.NewSignService(0).ResetAll() + if err != nil { + return cool.Fail(err.Error()), nil + } + return cool.Ok(result), nil +} diff --git a/modules/player/model/pet.go b/modules/player/model/pet.go index 5e8bec9a0..cccf6ea4b 100644 --- a/modules/player/model/pet.go +++ b/modules/player/model/pet.go @@ -383,6 +383,13 @@ func (pet *PetInfo) RnadEffect() { // 7 :繁殖加成 // 8 :体力提升加成 +const ( + maxHPUpEffectIdx uint16 = 60000 + maxHPUpEffectStatus byte = 8 + maxHPUpEffectEID uint16 = 26 + maxHPUpEffectCap = 20 +) + // 繁殖加成,体力提升加成 ,这里是防止和其他重复所以定义不同类别,但是实际上,能量珠那些事调用不同id的effect实现 // func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) { @@ -393,6 +400,47 @@ func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) { } +func (pet *PetInfo) AddMaxHPUpEffect(itemID uint32, value int) bool { + if pet == nil || value <= 0 { + return false + } + + if _, eff, ok := pet.GetEffect(int(maxHPUpEffectStatus)); ok { + current := 0 + if len(eff.Args) >= 2 && eff.Args[0] == 0 && eff.Args[1] > 0 { + current = eff.Args[1] + } + if current >= maxHPUpEffectCap { + return false + } + + next := current + value + if next > maxHPUpEffectCap { + next = maxHPUpEffectCap + } + + eff.ItemID = itemID + eff.Idx = maxHPUpEffectIdx + eff.Status = maxHPUpEffectStatus + eff.EID = maxHPUpEffectEID + eff.Args = []int{0, next} + return next > current + } + + if value > maxHPUpEffectCap { + value = maxHPUpEffectCap + } + + pet.EffectInfo = append(pet.EffectInfo, PetEffectInfo{ + ItemID: itemID, + Idx: maxHPUpEffectIdx, + Status: maxHPUpEffectStatus, + EID: maxHPUpEffectEID, + Args: []int{0, value}, + }) + return true +} + func (pet *PetInfo) Downgrade(level uint32) { for pet.Level > uint32(level) { diff --git a/modules/player/service/sign.go b/modules/player/service/sign.go index 577359015..59991e278 100644 --- a/modules/player/service/sign.go +++ b/modules/player/service/sign.go @@ -53,6 +53,13 @@ type SignClaimResult struct { Rewards []SignRewardResult `json:"rewards,omitempty"` } +// SignResetResult 表示管理端执行的签到重置结果。 +type SignResetResult struct { + SignRecordRows int64 `json:"sign_record_rows"` + CdkLogRows int64 `json:"cdk_log_rows"` + ResetCdkIDs []uint32 `json:"reset_cdk_ids"` +} + // SignService 管理玩家签到进度。 type SignService struct { BaseService @@ -117,6 +124,46 @@ func (s *SignService) Claim() (*SignClaimResult, error) { }, nil } +func (s *SignService) ResetAll() (*SignResetResult, error) { + result := &SignResetResult{} + + signRes, err := cool.DBM(model.NewSignInRecord()).Delete() + if err != nil { + return nil, err + } + if signRes != nil { + result.SignRecordRows, _ = signRes.RowsAffected() + } + + configs := configservice.NewSignInService().GetEnabled() + cdkIDs := make([]uint32, 0, len(configs)) + seen := make(map[uint32]struct{}, len(configs)) + for _, cfg := range configs { + if cfg.CdkID == 0 { + continue + } + if _, ok := seen[cfg.CdkID]; ok { + continue + } + seen[cfg.CdkID] = struct{}{} + cdkIDs = append(cdkIDs, cfg.CdkID) + } + sort.Slice(cdkIDs, func(i, j int) bool { return cdkIDs[i] < cdkIDs[j] }) + result.ResetCdkIDs = cdkIDs + + if len(cdkIDs) > 0 { + cdkRes, err := cool.DBM(model.NewCdkLog()).WhereIn("code_id", cdkIDs).Delete() + if err != nil { + return nil, err + } + if cdkRes != nil { + result.CdkLogRows, _ = cdkRes.RowsAffected() + } + } + + return result, nil +} + func (s *SignService) grantReachedStageRewards(record *model.SignInRecord) ([]SignRewardResult, error) { configs := configservice.NewSignInService().GetEnabled() if len(configs) == 0 {