```
feat(fight): 优化擂台战斗逻辑与状态管理 - 修改了擂台主人设置逻辑,引入 `Set` 方法统一处理玩家信息更新 - 增加对擂主是否可战斗的判断,防止无效挑战 - 调整连胜计算和广播机制,确保数据一致性 - 修复擂台挑战失败时的状态回滚问题 - 引入错误码替代硬编码返回值,提高代码可读性与维护性 - 统一访问擂台玩家的方式,移除冗余字段
This commit is contained in:
@@ -68,7 +68,7 @@ func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Playe
|
|||||||
// 加载进度
|
// 加载进度
|
||||||
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
||||||
if c.FightC == nil {
|
if c.FightC == nil {
|
||||||
return nil, errorcode.ErrorCodes.ErrBattleEnded
|
return nil, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
c.FightC.LoadPercent(c, int32(data.Percent))
|
c.FightC.LoadPercent(c, int32(data.Percent))
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ func (h Controller) ARENA_SET_OWENR(data *fight.ARENA_SET_OWENR, c *player.Playe
|
|||||||
c.Fightinfo.Mode = 0 //取消队列匹配
|
c.Fightinfo.Mode = 0 //取消队列匹配
|
||||||
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 0, 1) {
|
||||||
|
|
||||||
c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
|
c.GetSpace().Owner.Set(c)
|
||||||
c.GetSpace().Owner.Nick = c.GetInfo().Nick
|
|
||||||
c.GetSpace().ARENA_Player = c //添加用户
|
|
||||||
|
|
||||||
c.GetSpace().Broadcast(c, 2419, c.GetSpace().Owner)
|
c.GetSpace().Broadcast(c, 2419, c.GetSpace().Owner)
|
||||||
c.SendPackCmd(2419, c.GetSpace().Owner)
|
c.SendPackCmd(2419, c.GetSpace().Owner)
|
||||||
return
|
return
|
||||||
@@ -50,21 +47,42 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
|||||||
if c.Info.UserID == c.GetSpace().Owner.UserID {
|
if c.Info.UserID == c.GetSpace().Owner.UserID {
|
||||||
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.GetSpace().Owner.ARENA_Player == nil {
|
||||||
|
return nil, errorcode.ErrorCodes.ErrSystemError200007
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.GetSpace().Owner.ARENA_Player.CanFight() {
|
||||||
|
c.GetSpace().Owner.Set(c)
|
||||||
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
||||||
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
||||||
|
return
|
||||||
|
}
|
||||||
//原子操作,修改擂台状态
|
//原子操作,修改擂台状态
|
||||||
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 1, 2) {
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.Flag, 1, 2) {
|
||||||
//成功发起擂台挑战后才修改我放状态
|
//成功发起擂台挑战后才修改我放状态
|
||||||
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
c.Fightinfo.Mode = info.BattleMode.SINGLE_MODE
|
||||||
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
c.Fightinfo.Status = info.BattleMode.FIGHT_ARENA
|
||||||
|
|
||||||
_, err = fight.NewFight(c, c.GetSpace().ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
_, err = fight.NewFight(c, c.GetSpace().Owner.ARENA_Player, func(foi *info.FightOverInfo) { //我方邀请擂主挑战,我方先手
|
||||||
|
|
||||||
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
if foi.Reason != 0 && foi.WinnerId == c.GetInfo().UserID { //异常退出
|
||||||
c.GetSpace().ARENA_Player = nil
|
|
||||||
c.GetSpace().Owner.Reset()
|
c.GetSpace().Owner.Reset()
|
||||||
|
|
||||||
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
||||||
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
c.SendPackCmd(2419, &c.GetSpace().Owner)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if foi.Reason == 0 { //异常退出
|
||||||
|
|
||||||
|
if foi.WinnerId == c.GetInfo().UserID {
|
||||||
|
c.Info.MaxArenaWins += 1
|
||||||
|
} else {
|
||||||
|
c.GetSpace().Owner.ARENA_Player.GetInfo().MaxArenaWins += 1
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//todo 擂主输了,那就直接让他放弃擂台
|
//todo 擂主输了,那就直接让他放弃擂台
|
||||||
|
|
||||||
@@ -75,11 +93,7 @@ func (h Controller) ARENA_FIGHT_OWENR(data *fight.ARENA_FIGHT_OWENR, c *player.P
|
|||||||
//c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
//c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
||||||
//c.SendPackCmd(2419, &c.GetSpace().Owner)
|
//c.SendPackCmd(2419, &c.GetSpace().Owner)
|
||||||
} else {
|
} else {
|
||||||
//发起失败,改回1
|
|
||||||
// c.GetSpace().Owner.HostWins = 0 //连胜重置
|
|
||||||
// c.GetSpace().Owner.UserID = c.GetInfo().UserID //添加用户ID
|
|
||||||
// c.GetSpace().Owner.Nick = c.GetInfo().Nick
|
|
||||||
// c.GetSpace().ARENA_Player = c //添加用户
|
|
||||||
atomic.StoreUint32(&c.GetSpace().Owner.Flag, 1)
|
atomic.StoreUint32(&c.GetSpace().Owner.Flag, 1)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -107,9 +121,11 @@ func (h Controller) ARENA_GET_INFO(data *fight.ARENA_GET_INFO, c *player.Player)
|
|||||||
// 都需要通过2419包广播更新擂台状态
|
// 都需要通过2419包广播更新擂台状态
|
||||||
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
//原子操作,修改擂台状态
|
//原子操作,修改擂台状态
|
||||||
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID { //说明已经有人了
|
||||||
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
||||||
|
}
|
||||||
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.UserID, c.GetInfo().UserID, 0) {
|
if atomic.CompareAndSwapUint32(&c.GetSpace().Owner.UserID, c.GetInfo().UserID, 0) {
|
||||||
c.GetSpace().ARENA_Player = nil
|
|
||||||
c.GetSpace().Owner.Reset()
|
c.GetSpace().Owner.Reset()
|
||||||
|
|
||||||
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
c.GetSpace().Broadcast(c, 2419, &c.GetSpace().Owner)
|
||||||
@@ -129,19 +145,11 @@ func (h Controller) ARENA_UPFIGHT(data *fight.ARENA_UPFIGHT, c *player.Player) (
|
|||||||
func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) ARENA_OWENR_ACCE(data *fight.ARENA_OWENR_ACCE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
||||||
|
|
||||||
s := c.GetSpace()
|
s := c.GetSpace()
|
||||||
if atomic.LoadUint32(&s.Owner.UserID) != c.GetInfo().UserID && c.GetInfo().UserID != atomic.LoadUint32(&s.Owner.ChallengerID) { //说明已经有人了
|
|
||||||
return nil, -1
|
|
||||||
}
|
|
||||||
if c.GetInfo().UserID == atomic.LoadUint32(&s.Owner.UserID) {
|
|
||||||
c.Info.MaxArenaWins += 1
|
|
||||||
s.Owner.HostWins += 1 //连胜+1
|
|
||||||
|
|
||||||
} else {
|
if atomic.LoadUint32(&c.GetSpace().Owner.UserID) != c.GetInfo().UserID && c.GetInfo().UserID != atomic.LoadUint32(&c.GetSpace().Owner.ChallengerID) { //说明已经有人了
|
||||||
s.Owner.HostWins = 0 //连胜重置
|
return nil, errorcode.ErrorCodes.ErrChampionCannotCancel
|
||||||
s.Owner.UserID = c.GetInfo().UserID //添加用户ID
|
|
||||||
s.Owner.Nick = c.GetInfo().Nick
|
|
||||||
s.ARENA_Player = c //添加用户
|
|
||||||
}
|
}
|
||||||
|
s.Owner.Set(c)
|
||||||
|
|
||||||
atomic.StoreUint32(&s.Owner.Flag, 1)
|
atomic.StoreUint32(&s.Owner.Flag, 1)
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
|
|||||||
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
c.Fightinfo.Mode = info.BattleMode.MULTI_MODE
|
||||||
}
|
}
|
||||||
err = c.JoinFight(func(p common.PlayerI) bool {
|
err = c.JoinFight(func(p common.PlayerI) bool {
|
||||||
fight.NewFight(p, c, func(foi *info.FightOverInfo) {
|
_, err = fight.NewFight(p, c, func(foi *info.FightOverInfo) {
|
||||||
if foi.Reason == 0 { //我放获胜
|
if foi.Reason == 0 { //我放获胜
|
||||||
if foi.WinnerId == c.GetInfo().UserID {
|
if foi.WinnerId == c.GetInfo().UserID {
|
||||||
c.Info.MonKingWin += 1
|
c.Info.MonKingWin += 1
|
||||||
@@ -60,7 +60,10 @@ func (h Controller) PET_King(data *fight.PetKingJoinInboundInfo, c *player.Playe
|
|||||||
|
|
||||||
}
|
}
|
||||||
}) ///开始对战,房主方以及被邀请方
|
}) ///开始对战,房主方以及被邀请方
|
||||||
|
if err > 0 { //说明有报错
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ func (h Controller) UserMoreInfo(data *user.MoreUserInfoInboundInfo, c *player.P
|
|||||||
return ret, 0
|
return ret, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 射击
|
||||||
func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
|
func (h Controller) Aimat(data *user.AimatInboundInfo, c *player.Player) (result *user.AimatOutboundInfo, err errorcode.ErrorCode) {
|
||||||
result = &user.AimatOutboundInfo{
|
result = &user.AimatOutboundInfo{
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package effect
|
package effect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blazing/logic/service/fight/action"
|
||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
"blazing/logic/service/fight/input"
|
"blazing/logic/service/fight/input"
|
||||||
|
|
||||||
@@ -15,8 +16,18 @@ type NewSel36 struct {
|
|||||||
round int
|
round int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NewSel36) Damage_DIV_ex(t *info.DamageZone) bool {
|
func (e *NewSel36) Turn_Start(fattack *action.SelectSkillAction, sattack *action.SelectSkillAction) {
|
||||||
e.round++
|
e.round++
|
||||||
|
if e.round >= 5 {
|
||||||
|
e.round = 0
|
||||||
|
e.index++
|
||||||
|
if e.index >= len(e.Args()) {
|
||||||
|
e.index = 0
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (e *NewSel36) Damage_DIV_ex(t *info.DamageZone) bool {
|
||||||
|
|
||||||
e.Ctx().Our.AttackValue.State = uint32(e.Args()[e.index])
|
e.Ctx().Our.AttackValue.State = uint32(e.Args()[e.index])
|
||||||
|
|
||||||
@@ -32,22 +43,11 @@ func (e *NewSel36) Damage_DIV_ex(t *info.DamageZone) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Args()[e.index] == e.Ctx().SkillEntity.Type {
|
if e.Args()[e.index] != e.Ctx().SkillEntity.Type {
|
||||||
|
|
||||||
if e.round >= 5 {
|
t.Damage = decimal.NewFromInt(0)
|
||||||
e.round = 0
|
|
||||||
e.index++
|
|
||||||
if e.index >= len(e.Args()) {
|
|
||||||
e.index = 0
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Damage = decimal.NewFromInt(0)
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ type DefaultEndData struct {
|
|||||||
type EnumBattleOverReason int
|
type EnumBattleOverReason int
|
||||||
|
|
||||||
var BattleOverReason = enum.New[struct {
|
var BattleOverReason = enum.New[struct {
|
||||||
PlayerOffline EnumBattleOverReason `enum:"1"` //掉线
|
PlayerOffline EnumBattleOverReason `enum:"1"` //掉线
|
||||||
PlayerOVerTime EnumBattleOverReason `enum:"2"` //超时
|
PlayerOVerTime EnumBattleOverReason `enum:"2"` //超时
|
||||||
PlayerCaptureSuccess EnumBattleOverReason `enum:"3"` //捕捉成功
|
NOTwind EnumBattleOverReason `enum:"3"` //打成平手
|
||||||
DefaultEnd EnumBattleOverReason `enum:"4"` //默认结束
|
DefaultEnd EnumBattleOverReason `enum:"4"` //默认结束
|
||||||
PlayerEscape EnumBattleOverReason `enum:"5"` //逃跑
|
PlayerEscape EnumBattleOverReason `enum:"5"` //逃跑
|
||||||
}]()
|
}]()
|
||||||
|
|
||||||
// 战斗模式
|
// 战斗模式
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) {
|
|||||||
CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime),
|
CatchTime: uint32(f.Opp.CurrentPet.Info.CatchTime),
|
||||||
PetId: uint32(f.Opp.CurrentPet.ID),
|
PetId: uint32(f.Opp.CurrentPet.ID),
|
||||||
}))
|
}))
|
||||||
//f.Reason = info.BattleOverReason.PlayerCatch
|
//f.Reason = info.BattleOverReason.PlayerCaptureSuccess
|
||||||
//f.WinnerId = 0 //捕捉成功不算胜利
|
//f.WinnerId = 0 //捕捉成功不算胜利
|
||||||
|
|
||||||
f.closefight = true
|
f.closefight = true
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func (p *Player) JoinFight(fn func(p common.PlayerI) bool) errorcode.ErrorCode {
|
|||||||
if v.GetInfo().UserID != p.Info.UserID {
|
if v.GetInfo().UserID != p.Info.UserID {
|
||||||
//确认是乱斗模式
|
//确认是乱斗模式
|
||||||
|
|
||||||
if v.Getfightinfo() == p.Getfightinfo() {
|
if v.Getfightinfo() == p.Getfightinfo() && p.CanFight() {
|
||||||
|
|
||||||
// p.Fightinfo = nil //先将自身的准备信息置空
|
// p.Fightinfo = nil //先将自身的准备信息置空
|
||||||
// //value.PVPinfo = nil
|
// //value.PVPinfo = nil
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package space
|
package space
|
||||||
|
|
||||||
|
import (
|
||||||
|
"blazing/logic/service/common"
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
type ARENA struct {
|
type ARENA struct {
|
||||||
Flag uint32 // 0=清除ArenaInfo(flag为0时其他字段全为空) 1=站上擂台的信息 2=挑战中的信息
|
ARENA_Player common.PlayerI `struc:"skip"`
|
||||||
|
Flag uint32 // 0=清除ArenaInfo(flag为0时其他字段全为空) 1=站上擂台的信息 2=挑战中的信息
|
||||||
UserID uint32
|
UserID uint32
|
||||||
Nick string `struc:"[16]byte"`
|
Nick string `struc:"[16]byte"`
|
||||||
HostWins uint32 // 应该是擂台人的连胜数
|
HostWins uint32 // 应该是擂台人的连胜数
|
||||||
@@ -16,4 +22,24 @@ func (t *ARENA) Reset() {
|
|||||||
t.HostWins = 0
|
t.HostWins = 0
|
||||||
t.ChallengerID = 0
|
t.ChallengerID = 0
|
||||||
|
|
||||||
|
t.ARENA_Player = nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *ARENA) Set(c common.PlayerI) bool {
|
||||||
|
|
||||||
|
if c.GetInfo().UserID == atomic.LoadUint32(&t.UserID) {
|
||||||
|
|
||||||
|
t.HostWins += 1 //连胜+1
|
||||||
|
|
||||||
|
} else {
|
||||||
|
t.HostWins = 0 //连胜重置
|
||||||
|
t.UserID = c.GetInfo().UserID //添加用户ID
|
||||||
|
t.Nick = c.GetInfo().Nick
|
||||||
|
t.ARENA_Player = c //添加用户
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreUint32(&t.Flag, 1)
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ func (s *Space) Broadcast(c common.PlayerI, cmd uint32, data any) {
|
|||||||
func (s *Space) LeaveMap(c common.PlayerI) {
|
func (s *Space) LeaveMap(c common.PlayerI) {
|
||||||
|
|
||||||
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
if atomic.CompareAndSwapUint32(&s.Owner.UserID, c.GetInfo().UserID, 0) {
|
||||||
s.ARENA_Player = nil
|
|
||||||
|
|
||||||
s.Owner.Reset()
|
s.Owner.Reset()
|
||||||
|
|
||||||
|
|||||||
@@ -18,9 +18,8 @@ type Space struct {
|
|||||||
Super uint32
|
Super uint32
|
||||||
//SuperValue *int32
|
//SuperValue *int32
|
||||||
//ID uint32 // 地图ID
|
//ID uint32 // 地图ID
|
||||||
Name string //地图名称
|
Name string //地图名称
|
||||||
Owner ARENA
|
Owner ARENA
|
||||||
ARENA_Player common.PlayerI
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSyncMap 创建一个新的玩家同步map
|
// NewSyncMap 创建一个新的玩家同步map
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ type S2CDanceAction struct {
|
|||||||
type C2SPEOPLE_TRANSFROM struct {
|
type C2SPEOPLE_TRANSFROM struct {
|
||||||
Head common.TomeeHeader `cmd:"2111" struc:"skip"`
|
Head common.TomeeHeader `cmd:"2111" struc:"skip"`
|
||||||
|
|
||||||
// Reserve 固定参数(值为 10001)
|
// Reserve uint32// 固定参数(值为 10001)
|
||||||
SuitID uint32 `struc:"uint32,big"`
|
SuitID uint32 `struc:"uint32,big"`
|
||||||
}
|
}
|
||||||
type S2CPEOPLE_TRANSFROM struct {
|
type S2CPEOPLE_TRANSFROM struct {
|
||||||
|
|||||||
@@ -485,7 +485,7 @@
|
|||||||
<NewSeIdx
|
<NewSeIdx
|
||||||
Idx="92" Stat="1" Eid="36" Args="13 12" />
|
Idx="92" Stat="1" Eid="36" Args="13 12" />
|
||||||
|
|
||||||
<NewSeIdx Idx="93" Stat="1" Eid="37" Args="0 100"
|
<NewSeIdx Idx="93" Stat="1" Eid="37" Args="100"
|
||||||
Desc="自身一次受到大于100点的伤害时直接将对方体力降至0" />
|
Desc="自身一次受到大于100点的伤害时直接将对方体力降至0" />
|
||||||
|
|
||||||
<NewSeIdx Idx="94" Stat="1" Eid="24"
|
<NewSeIdx Idx="94" Stat="1" Eid="24"
|
||||||
|
|||||||
Reference in New Issue
Block a user