铁匠铺交易
This commit is contained in:
parent
31ec56ffbf
commit
b2a25608a3
@ -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,14 +25,24 @@ 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 {
|
||||||
errdata = &pb.ErrorData{
|
var customErr = new(comm.CustomError)
|
||||||
Code: pb.ErrorCode_DBError,
|
if errors.As(err, &customErr) {
|
||||||
Title: pb.ErrorCode_DBError.ToString(),
|
errdata = &pb.ErrorData{
|
||||||
Message: err.Error(),
|
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
|
cus = c
|
||||||
} else {
|
} else {
|
||||||
@ -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 {
|
||||||
|
@ -93,12 +93,22 @@ 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++ {
|
||||||
customer.Customers = append(customer.Customers, &pb.CustomerInfo{
|
randCustomerId := s.getCustomerRandom()
|
||||||
CustomerId: s.getCustomerRandom(),
|
conf, err := s.module.configure.GetSmithyCustomerConf(randCustomerId)
|
||||||
SuitId: s.GetSuitRandom(uid),
|
if err != nil {
|
||||||
EquipCount: s.module.modelStove.StoveSkillBuyEquip(uid),
|
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 {
|
if err := s.Add(uid, customer); err != nil {
|
||||||
s.module.Errorln(err)
|
s.module.Errorln(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{
|
||||||
|
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()
|
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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user