This commit is contained in:
meixiongfeng 2022-07-19 19:38:32 +08:00
parent ba3b102dd0
commit 0099f3d01c
7 changed files with 99 additions and 38 deletions

View File

@ -23,6 +23,7 @@ const ( //消息回复的头名称
StrengthenUpStar = "strengthenupstar" // 英雄升星
Awaken = "awaken" // 英雄觉醒
HeroLock = "lock" // 英雄锁定
DrawCard = "drawcard" // 抽卡
)
//组件初始化接口

View File

@ -0,0 +1,57 @@
package hero
import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"math/big"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) DrawCardCheck(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode) {
if req.DrawCount != 1 && req.DrawCount != 10 { // 只能是单抽或10抽
code = pb.ErrorCode_ReqParameterError
}
return
}
//抽卡
func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq) (code pb.ErrorCode, data proto.Message) {
var (
szCards []int32 // 最终抽到的卡牌
totalWeight int64 // 总权重
curWeigth int64 // 临时随机获得的权重
)
szCards = make([]int32, 0)
rsp := &pb.HeroDrawCardResp{}
// 抽卡相关
// 获取配置文件的权重信息
_conf, err := this.module.configure.GetHeroDrawConfig()
if err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
for _, v := range _conf.GetDataList() {
totalWeight += int64(v.Weight) // 统计所有权重
}
for i := 0; i < int(req.DrawCount); i++ {
n, _ := rand.Int(rand.Reader, big.NewInt(totalWeight)) // [0,totalWeight)
for _, v := range _conf.GetDataList() {
curWeigth += int64(v.Weight)
if curWeigth < n.Int64() { // 命中
szCards = append(szCards, v.Id)
break
}
}
}
if err := this.module.modelHero.createMultiHero(session.GetUserId(), szCards...); err != nil {
code = pb.ErrorCode_HeroCreate
return
}
rsp.Heroes = szCards
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
return
}

View File

