上传代码

This commit is contained in:
meixiongfeng 2023-11-04 20:55:35 +08:00
parent adce173e29
commit 4c521fe92e
8 changed files with 172 additions and 42 deletions

View File

@ -501,6 +501,8 @@ const ( //Rpc
Rpc_ActivityOver core.Rpc_Key = "Rpc_ActivityOver" //活动结束
Rpc_ActivityStar core.Rpc_Key = "Rpc_ActivityStar" //活动开启
RPC_XXLOffLine core.Rpc_Key = "RPC_XXLOffLine" //三消离线
)
// 事件类型定义处

View File

@ -233,3 +233,18 @@ func (this *configureComp) GetGameRandomConsumeBoxConf() (conf *cfg.GameConsumeB
conf, err = this.GetGameConsumeBoxConf(boxid[comm.GetRandW(szWeight)])
return
}
func (this *configureComp) GetGameBlockByKey(key int32) (conf *cfg.GameBlockData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_block); err == nil {
if configure, ok := v.(*cfg.GameBlock); ok {
if conf = configure.Get(key); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_block, key)
return
}

View File

@ -1,8 +1,10 @@
package entertainment
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/event"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
@ -52,7 +54,8 @@ func (this *Entertainment) Start() (err error) {
if err = this.ModuleBase.Start(); err != nil {
return
}
event.RegisterGO(comm.EventUserOffline, this.EventUserOffline)
this.service.RegisterFunctionName(string(comm.RPC_XXLOffLine), this.useroffline)
return
}
@ -117,3 +120,36 @@ func (this *Entertainment) ConsumXxlCard(session comm.IUserSession, card string)
})
return
}
// 用户离线处理
func (this *Entertainment) EventUserOffline(uid, sessionid string) {
this.Debugf("user offline: %s", uid)
// if list, err := this.model.getEntertainmList(uid); err == nil {
// var (
// serverPath string = fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId())
// )
// if serverPath != list.ServicePath { // RPC 通知房间所在的服务器
// _, err = this.service.RpcGo(
// context.Background(),
// list.ServicePath,
// string(comm.RPC_XXLOffLine),
// &pb.RPCGeneralReqA2{
// Param1: list.Roomid,
// Param2: list.Uid,
// },
// nil)
// if err != nil {
// this.Errorln(err)
// return
// }
// } else {
// this.useroffline(context.Background(), &pb.RPCGeneralReqA2{Param1: list.Roomid, Param2: list.Uid}, nil)
// }
// return
// }
}
func (this *Entertainment) useroffline(ctx context.Context, req *pb.RPCGeneralReqA2, resp *pb.RPCGeneralReqA2) (err error) {
return
}

View File

