169 lines
4.8 KiB
Go
169 lines
4.8 KiB
Go
package plunder
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"time"
|
|
)
|
|
|
|
// 参数校验
|
|
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 // 数据变化通知
|
|
atno []*pb.UserAtno // 打赢奖励
|
|
info []*pb.PlunderRecordData // 运输记录
|
|
)
|
|
|
|
if errdata = this.PvpChallengeOverCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
changeShip = make(map[string]*pb.ShipData)
|
|
if list, err = this.module.modelPlunder.getPlunderData(session); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
lock, err = this.module.modelLand.landMutexLock(list.Landid)
|
|
err = lock.Lock()
|
|
if 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...)
|
|
session.SendMsg(string(this.module.GetType()), "pvpchallengeover", &pb.PlunderPvpChallengeOverResp{
|
|
Atno: []*pb.UserAtno{},
|
|
})
|
|
|
|
info = append(info, &pb.PlunderRecordData{
|
|
Itype: 4,
|
|
P1: session.GetUserId(),
|
|
P2: land.Ship[req.Oid].Uid,
|
|
Cid: land.Ship[req.Oid].Line.Cid,
|
|
Ctime: configure.Now().Unix(),
|
|
Bid: req.Report.Info.Id,
|
|
Iswin: iswin,
|
|
})
|
|
//战报ID req.Report.Info.Id
|
|
err = this.module.modelRecord.AddRecordData(land.Id, info)
|
|
|
|
go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report, time.Now().Add(time.Hour*24*8))
|
|
return
|
|
}
|
|
list.Pvpcount++
|
|
land.Ship[req.Oid].Status = 3
|
|
if errdata, atno = this.module.DispenseAtno(session, conf.Keepreward, true); errdata != nil {
|
|
return
|
|
}
|
|
if conf.Numitem.N > 0 {
|
|
atno = append(atno, &pb.UserAtno{
|
|
A: conf.Numitem.A,
|
|
T: conf.Numitem.T,
|
|
N: conf.Numitem.N,
|
|
})
|
|
list.Score += conf.Numitem.N
|
|
land.Score[session.GetUserId()] = list.Score
|
|
this.module.ModuleUser.AddUserHidenum(session, conf.Hidenum)
|
|
}
|
|
// 修改状态
|
|
changeShip[req.Oid] = land.Ship[req.Oid]
|
|
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
|
|
"ship": land.Ship,
|
|
"score": land.Score,
|
|
})
|
|
|
|
this.module.modelPlunder.changePlunderData(session.GetUserId(), map[string]interface{}{
|
|
"score": list.Score,
|
|
"pvpcount": list.Pvpcount,
|
|
})
|
|
// 通知大家
|
|
this.module.SendMsgToUsers(string(this.module.GetType()), "change", &pb.PlunderChangePush{
|
|
Ship: changeShip,
|
|
}, users...)
|
|
session.SendMsg(string(this.module.GetType()), "pvpchallengeover", &pb.PlunderPvpChallengeOverResp{
|
|
Atno: atno,
|
|
})
|
|
info = append(info, &pb.PlunderRecordData{
|
|
Itype: 2,
|
|
P1: session.GetUserId(),
|
|
P2: land.Ship[req.Oid].Uid,
|
|
Cid: land.Ship[req.Oid].Line.Cid,
|
|
Ctime: configure.Now().Unix(),
|
|
Bid: req.Report.Info.Id,
|
|
Iswin: iswin,
|
|
})
|
|
err = this.module.modelRecord.AddRecordData(land.Id, info)
|
|
|
|
//写入战斗记录
|
|
go this.module.battlerecord.WrietBattleRecord(session.GetUserId(), req.Report, time.Now().Add(time.Hour*24*8))
|
|
return
|
|
}
|