Files
bl/logic/controller/fight_pvp_king.go
昔念 4751594ee8 ```
feat: 更新战斗系统模型结构和Redis消息处理

- 引入gredis依赖用于Redis消息处理
- 将战斗相关的枚举和结构体从info包迁移到model包
- 更新战斗结束原因、攻击值等类型的引用路径
- 添加新的zset工具包到工作区
- 修改Redis消息处理逻辑以正确解析gredis.Message类型
- 在战斗控制器中统一使用model包下的类型定义
2026-03-04 22:47:21 +08:00

99 lines
2.5 KiB
Go

package controller
import (
"blazing/common/socket/errorcode"
"blazing/modules/player/model"
"blazing/logic/service/common"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
"blazing/logic/service/player"
)
//大乱斗
func (h Controller) PetMelee(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.Fightinfo.Mode = info.BattleMode.PET_MELEE
c.Fightinfo.Status = info.BattleMode.PET_MELEE
err = c.JoinFight(func(p common.PlayerI) bool {
_, err = fight.NewFight(p, c, func(foi model.FightOverInfo) {
if foi.Reason == 0 { //我放获胜
if foi.WinnerId == c.GetInfo().UserID {
c.Info.MessWin += 1
c.MessWin(true)
p.MessWin(false)
} else {
p.GetInfo().MessWin += 1
p.MessWin(true)
c.MessWin(false)
}
}
if foi.Reason == model.BattleOverReason.PlayerOffline {
if foi.WinnerId == c.GetInfo().UserID {
p.MessWin(false)
} else {
c.MessWin(false)
}
}
}) ///开始对战,房主方以及被邀请方
return err <= 0
})
return
}
func (h Controller) PetKing(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
c.Fightinfo.Status = info.BattleMode.PET_TOPLEVEL
switch data.Type {
case 5:
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
case 6:
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
case 11:
//草","水","火","电","战斗","飞行","机械","地面","冰"
// 按顺序:草、水、火、电、战斗、飞行、机械、地面、冰
var ElementTypeNumbers = []int{1, 2, 3, 5, 11, 4, 6, 7, 9}
println("11", c.GetPetInfo()[0].Type(), ElementTypeNumbers[data.FightType-1])
if c.GetPetInfo()[0].Type() != int(ElementTypeNumbers[data.FightType-1]) {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrVictoryConditionNotMet)
}
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
c.Fightinfo.FightType = data.FightType
}
err = c.JoinFight(func(p common.PlayerI) bool {
_, err = fight.NewFight(p, c, func(foi model.FightOverInfo) {
if foi.Reason == 0 { //我放获胜
switch data.Type {
case 11:
if foi.WinnerId == c.GetInfo().UserID {
c.ItemAdd(80000000+int64(data.FightType), 1)
} else {
p.ItemAdd(80000000+int64(data.FightType), 1)
}
default:
if foi.WinnerId == c.GetInfo().UserID {
c.Info.MonKingWin += 1
} else {
p.GetInfo().MonKingWin += 1
}
}
}
}) ///开始对战,房主方以及被邀请方
return err <= 0
})
return
}