package controller import ( "blazing/common/socket/errorcode" "sync/atomic" "blazing/logic/service/common" "blazing/logic/service/fight" "blazing/logic/service/fight/info" "blazing/logic/service/player" ) // 接收战斗或者取消战斗的包 func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if c.GetSpace().Owner.UserID == c.Info.UserID { 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 } if !c.CanFight() { return nil, errorcode.ErrorCodes.ErrSystemError } //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 v.Getfightinfo().Status == 0 { resp.Result = 4 // 邀请已取消 v.SendPackCmd(2502, &resp) atomic.StoreUint32(&c.Fightinfo.Mode, 0) return } _, err = fight.NewFight(v, c, func(foi *info.FightOverInfo) { }) 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 *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { if c.GetSpace().Owner.UserID == c.Info.UserID { 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 *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { atomic.StoreUint32(&c.Fightinfo.Mode, 0) //设置状态为0 return }