@ -93,7 +93,7 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) {
}
// 随机一个玩法
func (this *Room) RandomPlayType() {
func (this *Room) RandomPlayType() (itype int32) {
var weight []int32 // 权重
// 开始随机玩法
list := this.module.configure.GetGameConsumeIntegral()
@ -101,15 +101,15 @@ func (this *Room) RandomPlayType() {
weight = append(weight, v.Weight)
}
this.Playtype = list[comm.GetRandW(weight)].Key
return list[comm.GetRandW(weight)].Key
}
func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room {
var room *Room
this.module = module
this.chessboard = new(MapData)
this.RandomPlayType()
this.chessboard.InitMap(module) // 初始化棋盘
this.Playtype = this.RandomPlayType()
this.chessboard.InitMap(module, this.Playtype) // 初始化棋盘
if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok {
this.module.PutUserSession(s1)
} else {
@ -682,8 +682,8 @@ func (this *Room) JoinRoom(module *Entertainment, p *pb.PlayerData) (room *Room,
this.player1 = p
this.module = module
this.chessboard = new(MapData)
this.RandomPlayType()
this.chessboard.InitMap(module) // 初始化棋盘
this.Playtype = this.RandomPlayType()
this.chessboard.InitMap(module, this.Playtype) // 初始化棋盘
if s1, ok := this.module.GetUserSession(p.Userinfo.Uid); !ok {
this.module.PutUserSession(s1)
} else {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"math/big"
)
@ -39,30 +40,83 @@ type MapData struct {
oid int32 // 唯一id
module *Entertainment
operElem []int32 // 当前移动的元素
iType int32 // 玩法类型
}
// 1~6随机一个数
func GetRandType() int32 {
func (this *MapData) GetRandType() int32 {
n, _ := rand.Int(rand.Reader, big.NewInt(6))
return int32(n.Int64() + 1)
}
func (this *MapData) CreateGride(index int32) *pb.GirdeData {
t := GetRandType()
// 玩法带入
func (this *MapData) CreateGride(index int32) (girde *pb.GirdeData) {
var (
szWeight []int32
szId []int32
id int32
conf *cfg.GameBlockData
err error
) // 权重带入
this.oid++
return &pb.GirdeData{
girde = &pb.GirdeData{ // 默认值
Oid: this.oid,
Color: t,
Cid: t,
Color: 1,
Cid: 1,
Score: 1,
Special: 0,
}
if this.iType == 4 {
for i := 1; i <= 6; i++ { // 6种颜色
if conf, err := this.module.configure.GetGameBlock(int32(i), 4); err == nil {
szWeight = append(szWeight, conf.Weight)
szId = append(szId, conf.Key)
}
if conf, err := this.module.configure.GetGameBlock(int32(i), 0); err == nil {
szWeight = append(szWeight, conf.Weight)
szId = append(szId, conf.Key)
}
}
id = szId[comm.GetRandW(szWeight)]
} else if this.iType == 3 { // 创建棋盘的时候此玩法类型执行效率低下 稍后采用同颜色替换模式处理
// 最多2个
var count int32
for _, v := range this.Plat {
if v.Special == 4 {
count++
if count >= 2 {
break
}
}
}
if count <= 2 {
n, _ := rand.Int(rand.Reader, big.NewInt(6)) // 随机一个颜色
if conf, err := this.module.configure.GetGameBlock(int32(n.Int64()+1), 4); err == nil {
id = conf.Key
}
}
} else {
id = this.GetRandType()
}
conf, err = this.module.configure.GetGameBlockByKey(id)
if err != nil {
return
}
girde.Color = conf.Color
girde.Cid = conf.Key
girde.Special = conf.Type
girde.Score = conf.Score
return
}
// 初始化地图数据
func (this *MapData) InitMap(module *Entertainment) {
func (this *MapData) InitMap(module *Entertainment, iType int32) {
this.module = module
this.iType = 1 //iType
this.oid = 1000 // 方便观察 从1000开始
this.Plat = make([]*pb.GirdeData, Width*Height)
for i := 0; i < Width*Height; i++ {
@ -389,7 +443,7 @@ func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc
CurSocre: curScore,
CurEnergy: energy,
})
this.Debugf()
//this.Debugf()
}
@ -427,7 +481,7 @@ func (this *MapData) DropGirde() bool {
}
}
}
//this.Debugf()
return bDrop
}
@ -595,15 +649,6 @@ func (this *MapData) SkillUp(pos int32, color int32, skillid int32, value int32,
return
}
// 随机生成 不可消除的 地图
func (this *MapData) CheckInitPlat() {
this.Plat = make([]*pb.GirdeData, Width*Height)
for i := 0; i < Width*Height; i++ {
this.Plat[i] = this.CreateGride(int32(i))
}
}
func (this *MapData) SetMap() {
sz2 := []int32{
3, 3, 2, 2, 1, 3, 1,
@ -1058,5 +1103,14 @@ func (this *MapData) SpecialElem(id int, s int32) (x map[int]struct{}) {
x[key] = struct{}{}
}
}
// for k := range x {
// if this.Plat[k].Special != 0 {
// for key := range this.SpecialElem(k, this.Plat[k].Special) { // 递归调用
// x[key] = struct{}{}
// }
// }
// }
return
}

View File

@ -86,7 +86,7 @@ func Test_Main(t *testing.T) {
// sz := utils.RandomNumbers(0, 2, 2)
// fmt.Printf("xxxx%v", sz)
m := new(entertainment.MapData)
m.InitMap(nil)
m.InitMap(nil, 1)
//m.SkillUp(24, 1, 3, 7, true)
m.SetMap()

View File

@ -41,6 +41,7 @@ const (
EffectTipsType_Bleed EffectTipsType = 15 //流血
EffectTipsType_Recovery EffectTipsType = 16 //复苏
EffectTipsType_BeatBack EffectTipsType = 17 //反击
EffectTipsType_Diseased EffectTipsType = 18 //禁疗
)
// Enum value maps for EffectTipsType.
@ -64,6 +65,7 @@ var (
15: "Bleed",
16: "Recovery",
17: "BeatBack",
18: "Diseased",
}
EffectTipsType_value = map[string]int32{
"Eff_Success": 0,
@ -84,6 +86,7 @@ var (
"Bleed": 15,
"Recovery": 16,
"BeatBack": 17,
"Diseased": 18,
}
)
@ -1948,7 +1951,7 @@ var file_battle_battle_struct_proto_rawDesc = []byte{
0x56, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x63, 0x75, 0x72,
0x56, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x26, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x53, 0x77, 0x69, 0x74,
0x63, 0x68, 0x53, 0x63, 0x65, 0x6e, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x63, 0x65, 0x6e, 0x65,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x2a, 0x9c, 0x02,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x63, 0x65, 0x6e, 0x65, 0x2a, 0xaa, 0x02,
0x0a, 0x0e, 0x45, 0x66, 0x66, 0x65, 0x63, 0x74, 0x54, 0x69, 0x70, 0x73, 0x54, 0x79, 0x70, 0x65,
0x12, 0x0f, 0x0a, 0x0b, 0x45, 0x66, 0x66, 0x5f, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10,
0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x4e, 0x6f, 0x74, 0x5f, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73,
@ -1966,8 +1969,9 @@ var file_battle_battle_struct_proto_rawDesc = []byte{
0x6e, 0x64, 0x65, 0x61, 0x64, 0x10, 0x0d, 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x6f, 0x69, 0x73, 0x6f,
0x6e, 0x65, 0x64, 0x10, 0x0e, 0x12, 0x09, 0x0a, 0x05, 0x42, 0x6c, 0x65, 0x65, 0x64, 0x10, 0x0f,
0x12, 0x0c, 0x0a, 0x08, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x10, 0x10, 0x12, 0x0c,
0x0a, 0x08, 0x42, 0x65, 0x61, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x10, 0x11, 0x42, 0x06, 0x5a, 0x04,
0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x0a, 0x08, 0x42, 0x65, 0x61, 0x74, 0x42, 0x61, 0x63, 0x6b, 0x10, 0x11, 0x12, 0x0c, 0x0a, 0x08,
0x44, 0x69, 0x73, 0x65, 0x61, 0x73, 0x65, 0x64, 0x10, 0x12, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b,
0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -374,7 +374,9 @@ type DBXXLData struct {
Rtime int64 `protobuf:"varint,5,opt,name=rtime,proto3" json:"rtime"` // 刷新时间 (客户端不用)
Playtype []int32 `protobuf:"varint,6,rep,packed,name=playtype,proto3" json:"playtype"` // 每天随机玩法
// map<int32,int64> boxid = 7; // 宝箱 key 宝箱id value 可领取的时间
Box []*BoxData `protobuf:"bytes,7,rep,name=box,proto3" json:"box"`
Box []*BoxData `protobuf:"bytes,7,rep,name=box,proto3" json:"box"`
Roomid string `protobuf:"bytes,8,opt,name=roomid,proto3" json:"roomid"` // 房间id 重连用
ServicePath string `protobuf:"bytes,9,opt,name=servicePath,proto3" json:"servicePath"` // 目标服务节点 重连RPC用
}
func (x *DBXXLData) Reset() {
@ -458,6 +460,20 @@ func (x *DBXXLData) GetBox() []*BoxData {
return nil
}
func (x *DBXXLData) GetRoomid() string {
if x != nil {
return x.Roomid
}
return ""
}
func (x *DBXXLData) GetServicePath() string {
if x != nil {
return x.ServicePath
}
return ""
}
var File_entertain_entertain_db_proto protoreflect.FileDescriptor
var file_entertain_entertain_db_proto_rawDesc = []byte{
@ -497,7 +513,7 @@ var file_entertain_entertain_db_proto_rawDesc = []byte{
0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x6f, 0x78, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x05, 0x62, 0x6f, 0x78, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, 0x65,
0x6e, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6f, 0x70, 0x65,
0x6e, 0x74, 0x69, 0x6d, 0x65, 0x22, 0xc9, 0x02, 0x0a, 0x09, 0x44, 0x42, 0x58, 0x58, 0x4c, 0x44,
0x6e, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x83, 0x03, 0x0a, 0x09, 0x44, 0x42, 0x58, 0x58, 0x4c, 0x44,
0x61, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x2e, 0x0a, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x18,
@ -510,16 +526,19 @@ var file_entertain_entertain_db_proto_rawDesc = []byte{
0x72, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x74, 0x79, 0x70,
0x65, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x79, 0x74, 0x79, 0x70,
0x65, 0x12, 0x1a, 0x0a, 0x03, 0x62, 0x6f, 0x78, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x08,
0x2e, 0x42, 0x6f, 0x78, 0x44, 0x61, 0x74, 0x61, 0x52, 0x03, 0x62, 0x6f, 0x78, 0x1a, 0x39, 0x0a,
0x0b, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 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, 0x1a, 0x37, 0x0a, 0x09, 0x43, 0x61, 0x72, 0x64,
0x45, 0x6e, 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, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x2e, 0x42, 0x6f, 0x78, 0x44, 0x61, 0x74, 0x61, 0x52, 0x03, 0x62, 0x6f, 0x78, 0x12, 0x16, 0x0a,
0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72,
0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x50, 0x61, 0x74, 0x68, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x65, 0x72, 0x76,
0x69, 0x63, 0x65, 0x50, 0x61, 0x74, 0x68, 0x1a, 0x39, 0x0a, 0x0b, 0x52, 0x65, 0x77, 0x61, 0x72,
0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
0x01, 0x28, 0x05, 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, 0x1a, 0x37, 0x0a, 0x09, 0x43, 0x61, 0x72, 0x64, 0x45, 0x6e, 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, 0x42, 0x06, 0x5a, 0x04, 0x2e,
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (