Files
bl/logic/controller/fight.go
昔念 39893e4df9 refactor(fight): 重构战斗模块
- 移除未使用的结构体和接口
- 优化战斗准备和邀请逻辑
- 调整玩家和怪物信息的处理方式
- 更新战斗相关的数据结构
- 重构战斗模式和邀请相关代码
2025-09-02 00:45:29 +08:00

87 lines
2.3 KiB
Go

package controller
import (
"blazing/common/data/socket"
"blazing/common/socket/errorcode"
"blazing/common/socket/handler"
"math/rand"
"time"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/modules/blazing/model"
"github.com/jinzhu/copier"
)
func (h Controller) OnPlayerFightNpcMonster(data *info.FightNpcMonsterInboundInfo, c *socket.Player) (result *info.NullOutboundInfo, err errorcode.ErrorCode) {
c.IsFighting = true
ttt := info.NoteReadyToFightInfo{
OwnerID: data.Head.UserID,
FightId: 3,
}
copier.Copy(&ttt.OurInfo, &c.Info)
len := len(c.Info.PetList)
ttt.OurPetList = make([]info.ReadyFightPetInfo, len)
for i := 0; i < len; i++ {
err := copier.CopyWithOption(&ttt.OurPetList[i], &c.Info.PetList[i], copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err != nil {
panic(err)
}
}
ttt.OpponentInfo = info.FightUserInfo{UserID: 0}
refpet := c.OgreInfo.Data[data.Number]
dv := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(32)
mo := model.GenPetInfo(refpet.Id, uint32(dv), 0, 1006, refpet.Shiny, refpet.Lv)
ttt.OpponentPetList = make([]info.ReadyFightPetInfo, 1)
err1 := copier.CopyWithOption(&ttt.OpponentPetList[0], &mo, copier.Option{IgnoreEmpty: true, DeepCopy: true})
if err1 != nil {
panic(err)
}
fight.NewFight(&ttt, c) //把两个玩家都传进去
return nil, -1
}
// 准备战斗
func (h Controller) OnReadyToFight(data *info.ReadyToFightInboundInfo, c *socket.Player) (result *info.NullOutboundInfo, err errorcode.ErrorCode) {
fight.ReadyFight(c)
return nil, -1
}
// 接收战斗或者取消战斗的包
func (h Controller) OnPlayerHandleFightInvite(data *info.HandleFightInviteInboundInfo, c *socket.Player) (result *info.NullOutboundInfo, err errorcode.ErrorCode) {
return nil, -1
}
// 使用技能包
func (h Controller) UseSkill(data *info.UseSkillInboundInfo, c *socket.Player) (result *info.NullOutboundInfo, err errorcode.ErrorCode) {
return nil, 0
}
// 战斗逃跑
func (h Controller) Escape(data *info.EscapeFightInboundInfo, c *socket.Player) (result *info.NullOutboundInfo, err errorcode.ErrorCode) {
defer func() {
//战斗结束Escape
ttt := handler.NewTomeeHeader(2506, c.Info.UserID)
c.SendPack(ttt.Pack(&info.FightOverInfo{
Reason: 0,
}))
c.IsFighting = false
}()
return nil, 0
}