149 lines
3.9 KiB
Go
149 lines
3.9 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"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) ReachCheck(session comm.IUserSession, req *pb.PlunderReachReq) (errdata *pb.ErrorData) {
|
|
if len(req.Oid) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 船到达 领奖
|
|
func (this *apiComp) Reach(session comm.IUserSession, req *pb.PlunderReachReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
list *pb.DBPlunder
|
|
land *pb.DBPlunderLand // 岛屿数据
|
|
//changeShip map[string]*pb.ShipData // 变化的信息
|
|
lock *redis.RedisMutex
|
|
bPlunder bool // 到达检测 是否被掠夺
|
|
cid int32
|
|
conf *cfg.GamePlunderData
|
|
res []*cfg.Gameatn // 奖励
|
|
bExReward bool // 是否是高级运输
|
|
atno []*pb.UserAtno
|
|
)
|
|
//changeShip = make(map[string]*pb.ShipData, 0)
|
|
if errdata = this.ReachCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
|
|
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 _, oid := range req.Oid {
|
|
if _, ok := land.Ship[oid]; !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlunderNotFoundShip,
|
|
Title: pb.ErrorCode_PlunderNotFoundShip.ToString(),
|
|
}
|
|
return
|
|
} else {
|
|
if land.Ship[oid].Line.Etime > configure.Now().Unix() { // 还没到时间 船没到达
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_PlundeShipUnReach,
|
|
Title: pb.ErrorCode_PlundeShipUnReach.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if land.Ship[oid].Line.Itype != 0 {
|
|
bExReward = true
|
|
if land.Ship[oid].Status == 3 { // 高级船
|
|
bPlunder = true
|
|
}
|
|
}
|
|
for _, v := range list.Line {
|
|
if v.Oid == oid {
|
|
v.Oid = ""
|
|
break
|
|
}
|
|
}
|
|
cid = land.Ship[oid].Line.Cid
|
|
delete(land.Ship, oid)
|
|
}
|
|
}
|
|
// 配置校验
|
|
if conf, err = this.module.configure.getGamePlunderDataById(cid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if !bExReward { // 普通奖励
|
|
res = append(res, conf.Keepreward...)
|
|
list.Score += conf.Numitem.N
|
|
land.Score[session.GetUserId()] = list.Score
|
|
this.module.ModuleUser.AddUserHidenum(session, conf.Hidenum)
|
|
} else {
|
|
res = append(res, conf.Exreward...) // 高级奖励
|
|
if !bPlunder { // 没有被掠夺
|
|
res = append(res, conf.Keepreward...)
|
|
list.Score += conf.Numitem.N
|
|
land.Score[session.GetUserId()] = list.Score
|
|
this.module.ModuleUser.AddUserHidenum(session, conf.Hidenum)
|
|
}
|
|
}
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil {
|
|
return
|
|
}
|
|
if bExReward && !bPlunder { // 高级运输且没用被掠夺
|
|
if conf.Numitem.N > 0 {
|
|
atno = append(atno, &pb.UserAtno{
|
|
A: conf.Numitem.A,
|
|
T: conf.Numitem.T,
|
|
N: conf.Numitem.N,
|
|
})
|
|
}
|
|
}
|
|
this.module.modelPlunder.changePlunderData(session.GetUserId(), map[string]interface{}{
|
|
"line": list.Line,
|
|
"score": list.Score,
|
|
})
|
|
this.module.modelLand.changePlunderLandData(land.Id, map[string]interface{}{
|
|
"ship": land.Ship,
|
|
"score": land.Score,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "reach", &pb.PlunderReachResp{
|
|
Line: list.Line,
|
|
Atno: atno,
|
|
Oid: req.Oid,
|
|
})
|
|
return
|
|
}
|