Files
bl/logic/controller/fight_tawor.go
昔念 d88a2d19ea ```
feat(fight): 支持勇者之塔和试炼之塔战斗功能

- 实现勇者之塔(CMD 2414)和试炼之塔(CMD 2428)的战斗逻辑
- 添加Tower500Service和Tower600Service的Boss查询功能
- 统一处理两个塔的BossId
2026-01-01 15:37:43 +08:00

171 lines
4.9 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"
"blazing/modules/blazing/model"
configmodel "blazing/modules/config/model"
"blazing/modules/config/service"
configservice "blazing/modules/config/service"
"sync/atomic"
"github.com/jinzhu/copier"
)
// 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: //试炼之塔
c.Info.CurrentFreshStage = uint32((data.Level-1)*10) + 1
case 2414: //勇者之塔
c.Info.CurrentStage = uint32((data.Level-1)*10) + 1
}
}
var boss *configmodel.BaseTowerConfig
switch data.Head.CMD {
case 2428: //试炼之塔
result.CurFightLevel = uint(c.Info.CurrentFreshStage)
boss = service.NewTower600Service().Boss(c.Info.CurrentFreshStage)
case 2414: //勇者之塔
result.CurFightLevel = uint(c.Info.CurrentStage)
boss = service.NewTower500Service().Boss(c.Info.CurrentFreshStage)
//next := service.NewTower600Service().Boss(c.Info.CurrentFreshStage + 1)
}
if boss != nil {
for _, v := range boss.BossIds {
r := configservice.NewBossService().Get(v)
result.BossId = append(result.BossId, uint32(r.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) {
if !c.CanFight() {
return nil, errorcode.ErrorCodes.ErrSystemError
}
c.Fightinfo.Mode = fightinfo.BattleMode.MULTI_MODE
c.Fightinfo.Status = fightinfo.BattleMode.FIGHT_WITH_NPC
monsterInfo := &model.PlayerInfo{}
var boss *configmodel.BaseTowerConfig
var next *configmodel.BaseTowerConfig
result = &fight.S2C_ChoiceLevelRequestInfo{}
switch data.Head.CMD {
case 2429: //试炼之塔
boss = service.NewTower600Service().Boss(c.Info.CurrentFreshStage)
next = service.NewTower600Service().Boss(c.Info.CurrentFreshStage + 1)
if next != nil {
for _, v := range next.BossIds {
r := configservice.NewBossService().Get(v)
result.BossID = append(result.BossID, uint32(r.MonID))
}
}
result.CurFightLevel = uint32(c.Info.CurrentFreshStage)
case 2415: //勇者之塔
boss = service.NewTower500Service().Boss(c.Info.CurrentStage)
next = service.NewTower500Service().Boss(c.Info.CurrentStage + 1)
result.CurFightLevel = uint32(c.Info.CurrentStage)
}
if next == nil {
for _, v := range next.BossIds {
r := configservice.NewBossService().Get(v)
result.BossID = append(result.BossID, uint32(r.MonID))
}
}
for i, v := range boss.BossIds {
r := configservice.NewBossService().Get(v)
if r != nil {
monster := model.GenPetInfo(int(r.MonID), int(r.Lv), int(r.Nature), 0, int(r.Lv), nil)
if r.Hp != 0 {
monster.Hp = uint32(r.Hp)
monster.MaxHp = uint32(r.Hp)
}
if len(r.Prop) != 0 {
copy(monster.Prop[:], r.Prop)
}
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]
}
}
}
//todo 特性填装
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.Info.CurrentFreshStage++
case 2415: //勇者之塔
c.Info.CurrentStage++
}
}
}) ///开始对战,房主方以及被邀请方
return
}