This commit is contained in:
liwei 2023-06-29 18:03:13 +08:00
commit 0f0411a5b3
2 changed files with 55 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package smithy package smithy
import ( import (
"errors"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/utils" "go_dreamfactory/utils"
@ -24,8 +25,17 @@ func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerR
cus, err := this.module.modelTrade.getDBCustomer(session.GetUserId()) cus, err := this.module.modelTrade.getDBCustomer(session.GetUserId())
if err != nil { if err != nil {
if err == mongo.ErrNoDocuments { if err == mongo.ErrNoDocuments {
c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount) //3个顾客 c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount)
if err != nil { if err != nil {
var customErr = new(comm.CustomError)
if errors.As(err, &customErr) {
errdata = &pb.ErrorData{
Code: customErr.Code,
Title: customErr.Code.ToString(),
Message: err.Error(),
}
return
} else {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError, Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(), Title: pb.ErrorCode_DBError.ToString(),
@ -33,6 +43,7 @@ func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerR
} }
return return
} }
}
cus = c cus = c
} else { } else {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
@ -43,8 +54,7 @@ func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerR
return return
} }
} }
if utils.IsFirstTody(cus.LastRefreshTime) || (cus.Customers == nil || len(cus.Customers) == 0) {
if utils.IsFirstTody(cus.LastRefreshTime) {
this.module.modelTrade.DelByUId(session.GetUserId()) this.module.modelTrade.DelByUId(session.GetUserId())
c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount) c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount)
if err != nil { if err != nil {

View File

@ -93,13 +93,23 @@ func (s *modelTrade) addCustomer(uid string, num int32) (*pb.DBCustomer, error)
Total: num, Total: num,
LastRefreshTime: configure.Now().Unix(), LastRefreshTime: configure.Now().Unix(),
} }
for i := 0; i < int(num); i++ { for i := 0; i < int(num); i++ {
randCustomerId := s.getCustomerRandom()
conf, err := s.module.configure.GetSmithyCustomerConf(randCustomerId)
if err != nil {
return nil, comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
}
suitId := s.GetSuitRandom(uid, conf.CustomerType)
if suitId != 0 {
customer.Customers = append(customer.Customers, &pb.CustomerInfo{ customer.Customers = append(customer.Customers, &pb.CustomerInfo{
CustomerId: s.getCustomerRandom(), CustomerId: randCustomerId,
SuitId: s.GetSuitRandom(uid), SuitId: suitId,
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid), EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
}) })
} }
}
if err := s.Add(uid, customer); err != nil { if err := s.Add(uid, customer); err != nil {
s.module.Errorln(err) s.module.Errorln(err)
return nil, err return nil, err
@ -139,12 +149,20 @@ func (s *modelTrade) updateCustomer(uid string, customerId int32) (*pb.DBCustome
if left < 0 { if left < 0 {
return nil, comm.NewCustomError(pb.ErrorCode_SmithyCustomerLimit) return nil, comm.NewCustomError(pb.ErrorCode_SmithyCustomerLimit)
} }
randCustomerId := s.getCustomerRandom()
conf, err := s.module.configure.GetSmithyCustomerConf(randCustomerId)
if err != nil {
return nil, comm.NewCustomError(pb.ErrorCode_ConfigNoFound)
}
suiteId := s.GetSuitRandom(uid, conf.CustomerType)
if suiteId != 0 {
cus.Customers = append(cus.Customers, &pb.CustomerInfo{ cus.Customers = append(cus.Customers, &pb.CustomerInfo{
CustomerId: s.getCustomerRandom(), CustomerId: randCustomerId,
SuitId: s.GetSuitRandom(uid), SuitId: suiteId,
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid), EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
}) })
}
cus.LastRefreshTime = configure.Now().Unix() cus.LastRefreshTime = configure.Now().Unix()
update := map[string]interface{}{ update := map[string]interface{}{
"customers": cus.Customers, "customers": cus.Customers,
@ -159,7 +177,7 @@ func (s *modelTrade) updateCustomer(uid string, customerId int32) (*pb.DBCustome
} }
// 返回概率下的套装 // 返回概率下的套装
func (s *modelTrade) GetSuitRandom(uid string) (suiteId int32) { func (s *modelTrade) GetSuitRandom(uid string, ctype int32) (suiteId int32) {
//获取玩家所有解锁套装 //获取玩家所有解锁套装
uex, err := s.module.ModuleUser.GetUserExpand(uid) uex, err := s.module.ModuleUser.GetUserExpand(uid)
if err != nil { if err != nil {
@ -187,7 +205,14 @@ func (s *modelTrade) GetSuitRandom(uid string) (suiteId int32) {
}) })
} }
merge := append(unlockSuiteItems, ownerSuiteItems...) var merge []*WeightItem
if ctype == 1 {
merge = append(unlockSuiteItems, ownerSuiteItems...)
} else if ctype == 2 {
merge = unlockSuiteItems
}
// 设置权重 // 设置权重
wr := newWeightedRandom(merge) wr := newWeightedRandom(merge)
if c := wr.pick(); c != nil { if c := wr.pick(); c != nil {