feat(space): 替换并发安全map实现以提升性能 将原来基于`utils.ConcurrentMap`的玩家存储结构替换为 `github.com/mhmtszr/concurrent-swiss-map`提供的`CsMap`, 以获得更高效的并发读写能力。 同时修改了相关API调用方式: - `Set` 改为 `Store` - `Remove` 改为 `Delete` - `IterCb` 改为 `Range`,并支持提前终止迭代 - `Items()` 不再使用 此外,调整了部分业务逻辑中对玩家列表遍历的方式, 确保在发送网络包后及时跳出循环,避免不必要的操作。 新增战斗类型处理函数`PET_King`用于处理宠物王相关的 战斗请求,并修复了`PET_MELEE`方法中的逻辑问题。 更新了go.mod和go.sum引入新的依赖库。 ```
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/player"
|
|
)
|
|
|
|
//大乱斗
|
|
|
|
func (h Controller) PET_MELEE(data *fight.StartPetWarInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if !c.CanFight() {
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
|
}
|
|
|
|
c.PVPinfo = &info.PVPinfo{
|
|
Mode: info.BattleMode.PET_MELEE,
|
|
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
|
|
g := c.Pet_joinFight()
|
|
if g != nil {
|
|
fight.NewFight(info.BattleMode.PET_MELEE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
|
}
|
|
|
|
return
|
|
}
|
|
func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if !c.CanFight() {
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
|
}
|
|
|
|
c.PVPinfo = &info.PVPinfo{
|
|
|
|
Status: info.BattleStatus.FIGHT_WITH_PLAYER}
|
|
|
|
switch data.Type {
|
|
case 5:
|
|
c.PVPinfo.Mode = info.BattleMode.SINGLE_MODE
|
|
case 6:
|
|
c.PVPinfo.Mode = info.BattleMode.MULTI_MODE
|
|
}
|
|
g := c.Pet_joinFight()
|
|
if g != nil {
|
|
switch data.Type {
|
|
case 5:
|
|
fight.NewFight(info.BattleMode.SINGLE_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
|
case 6:
|
|
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_PLAYER, g, c) ///开始对战,房主方以及被邀请方
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
}
|