@ -1537,7 +1537,8 @@ func (x *HeroDelHeroPush) GetHeros() map[string]int32 {
return nil
}
type HeroDrawReq struct {
// 抽卡
type HeroDrawCardReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
@ -1545,8 +1546,8 @@ type HeroDrawReq struct {
DrawCount int32 `protobuf:"varint,1,opt,name=drawCount,proto3" json:"drawCount"` // 抽卡次数, 只能是单抽和十抽
}
func (x *HeroDrawReq) Reset() {
*x = HeroDrawReq{}
func (x *HeroDrawCardReq) Reset() {
*x = HeroDrawCardReq{}
if protoimpl.UnsafeEnabled {
mi := &file_hero_hero_msg_proto_msgTypes[29]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -1554,13 +1555,13 @@ func (x *HeroDrawReq) Reset() {
}
}
func (x *HeroDrawReq) String() string {
func (x *HeroDrawCardReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HeroDrawReq) ProtoMessage() {}
func (*HeroDrawCardReq) ProtoMessage() {}
func (x *HeroDrawReq) ProtoReflect() protoreflect.Message {
func (x *HeroDrawCardReq) ProtoReflect() protoreflect.Message {
mi := &file_hero_hero_msg_proto_msgTypes[29]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -1572,28 +1573,28 @@ func (x *HeroDrawReq) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use HeroDrawReq.ProtoReflect.Descriptor instead.
func (*HeroDrawReq) Descriptor() ([]byte, []int) {
// Deprecated: Use HeroDrawCardReq.ProtoReflect.Descriptor instead.
func (*HeroDrawCardReq) Descriptor() ([]byte, []int) {
return file_hero_hero_msg_proto_rawDescGZIP(), []int{29}
}
func (x *HeroDrawReq) GetDrawCount() int32 {
func (x *HeroDrawCardReq) GetDrawCount() int32 {
if x != nil {
return x.DrawCount
}
return 0
}
type HeroDrawResp struct {
type HeroDrawCardResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Heroes []*DBHero `protobuf:"bytes,1,rep,name=heroes,proto3" json:"heroes"`
Heroes []int32 `protobuf:"varint,1,rep,packed,name=heroes,proto3" json:"heroes"` // 返回英雄的configID
}
func (x *HeroDrawResp) Reset() {
*x = HeroDrawResp{}
func (x *HeroDrawCardResp) Reset() {
*x = HeroDrawCardResp{}
if protoimpl.UnsafeEnabled {
mi := &file_hero_hero_msg_proto_msgTypes[30]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -1601,13 +1602,13 @@ func (x *HeroDrawResp) Reset() {
}
}
func (x *HeroDrawResp) String() string {
func (x *HeroDrawCardResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HeroDrawResp) ProtoMessage() {}
func (*HeroDrawCardResp) ProtoMessage() {}
func (x *HeroDrawResp) ProtoReflect() protoreflect.Message {
func (x *HeroDrawCardResp) ProtoReflect() protoreflect.Message {
mi := &file_hero_hero_msg_proto_msgTypes[30]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -1619,12 +1620,12 @@ func (x *HeroDrawResp) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use HeroDrawResp.ProtoReflect.Descriptor instead.
func (*HeroDrawResp) Descriptor() ([]byte, []int) {
// Deprecated: Use HeroDrawCardResp.ProtoReflect.Descriptor instead.
func (*HeroDrawCardResp) Descriptor() ([]byte, []int) {
return file_hero_hero_msg_proto_rawDescGZIP(), []int{30}
}
func (x *HeroDrawResp) GetHeroes() []*DBHero {
func (x *HeroDrawCardResp) GetHeroes() []int32 {
if x != nil {
return x.Heroes
}
@ -1781,13 +1782,13 @@ var file_hero_hero_msg_proto_rawDesc = []byte{
0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22,
0x2b, 0x0a, 0x0b, 0x48, 0x65, 0x72, 0x6f, 0x44, 0x72, 0x61, 0x77, 0x52, 0x65, 0x71, 0x12, 0x1c,
0x0a, 0x09, 0x64, 0x72, 0x61, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x09, 0x64, 0x72, 0x61, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x2f, 0x0a, 0x0c,
0x48, 0x65, 0x72, 0x6f, 0x44, 0x72, 0x61, 0x77, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1f, 0x0a, 0x06,
0x68, 0x65, 0x72, 0x6f, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44,
0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x65, 0x73, 0x42, 0x06, 0x5a,
0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x2f, 0x0a, 0x0f, 0x48, 0x65, 0x72, 0x6f, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64, 0x52,
0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x64, 0x72, 0x61, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x64, 0x72, 0x61, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74,
0x22, 0x2a, 0x0a, 0x10, 0x48, 0x65, 0x72, 0x6f, 0x44, 0x72, 0x61, 0x77, 0x43, 0x61, 0x72, 0x64,
0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x65, 0x73, 0x18, 0x01,
0x20, 0x03, 0x28, 0x05, 0x52, 0x06, 0x68, 0x65, 0x72, 0x6f, 0x65, 0x73, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -1833,8 +1834,8 @@ var file_hero_hero_msg_proto_goTypes = []interface{}{
(*HeroGetSpecifiedReq)(nil), // 26: HeroGetSpecifiedReq
(*HeroGetSpecifiedResp)(nil), // 27: HeroGetSpecifiedResp
(*HeroDelHeroPush)(nil), // 28: HeroDelHeroPush
(*HeroDrawReq)(nil), // 29: HeroDrawReq
(*HeroDrawResp)(nil), // 30: HeroDrawResp
(*HeroDrawCardReq)(nil), // 29: HeroDrawCardReq
(*HeroDrawCardResp)(nil), // 30: HeroDrawCardResp
nil, // 31: HeroStrengthenUplvReq.ExpCardsEntry
nil, // 32: HeroPropertyPush.PropertyEntry
nil, // 33: HeroPropertyPush.AddPropertyEntry
@ -1862,12 +1863,11 @@ var file_hero_hero_msg_proto_depIdxs = []int32{
35, // 17: HeroAddNewHeroPush.hero:type_name -> DBHero
35, // 18: HeroGetSpecifiedResp.hero:type_name -> DBHero
34, // 19: HeroDelHeroPush.heros:type_name -> HeroDelHeroPush.HerosEntry
35, // 20: HeroDrawResp.heroes:type_name -> DBHero
21, // [21:21] is the sub-list for method output_type
21, // [21:21] is the sub-list for method input_type
21, // [21:21] is the sub-list for extension type_name
21, // [21:21] is the sub-list for extension extendee
0, // [0:21] is the sub-list for field type_name
20, // [20:20] is the sub-list for method output_type
20, // [20:20] is the sub-list for method input_type
20, // [20:20] is the sub-list for extension type_name
20, // [20:20] is the sub-list for extension extendee
0, // [0:20] is the sub-list for field type_name
}
func init() { file_hero_hero_msg_proto_init() }
@ -2226,7 +2226,7 @@ func file_hero_hero_msg_proto_init() {
}
}
file_hero_hero_msg_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HeroDrawReq); i {
switch v := v.(*HeroDrawCardReq); i {
case 0:
return &v.state
case 1:
@ -2238,7 +2238,7 @@ func file_hero_hero_msg_proto_init() {
}
}
file_hero_hero_msg_proto_msgTypes[30].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HeroDrawResp); i {
switch v := v.(*HeroDrawCardResp); i {
case 0:
return &v.state
case 1:

View File

@ -145,8 +145,11 @@ message HeroDelHeroPush {
map<string,int32> heros = 1;
}
message HeroDrawReq {
//
message HeroDrawCardReq {
int32 drawCount = 1; // ,
}
message HeroDrawResp { repeated DBHero heroes = 1; }
message HeroDrawCardResp {
repeated int32 heroes = 1; // configID
}