feat: 更新战斗系统模型结构和Redis消息处理 - 引入gredis依赖用于Redis消息处理 - 将战斗相关的枚举和结构体从info包迁移到model包 - 更新战斗结束原因、攻击值等类型的引用路径 - 添加新的zset工具包到工作区 - 修改Redis消息处理逻辑以正确解析gredis.Message类型 - 在战斗控制器中统一使用model包下的类型定义
102 lines
2.9 KiB
Go
102 lines
2.9 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/modules/player/model"
|
|
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/player"
|
|
)
|
|
|
|
// checkFightStatus 检查战斗状态
|
|
func (h Controller) checkFightStatus(c *player.Player) errorcode.ErrorCode {
|
|
if c.FightC == nil {
|
|
return errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// OnReadyToFight 准备战斗
|
|
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
go c.FightC.ReadyFight(c)
|
|
return nil, -1
|
|
}
|
|
|
|
// UseSkill 使用技能包
|
|
func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
go c.FightC.UseSkill(c, data.SkillId)
|
|
return nil, 0
|
|
}
|
|
|
|
// Escape 战斗逃跑
|
|
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
|
|
go c.FightC.Over(c, model.BattleOverReason.PlayerEscape)
|
|
return nil, 0
|
|
}
|
|
|
|
// ChangePet 切换精灵
|
|
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *info.ChangePetInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
go c.FightC.ChangePet(c, data.CatchTime)
|
|
return nil, -1
|
|
}
|
|
|
|
// Capture 捕捉精灵
|
|
func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
if c.GetSpace().IsTime {
|
|
if data.CapsuleId < 300009 {
|
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
|
}
|
|
}
|
|
go c.FightC.Capture(c, data.CapsuleId)
|
|
return nil, -1
|
|
}
|
|
|
|
// LoadPercent 加载进度
|
|
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, -1
|
|
}
|
|
go c.FightC.LoadPercent(c, int32(data.Percent))
|
|
return nil, -1
|
|
}
|
|
|
|
// UsePetItemInboundInfo 使用宠物道具
|
|
func (h Controller) UsePetItemInboundInfo(data *fight.UsePetItemInboundInfo, c *player.Player) (result *info.UsePetIteminfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
if c.GetSpace().IsTime {
|
|
if data.ItemId < 300009 {
|
|
return nil, errorcode.ErrorCodes.ErrCannotPerformAction
|
|
}
|
|
}
|
|
go c.FightC.UseItem(c, data.CatchTime, data.ItemId)
|
|
return nil, -1
|
|
}
|
|
|
|
// FightChat 战斗聊天
|
|
func (h Controller) FightChat(data *fight.ChatInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if err := h.checkFightStatus(c); err != 0 {
|
|
return nil, err
|
|
}
|
|
go c.FightC.Chat(c, data.Message)
|
|
return nil, -1
|
|
}
|