上传竞技场代码
This commit is contained in:
parent
d2512f3d6b
commit
ad42740fb3
@ -500,6 +500,8 @@ type (
|
|||||||
PvpFinishPush(out *pb.BattleFinishPush)
|
PvpFinishPush(out *pb.BattleFinishPush)
|
||||||
//用户离线
|
//用户离线
|
||||||
UserOffline(roomid string, uid string) (err error)
|
UserOffline(roomid string, uid string) (err error)
|
||||||
|
//创建pvp战斗
|
||||||
|
CreateRoomById(id string, ptype pb.PvpType, sessions []IUserSession, uinfos []*pb.BaseUserInfo) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
ISmithy interface {
|
ISmithy interface {
|
||||||
|
@ -151,6 +151,40 @@ func (this *Pvp) CreateRoom(sessions []comm.IUserSession, rulesStr string) (room
|
|||||||
return
|
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) {
|
func (this *Pvp) PvpOutCmdPush(out *pb.PvpOutCmdPush) {
|
||||||
this.Debug("PvpOutCmdPush", log.Field{Key: "args", Value: out})
|
this.Debug("PvpOutCmdPush", log.Field{Key: "args", Value: out})
|
||||||
|
@ -25,6 +25,7 @@ func NewModule() core.IModule {
|
|||||||
type RealArena struct {
|
type RealArena struct {
|
||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
|
pvp comm.IPvp
|
||||||
apicomp *apiComp
|
apicomp *apiComp
|
||||||
model *modelComp
|
model *modelComp
|
||||||
match *matchComp
|
match *matchComp
|
||||||
@ -49,6 +50,12 @@ func (this *RealArena) Start() (err error) {
|
|||||||
if err = this.ModuleBase.Start(); err != nil {
|
if err = this.ModuleBase.Start(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var module core.IModule
|
||||||
|
|
||||||
|
if module, err = this.service.GetModule(comm.ModulePvp); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.pvp = module.(comm.IPvp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ func (this *Room) selectheros(uid string, heros []string) (err error) {
|
|||||||
err = fmt.Errorf("cant handle!")
|
err = fmt.Errorf("cant handle!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if uid == this.members[1].User.Uid {
|
||||||
|
this.step++
|
||||||
|
}
|
||||||
for _, v := range this.members {
|
for _, v := range this.members {
|
||||||
if v.User.Uid == uid {
|
if v.User.Uid == uid {
|
||||||
v.Heros = heros
|
v.Heros = heros
|
||||||
@ -61,17 +63,59 @@ func (this *Room) selectheros(uid string, heros []string) (err error) {
|
|||||||
Num: 2,
|
Num: 2,
|
||||||
Countdown: 10,
|
Countdown: 10,
|
||||||
})
|
})
|
||||||
|
if this.step == 4 { //选完了
|
||||||
|
this.PushMessage("startdisableHero", &pb.RealArenaStartDisableHeroPush{
|
||||||
|
Uid: this.members[0].User.Uid,
|
||||||
|
Countdown: 10,
|
||||||
|
})
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//禁用英雄
|
//禁用英雄
|
||||||
func (this *Room) disableheros(uid string, index int32) (err error) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//选择队长
|
//选择队长
|
||||||
func (this *Room) selectleader(uid string, index int32) (err error) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,19 @@ const (
|
|||||||
type PvpType int32
|
type PvpType int32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PvpType_friends PvpType = 0 //好友切磋
|
PvpType_friends PvpType = 0 //好友切磋
|
||||||
|
PvpType_realarena PvpType = 1 //实时竞技场
|
||||||
)
|
)
|
||||||
|
|
||||||
// Enum value maps for PvpType.
|
// Enum value maps for PvpType.
|
||||||
var (
|
var (
|
||||||
PvpType_name = map[int32]string{
|
PvpType_name = map[int32]string{
|
||||||
0: "friends",
|
0: "friends",
|
||||||
|
1: "realarena",
|
||||||
}
|
}
|
||||||
PvpType_value = map[string]int32{
|
PvpType_value = map[string]int32{
|
||||||
"friends": 0,
|
"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,
|
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,
|
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,
|
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,
|
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, 0x2a, 0x43, 0x0a, 0x08, 0x50,
|
0x0a, 0x07, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x72,
|
||||||
0x76, 0x70, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x76, 0x6f, 0x69, 0x64, 0x10,
|
0x65, 0x61, 0x6c, 0x61, 0x72, 0x65, 0x6e, 0x61, 0x10, 0x01, 0x2a, 0x43, 0x0a, 0x08, 0x50, 0x76,
|
||||||
0x00, 0x12, 0x09, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06,
|
0x70, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x76, 0x6f, 0x69, 0x64, 0x10, 0x00,
|
||||||
0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x61, 0x6e, 0x63,
|
0x12, 0x09, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x62,
|
||||||
0x65, 0x6c, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x10, 0x04,
|
0x61, 0x74, 0x74, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x63, 0x61, 0x6e, 0x63, 0x65,
|
||||||
0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
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 (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user