Files
bl/logic/controller/fight_塔.go
昔念 a48619dde5
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(game): 更新试炼之塔和勇者之塔等级验证逻辑

- 修改fight_塔.go中等级验证条件,添加data.Level != 1的特殊处理
- 防止等级1时的错误验证,允许重新挑战第1层
- 保持原有的最大等级限制逻辑

docs(README): 添加新的pprof性能分析命令示例

- 增加针对端口43892的性能分析命令
- 添加300秒CPU数据采样的HTTP可视化命令
- 为性能调试提供更多示例选项
2026-03-04 17:11:57 +08:00

216 lines
6.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controller
import (
"blazing/common/socket/errorcode"
"blazing/common/utils"
"blazing/logic/service/fight"
fightinfo "blazing/logic/service/fight/info"
"blazing/logic/service/player"
"blazing/logic/service/space/info"
configmodel "blazing/modules/config/model"
"blazing/modules/config/service"
"blazing/modules/player/model"
"sync/atomic"
"github.com/gogf/gf/v2/util/gconv"
"github.com/jinzhu/copier"
)
// 暗黑门进入boss
func (h Controller) FreshOpen(data *fight.C2S_OPEN_DARKPORTAL, c *player.Player) (result *fight.S2C_OPEN_DARKPORTAL, err errorcode.ErrorCode) {
result = &fight.S2C_OPEN_DARKPORTAL{}
// c.Info.CurrentFreshStage = utils.Max(c.Info.CurrentFreshStage, 1)
// c.Info.CurrentStage = utils.Max(c.Info.CurrentStage, 1)
boss := service.NewTower110Service().Boss(uint32(data.Level))
if len(boss) == 0 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
if len(boss[0].BossIds) == 0 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
result = &fight.S2C_OPEN_DARKPORTAL{}
r := service.NewBossService().Get(boss[0].BossIds[0])
result.CurBossID = uint32(r[0].MonID)
c.CurDark = uint32(data.Level)
defer c.GetSpace().LeaveMap(c)
return result, 0
}
// FreshChoiceFightLevel 处理玩家选择挑战模式(试炼之塔或勇者之塔)
// 根据不同的CMD值设置玩家的挑战状态和地图信息并返回当前挑战层级信息
// 参数:
//
// data: 客户端发送的挑战层级选择请求数据包含CMD和挑战层级
// c: 玩家对象,包含玩家的详细信息
//
// 返回值:
//
// result: 服务器返回给客户端的挑战层级信息包含当前战斗层级和Boss ID
// err: 错误码,表示处理过程中是否出现错误
func (h Controller) FreshChoiceFightLevel(data *fight.C2S_FRESH_CHOICE_FIGHT_LEVEL, c *player.Player) (result *fight.S2C_FreshChoiceLevelRequestInfo, err errorcode.ErrorCode) {
result = &fight.S2C_FreshChoiceLevelRequestInfo{}
c.Info.CurrentFreshStage = utils.Max(c.Info.CurrentFreshStage, 1)
c.Info.CurrentStage = utils.Max(c.Info.CurrentStage, 1)
if data.Level > 0 {
switch data.Head.CMD {
case 2428: //试炼之塔
if data.Level > uint(c.Info.MaxFreshStage) && data.Level != 1 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
c.Info.CurrentFreshStage = uint32(data.Level)
case 2414: //勇者之塔
if data.Level > uint(c.Info.MaxStage) && data.Level != 1 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
c.Info.CurrentStage = uint32(data.Level)
}
}
var boss []configmodel.BaseTowerConfig
switch data.Head.CMD {
case 2428: //试炼之塔
result.CurFightLevel = uint32(c.Info.CurrentFreshStage)
boss = service.NewTower600Service().Boss(c.Info.CurrentFreshStage)
case 2414: //勇者之塔
result.CurFightLevel = uint32(c.Info.CurrentStage)
boss = service.NewTower500Service().Boss(c.Info.CurrentStage)
//next := service.NewTower600Service().Boss(c.Info.CurrentFreshStage + 1)
}
if len(boss) != 0 && len(boss[0].BossIds) != 0 {
//单节点,取获取到的一个,然后因为不是剧情,所以只有一层
r := service.NewBossService().Get(boss[0].BossIds[0])
for _, v := range r {
result.BossId = append(result.BossId, uint32(v.MonID))
}
}
// 重置玩家的Canmon标志位为0表示可以刷怪
atomic.StoreUint32(&c.Canmon, 0)
// 在函数结束时将玩家传送到对应地图
defer c.GetSpace().LeaveMap(c)
return result, 0
}
func (h Controller) FreshLeaveFightLevel(data *fight.FRESH_LEAVE_FIGHT_LEVEL, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
defer c.GetSpace().EnterMap(c)
out := info.NewOutInfo()
copier.CopyWithOption(out, c.GetInfo(), copier.Option{DeepCopy: true})
//c.SendPackCmd(2001, out)
return result, 0
}
func (h Controller) PetTawor(data *fight.StartTwarInboundInfo, c *player.Player) (result *fight.S2C_ChoiceLevelRequestInfo, err errorcode.ErrorCode) {
r := c.CanFight()
if c.CanFight() != 0 {
return nil, r
}
c.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
c.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
monsterInfo := &model.PlayerInfo{}
var boss []configmodel.BaseTowerConfig
result = &fight.S2C_ChoiceLevelRequestInfo{}
switch data.Head.CMD {
case 2429: //试炼之塔
boss = service.NewTower600Service().Boss(c.Info.CurrentFreshStage, c.Info.CurrentFreshStage+1)
result.CurFightLevel = uint32(c.Info.CurrentFreshStage)
case 2415: //勇者之塔
boss = service.NewTower500Service().Boss(c.Info.CurrentStage, c.Info.CurrentStage+1)
result.CurFightLevel = uint32(c.Info.CurrentStage)
case 2425:
boss = service.NewTower110Service().Boss(c.CurDark)
}
if len(boss) > 1 {
r := service.NewBossService().Get(boss[1].BossIds[0])
for _, v := range r {
result.BossID = append(result.BossID, uint32(v.MonID))
}
}
bosss := service.NewBossService().Get(boss[0].BossIds[0])
monsterInfo.Nick = boss[0].Name
for i, r := range bosss {
monster := model.GenPetInfo(int(r.MonID), 24, int(r.Nature), 0, int(r.Lv), nil, 0)
if r.Hp != 0 {
monster.Hp = uint32(r.Hp)
monster.MaxHp = uint32(r.Hp)
}
for i, v := range r.Prop {
if v != 0 {
monster.Prop[i] = v
}
}
if len(r.SKill) != 0 {
for i := 0; i < len(monster.SkillList); i++ {
if r.SKill[i] != 0 {
monster.SkillList[i].ID = r.SKill[i]
}
}
}
effects := service.NewEffectService().Args(r.Effect)
for _, v := range effects {
monster.EffectInfo = append(monster.EffectInfo, model.PetEffectInfo{
Idx: uint16(v.SeIdx),
EID: gconv.Uint16(v.Eid),
Args: gconv.Ints(v.Args),
})
}
monster.CatchTime = uint32(i)
monsterInfo.PetList = append(monsterInfo.PetList, *monster)
}
ai := player.NewAI_player(monsterInfo)
_, err = fight.NewFight(c, ai, func(foi fightinfo.FightOverInfo) {
if foi.Reason == 0 && foi.WinnerId == c.Info.UserID { //我放获胜
switch data.Head.CMD {
case 2429: //试炼之塔
c.TawerCompletedTask(600, int(c.Info.CurrentFreshStage))
c.Info.CurrentFreshStage++
if c.Info.CurrentFreshStage >= c.Info.MaxFreshStage {
c.Info.MaxFreshStage = c.Info.CurrentFreshStage
}
case 2415: //勇者之塔
c.TawerCompletedTask(500, int(c.Info.CurrentStage))
c.Info.CurrentStage++
if c.Info.CurrentStage >= c.Info.MaxStage {
c.Info.MaxStage = c.Info.CurrentStage
}
case 2425:
c.TawerCompletedTask(110, int(c.CurDark))
}
}
}) ///开始对战,房主方以及被邀请方
return
}