上传竞技场代码
This commit is contained in:
parent
d2512f3d6b
commit
ad42740fb3
@ -500,6 +500,8 @@ type (
|
||||
PvpFinishPush(out *pb.BattleFinishPush)
|
||||
//用户离线
|
||||
UserOffline(roomid string, uid string) (err error)
|
||||
//创建pvp战斗
|
||||
CreateRoomById(id string, ptype pb.PvpType, sessions []IUserSession, uinfos []*pb.BaseUserInfo) (err error)
|
||||
}
|
||||
|
||||
ISmithy interface {
|
||||
|
@ -151,6 +151,40 @@ func (this *Pvp) CreateRoom(sessions []comm.IUserSession, rulesStr string) (room
|
||||
return
|
||||
}
|
||||
|
||||
// 创建Pvp
|
||||
func (this *Pvp) CreateRoomById(id string, ptype pb.PvpType, sessions []comm.IUserSession, uinfos []*pb.BaseUserInfo) (err error) {
|
||||
this.Debug("CreatePvp", log.Field{Key: "ptype", Value: ptype}, log.Field{Key: "sessions", Value: sessions})
|
||||
var (
|
||||
battle *BattleItem
|
||||
)
|
||||
|
||||
battle = &BattleItem{
|
||||
Id: id,
|
||||
Ptype: ptype,
|
||||
State: pb.PvpState_ready,
|
||||
RedSession: sessions[0],
|
||||
BlueSession: sessions[1],
|
||||
Red: uinfos[0],
|
||||
Blue: uinfos[1],
|
||||
readytimer: timewheel.Add(time.Second*60, this.readyTimeOut, id),
|
||||
curroperate: &pb.ComWaitInputSkill{},
|
||||
}
|
||||
|
||||
this.lock.Lock()
|
||||
this.battles[battle.Id] = battle
|
||||
this.lock.Unlock()
|
||||
if err = this.SendMsgToSession(string(comm.ModulePvp), "ready", &pb.PvpReadyPush{
|
||||
ServicePath: fmt.Sprintf("%s/%s", this.service.GetType(), this.service.GetId()),
|
||||
Battleid: battle.Id,
|
||||
Red: battle.Red,
|
||||
Blue: battle.Blue,
|
||||
Countdown: 60,
|
||||
}, battle.RedSession, battle.BlueSession); err != nil {
|
||||
this.Errorln(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 推送战斗输出指令
|
||||
func (this *Pvp) PvpOutCmdPush(out *pb.PvpOutCmdPush) {
|
||||
this.Debug("PvpOutCmdPush", log.Field{Key: "args", Value: out})
|
||||
|
@ -25,6 +25,7 @@ func NewModule() core.IModule {
|
||||
type RealArena struct {
|
||||
modules.ModuleBase
|
||||
service base.IRPCXService
|
||||
pvp comm.IPvp
|
||||
apicomp *apiComp
|
||||
model *modelComp
|
||||
match *matchComp
|
||||
@ -49,6 +50,12 @@ func (this *RealArena) Start() (err error) {
|
||||
if err = this.ModuleBase.Start(); err != nil {
|
||||
return
|
||||
}
|
||||
var module core.IModule
|
||||
|
||||
if module, err = this.service.GetModule(comm.ModulePvp); err != nil {
|
||||
return
|
||||
}
|
||||
this.pvp = module.(comm.IPvp)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,9 @@ func (this *Room) selectheros(uid string, heros []string) (err error) {
|
||||
err = fmt.Errorf("cant handle!")
|
||||
return
|
||||
}
|
||||
|
||||
if uid == this.members[1].User.Uid {
|
||||
this.step++
|
||||
}
|
||||
for _, v := range this.members {
|
||||
if v.User.Uid == uid {
|
||||
v.Heros = heros
|
||||
@ -61,17 +63,59 @@ func (this *Room) selectheros(uid string, heros []string) (err error) {
|
||||
Num: 2,
|
||||
Countdown: 10,
|
||||
})
|
||||
if this.step == 4 { //选完了
|
||||
this.PushMessage("startdisableHero", &pb.RealArenaStartDisableHeroPush{
|
||||
Uid: this.members[0].User.Uid,
|
||||
Countdown: 10,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//禁用英雄
|
||||
func (this *Room) disableheros(uid string, index int32) (err error) {
|
||||
|
||||
var isend bool
|
||||
for _, v := range this.members {
|
||||
if v.User.Uid == uid {
|
||||
v.Disable = index
|
||||
}
|
||||
if v.Disable == -1 {
|
||||
isend = false
|
||||
}
|
||||
}
|
||||
this.PushMessage("selecthero", &pb.RealArenaDisableHeroPush{
|
||||
Uid: uid,
|
||||
Index: index,
|
||||
})
|
||||
if isend {
|
||||
this.PushMessage("startselectleader", &pb.RealArenaStartSelectLeaderPush{
|
||||
Uid: this.members[0].User.Uid,
|
||||
Countdown: 10,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
//选择队长
|
||||
func (this *Room) selectleader(uid string, index int32) (err error) {
|
||||
var isend bool
|
||||
for _, v := range this.members {
|
||||
if v.User.Uid == uid {
|
||||
v.Leader = index
|
||||
}
|
||||
if v.Leader == -1 {
|
||||
isend = false
|
||||
}
|
||||
}
|
||||
this.PushMessage("selectleader", &pb.RealArenaSelectLeaderPush{
|
||||
Uid: uid,
|
||||
Index: index,
|
||||
})
|
||||
if isend {
|
||||
var uinfos []*pb.BaseUserInfo = make([]*pb.BaseUserInfo, 0)
|
||||
uinfos = append(uinfos, this.members[0].User, this.members[1].User)
|
||||
err = this.module.pvp.CreateRoomById(this.Id, pb.PvpType_realarena, this.sessions, uinfos)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -25,15 +25,18 @@ type PvpType int32
|
||||
|
||||
const (
|
||||
PvpType_friends PvpType = 0 //好友切磋
|
||||
PvpType_realarena PvpType = 1 //实时竞技场
|
||||
)
|
||||
|
||||
// Enum value maps for PvpType.
|
||||
var (
|
||||
PvpType_name = map[int32]string{
|
||||
0: "friends",
|
||||
1: "realarena",
|
||||
}
|
||||
PvpType_value = map[string]int32{
|
||||
"friends": 0,
|
||||
"realarena": 1,
|
||||
}
|
||||
)
|
||||
|
||||
@ -274,13 +277,14 @@ var file_pvp_pvp_db_proto_rawDesc = []byte{
|
||||
0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x03, 0x72, 0x65, 0x64,
|
||||
0x12, 0x21, 0x0a, 0x04, 0x62, 0x6c, 0x75, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d,
|
||||
0x2e, 0x42, 0x61, 0x73, 0x65, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x04, 0x62,
|
||||
0x6c, 0x75, 0x65, 0x2a, 0x16, 0x0a, 0x07, 0x50, 0x76, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b,
|
||||
0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x10, 0x00, 0x2a, 0x43, 0x0a, 0x08, 0x50,
|
||||
0x76, 0x70, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x76, 0x6f, 0x69, 0x64, 0x10,
|
||||
0x00, 0x12, 0x09, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06,
|
||||
0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x61, 0x6e, 0x63,
|
||||
0x65, 0x6c, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x10, 0x04,
|
||||
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6c, 0x75, 0x65, 0x2a, 0x25, 0x0a, 0x07, 0x50, 0x76, 0x70, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b,
|
||||
0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x72,
|
||||
0x65, 0x61, 0x6c, 0x61, 0x72, 0x65, 0x6e, 0x61, 0x10, 0x01, 0x2a, 0x43, 0x0a, 0x08, 0x50, 0x76,
|
||||
0x70, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x76, 0x6f, 0x69, 0x64, 0x10, 0x00,
|
||||
0x12, 0x09, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x62,
|
||||
0x61, 0x74, 0x74, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x61, 0x6e, 0x63, 0x65,
|
||||
0x6c, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x10, 0x04, 0x42,
|
||||
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user