diff --git a/bin/json/game_heroupstorychapter.json b/bin/json/game_heroupstorychapter.json index d4f39ec64..00e956e22 100644 --- a/bin/json/game_heroupstorychapter.json +++ b/bin/json/game_heroupstorychapter.json @@ -159,7 +159,7 @@ "levellink": [ 4 ], - "leveltype": 1, + "leveltype": 4, "startstory": 301054, "battle": 0, "reward": [ @@ -342,7 +342,7 @@ "levellink": [ 4 ], - "leveltype": 1, + "leveltype": 4, "startstory": 301063, "battle": 0, "reward": [ @@ -525,7 +525,7 @@ "levellink": [ 4 ], - "leveltype": 1, + "leveltype": 4, "startstory": 301083, "battle": 0, "reward": [ diff --git a/bin/json/game_reddot.json b/bin/json/game_reddot.json index 3d6627d6e..9512d4ff3 100644 --- a/bin/json/game_reddot.json +++ b/bin/json/game_reddot.json @@ -716,7 +716,7 @@ "show_type": 1, "count_type": 1, "opencond_id": "PS", - "path": "", + "path": "Root|Ps", "header": "" } ] \ No newline at end of file diff --git a/modules/parkour/ai.go b/modules/parkour/ai.go index f702cd732..652d5c136 100644 --- a/modules/parkour/ai.go +++ b/modules/parkour/ai.go @@ -4,12 +4,10 @@ import ( "fmt" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" - "go_dreamfactory/lego/sys/timewheel" + "go_dreamfactory/modules/parkour/ai" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" - "math/rand" "sync" - "time" ) /* @@ -17,14 +15,11 @@ AI 逻辑组件 */ type aiComp struct { cbase.ModuleCompBase - service core.IService - module *Parkour - conf []*cfg.GameBuzkashiGradeData - lock sync.RWMutex - ais map[string][]*AI - handleS []AIHandleType - handleSS []AIHandleType - handleSSS []AIHandleType + service core.IService + module *Parkour + conf []*cfg.GameBuzkashiGradeData + lock sync.RWMutex + ais map[string][]*ai.AI } //组件初始化接口 @@ -32,11 +27,7 @@ func (this *aiComp) Init(service core.IService, module core.IModule, comp core.I this.ModuleCompBase.Init(service, module, comp, options) this.module = module.(*Parkour) this.service = service - this.ais = make(map[string][]*AI) - this.handleS = make([]AIHandleType, 100) - this.handleSS = make([]AIHandleType, 100) - this.handleSSS = make([]AIHandleType, 100) - this.inithandle() + this.ais = make(map[string][]*ai.AI) return } @@ -45,86 +36,16 @@ func (this *aiComp) Start() (err error) { if this.conf, err = this.module.configure.getGameBuzkashiGrades(); err != nil { return } - timewheel.AddCron(time.Second*3, this.aihandle) + // timewheel.AddCron(time.Second*3, this.aihandle) return } -func (this *aiComp) inithandle() { - var index int32 - //AILevelS - for i := 0; i < 40; i++ { //失败躲避次数 40 - this.handleS[index] = AIHandle_Avoid0 - index++ - } - for i := 0; i < 10; i++ { //成功躲避次数 10 - this.handleS[index] = AIHandle_Avoid1 - index++ - } - for i := 0; i < 5; i++ { //完美躲避次数 5 - this.handleS[index] = AIHandle_Avoid2 - index++ - } - for i := 0; i < 7; i++ { //射门失败次数 5 - this.handleS[index] = AIHandle_Shots0 - index++ - } - for i := 0; i < 3; i++ { //射门成功次数 3 - this.handleS[index] = AIHandle_Shots1 - index++ - } - index = 0 - //AILevelSS - for i := 0; i < 30; i++ { //失败躲避次数 30 - this.handleSS[index] = AIHandle_Avoid0 - index++ - } - for i := 0; i < 20; i++ { //成功躲避次数 20 - this.handleSS[index] = AIHandle_Avoid1 - index++ - } - for i := 0; i < 10; i++ { //完美躲避次数 10 - this.handleSS[index] = AIHandle_Avoid2 - index++ - } - for i := 0; i < 5; i++ { //射门失败次数 5 - this.handleSS[index] = AIHandle_Shots0 - index++ - } - for i := 0; i < 5; i++ { //射门成功次数 5 - this.handleSS[index] = AIHandle_Shots1 - index++ - } - - index = 0 - //AILevelSSS - for i := 0; i < 10; i++ { //失败躲避次数 10 - this.handleSSS[index] = AIHandle_Avoid0 - index++ - } - for i := 0; i < 30; i++ { //成功躲避次数 30 - this.handleSSS[index] = AIHandle_Avoid1 - index++ - } - for i := 0; i < 15; i++ { //完美躲避次数 15 - this.handleSSS[index] = AIHandle_Avoid2 - index++ - } - for i := 0; i < 2; i++ { //射门失败次数 2 - this.handleSSS[index] = AIHandle_Shots0 - index++ - } - for i := 0; i < 8; i++ { //射门成功次数 8 - this.handleSSS[index] = AIHandle_Shots1 - index++ - } -} - //创建战斗ai -func (this *aiComp) createAi(battleid string, users []*pb.DBRaceMember) (err error) { +func (this *aiComp) createAi(battleid string, btype pb.RaceType, users []*pb.DBRaceMember) (err error) { var ( - ok bool - ais []*AI - r *rand.Rand = rand.New(rand.NewSource(time.Now().Unix())) + ok bool + ais []*ai.AI + conf *cfg.GameBukashiAiData ) if battleid == "" || users == nil || len(users) == 0 { err = fmt.Errorf("battleid:%s users:%v parameter exceptions", battleid, users) @@ -138,35 +59,13 @@ func (this *aiComp) createAi(battleid string, users []*pb.DBRaceMember) (err err err = fmt.Errorf("battle:%s already exists", battleid) return } - ais = make([]*AI, len(users)) + ais = make([]*ai.AI, len(users)) for i, v := range users { - ais[i] = &AI{ - BattleId: battleid, - UId: v.Uid, - AILevel: AILevelS, - Handle: make([]AIHandleType, 100), - LastTime: time.Now(), - } - switch ais[i].AILevel { - case AILevelS: - ais[i].Interval = time.Second*10 + time.Second*time.Duration(rand.Int31n(5)) - for ii, vv := range r.Perm(len(this.handleS)) { - ais[i].Handle[ii] = this.handleS[vv] - } - break - case AILevelSS: - ais[i].Interval = time.Second*7 + time.Second*time.Duration(rand.Int31n(5)) - for ii, vv := range r.Perm(len(this.handleSS)) { - ais[i].Handle[ii] = this.handleSS[vv] - } - break - case AILevelSSS: - ais[i].Interval = time.Second*5 + time.Second*time.Duration(rand.Int31n(3)) - for ii, vv := range r.Perm(len(this.handleSSS)) { - ais[i].Handle[ii] = this.handleSSS[vv] - } - break + if conf, err = this.module.configure.getgameBukashiAiDataByDan(int32(btype), v.Dan); err != nil { + return } + ais[i] = ai.NewAI(battleid, v.Uid, conf) + } this.lock.Lock() this.ais[battleid] = ais @@ -182,44 +81,44 @@ func (this *aiComp) removeAi(battleid string) { } //ai自动化 -func (this *aiComp) aihandle(task *timewheel.Task, args ...interface{}) { - var ( - ok bool - ais map[string][]*AI = make(map[string][]*AI) - ) - this.lock.RLock() - if len(this.ais) > 0 { - ok = true - for k, v := range this.ais { - ais[k] = v - } - } - this.lock.RUnlock() - if ok { - for id, member := range ais { - for _, ai := range member { - if time.Now().Sub(ai.LastTime) > ai.Interval { - switch ai.Handle[ai.CurrIndex] { - case AIHandle_Avoid0: //躲避障碍 失败 - go this.module.avoid(id, ai.UId, nil) - break - case AIHandle_Avoid1: //躲避障碍 成功 - go this.module.avoid(id, ai.UId, this.conf[1]) - break - case AIHandle_Avoid2: //躲避障碍 完美 - go this.module.avoid(id, ai.UId, this.conf[0]) - break - case AIHandle_Shots0: //射门 失败 - break - case AIHandle_Shots1: //射门 成功 - go this.module.shot(id, ai.UId) - break - } - ai.LastTime = time.Now() - ai.CurrIndex++ - ai.CurrIndex = ai.CurrIndex % int32(len(ai.Handle)) - } - } - } - } -} +// func (this *aiComp) aihandle(task *timewheel.Task, args ...interface{}) { +// var ( +// ok bool +// ais map[string][]*AI = make(map[string][]*AI) +// ) +// this.lock.RLock() +// if len(this.ais) > 0 { +// ok = true +// for k, v := range this.ais { +// ais[k] = v +// } +// } +// this.lock.RUnlock() +// if ok { +// for id, member := range ais { +// for _, ai := range member { +// if time.Now().Sub(ai.LastTime) > ai.Interval { +// switch ai.Handle[ai.CurrIndex] { +// case AIHandle_Avoid0: //躲避障碍 失败 +// go this.module.avoid(id, ai.UId, nil) +// break +// case AIHandle_Avoid1: //躲避障碍 成功 +// go this.module.avoid(id, ai.UId, this.conf[1]) +// break +// case AIHandle_Avoid2: //躲避障碍 完美 +// go this.module.avoid(id, ai.UId, this.conf[0]) +// break +// case AIHandle_Shots0: //射门 失败 +// break +// case AIHandle_Shots1: //射门 成功 +// go this.module.shot(id, ai.UId) +// break +// } +// ai.LastTime = time.Now() +// ai.CurrIndex++ +// ai.CurrIndex = ai.CurrIndex % int32(len(ai.Handle)) +// } +// } +// } +// } +// } diff --git a/modules/parkour/ai/core.go b/modules/parkour/ai/core.go new file mode 100644 index 000000000..382659b39 --- /dev/null +++ b/modules/parkour/ai/core.go @@ -0,0 +1,46 @@ +package ai + +import ( + cfg "go_dreamfactory/sys/configure/structs" +) + +type AILevel int32 + +const ( + AILevelS AILevel = iota + AILevelSS + AILevelSSS +) + +type AIHandleType int32 + +const ( + AIHandle_Null AIHandleType = iota //空操作 + AIHandle_Avoid //躲避障碍 + AIHandle_Shot //射门 + AIHandle_AddBlood //加血 +) + +type AIHandle struct { + htype AIHandleType + cd int32 + weight int32 +} + +//捕羊大赛AI对象 +type AI struct { + Bid string //战场id + Uid string //用户id + Conf *cfg.GameBukashiAiData //配置 + Handles []*AIHandle //操作列表 + Lastopttime int64 //最后一次操作时间 +} + +func NewAI(battleid string, uid string, conf *cfg.GameBukashiAiData) (_ai *AI) { + _ai = &AI{ + Bid: battleid, + Uid: uid, + Conf: conf, + } + return +} diff --git a/modules/parkour/configure.go b/modules/parkour/configure.go index d78d1c99f..836a1adef 100644 --- a/modules/parkour/configure.go +++ b/modules/parkour/configure.go @@ -119,6 +119,42 @@ func (this *configureComp) getGameBuzkashiQteLv(time float32) (configure *cfg.Ga } return } +func (this *configureComp) getgameBukashiAiData(id int32) (conf *cfg.GameBukashiAiData, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_bukashiai); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + if conf, ok = v.(*cfg.GameBukashiAi).GetDataMap()[id]; !ok { + err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_buzkashiqtelv, id) + this.module.Errorln(err) + return + } + } + return +} +func (this *configureComp) getgameBukashiAiDataByDan(btype, dan int32) (conf *cfg.GameBukashiAiData, err error) { + var ( + v interface{} + ) + if v, err = this.GetConfigure(game_bukashiai); err != nil { + this.module.Errorf("err:%v", err) + return + } else { + for _, v := range v.(*cfg.GameBukashiAi).GetDataList() { + if v.MatchType == btype && v.QualifyingType == dan { + conf = v + return + } + } + err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_buzkashiqtelv, fmt.Sprintf("%d:%d", btype, dan)) + this.module.Errorln(err) + } + return +} // func (this *configureComp) getGameBuzkashiReward(id int32) (configure *cfg.GameBuzkashiRewardData) { // if v, err := this.GetConfigure(game_buzkashireward); err == nil { diff --git a/modules/parkour/core.go b/modules/parkour/core.go index 05d3c98c0..aa40a6606 100644 --- a/modules/parkour/core.go +++ b/modules/parkour/core.go @@ -5,7 +5,6 @@ import ( "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/pb" "sync" - "time" ) type Recommend struct { @@ -16,44 +15,13 @@ type Recommend struct { ///捕羊大赛对象 type RaceItem struct { - Id string //战斗id - lock sync.Mutex //战斗锁 防止计时器和消息同时操作对象 - RedMember []*pb.DBRaceMember //红方成员 - RedScore int32 //红方分值 - // RedEnergy int32 //红方能量 + Id string //战斗id + lock sync.Mutex //战斗锁 防止计时器和消息同时操作对象 + Rtype pb.RaceType //比赛类型 + RedMember []*pb.DBRaceMember //红方成员 + RedScore int32 //红方分值 BuleMember []*pb.DBRaceMember //蓝方成员 Session map[string]comm.IUserSession - BuleScore int32 //蓝方分值 - // BuleEnergy int32 //蓝方能量 - overtimer *timewheel.Task //准备倒计时定时器 -} - -type AILevel int32 - -const ( - AILevelS AILevel = iota - AILevelSS - AILevelSSS -) - -type AIHandleType int32 - -const ( - AIHandle_Null AIHandleType = iota //空操作 - AIHandle_Avoid0 //躲避障碍 失败 - AIHandle_Avoid1 //躲避障碍 成功 - AIHandle_Avoid2 //躲避障碍 完美 - AIHandle_Shots0 //射门 失败 - AIHandle_Shots1 //射门 成功 -) - -//捕羊大赛AI对象 -type AI struct { - BattleId string //战场id - UId string //用户id - AILevel AILevel //AI级别 - Handle []AIHandleType //操作列表 - CurrIndex int32 //当前执行下标 - LastTime time.Time //上一次操作时间 - Interval time.Duration //最小操作时间 + BuleScore int32 //蓝方分值 + overtimer *timewheel.Task //准备倒计时定时器 } diff --git a/modules/parkour/module.go b/modules/parkour/module.go index c4429742c..1f38ea62c 100644 --- a/modules/parkour/module.go +++ b/modules/parkour/module.go @@ -207,7 +207,7 @@ func (this *Parkour) startbattle(id string) { member = append(member, v) } } - if err = this.ai.createAi(battle.Id, member); err != nil { + if err = this.ai.createAi(battle.Id, battle.Rtype, member); err != nil { this.Errorln(err) return } diff --git a/pb/mail_msg.pb.go b/pb/mail_msg.pb.go index 10ef38007..d0a2ec164 100644 --- a/pb/mail_msg.pb.go +++ b/pb/mail_msg.pb.go @@ -483,8 +483,9 @@ type MailGetAllMailAttachmentResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Res []*UserAtno `protobuf:"bytes,1,rep,name=res,proto3" json:"res"` //资源类型 - Ids []string `protobuf:"bytes,2,rep,name=ids,proto3" json:"ids"` // 已经领取的邮件唯一id + Res []*UserAtno `protobuf:"bytes,1,rep,name=res,proto3" json:"res"` //资源类型 + Ids []string `protobuf:"bytes,2,rep,name=ids,proto3" json:"ids"` // 已经领取的邮件唯一id + Reward []*UserAtno `protobuf:"bytes,3,rep,name=reward,proto3" json:"reward"` //获取资源 } func (x *MailGetAllMailAttachmentResp) Reset() { @@ -533,6 +534,13 @@ func (x *MailGetAllMailAttachmentResp) GetIds() []string { return nil } +func (x *MailGetAllMailAttachmentResp) GetReward() []*UserAtno { + if x != nil { + return x.Reward + } + return nil +} + type MailDelAllMailReq struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -652,18 +660,20 @@ var file_mail_mail_msg_proto_rawDesc = []byte{ 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x4d, 0x61, 0x69, 0x6c, 0x22, 0x1d, 0x0a, 0x1b, 0x4d, 0x61, 0x69, 0x6c, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, - 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x22, 0x4d, 0x0a, 0x1c, 0x4d, 0x61, + 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x22, 0x70, 0x0a, 0x1c, 0x4d, 0x61, 0x69, 0x6c, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x74, 0x6e, 0x6f, 0x52, 0x03, 0x72, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x64, 0x73, 0x18, 0x02, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x22, 0x13, 0x0a, 0x11, 0x4d, 0x61, 0x69, - 0x6c, 0x44, 0x65, 0x6c, 0x41, 0x6c, 0x6c, 0x4d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x22, 0x37, - 0x0a, 0x12, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x65, 0x6c, 0x41, 0x6c, 0x6c, 0x4d, 0x61, 0x69, 0x6c, - 0x52, 0x65, 0x73, 0x70, 0x12, 0x21, 0x0a, 0x05, 0x4d, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, - 0x52, 0x05, 0x4d, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x03, 0x69, 0x64, 0x73, 0x12, 0x21, 0x0a, 0x06, 0x72, 0x65, 0x77, + 0x61, 0x72, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x55, 0x73, 0x65, 0x72, + 0x41, 0x74, 0x6e, 0x6f, 0x52, 0x06, 0x72, 0x65, 0x77, 0x61, 0x72, 0x64, 0x22, 0x13, 0x0a, 0x11, + 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x65, 0x6c, 0x41, 0x6c, 0x6c, 0x4d, 0x61, 0x69, 0x6c, 0x52, 0x65, + 0x71, 0x22, 0x37, 0x0a, 0x12, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x65, 0x6c, 0x41, 0x6c, 0x6c, 0x4d, + 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x12, 0x21, 0x0a, 0x05, 0x4d, 0x61, 0x69, 0x6c, 0x73, + 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x69, 0x6c, 0x44, + 0x61, 0x74, 0x61, 0x52, 0x05, 0x4d, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, + 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -702,12 +712,13 @@ var file_mail_mail_msg_proto_depIdxs = []int32{ 13, // 2: MailGetUserMailAttachmentResp.Mail:type_name -> DBMailData 13, // 3: MailGetNewMailPush.Mail:type_name -> DBMailData 14, // 4: MailGetAllMailAttachmentResp.res:type_name -> UserAtno - 13, // 5: MailDelAllMailResp.Mails:type_name -> DBMailData - 6, // [6:6] is the sub-list for method output_type - 6, // [6:6] is the sub-list for method input_type - 6, // [6:6] is the sub-list for extension type_name - 6, // [6:6] is the sub-list for extension extendee - 0, // [0:6] is the sub-list for field type_name + 14, // 5: MailGetAllMailAttachmentResp.reward:type_name -> UserAtno + 13, // 6: MailDelAllMailResp.Mails:type_name -> DBMailData + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_mail_mail_msg_proto_init() } diff --git a/pb/parkour_db.pb.go b/pb/parkour_db.pb.go index 89adad1d4..c9b6a678f 100644 --- a/pb/parkour_db.pb.go +++ b/pb/parkour_db.pb.go @@ -23,8 +23,8 @@ const ( type RaceType int32 const ( - RaceType_ordinary RaceType = 0 - RaceType_prop RaceType = 1 + RaceType_ordinary RaceType = 0 //训练模式 + RaceType_prop RaceType = 1 //排位模式 ) // Enum value maps for RaceType. diff --git a/sys/configure/structs/Tables.go b/sys/configure/structs/Tables.go index efee8931a..a83fdb180 100644 --- a/sys/configure/structs/Tables.go +++ b/sys/configure/structs/Tables.go @@ -273,6 +273,7 @@ type Tables struct { ConsumeHero *GameConsumeHero PlayerSkill *GamePlayerSkill ConsumeBox *GameConsumeBox + BukashiAi *GameBukashiAi } func NewTables(loader JsonLoader) (*Tables, error) { @@ -1852,5 +1853,11 @@ func NewTables(loader JsonLoader) (*Tables, error) { if tables.ConsumeBox, err = NewGameConsumeBox(buf) ; err != nil { return nil, err } + if buf, err = loader("game_bukashiai") ; err != nil { + return nil, err + } + if tables.BukashiAi, err = NewGameBukashiAi(buf) ; err != nil { + return nil, err + } return tables, nil }