上传代码

This commit is contained in:
meixiongfeng 2023-12-21 20:21:30 +08:00
parent 71178bd773
commit 0dee7fb67e
6 changed files with 275 additions and 104 deletions

View File

@ -437,6 +437,8 @@ const (
// 三消Rank
TableEntertainRank = "xxlrank" //排名
TableEntertainRecode = "xxlrecode" //战报
)
// RPC服务接口定义处

View File

@ -0,0 +1,68 @@
package entertainment
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelRecode struct {
modules.MCompModel
module *Entertainment
}
// 组件初始化接口
func (this *modelRecode) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
this.TableName = comm.TableEntertainRecode
this.MCompModel.Init(service, module, comp, opt)
this.module = module.(*Entertainment)
// 通过uid创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
// 更新排名
func (this *modelRecode) updateXxlRecord(record ...*pb.DBXxlRecord) (err error) {
var (
data []interface{}
)
for _, v := range record {
data = append(data, v)
}
if _, err = this.DBModel.DB.InsertMany(core.SqlTable(this.TableName), data); err != nil {
this.module.Errorln(err)
return
}
return
}
func (this *modelRecode) getXxlRecord(uid string) (results []*pb.DBXxlRecord, err error) {
var (
cursor *mongo.Cursor
)
results = make([]*pb.DBXxlRecord, 0)
if cursor, err = this.DBModel.DB.Find(comm.TableEntertainRecode, bson.M{"uid": uid}, options.Find().SetSort(bson.M{"ctime": -1}), options.Find().SetLimit(int64(comm.MaxRankList))); err != nil {
this.module.Errorln(err)
return
} else {
for cursor.Next(context.Background()) {
temp := &pb.DBXxlRecord{}
if err = cursor.Decode(temp); err != nil {
this.module.Errorln(err)
return
}
results = append(results, temp)
}
}
return
}

View File

