package plunder import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/redis" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) PvpChallengeOverCheck(session comm.IUserSession, req *pb.PlunderPvpChallengeOverReq) (errdata *pb.ErrorData) { if req.Report == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } // /挑战 func (this *apiComp) PvpChallengeOver(session comm.IUserSession, req *pb.PlunderPvpChallengeOverReq) (errdata *pb.ErrorData) { var ( err error land *pb.DBPlunderLand // 岛屿数据 list *pb.DBPlunder iswin bool conf *cfg.GamePlunderData users []string lock *redis.RedisMutex changeShip map[string]*pb.ShipData // 数据变化通知 ) if errdata = this.PvpChallengeOverCheck(session, req); errdata != nil { return } changeShip = make(map[string]*pb.ShipData) if list, err = this.module.modelPlunder.getPlunderData(session.GetUserId()); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Message: err.Error(), } return } if lock, err = this.module.modelLand.landMutexLock(list.Landid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } defer lock.Unlock() if land, err = this.module.modelLand.getPlunderLandData(list.Landid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Message: err.Error(), } return } for _, v := range land.Uinfo { users = append(users, v.Uid) } // 校验oid if _, ok := land.Ship[req.Oid]; !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PlunderNotFoundShip, Title: pb.ErrorCode_PlunderNotFoundShip.ToString(), } return } if errdata, iswin = this.module.battle.CheckBattleReport(session, req.Report); errdata != nil { return } // 配置校验 if conf, err = this.module.configure.getGamePlunderDataById(land.Ship[req.Oid].Line.Cid); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if !iswin { land.Ship[req.Oid].Cd = configure.Now().Unix() + int64(conf.Protecttime) land.Ship[req.Oid].Status = 2 changeShip[req.Oid] = land.Ship[req.Oid] this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{ "ship": land.Ship, }) // 通知大家 this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{ Ship: changeShip, }, users...) return } land.Ship[req.Oid].Status = 3 // 修改状态 changeShip[req.Oid] = land.Ship[req.Oid] this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{ "ship": land.Ship, }) // 通知大家 this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{ Ship: changeShip, }, users...) session.SendMsg(string(this.module.GetType()), "pvpchallengeover", &pb.PlunderPvpChallengeOverResp{ Atno: []*pb.UserAtno{}, }) return }