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

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"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"math"
"time"
"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) {
var (
global *cfg.GameGlobalData
info *pb.DBArenaUser
user *pb.DBUser
model *db.DBModel
duration time.Duration
ticketNum int32
err error
global *cfg.GameGlobalData
info *pb.DBArenaUser
user *pb.DBUser
model *db.DBModel
err error
)
if code = this.InfoCheck(session, req); code != pb.ErrorCode_Success {
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 {
this.module.Errorln(err)
}
} else if info.Ticket < global.ArenaTicketMax && info.Lastrtickettime > 0 {
duration = time.Now().Sub(time.Unix(info.Lastrtickettime, 0))
ticketNum = int32(math.Floor(duration.Minutes() / float64(global.ArenaTicketRecoveryTime)))
if ticketNum > 0 {
info.Ticket += ticketNum
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()
}
} else {
this.module.modelArena.recoverTicket(info)
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
code = pb.ErrorCode_DBError
return
}
}
session.SendMsg(string(this.module.GetType()), "info", &pb.ArenaInfoResp{Info: info})

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"math/rand"
"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) {
var (
model *db.DBModel
)
equipments = make([]*pb.DB_Equipment, 0)
if err = this.GetList(uId, &equipments); err != nil {
this.module.Errorf("err:%v", err)
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.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
}
@ -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) {
var (
configure *cfg.GameEquip
// equipments []*pb.DB_Equipment
// iskeep bool
add map[string]*pb.DB_Equipment
// update map[string]*pb.DB_Equipment
uId string = session.GetUserId()
add map[string]*pb.DB_Equipment
uId string = session.GetUserId()
)
if configure, err = this.module.configure.GetEquipmentConfigure(); err != nil {
return
}
// if equipments, err = this.QueryUserEquipments(uId); err != nil {
// return
// }
add = make(map[string]*pb.DB_Equipment)
// update = make(map[string]*pb.DB_Equipment)
change = make([]*pb.DB_Equipment, 0, 10)
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 {
for i := uint32(0); i < v; i++ {
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)
}
}
}
// }
}
if len(add) > 0 {
if err = this.AddLists(uId, add); err != nil {
this.module.Errorf("err:%v", err)
return
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, 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
}
//删除装备
func (this *modelEquipmentComp) DelEquipments(uId string, eIds []string) (change []*pb.DB_Equipment, err error) {
var (
model *db.DBModel
)
change = make([]*pb.DB_Equipment, 0)
if err = this.DelListlds(uId, eIds...); err != nil {
this.module.Errorln(err)
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.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 {
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) {
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
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 {
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
}

View File

@ -7,6 +7,7 @@ import (
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"time"
"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) {
var (
model *db.DBModel
)
itmes = make([]*pb.DB_UserItemData, 0)
if err = this.GetList(uId, &itmes); err != nil {
this.module.Errorf("err:%v", err)
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.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
}
///查询用户指定格子的物品数据
func (this *ModelItemsComp) QueryUserPackByGridId(uId string, grid string) (itme *pb.DB_UserItemData, err error) {
var (
model *db.DBModel
)
itme = &pb.DB_UserItemData{}
if err = this.GetListObj(uId, grid, itme); err != nil {
this.module.Errorf("err:%v", err)
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.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
}
//更新用户的背包信息
func (this *ModelItemsComp) AddUserPack(uId string, itmes ...*pb.DB_UserItemData) (err error) {
data := make(map[string]*pb.DB_UserItemData)
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
}
//更新用户的背包信息
func (this *ModelItemsComp) UpdateUserPack(uid string, itmes ...*pb.DB_UserItemData) (err error) {
for _, v := range itmes {
this.ChangeList(uid, v.GridId, map[string]interface{}{
"amount": v.Amount,
"isNewItem": v.IsNewItem,
"lastopt": time.Now().Unix(),
})
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 {
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
}
//更新用户的背包信息
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))
for i, v := range itmes {
gridIds[i] = v.GridId
}
if err = this.DelListlds(uId, gridIds...); err != nil {
this.module.Errorf("err:%v", err)
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.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
}

View File

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