@ -29,6 +29,7 @@ type Entertainment struct {
//room *Room
match *matchComp
modelRank *modelRank
modelRecode *modelRecode
}
// 模块名
@ -55,6 +56,7 @@ func (this *Entertainment) OnInstallComp() {
//this.room = this.RegisterComp(new(Room)).(*Room)
this.match = this.RegisterComp(new(matchComp)).(*matchComp)
this.modelRank = this.RegisterComp(new(modelRank)).(*modelRank)
this.modelRecode = this.RegisterComp(new(modelRecode)).(*modelRecode)
}
func (this *Entertainment) Start() (err error) {

View File

@ -121,76 +121,6 @@ func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.Play
}
// AI 操作了
func (this *Room) AiOperator() {
var (
curScore int32
szMap []*pb.MapData
bAddPs bool
oid1 int32
oid2 int32
)
this.player2.Ps--
// 交换元素
szMap, oid1, oid2, bAddPs = this.chessboard.AiSwapGirde()
if bAddPs {
this.player2.Ps++
if this.player2.Ps > MaxPs {
this.player2.Ps = MaxPs
}
}
if this.player2.Ps <= 0 { // 权限给下一个人
this.NexPower = this.player1.Userinfo.Uid
this.player1.Ps = MaxPs
this.round++
}
// 校验下次是不是消除
if !this.chessboard.CheckAndRefreshPlat() {
this.chessboard.RedsetPlatData()
szMap = append(szMap, &pb.MapData{
Data: this.chessboard.GetPalatData(),
ChangeType: 1,
})
}
for _, v := range szMap { //
curScore += v.CurSocre
this.player2.Score += v.CurSocre
v.CurSocre = this.player2.Score
this.player2.Energy += v.CurEnergy
v.CurEnergy = this.player2.Energy
}
// 广播消息
if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "operatorrst", &pb.EntertainOperatorRstPush{
Mpadata: szMap,
Power: this.NexPower,
Curpower: this.curPower,
Score: curScore,
Round: this.round,
User1: this.player1,
User2: this.player2,
Itype: 0,
Curid: oid1,
Targetid: oid2,
}, this.szSession...); err != nil {
this.module.Errorln(err)
}
if this.round > this.MaxRound { // 游戏结束
if this.player1.Score == this.player2.Score {
this.MaxRound += 1 // 增加一回合
} else {
this.GameOver(nil)
}
return
}
this.curPower = this.NexPower
if this.RoomType == 2 && this.curPower == this.player2.Userinfo.Uid {
//this.AiOperator()
this.AutoOperator(this.curPower)
}
}
func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg proto.Message) (errdata *pb.ErrorData) {
switch stype {
@ -542,6 +472,9 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
lostPlayer *pb.PlayerData // 输的玩家
box *pb.BoxData // 是否可以获得宝箱奖励
pl []*pb.XxlPlayer
winScore int32 // 胜利获得的积分
lostScore int32 // 失败扣的积分
szRecord []*pb.DBXxlRecord
)
if winner == nil {
if this.player1.Score < this.player2.Score {
@ -563,13 +496,14 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
update map[string]interface{}
)
update = make(map[string]interface{})
if list, err = this.module.model.getEntertainmList(winner.Userinfo.Uid); err == nil {
if list, err = this.module.model.getEntertainmList(winner.Userinfo.Uid); err != nil {
return
}
if conf, err := this.module.configure.GetGameConsumeintegral(list.Consumeexp); err == nil {
for _, v := range conf.Rewards {
if v.A == "attr" && v.T == "consumeexp" {
list.Consumeexp += v.N
winScore = v.N
update["consumeexp"] = list.Consumeexp
winner.Consumeexp = list.Consumeexp
if list.Consumeexp > list.Maxconsumeexp { // 写最高积分
@ -626,7 +560,7 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
}
if lostPlayer.Userinfo.Uid != "999" {
if conf, err := this.module.configure.GetGameConsumeHero(lostPlayer.Cardid); err == nil {
if conf, err := this.module.configure.GetGameConsumeHero(lostPlayer.Cardid); err != nil {
update := map[string]interface{}{}
if list, err := this.module.model.getEntertainmList(lostPlayer.Userinfo.Uid); err == nil {
if list.Liansheng != 0 {
@ -643,6 +577,7 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
if conf, err := this.module.configure.GetGameConsumeintegral(list.Consumeexp); err == nil { // 战败扣除积分
for _, v := range conf.Rewards {
if v.A == "attr" && v.T == "consumeexp" {
lostScore = v.N
list.Consumeexp -= v.N
if list.Consumeexp <= 0 {
list.Consumeexp = 0
@ -678,10 +613,40 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
}
}
}
}
// 更新排行榜数据
this.module.modelRank.updateXxlRank(pl...)
// 写记录
go func() {
if winner.Userinfo.Uid != "999" {
recode := &pb.DBXxlRecord{
Id: primitive.NewObjectID().Hex(),
Uid: winner.Userinfo.Uid,
Uinfo: lostPlayer.Userinfo,
Battlescore: winScore,
Wescore: winner.Score,
Discore: lostPlayer.Score,
Victory: true,
Ctime: configure.Now().Unix(),
}
szRecord = append(szRecord, recode)
}
recode1 := &pb.DBXxlRecord{
Id: primitive.NewObjectID().Hex(),
Uid: lostPlayer.Userinfo.Uid,
Uinfo: winner.Userinfo,
Battlescore: lostScore,
Wescore: lostPlayer.Score,
Discore: winner.Score,
Victory: false,
Ctime: configure.Now().Unix(),
}
szRecord = append(szRecord, recode1)
this.module.modelRecode.updateXxlRecord(szRecord...)
}()
// 修改房间状态
this.Status = 2
this.module.SendMsgSyncToSession(string(this.module.GetType()), "gameover", &pb.EntertainGameOverPush{
@ -701,6 +666,7 @@ func (this *Room) GameOver(winner *pb.PlayerData) (errdata *pb.ErrorData) {
timewheel.Remove(this.closeRoomTimer)
this.closeRoomTimer = nil
}
this.curPower = ""
return
}
@ -840,7 +806,7 @@ func (this *Room) AutoOperator(uid string) {
}, this.szSession...); err != nil {
this.module.Errorln(err)
}
this.curPower = this.NexPower
if this.round > this.MaxRound { // 游戏结束
if this.player1.Score == this.player2.Score {
this.MaxRound += 1 // 增加一回合
@ -849,7 +815,7 @@ func (this *Room) AutoOperator(uid string) {
}
return
}
this.curPower = this.NexPower
if this.RoomType == 2 && this.curPower == p.Userinfo.Uid {
this.AutoOperator(this.curPower)
}

View File

@ -191,6 +191,7 @@ func (this *apiComp) TalentLearn(session comm.IUserSession, req *pb.HeroTalentLe
if heroObj := this.module.QueryHeroByConfId(session.GetUserId(), talent.HeroId); heroObj != nil {
var tasks []*pb.BuriedParam
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype123, heroObj.HeroID, heroObj.Star))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype39, 1)) //累计英雄共鸣xx次
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype124, heroObj.HeroID))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype123, 1, int32(len(talent.Talent)), heroObj.Star))
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype124, 1))

View File

@ -801,6 +801,110 @@ func (x *XxlPlayer) GetMaxsocre() int32 {
return 0
}
// 三消对局记录
type DBXxlRecord struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID
Uinfo *BaseUserInfo `protobuf:"bytes,3,opt,name=uinfo,proto3" json:"uinfo"` //对方基本信息
Battlescore int32 `protobuf:"varint,4,opt,name=battlescore,proto3" json:"battlescore"` // 对局积分
Wescore int32 `protobuf:"varint,5,opt,name=wescore,proto3" json:"wescore"` // 我方积分
Discore int32 `protobuf:"varint,6,opt,name=discore,proto3" json:"discore"` // 对方积分
Victory bool `protobuf:"varint,7,opt,name=victory,proto3" json:"victory"` // true 胜利
Ctime int64 `protobuf:"varint,8,opt,name=ctime,proto3" json:"ctime"` // 创建时间
}
func (x *DBXxlRecord) Reset() {
*x = DBXxlRecord{}
if protoimpl.UnsafeEnabled {
mi := &file_entertain_entertain_db_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DBXxlRecord) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DBXxlRecord) ProtoMessage() {}
func (x *DBXxlRecord) ProtoReflect() protoreflect.Message {
mi := &file_entertain_entertain_db_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DBXxlRecord.ProtoReflect.Descriptor instead.
func (*DBXxlRecord) Descriptor() ([]byte, []int) {
return file_entertain_entertain_db_proto_rawDescGZIP(), []int{9}
}
func (x *DBXxlRecord) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *DBXxlRecord) GetUid() string {
if x != nil {
return x.Uid
}
return ""
}
func (x *DBXxlRecord) GetUinfo() *BaseUserInfo {
if x != nil {
return x.Uinfo
}
return nil
}
func (x *DBXxlRecord) GetBattlescore() int32 {
if x != nil {
return x.Battlescore
}
return 0
}
func (x *DBXxlRecord) GetWescore() int32 {
if x != nil {
return x.Wescore
}
return 0
}
func (x *DBXxlRecord) GetDiscore() int32 {
if x != nil {
return x.Discore
}
return 0
}
func (x *DBXxlRecord) GetVictory() bool {
if x != nil {
return x.Victory
}
return false
}
func (x *DBXxlRecord) GetCtime() int64 {
if x != nil {
return x.Ctime
}
return 0
}
var File_entertain_entertain_db_proto protoreflect.FileDescriptor
var file_entertain_entertain_db_proto_rawDesc = []byte{
@ -939,8 +1043,22 @@ var file_entertain_entertain_db_proto_rawDesc = []byte{
0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x65, 0x78, 0x70, 0x18, 0x04, 0x20,
0x01, 0x28, 0x05, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x65, 0x78, 0x70, 0x12,
0x1a, 0x0a, 0x08, 0x6d, 0x61, 0x78, 0x73, 0x6f, 0x63, 0x72, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
0x05, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x73, 0x6f, 0x63, 0x72, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e,
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x05, 0x52, 0x08, 0x6d, 0x61, 0x78, 0x73, 0x6f, 0x63, 0x72, 0x65, 0x22, 0xda, 0x01, 0x0a, 0x0b,
0x44, 0x42, 0x58, 0x78, 0x6c, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 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, 0x23, 0x0a,
0x05, 0x75, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x42,
0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x75, 0x69, 0x6e,
0x66, 0x6f, 0x12, 0x20, 0x0a, 0x0b, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x73, 0x63, 0x6f, 0x72,
0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x73,
0x63, 0x6f, 0x72, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x65, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18,
0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x77, 0x65, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x18,
0x0a, 0x07, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52,
0x07, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x63, 0x74,
0x6f, 0x72, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x63, 0x74, 0x6f,
0x72, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28,
0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -955,7 +1073,7 @@ func file_entertain_entertain_db_proto_rawDescGZIP() []byte {
return file_entertain_entertain_db_proto_rawDescData
}
var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 17)
var file_entertain_entertain_db_proto_goTypes = []interface{}{
(*MapData)(nil), // 0: MapData
(*GirdeData)(nil), // 1: GirdeData
@ -966,34 +1084,36 @@ var file_entertain_entertain_db_proto_goTypes = []interface{}{
(*DBXXLData)(nil), // 6: DBXXLData
(*DBXxlRules)(nil), // 7: DBXxlRules
(*XxlPlayer)(nil), // 8: XxlPlayer
nil, // 9: PlayerData.SkillEntry
nil, // 10: DBXXLMatch.SkillEntry
nil, // 11: DBXXLData.RewardEntry
nil, // 12: DBXXLData.CardEntry
nil, // 13: DBXXLData.SkillEntry
nil, // 14: DBXxlRules.Skill1Entry
nil, // 15: DBXxlRules.Skill2Entry
(*BaseUserInfo)(nil), // 16: BaseUserInfo
(*DBXxlRecord)(nil), // 9: DBXxlRecord
nil, // 10: PlayerData.SkillEntry
nil, // 11: DBXXLMatch.SkillEntry
nil, // 12: DBXXLData.RewardEntry
nil, // 13: DBXXLData.CardEntry
nil, // 14: DBXXLData.SkillEntry
nil, // 15: DBXxlRules.Skill1Entry
nil, // 16: DBXxlRules.Skill2Entry
(*BaseUserInfo)(nil), // 17: BaseUserInfo
}
var file_entertain_entertain_db_proto_depIdxs = []int32{
1, // 0: MapData.data:type_name -> GirdeData
16, // 1: PlayerData.userinfo:type_name -> BaseUserInfo
9, // 2: PlayerData.skill:type_name -> PlayerData.SkillEntry
16, // 3: DBXXLMatch.userinfo:type_name -> BaseUserInfo
10, // 4: DBXXLMatch.skill:type_name -> DBXXLMatch.SkillEntry
11, // 5: DBXXLData.reward:type_name -> DBXXLData.RewardEntry
12, // 6: DBXXLData.card:type_name -> DBXXLData.CardEntry
17, // 1: PlayerData.userinfo:type_name -> BaseUserInfo
10, // 2: PlayerData.skill:type_name -> PlayerData.SkillEntry
17, // 3: DBXXLMatch.userinfo:type_name -> BaseUserInfo
11, // 4: DBXXLMatch.skill:type_name -> DBXXLMatch.SkillEntry
12, // 5: DBXXLData.reward:type_name -> DBXXLData.RewardEntry
13, // 6: DBXXLData.card:type_name -> DBXXLData.CardEntry
5, // 7: DBXXLData.box:type_name -> BoxData
13, // 8: DBXXLData.skill:type_name -> DBXXLData.SkillEntry
16, // 9: DBXXLData.uinfo:type_name -> BaseUserInfo
14, // 10: DBXxlRules.skill1:type_name -> DBXxlRules.Skill1Entry
15, // 11: DBXxlRules.skill2:type_name -> DBXxlRules.Skill2Entry
16, // 12: XxlPlayer.uinfo:type_name -> BaseUserInfo
13, // [13:13] is the sub-list for method output_type
13, // [13:13] is the sub-list for method input_type
13, // [13:13] is the sub-list for extension type_name
13, // [13:13] is the sub-list for extension extendee
0, // [0:13] is the sub-list for field type_name
14, // 8: DBXXLData.skill:type_name -> DBXXLData.SkillEntry
17, // 9: DBXXLData.uinfo:type_name -> BaseUserInfo
15, // 10: DBXxlRules.skill1:type_name -> DBXxlRules.Skill1Entry
16, // 11: DBXxlRules.skill2:type_name -> DBXxlRules.Skill2Entry
17, // 12: XxlPlayer.uinfo:type_name -> BaseUserInfo
17, // 13: DBXxlRecord.uinfo:type_name -> BaseUserInfo
14, // [14:14] is the sub-list for method output_type
14, // [14:14] is the sub-list for method input_type
14, // [14:14] is the sub-list for extension type_name
14, // [14:14] is the sub-list for extension extendee
0, // [0:14] is the sub-list for field type_name
}
func init() { file_entertain_entertain_db_proto_init() }
@ -1111,6 +1231,18 @@ func file_entertain_entertain_db_proto_init() {
return nil
}
}
file_entertain_entertain_db_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DBXxlRecord); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -1118,7 +1250,7 @@ func file_entertain_entertain_db_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_entertain_entertain_db_proto_rawDesc,
NumEnums: 0,
NumMessages: 16,
NumMessages: 17,
NumExtensions: 0,
NumServices: 0,
},