上传资源消耗发放跨服适配

This commit is contained in:
liwei1dao 2022-10-27 11:32:59 +08:00
parent 4c67d2e077
commit bf3dfde9b6
4 changed files with 184 additions and 78 deletions

View File

@ -6,7 +6,6 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"math"
"time" "time"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -21,13 +20,11 @@ func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.ArenaInfoReq)
///获取自己的排行榜信息 ///获取自己的排行榜信息
func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
global *cfg.GameGlobalData global *cfg.GameGlobalData
info *pb.DBArenaUser info *pb.DBArenaUser
user *pb.DBUser user *pb.DBUser
model *db.DBModel model *db.DBModel
duration time.Duration err error
ticketNum int32
err error
) )
if code = this.InfoCheck(session, req); code != pb.ErrorCode_Success { if code = this.InfoCheck(session, req); code != pb.ErrorCode_Success {
return return
@ -64,17 +61,11 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code
if err = this.module.modelArena.Add(session.GetUserId(), info); err != nil { if err = this.module.modelArena.Add(session.GetUserId(), info); err != nil {
this.module.Errorln(err) this.module.Errorln(err)
} }
} else if info.Ticket < global.ArenaTicketMax && info.Lastrtickettime > 0 { } else {
duration = time.Now().Sub(time.Unix(info.Lastrtickettime, 0)) this.module.modelArena.recoverTicket(info)
ticketNum = int32(math.Floor(duration.Minutes() / float64(global.ArenaTicketRecoveryTime))) if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
if ticketNum > 0 { code = pb.ErrorCode_DBError
info.Ticket += ticketNum return
if info.Ticket > global.ArenaTicketMax {
info.Ticket = global.ArenaTicketMax
info.Lastrtickettime = 0
} else {
info.Lastrtickettime = time.Unix(info.Lastrtickettime, 0).Add(time.Duration(ticketNum) * time.Minute).Unix()
}
} }
} }
session.SendMsg(string(this.module.GetType()), "info", &pb.ArenaInfoResp{Info: info}) session.SendMsg(string(this.module.GetType()), "info", &pb.ArenaInfoResp{Info: info})

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"math/rand" "math/rand"
"time" "time"
@ -50,10 +51,24 @@ func (this *modelEquipmentComp) QueryUserEquipmentsByIds(uId string, ids []strin
///查询用户的武器背包 ///查询用户的武器背包
func (this *modelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) { func (this *modelEquipmentComp) QueryUserEquipments(uId string) (equipments []*pb.DB_Equipment, err error) {
var (
model *db.DBModel
)
equipments = make([]*pb.DB_Equipment, 0) equipments = make([]*pb.DB_Equipment, 0)
if err = this.GetList(uId, &equipments); err != nil { if this.module.IsCross() {
this.module.Errorf("err:%v", err) if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
this.module.Errorln(err)
} else {
if err = model.GetList(uId, &equipments); err != nil {
this.module.Errorf("err:%v", err)
}
}
} else {
if err = this.GetList(uId, &equipments); err != nil {
this.module.Errorf("err:%v", err)
}
} }
return return
} }
@ -79,33 +94,15 @@ func (this *modelEquipmentComp) QueryEquipmentAmount(uid string, equipmentId str
func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds map[string]uint32) (change []*pb.DB_Equipment, err error) { func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds map[string]uint32) (change []*pb.DB_Equipment, err error) {
var ( var (
configure *cfg.GameEquip configure *cfg.GameEquip
// equipments []*pb.DB_Equipment add map[string]*pb.DB_Equipment
// iskeep bool uId string = session.GetUserId()
add map[string]*pb.DB_Equipment
// update map[string]*pb.DB_Equipment
uId string = session.GetUserId()
) )
if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil { if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return return
} }
// if equipments, err = this.QueryUserEquipments(uId); err != nil {
// return
// }
add = make(map[string]*pb.DB_Equipment) add = make(map[string]*pb.DB_Equipment)
// update = make(map[string]*pb.DB_Equipment)
change = make([]*pb.DB_Equipment, 0, 10) change = make([]*pb.DB_Equipment, 0, 10)
for k, v := range cIds { for k, v := range cIds {
// iskeep = false
// for _, equipment := range equipments {
// if equipment.CId == k && equipment.IsInitialState {
// update[equipment.Id] = equipment
// change = append(change, equipment)
// equipment.OverlayNum += v
// iskeep = true
// break
// }
// }
// if !iskeep {
if c, ok := configure.GetDataMap()[k]; ok { if c, ok := configure.GetDataMap()[k]; ok {
for i := uint32(0); i < v; i++ { for i := uint32(0); i < v; i++ {
if equipment, err := this.newEquipment(uId, c); err != nil { if equipment, err := this.newEquipment(uId, c); err != nil {
@ -117,32 +114,52 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma
change = append(change, equipment) change = append(change, equipment)
} }
} }
} }
// }
} }
if len(add) > 0 { if len(add) > 0 {
if err = this.AddLists(uId, add); err != nil { var (
this.module.Errorf("err:%v", err) model *db.DBModel
return )
if this.module.IsCross() {
if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
this.module.Errorln(err)
} else {
if err = model.AddLists(uId, add); err != nil {
this.module.Errorf("err:%v", err)
return
}
}
} else {
if err = this.AddLists(uId, add); err != nil {
this.module.Errorf("err:%v", err)
return
}
} }
}
// for _, v := range update { }
// if err = this.ChangeList(uId, v.Id, map[string]interface{}{"overlayNum": v.OverlayNum}); err != nil {
// log.Errorf("err:%v", err)
// return
// }
// }
return return
} }
//删除装备 //删除装备
func (this *modelEquipmentComp) DelEquipments(uId string, eIds []string) (change []*pb.DB_Equipment, err error) { func (this *modelEquipmentComp) DelEquipments(uId string, eIds []string) (change []*pb.DB_Equipment, err error) {
var (
model *db.DBModel
)
change = make([]*pb.DB_Equipment, 0) change = make([]*pb.DB_Equipment, 0)
if err = this.DelListlds(uId, eIds...); err != nil { if this.module.IsCross() {
this.module.Errorln(err) if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
return this.module.Errorln(err)
} else {
if err = model.DelListlds(uId, eIds...); err != nil {
this.module.Errorln(err)
return
}
}
} else {
if err = this.DelListlds(uId, eIds...); err != nil {
this.module.Errorln(err)
return
}
} }
for _, v := range eIds { for _, v := range eIds {
change = append(change, &pb.DB_Equipment{ change = append(change, &pb.DB_Equipment{
@ -156,14 +173,33 @@ func (this *modelEquipmentComp) DelEquipments(uId string, eIds []string) (change
//更新武器挂载信息 //更新武器挂载信息
func (this *modelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) { func (this *modelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_Equipment) (err error) {
for _, v := range equipments { var (
if err = this.ChangeList(uid, v.Id, map[string]interface{}{ model *db.DBModel
"heroId": v.HeroId, )
}); err != nil { if this.module.IsCross() {
this.module.Errorf("err:%v", err) if model, err = this.module.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
return this.module.Errorln(err)
} else {
for _, v := range equipments {
if err = model.ChangeList(uid, v.Id, map[string]interface{}{
"heroId": v.HeroId,
}); err != nil {
this.module.Errorf("err:%v", err)
return
}
}
}
} else {
for _, v := range equipments {
if err = this.ChangeList(uid, v.Id, map[string]interface{}{
"heroId": v.HeroId,
}); err != nil {
this.module.Errorf("err:%v", err)
return
}
} }
} }
return return
} }

View File

@ -7,6 +7,7 @@ import (
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"time" "time"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
@ -34,51 +35,130 @@ func (this *ModelItemsComp) Init(service core.IService, module core.IModule, com
///查询用户背包数据 ///查询用户背包数据
func (this *ModelItemsComp) QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) { func (this *ModelItemsComp) QueryUserPack(uId string) (itmes []*pb.DB_UserItemData, err error) {
var (
model *db.DBModel
)
itmes = make([]*pb.DB_UserItemData, 0) itmes = make([]*pb.DB_UserItemData, 0)
if err = this.GetList(uId, &itmes); err != nil { if this.module.IsCross() {
this.module.Errorf("err:%v", err) if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
this.module.Errorln(err)
} else {
if err = model.GetList(uId, &itmes); err != nil {
this.module.Errorf("err:%v", err)
}
}
} else {
if err = this.GetList(uId, &itmes); err != nil {
this.module.Errorf("err:%v", err)
}
} }
return return
} }
///查询用户指定格子的物品数据 ///查询用户指定格子的物品数据
func (this *ModelItemsComp) QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) { func (this *ModelItemsComp) QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) {
var (
model *db.DBModel
)
itme = &pb.DB_UserItemData{} itme = &pb.DB_UserItemData{}
if err = this.GetListObj(uId, grid, itme); err != nil { if this.module.IsCross() {
this.module.Errorf("err:%v", err) if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
this.module.Errorln(err)
} else {
if err = model.GetListObj(uId, grid, itme); err != nil {
this.module.Errorf("err:%v", err)
}
}
} else {
if err = this.GetListObj(uId, grid, itme); err != nil {
this.module.Errorf("err:%v", err)
}
} }
return return
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *ModelItemsComp) AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { func (this *ModelItemsComp) AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) {
data := make(map[string]*pb.DB_UserItemData)
for _, v := range itmes { for _, v := range itmes {
this.AddList(uId, v.GridId, v) data[v.GridId] = v
} }
var (
model *db.DBModel
)
if this.module.IsCross() {
if model, err = this.module.GetDBNoduleByUid(uId, this.TableName, this.Expired); err != nil {
this.module.Errorln(err)
} else {
if err = model.AddLists(uId, data); err != nil {
this.module.Errorf("err:%v", err)
}
}
} else {
if err = this.AddLists(uId, data); err != nil {
this.module.Errorln(err)
}
}
return return
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *ModelItemsComp) UpdateUserPack(uid string, itmes ...*pb.DB_UserItemData) (err error) { func (this *ModelItemsComp) UpdateUserPack(uid string, itmes ...*pb.DB_UserItemData) (err error) {
for _, v := range itmes { var (
this.ChangeList(uid, v.GridId, map[string]interface{}{ model *db.DBModel
"amount": v.Amount, )
"isNewItem": v.IsNewItem, if this.module.IsCross() {
"lastopt": time.Now().Unix(), if model, err = this.module.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
}) this.module.Errorln(err)
} else {
for _, v := range itmes {
model.ChangeList(uid, v.GridId, map[string]interface{}{
"amount": v.Amount,
"isNewItem": v.IsNewItem,
"lastopt": time.Now().Unix(),
})
}
}
} else {
for _, v := range itmes {
this.ChangeList(uid, v.GridId, map[string]interface{}{
"amount": v.Amount,
"isNewItem": v.IsNewItem,
"lastopt": time.Now().Unix(),
})
}
} }
return return
} }
//更新用户的背包信息 //更新用户的背包信息
func (this *ModelItemsComp) DeleteUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) { func (this *ModelItemsComp) DeleteUserPack(uid string, itmes ...*pb.DB_UserItemData) (err error) {
var (
model *db.DBModel
)
gridIds := make([]string, len(itmes)) gridIds := make([]string, len(itmes))
for i, v := range itmes { for i, v := range itmes {
gridIds[i] = v.GridId gridIds[i] = v.GridId
} }
if err = this.DelListlds(uId, gridIds...); err != nil { if this.module.IsCross() {
this.module.Errorf("err:%v", err) if model, err = this.module.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil {
return this.module.Errorln(err)
} else {
if err = model.DelListlds(uid, gridIds...); err != nil {
this.module.Errorf("err:%v", err)
return
}
}
} else {
if err = this.DelListlds(uid, gridIds...); err != nil {
this.module.Errorf("err:%v", err)
return
}
} }
return return
} }

View File

@ -269,7 +269,6 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn
this.Errorf("not found res type") // 找不到资源类型 this.Errorf("not found res type") // 找不到资源类型
} }
} }
// 校验数量 // 校验数量
for k, v := range attrs { for k, v := range attrs {
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -int64(v) { // -v 负负得正 if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -int64(v) { // -v 负负得正