上传捕羊大赛代码

This commit is contained in:
liwei1dao 2023-04-21 19:03:50 +08:00
parent 8bb7c27a7b
commit 2ff92487cf
3 changed files with 164 additions and 52 deletions

View File

@ -150,13 +150,13 @@ func (this *aiComp) createAi(battleid string, users []*pb.DBRaceMember) (err err
}
break
case AILevelSS:
ais[i].Interval = time.Second*5 + time.Second*time.Duration(rand.Int31n(5))
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*3 + time.Second*time.Duration(rand.Int31n(3))
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]
}
@ -210,6 +210,7 @@ func (this *aiComp) aihandle(task *timewheel.Task, args ...interface{}) {
go this.module.shot(id, ai.UId)
break
}
ai.LastTime = time.Now()
ai.CurrIndex++
ai.CurrIndex = ai.CurrIndex % int32(len(ai.Handle))
}

View File

@ -210,6 +210,7 @@ func (this *Parkour) shot(id string, uid string) {
this.Debug("shot", log.Field{Key: "id", Value: id})
var (
battle *RaceItem
side int32
ok bool
sessions []comm.IUserSession = make([]comm.IUserSession, 0)
err error
@ -218,13 +219,34 @@ func (this *Parkour) shot(id string, uid string) {
battle, ok = this.battles[id]
this.lock.RUnlock()
if ok {
for _, v := range battle.RedMember {
if v.Uid == uid {
ok = true
side = 1
}
}
if !ok {
for _, v := range battle.BuleMember {
if v.Uid == uid {
ok = true
side = 2
}
}
}
if side == 1 {
battle.RedScore += 3
} else {
battle.BuleScore += 3
}
for _, v := range battle.Session {
sessions = append(sessions, v)
}
if err = this.SendMsgToSession(string(this.GetType()), "scorechanage", &pb.ParkourScoreChanagePush{
Red: battle.RedScore,
Blue: battle.BuleScore,
Redscore: battle.RedScore,
Redenergy: battle.RedEnergy,
Bluescore: battle.BuleScore,
Blueenergy: battle.BuleEnergy,
}, sessions...); err != nil {
this.Errorln(err)
}
@ -236,6 +258,7 @@ func (this *Parkour) avoid(id string, uid string, dis int32) {
var (
battle *RaceItem
ok bool
side int32
member *pb.DBRaceMember
sessions []comm.IUserSession = make([]comm.IUserSession, 0)
err error
@ -249,6 +272,7 @@ func (this *Parkour) avoid(id string, uid string, dis int32) {
if v.Uid == uid {
member = v
ok = true
side = 1
}
}
if !ok {
@ -256,6 +280,7 @@ func (this *Parkour) avoid(id string, uid string, dis int32) {
if v.Uid == uid {
member = v
ok = true
side = 2
}
}
}
@ -263,16 +288,32 @@ func (this *Parkour) avoid(id string, uid string, dis int32) {
this.Error("躲避障碍物逻辑异常 未找到玩家!", log.Field{Key: "battleid", Value: id}, log.Field{Key: "uid", Value: uid})
return
}
if dis < 0 {
member.Hp--
} else {
}
for _, v := range battle.Session {
sessions = append(sessions, v)
}
if dis < 0 {
member.Hp--
if member.Hp < 0 {
// timewheel.Add(time.Second*10, this.resurrectiontimer, battle.Id, member.Uid)
}
} else {
if side == 1 {
battle.RedEnergy += 3
} else {
battle.BuleEnergy += 3
}
if err = this.SendMsgToSession(string(this.GetType()), "playerhpchanage", &pb.ParkourScoreChanagePush{
Redscore: battle.RedScore,
Redenergy: battle.RedEnergy,
Bluescore: battle.BuleScore,
Blueenergy: battle.BuleEnergy,
}, sessions...); err != nil {
this.Errorln(err)
}
}
if err = this.SendMsgToSession(string(this.GetType()), "playerhpchanage", &pb.ParkourPlayerHPChanagePush{
Uid: uid,
Hp: member.Hp,
@ -549,3 +590,51 @@ func (this *Parkour) trusteeship(ctx context.Context, req *pb.RPC_ParkourTrustee
}
return
}
func (this *Parkour) resurrectiontimer(task *timewheel.Task, args ...interface{}) {
var (
battleid string
uid string
battle *RaceItem
member *pb.DBRaceMember
sessions []comm.IUserSession = make([]comm.IUserSession, 0)
ok bool
err error
)
battleid = args[0].(string)
uid = args[1].(string)
this.lock.RLock()
battle, ok = this.battles[battleid]
this.lock.RUnlock()
if ok {
ok = false
for _, v := range battle.RedMember {
if v.Uid == uid {
member = v
ok = true
}
}
if !ok {
for _, v := range battle.BuleMember {
if v.Uid == uid {
member = v
ok = true
}
}
}
if ok {
member.Hp = 2
for _, v := range battle.Session {
sessions = append(sessions, v)
}
if err = this.SendMsgToSession(string(this.GetType()), "playerhpchanage", &pb.ParkourPlayerHPChanagePush{
Uid: uid,
Hp: member.Hp,
}, sessions...); err != nil {
this.Errorln(err)
}
}
}
}

View File

@ -227,7 +227,7 @@ func (x *ParkourChangeMtsResp) GetMtsid() string {
return ""
}
//推送捕羊大赛用户信息改变
// //推送捕羊大赛用户信息改变
type ParkourInfoChangePush struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -1553,8 +1553,10 @@ type ParkourScoreChanagePush struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Red int32 `protobuf:"varint,1,opt,name=red,proto3" json:"red"`
Blue int32 `protobuf:"varint,2,opt,name=blue,proto3" json:"blue"`
Redscore int32 `protobuf:"varint,1,opt,name=redscore,proto3" json:"redscore"`
Redenergy int32 `protobuf:"varint,2,opt,name=redenergy,proto3" json:"redenergy"`
Bluescore int32 `protobuf:"varint,3,opt,name=bluescore,proto3" json:"bluescore"`
Blueenergy int32 `protobuf:"varint,4,opt,name=blueenergy,proto3" json:"blueenergy"`
}
func (x *ParkourScoreChanagePush) Reset() {
@ -1589,16 +1591,30 @@ func (*ParkourScoreChanagePush) Descriptor() ([]byte, []int) {
return file_parkour_parkour_msg_proto_rawDescGZIP(), []int{32}
}
func (x *ParkourScoreChanagePush) GetRed() int32 {
func (x *ParkourScoreChanagePush) GetRedscore() int32 {
if x != nil {
return x.Red
return x.Redscore
}
return 0
}
func (x *ParkourScoreChanagePush) GetBlue() int32 {
func (x *ParkourScoreChanagePush) GetRedenergy() int32 {
if x != nil {
return x.Blue
return x.Redenergy
}
return 0
}
func (x *ParkourScoreChanagePush) GetBluescore() int32 {
if x != nil {
return x.Bluescore
}
return 0
}
func (x *ParkourScoreChanagePush) GetBlueenergy() int32 {
if x != nil {
return x.Blueenergy
}
return 0
}
@ -2129,42 +2145,48 @@ var file_parkour_parkour_msg_proto_rawDesc = []byte{
0x6b, 0x6f, 0x75, 0x72, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x48, 0x50, 0x43, 0x68, 0x61, 0x6e,
0x61, 0x67, 0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x68, 0x70, 0x18,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x68, 0x70, 0x22, 0x3f, 0x0a, 0x17, 0x50, 0x61, 0x72,
0x6b, 0x6f, 0x75, 0x72, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x61, 0x67, 0x65,
0x50, 0x75, 0x73, 0x68, 0x12, 0x10, 0x0a, 0x03, 0x72, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
0x05, 0x52, 0x03, 0x72, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x22, 0x2f, 0x0a, 0x13, 0x50, 0x61,
0x72, 0x6b, 0x6f, 0x75, 0x72, 0x52, 0x61, 0x63, 0x65, 0x4f, 0x76, 0x65, 0x72, 0x50, 0x75, 0x73,
0x68, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x05, 0x52, 0x07, 0x77, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x22, 0x5d, 0x0a, 0x16, 0x52,
0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4a, 0x6f, 0x69, 0x6e, 0x4d, 0x61, 0x74,
0x63, 0x68, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69, 0x6e,
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69,
0x6e, 0x69, 0x64, 0x12, 0x25, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63, 0x65, 0x4d, 0x65, 0x6d, 0x62,
0x65, 0x72, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x19, 0x0a, 0x17, 0x52, 0x50,
0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4a, 0x6f, 0x69, 0x6e, 0x4d, 0x61, 0x74, 0x63,
0x68, 0x52, 0x65, 0x73, 0x70, 0x22, 0x38, 0x0a, 0x18, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b,
0x6f, 0x75, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65,
0x71, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x64, 0x22,
0x1b, 0x0a, 0x19, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x43, 0x61, 0x6e,
0x63, 0x65, 0x6c, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x22, 0x5c, 0x0a, 0x16,
0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x53,
0x75, 0x63, 0x63, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x03, 0x72, 0x65, 0x64, 0x18, 0x02, 0x20,
0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63, 0x65, 0x4d, 0x65, 0x6d, 0x62,
0x65, 0x72, 0x52, 0x03, 0x72, 0x65, 0x64, 0x12, 0x21, 0x0a, 0x04, 0x62, 0x75, 0x6c, 0x65, 0x18,
0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63, 0x65, 0x4d, 0x65,
0x6d, 0x62, 0x65, 0x72, 0x52, 0x04, 0x62, 0x75, 0x6c, 0x65, 0x22, 0x19, 0x0a, 0x17, 0x52, 0x50,
0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x53, 0x75, 0x63,
0x63, 0x52, 0x65, 0x73, 0x70, 0x22, 0x49, 0x0a, 0x19, 0x52, 0x50, 0x43, 0x5f, 0x50, 0x61, 0x72,
0x6b, 0x6f, 0x75, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x65, 0x73, 0x68, 0x69, 0x70, 0x52,
0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x69, 0x64, 0x12, 0x10,
0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64,
0x22, 0x1c, 0x0a, 0x1a, 0x52, 0x50, 0x43, 0x5f, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x54,
0x72, 0x75, 0x73, 0x74, 0x65, 0x65, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06,
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x68, 0x70, 0x22, 0x91, 0x01, 0x0a, 0x17, 0x50, 0x61,
0x72, 0x6b, 0x6f, 0x75, 0x72, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x61, 0x67,
0x65, 0x50, 0x75, 0x73, 0x68, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x64, 0x73, 0x63, 0x6f, 0x72,
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x64, 0x73, 0x63, 0x6f, 0x72,
0x65, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x18, 0x02,
0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x72, 0x65, 0x64, 0x65, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x12,
0x1c, 0x0a, 0x09, 0x62, 0x6c, 0x75, 0x65, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01,
0x28, 0x05, 0x52, 0x09, 0x62, 0x6c, 0x75, 0x65, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x1e, 0x0a,
0x0a, 0x62, 0x6c, 0x75, 0x65, 0x65, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28,
0x05, 0x52, 0x0a, 0x62, 0x6c, 0x75, 0x65, 0x65, 0x6e, 0x65, 0x72, 0x67, 0x79, 0x22, 0x2f, 0x0a,
0x13, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x52, 0x61, 0x63, 0x65, 0x4f, 0x76, 0x65, 0x72,
0x50, 0x75, 0x73, 0x68, 0x12, 0x18, 0x0a, 0x07, 0x77, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x77, 0x69, 0x6e, 0x73, 0x69, 0x64, 0x65, 0x22, 0x5d,
0x0a, 0x16, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4a, 0x6f, 0x69, 0x6e,
0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x70, 0x74,
0x61, 0x69, 0x6e, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x70,
0x74, 0x61, 0x69, 0x6e, 0x69, 0x64, 0x12, 0x25, 0x0a, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72,
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63, 0x65, 0x4d,
0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x06, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x19, 0x0a,
0x17, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4a, 0x6f, 0x69, 0x6e, 0x4d,
0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x22, 0x38, 0x0a, 0x18, 0x52, 0x50, 0x43, 0x50,
0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x61, 0x74, 0x63,
0x68, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69, 0x6e, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x70, 0x74, 0x61, 0x69, 0x6e,
0x69, 0x64, 0x22, 0x1b, 0x0a, 0x19, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72,
0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, 0x22,
0x5c, 0x0a, 0x16, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4d, 0x61, 0x74,
0x63, 0x68, 0x53, 0x75, 0x63, 0x63, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x03, 0x72, 0x65, 0x64,
0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63, 0x65, 0x4d,
0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x03, 0x72, 0x65, 0x64, 0x12, 0x21, 0x0a, 0x04, 0x62, 0x75,
0x6c, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x44, 0x42, 0x52, 0x61, 0x63,
0x65, 0x4d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x52, 0x04, 0x62, 0x75, 0x6c, 0x65, 0x22, 0x19, 0x0a,
0x17, 0x52, 0x50, 0x43, 0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x4d, 0x61, 0x74, 0x63, 0x68,
0x53, 0x75, 0x63, 0x63, 0x52, 0x65, 0x73, 0x70, 0x22, 0x49, 0x0a, 0x19, 0x52, 0x50, 0x43, 0x5f,
0x50, 0x61, 0x72, 0x6b, 0x6f, 0x75, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x65, 0x73, 0x68,
0x69, 0x70, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x69,
0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x75, 0x69, 0x64, 0x22, 0x1c, 0x0a, 0x1a, 0x52, 0x50, 0x43, 0x5f, 0x50, 0x61, 0x72, 0x6b, 0x6f,
0x75, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x65, 0x65, 0x73, 0x68, 0x69, 0x70, 0x52, 0x65, 0x73,
0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
}
var (