2025-11-15 19:11:23 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
2026-02-18 22:07:50 +08:00
|
|
|
"blazing/common/data"
|
2025-11-15 19:11:23 +08:00
|
|
|
"blazing/common/socket/errorcode"
|
2026-03-04 22:47:21 +08:00
|
|
|
"blazing/modules/player/model"
|
2025-11-19 16:11:02 +08:00
|
|
|
"sync/atomic"
|
2025-11-15 22:17:43 +00:00
|
|
|
|
2026-04-05 07:24:36 +08:00
|
|
|
"blazing/logic/service/common"
|
2025-11-15 19:11:23 +08:00
|
|
|
"blazing/logic/service/fight"
|
|
|
|
|
"blazing/logic/service/fight/info"
|
|
|
|
|
"blazing/logic/service/player"
|
|
|
|
|
"blazing/logic/service/space"
|
|
|
|
|
)
|
|
|
|
|
|
2026-04-05 07:24:36 +08:00
|
|
|
type ARENA_SET_OWENR struct {
|
|
|
|
|
Head common.TomeeHeader `cmd:"2417" struc:"skip"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// ArenaSetOwner 处理玩家占据擂台的请求
|
2025-12-24 19:03:11 +08:00
|
|
|
// ArenaSetOwner 都需要通过2419包广播更新擂台状态
|
2026-04-05 07:24:36 +08:00
|
|
|
func (h Controller) ArenaSetOwner(data *ARENA_SET_OWENR, c *player.Player) (result *struct{}, err errorcode.ErrorCode) {
|
2026-02-25 16:18:10 +08:00
|
|
|
r := c.CanFight()
|
|
|
|
|
if r != 0 {
|
|
|
|
|
return nil, r
|
2025-11-21 02:40:27 +08:00
|
|
|
}
|
|
|
|
|
c.Fightinfo.Mode = 0 //取消队列匹配
|
2025-11-19 16:11:02 +08:00
|
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
|
|
|
|
|
|
2025-11-28 00:16:51 +08:00
|
|
|
c.GetSpace().Owner.Set(c)
|
2025-11-20 05:57:29 +08:00
|
|
|
c.GetSpace().Broadcast(c, 2419, c.GetSpace().Owner)
|
|
|
|
|
c.SendPackCmd(2419, c.GetSpace().Owner)
|
|
|
|
|
return
|
2025-11-15 19:11:23 +08:00
|
|
|
}
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrChampionExists
|
2025-11-15 19:11:23 +08:00
|
|
|
}
|
2026-04-05 07:24:36 +08:00
|
|
|
type ARENA_FIGHT_OWENR struct {
|
|
|
|
|
Head common.TomeeHeader `cmd:"2418" struc:"skip"`
|
|
|
|
|
}
|
2025-12-23 10:46:17 +08:00
|
|
|
// ArenaFightOwner 挑战擂台的包
|
2025-11-15 19:11:23 +08:00
|
|
|
// 还是后端主动发送2503的包给双方前端后 等待前端加载完毕 主动发送2404包通知后端开始战斗
|
2025-12-24 19:03:11 +08:00
|
|
|
// ArenaFightOwner 并不会通知对方是否接受挑战。只要有人挑战就直接进入对战
|
2026-04-05 07:24:36 +08:00
|
|
|
func (h Controller) ArenaFightOwner(data1 *ARENA_FIGHT_OWENR, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-15 19:11:23 +08:00
|
|
|
|
2026-02-25 16:18:10 +08:00
|
|
|
r := c.CanFight()
|
|
|
|
|
if r != 0 {
|
|
|
|
|
return nil, r
|
2025-11-20 21:37:37 +08:00
|
|
|
}
|
2025-11-21 02:40:27 +08:00
|
|
|
|
2026-04-02 23:05:18 +08:00
|
|
|
if c.IsArenaHost() {
|
2025-11-21 02:40:27 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
|
|
|
|
}
|
2025-11-28 00:16:51 +08:00
|
|
|
|
|
|
|
|
if c.GetSpace().Owner.ARENA_Player == nil {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrSystemError200007
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 16:18:10 +08:00
|
|
|
if c.GetSpace().Owner.ARENA_Player.CanFight() != 0 {
|
2025-11-28 00:16:51 +08:00
|
|
|
c.GetSpace().Owner.Set(c)
|
|
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
|
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-11-19 16:11:02 +08:00
|
|
|
//原子操作,修改擂台状态
|
2025-11-20 05:57:29 +08:00
|
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 1, 2) {
|
2025-11-19 16:11:02 +08:00
|
|
|
//成功发起擂台挑战后才修改我放状态
|
|
|
|
|
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
2025-11-21 02:40:27 +08:00
|
|
|
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
2025-11-19 16:11:02 +08:00
|
|
|
|
2026-03-24 01:38:02 +08:00
|
|
|
_, err = fight.NewFight(c, c.GetSpace().Owner.ARENA_Player, c.Info.PetList, c.GetSpace().Owner.ARENA_Player.GetInfo().PetList, func(foi model.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
2025-11-15 23:02:46 +00:00
|
|
|
|
2025-11-21 02:40:27 +08:00
|
|
|
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
2025-11-28 00:16:51 +08:00
|
|
|
|
2025-11-21 02:40:27 +08:00
|
|
|
c.GetSpace().Owner.Reset()
|
|
|
|
|
|
|
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
|
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
|
|
2025-11-28 00:16:51 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-13 22:57:05 +08:00
|
|
|
if foi.Reason == 0 { //正常获胜
|
2026-02-18 15:48:52 +08:00
|
|
|
// addev := int64(int(1) * int(cool.Connected) * int(c.GetSpace().Owner.HostWins) * (int(c.GetSpace().User.Count()) / int(cool.Connected)))
|
2026-02-18 22:07:50 +08:00
|
|
|
addev := int64(int(2) * int(c.GetSpace().Owner.HostWins) * (int(c.GetSpace().User.Count())))
|
2025-11-28 00:16:51 +08:00
|
|
|
if foi.WinnerId == c.GetInfo().UserID {
|
|
|
|
|
c.Info.MaxArenaWins += 1
|
2026-02-18 22:07:50 +08:00
|
|
|
if addev != 0 {
|
|
|
|
|
c.Info.EVPool += addev
|
|
|
|
|
|
|
|
|
|
c.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{ //发送EV
|
2026-02-22 01:01:37 +08:00
|
|
|
ItemList: []data.ItemInfo{{
|
2026-02-18 22:07:50 +08:00
|
|
|
ItemId: 9,
|
|
|
|
|
ItemCnt: int64(addev),
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-02-14 03:05:51 +08:00
|
|
|
|
2025-11-28 00:16:51 +08:00
|
|
|
} else {
|
2026-02-16 15:01:28 +08:00
|
|
|
oper := c.GetSpace().Owner.ARENA_Player
|
2026-02-14 23:14:43 +08:00
|
|
|
if oper != nil {
|
2026-02-16 15:01:28 +08:00
|
|
|
if oper.GetInfo() != nil {
|
|
|
|
|
c.GetSpace().Owner.ARENA_Player.GetInfo().MaxArenaWins += 1
|
2026-02-18 22:07:50 +08:00
|
|
|
if addev != 0 {
|
|
|
|
|
c.GetSpace().Owner.ARENA_Player.GetInfo().EVPool += addev
|
2026-02-14 03:05:51 +08:00
|
|
|
|
2026-02-18 22:07:50 +08:00
|
|
|
c.GetSpace().Owner.ARENA_Player.SendPackCmd(8004, &info.S2C_GET_BOSS_MONSTER{ //发送EV
|
2026-02-22 01:01:37 +08:00
|
|
|
ItemList: []data.ItemInfo{{
|
2026-02-18 22:07:50 +08:00
|
|
|
ItemId: 9,
|
|
|
|
|
ItemCnt: int64(addev),
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-02-16 15:01:28 +08:00
|
|
|
|
|
|
|
|
}
|
2026-02-14 23:14:43 +08:00
|
|
|
|
|
|
|
|
}
|
2026-02-14 03:05:51 +08:00
|
|
|
|
2025-11-28 00:16:51 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-21 02:40:27 +08:00
|
|
|
}
|
|
|
|
|
//todo 擂主输了,那就直接让他放弃擂台
|
|
|
|
|
|
2025-11-15 23:02:46 +00:00
|
|
|
}) ///开始对战,房主方以及被邀请方
|
2025-11-15 19:11:23 +08:00
|
|
|
|
2025-11-19 16:11:02 +08:00
|
|
|
if err <= 0 { //发起战斗成功
|
2025-11-20 05:57:29 +08:00
|
|
|
atomic.StoreUint32(&c.GetSpace().Owner.ChallengerID, c.GetInfo().UserID) //传回的指针赋值给ID
|
2025-11-20 21:37:37 +08:00
|
|
|
//c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
|
|
|
//c.SendPackCmd(2419, &c.GetSpace().Owner)
|
2025-11-19 16:11:02 +08:00
|
|
|
} else {
|
2025-11-28 00:16:51 +08:00
|
|
|
|
2025-11-20 05:57:29 +08:00
|
|
|
atomic.StoreUint32(&c.GetSpace().Owner.Flag, 1)
|
|
|
|
|
|
2025-11-18 22:16:55 +00:00
|
|
|
}
|
2025-11-20 21:37:37 +08:00
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
|
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
2025-11-20 05:57:29 +08:00
|
|
|
return
|
2025-11-19 16:11:02 +08:00
|
|
|
}
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrChampionExists
|
|
|
|
|
|
2025-11-15 19:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// ArenaGetInfo 获取星际擂台信息的包 进入空间站地图前端会发送请求包 或者 有人站到星际擂台上后 广播回包
|
2025-11-15 19:11:23 +08:00
|
|
|
// 前端到后端无数据内容
|
2025-12-24 19:03:11 +08:00
|
|
|
// ArenaGetInfo 后端到前端
|
2026-04-05 07:24:36 +08:00
|
|
|
func (h Controller) ArenaGetInfo(data *ARENA_GET_INFO, c *player.Player) (result *space.ARENA, err errorcode.ErrorCode) {
|
2025-11-15 19:11:23 +08:00
|
|
|
|
2025-11-20 05:57:29 +08:00
|
|
|
result = &c.GetSpace().Owner
|
|
|
|
|
return
|
2025-11-15 19:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// ArenaUpfight 放弃擂台挑战的包
|
2025-12-24 19:03:11 +08:00
|
|
|
// ArenaUpfight 都需要通过2419包广播更新擂台状态
|
2026-04-05 07:24:36 +08:00
|
|
|
func (h Controller) ArenaUpfight(data *ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-19 16:11:02 +08:00
|
|
|
//原子操作,修改擂台状态
|
2025-11-28 00:16:51 +08:00
|
|
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID { //说明已经有人了
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
|
|
|
|
}
|
2025-11-20 05:57:29 +08:00
|
|
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.UserID, c.GetInfo().UserID, 0) {
|
2025-11-28 00:16:51 +08:00
|
|
|
|
2025-11-20 05:57:29 +08:00
|
|
|
c.GetSpace().Owner.Reset()
|
|
|
|
|
|
|
|
|
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
|
|
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
|
return nil, -1
|
2025-11-19 16:11:02 +08:00
|
|
|
}
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
|
|
|
|
|
2025-11-15 19:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-23 10:46:17 +08:00
|
|
|
// ArenaOwnerAcce 此包为擂台战对战结束后 胜方前端会发送给后端 具体作用为通知后端发送2419包更新擂台信息。
|
2025-11-15 19:11:23 +08:00
|
|
|
// 前端到后端无数据内容
|
|
|
|
|
// 后端到前端无数据内容
|
|
|
|
|
// public static const ARENA_OWENR_OUT:uint = 2423;
|
2025-12-24 19:03:11 +08:00
|
|
|
// ArenaOwnerAcce 此包不清楚具体怎么触发 但已知此包为后端主动发送。不清楚什么情况下回用到
|
2026-04-05 07:24:36 +08:00
|
|
|
func (h Controller) ArenaOwnerAcce(data *ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
|
|
|
s := c.GetSpace()
|
2025-11-28 00:16:51 +08:00
|
|
|
|
|
|
|
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID && c.GetInfo().UserID != atomic.LoadUint32(&c.GetSpace().Owner.ChallengerID) { //说明已经有人了
|
2025-11-29 19:26:56 +08:00
|
|
|
return nil, -1
|
2025-11-19 16:11:02 +08:00
|
|
|
}
|
2025-11-28 00:16:51 +08:00
|
|
|
s.Owner.Set(c)
|
2025-11-19 16:11:02 +08:00
|
|
|
|
|
|
|
|
atomic.StoreUint32(&s.Owner.Flag, 1)
|
|
|
|
|
|
|
|
|
|
s.Broadcast(c, 2419, &s.Owner)
|
2025-11-20 05:57:29 +08:00
|
|
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
|
|
|
|
|
|
|
|
|
return nil, -1
|
2025-12-24 19:03:11 +08:00
|
|
|
}
|