feat(broadcast): 添加全服广播功能并完善相关逻辑 新增 Broadcast 结构体及 Server 的 Broadcast 方法,用于实现全服广播消息, 并在 RPC 客户端中增加对应接口。同时在 fight 模块中添加聊天信息结构体和处理逻辑。 refactor(pet_skill): 优化宠物技能设置逻辑 修复宠物技能替换判断条件错误的问题,并调整相关逻辑顺序以提高代码可读性与健壮性。 feat(chat): 实现战斗内聊天功能 新增战斗中的聊天指令结构体 ChatInfo 和对应的控制器方法 FightChat, 支持玩家在战斗中发送聊天消息。 refactor(item_buy): 调整金币购买道具的扣费方式 将原直接比较金币数量改为调用
96 lines
2.7 KiB
Go
96 lines
2.7 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"sync/atomic"
|
|
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/player"
|
|
)
|
|
|
|
// 准备战斗
|
|
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
c.FightC.ReadyFight(c)
|
|
return nil, -1
|
|
}
|
|
|
|
// 使用技能包
|
|
func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
c.FightC.UseSkill(c, (data.SkillId))
|
|
return nil, 0
|
|
}
|
|
|
|
// 战斗逃跑
|
|
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
|
|
if atomic.LoadUint32(&c.Fightinfo.Mode) == 0 {
|
|
|
|
return nil, errorcode.ErrorCodes.ErrBattleNotStarted //,没开始对战
|
|
}
|
|
if atomic.LoadUint32(&c.Fightinfo.Mode) == 1 { //用户对战不能逃跑
|
|
|
|
return nil, errorcode.ErrorCodes.ErrCannotFleePlayerBattle
|
|
}
|
|
c.FightC.Over(c, info.BattleOverReason.PlayerEscape)
|
|
return nil, 0
|
|
}
|
|
|
|
// 切换精灵
|
|
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
|
|
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) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
c.FightC.Capture(c, data.CapsuleId)
|
|
return nil, -1
|
|
}
|
|
|
|
// 加载进度
|
|
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
|
|
c.FightC.LoadPercent(c, int32(data.Percent))
|
|
return nil, -1
|
|
}
|
|
func (h Controller) UsePetItemInboundInfo(data *fight.UsePetItemInboundInfo, c *player.Player) (result *info.UsePetIteminfo, err errorcode.ErrorCode) {
|
|
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
|
|
c.FightC.UseItem(c, data.CatchTime, data.ItemId)
|
|
|
|
return nil, -1
|
|
}
|
|
func (h Controller) FightChat(data *fight.ChatInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.FightC == nil {
|
|
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
|
}
|
|
|
|
c.FightC.Chat(c, data.Message)
|
|
|
|
return nil, -1
|
|
}
|