110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
package controller
|
|
|
|
import (
|
|
"blazing/common/socket/errorcode"
|
|
"blazing/modules/player/model"
|
|
"sync/atomic"
|
|
|
|
"blazing/logic/service/common"
|
|
"blazing/logic/service/fight"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/logic/service/player"
|
|
)
|
|
|
|
// 接收战斗或者取消战斗的包
|
|
func (h Controller) OnPlayerHandleFightInvite(data *HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.IsArenaPVPLocked() {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
if c.GetSpace().Owner.UserID == data.UserID {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
if !atomic.CompareAndSwapUint32(&c.Fightinfo.Mode, 0, data.Mode) { //邀请前提是自己没在战斗
|
|
return nil, errorcode.ErrorCodes.ErrInBattle
|
|
|
|
}
|
|
|
|
r := c.CanFight()
|
|
if c.CanFight() != 0 {
|
|
return nil, r
|
|
}
|
|
|
|
//c.Fightinfo.Status = info.BattleMode.FIGHT_WITH_NPC
|
|
|
|
resp := &info.S2C_NOTE_HANDLE_FIGHT_INVITE{
|
|
UserID: c.Info.UserID,
|
|
Nick: c.Info.Nick,
|
|
}
|
|
|
|
for _, v := range c.HavePVPinfo {
|
|
if v.GetInfo().UserID == data.UserID && v.Getfightinfo().Mode == data.Mode {
|
|
|
|
resp.Result = data.Flag
|
|
if resp.Result == 0 {
|
|
|
|
v.SendPackCmd(2502, &resp)
|
|
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
|
|
|
|
return
|
|
}
|
|
// 检查邀请者的邀请是否有效(对方已取消邀请)
|
|
if v.Getfightinfo().Status == 0 {
|
|
resp.Result = 4 // 邀请已取消
|
|
v.SendPackCmd(2502, &resp)
|
|
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
|
|
return
|
|
}
|
|
|
|
_, err = fight.NewFight(v, c, v.GetPetInfo(100), c.GetPetInfo(100), func(foi model.FightOverInfo) {
|
|
|
|
//println("好友对战测试", foi.Reason)
|
|
|
|
})
|
|
|
|
if err <= 0 { //成功发起对战
|
|
c.HavePVPinfo = make([]common.PlayerI, 0)
|
|
return
|
|
} else {
|
|
resp.Result = 3
|
|
v.SendPackCmd(2502, &resp)
|
|
atomic.StoreUint32(&c.Fightinfo.Mode, 0)
|
|
return
|
|
}
|
|
|
|
}
|
|
}
|
|
atomic.StoreUint32(&c.Fightinfo.Status, 0)
|
|
return
|
|
}
|
|
|
|
// 邀请其他人进行战斗
|
|
func (h Controller) OnPlayerInviteOtherFight(data *InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
if c.IsArenaPVPLocked() {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
if c.GetSpace().Owner.ChallengerID == c.Info.UserID {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
if c.GetSpace().Owner.UserID == data.UserID {
|
|
return nil, errorcode.ErrorCodes.ErrSystemError
|
|
}
|
|
// c.Fightinfo.PlayerID = data.UserID
|
|
c.Fightinfo.Mode = data.Mode
|
|
c.Fightinfo.Status = 1
|
|
// c.Fightinfo.Type = 0
|
|
|
|
v, ok := c.GetSpace().User.Load(data.UserID)
|
|
|
|
if ok {
|
|
v.InvitePlayer(c)
|
|
|
|
}
|
|
return nil, 0
|
|
}
|
|
|
|
// 取消队列
|
|
func (h Controller) OnPlayerCanceledOtherInviteFight(data *InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
atomic.StoreUint32(&c.Fightinfo.Mode, 0) //设置状态为0
|
|
return
|
|
}
|