Compare commits

...

2 Commits

2 changed files with 55 additions and 20 deletions

View File

@ -1,6 +1,7 @@
package smithy
import (
"errors"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
@ -24,14 +25,24 @@ func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerR
cus, err := this.module.modelTrade.getDBCustomer(session.GetUserId())
if err != nil {
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 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
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{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
return
}
cus = c
} else {
@ -43,8 +54,7 @@ func (this *apiComp) Customer(session comm.IUserSession, req *pb.SmithyCustomerR
return
}
}
if utils.IsFirstTody(cus.LastRefreshTime) {
if utils.IsFirstTody(cus.LastRefreshTime) || (cus.Customers == nil || len(cus.Customers) == 0) {
this.module.modelTrade.DelByUId(session.GetUserId())
c, err := this.module.modelTrade.addCustomer(session.GetUserId(), customerCount)
if err != nil {

View File

@ -93,12 +93,22 @@ func (s *modelTrade) addCustomer(uid string, num int32) (*pb.DBCustomer, error)
Total: num,
LastRefreshTime: configure.Now().Unix(),
}
for i := 0; i < int(num); i++ {
customer.Customers = append(customer.Customers, &pb.CustomerInfo{
CustomerId: s.getCustomerRandom(),
SuitId: s.GetSuitRandom(uid),
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
})
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{
CustomerId: randCustomerId,
SuitId: suitId,
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
})
}
}
if err := s.Add(uid, customer); err != nil {
s.module.Errorln(err)
@ -139,12 +149,20 @@ func (s *modelTrade) updateCustomer(uid string, customerId int32) (*pb.DBCustome
if left < 0 {
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{
CustomerId: randCustomerId,
SuitId: suiteId,
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
})
}
cus.Customers = append(cus.Customers, &pb.CustomerInfo{
CustomerId: s.getCustomerRandom(),
SuitId: s.GetSuitRandom(uid),
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
})
cus.LastRefreshTime = configure.Now().Unix()
update := map[string]interface{}{
"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)
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)
if c := wr.pick(); c != nil {