feat(fight): 新增团战胜利关闭和超时退出功能 新增 GroupFightWinClose 和 GroupFightTimeoutExit 方法, 用于处理团战胜利关闭和超时退出逻辑,统一调用 QuitFight() 退出战斗。 fix(gold_list): 修复挂单服务中的逻辑错误和潜在异常 修复了 GoldListService 中的多处问题: - 修正条件判断语句格式 - 添加数据库查询错误检查 - 优化
175 lines
5.7 KiB
Go
175 lines
5.7 KiB
Go
package controller
|
||
|
||
import (
|
||
"blazing/common/socket/errorcode"
|
||
|
||
"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 *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
|
||
}
|
||
|
||
// GroupReadyFightFinish 旧组队协议准备完成。
|
||
func (h Controller) GroupReadyFightFinish(data *GroupReadyFightFinishInboundInfo, 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
|
||
}
|
||
|
||
func (h Controller) GroupUseSkill(data *GroupUseSkillInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
targetRelation := fight.SkillTargetOpponent
|
||
if data.TargetSide == 1 {
|
||
targetRelation = fight.SkillTargetAlly
|
||
}
|
||
h.dispatchFightActionEnvelope(c, fight.NewSkillActionEnvelope(data.SkillId, int(data.ActorIndex), int(data.TargetPos), targetRelation, 0))
|
||
c.SendPackCmd(7558, nil)
|
||
return nil, -1
|
||
}
|
||
|
||
func (h Controller) GroupUseItem(data *GroupUseItemInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, fight.NewItemActionEnvelope(0, data.ItemId, int(data.ActorIndex), int(data.ActorIndex), fight.SkillTargetSelf))
|
||
return nil, -1
|
||
}
|
||
|
||
func (h Controller) GroupChangePet(data *GroupChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, fight.NewChangeActionEnvelope(data.CatchTime, int(data.ActorIndex)))
|
||
return nil, -1
|
||
}
|
||
|
||
func (h Controller) GroupEscape(data *GroupEscapeInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
if fightC, ok := c.FightC.(*fight.FightC); ok && fightC != nil && fightC.LegacyGroupProtocol {
|
||
fightC.SendLegacyEscapeSuccess(c, int(data.ActorIndex))
|
||
}
|
||
h.dispatchFightActionEnvelope(c, fight.NewEscapeActionEnvelope())
|
||
return nil, 0
|
||
}
|
||
|
||
func (h Controller) GroupFightWinClose(data *GroupFightWinCloseInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if c != nil {
|
||
c.QuitFight()
|
||
}
|
||
return nil, -1
|
||
}
|
||
|
||
func (h Controller) GroupFightTimeoutExit(data *GroupFightTimeoutExitInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if c != nil {
|
||
c.QuitFight()
|
||
}
|
||
return nil, -1
|
||
}
|
||
|
||
// UseSkill 使用技能包
|
||
func (h Controller) UseSkill(data *UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, buildLegacyUseSkillEnvelope(data))
|
||
return nil, 0
|
||
}
|
||
|
||
// UseSkillAt 组队/多战位技能包(cmd=7505)。
|
||
// 目标关系:0=对方 1=自己 2=队友。
|
||
func (h Controller) UseSkillAt(data *UseSkillAtInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, buildIndexedUseSkillEnvelope(data))
|
||
return nil, 0
|
||
}
|
||
|
||
// Escape 战斗逃跑
|
||
func (h Controller) Escape(data *EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, buildLegacyEscapeEnvelope())
|
||
return nil, 0
|
||
}
|
||
|
||
// ChangePet 切换精灵
|
||
func (h Controller) ChangePet(data *ChangePetInboundInfo, c *player.Player) (result *info.ChangePetInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, buildLegacyChangeEnvelope(data))
|
||
return nil, -1
|
||
}
|
||
|
||
// Capture 捕捉精灵
|
||
func (h Controller) Capture(data *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 {
|
||
go c.FightC.UseSkill(c, 0)
|
||
return nil, -1
|
||
}
|
||
}
|
||
go c.FightC.Capture(c, data.CapsuleId)
|
||
return nil, -1
|
||
}
|
||
|
||
// LoadPercent 加载进度
|
||
func (h Controller) LoadPercent(data *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 *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 {
|
||
go c.FightC.UseSkill(c, 0)
|
||
}
|
||
}
|
||
|
||
h.dispatchFightActionEnvelope(c, buildLegacyUseItemEnvelope(data))
|
||
return nil, -1
|
||
}
|
||
|
||
// FightChat 战斗聊天
|
||
func (h Controller) FightChat(data *ChatInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||
if err := h.checkFightStatus(c); err != 0 {
|
||
return nil, err
|
||
}
|
||
h.dispatchFightActionEnvelope(c, buildChatEnvelope(data))
|
||
return nil, -1
|
||
}
|