Files
bl/logic/controller/fight.go
昔念 9c25ccc214 ```
feat(fight): 实现玩家间战斗邀请与处理功能

新增战斗邀请与处理逻辑,包括邀请发送、邀请接受/拒绝流程。
添加战斗模式支持(1v1 和 6v6)及相关数据结构定义。
优化玩家战斗准备逻辑,完善战斗初始化流程。
修复玩家离线保存数据时的空指针问题。
调整战斗相关枚举类型,统一管理战斗模式。
完善邀请战斗消息结构体及通信协议。
```
2025-09-20 00:17:29 +08:00

116 lines
3.2 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
)
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
var petid int
var mo *model.PetInfo
if c.MapID() == 515 && data.BossId == 0 { //说明是新手,随机生成
switch c.Info.PetList[0].ID {
case 1:
petid = 4
case 7:
petid = 1
case 4:
petid = 7
}
mo = model.GenPetInfo(
int(petid), []int{0, 31},
[]int{0, 24},
[]int{0}, //野怪没特性
[]int{int(0)},
[]int{int(2)})
}
if c.FightC != nil {
return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight
}
ai := player.NewAI_player(model.PlayerInfo{}, *mo)
fight.NewFight(info.BattleMode.PVE, c, ai)
return nil, -1
}
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
refpet := c.OgreInfo.Data[data.Number]
if refpet.Id == 0 {
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
}
mo := model.GenPetInfo(
int(refpet.Id), []int{0, 31},
[]int{0, 24},
[]int{0}, //野怪没特性
[]int{int(refpet.Shiny)},
[]int{int(refpet.Lv)})
if c.FightC != nil {
return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight
}
ai := player.NewAI_player(model.PlayerInfo{}, *mo)
fight.NewFight(info.BattleMode.PVE, c, ai)
return nil, -1
}
// 准备战斗
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.ReadyFight(c)
return nil, -1
}
// 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
fight.NewFight(info.EnumBattleMode(data.Mode), p1, c) ///开始对战,房主方以及被邀请方
}
return nil, -1
}
// 邀请其他人进行战斗
func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.InvitePlayerToBattle(data.UserID, info.EnumBattleMode(data.Mode))
return nil, 0
}
// 使用技能包
func (h Controller) UseSkill(data *fight.UseSkillInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.UseSkill(c, int32(data.SkillId))
return nil, 0
}
// 战斗逃跑
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.Escape(c)
return nil, 0
}
// 切换精灵
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.FightC.ChangePet(c, data.CatchTime)
return nil, -1
}
// 切换精灵
func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) {
c.FightC.Capture(c, (data.CapsuleId))
return nil, -1
}