241 lines
6.0 KiB
Go
241 lines
6.0 KiB
Go
package practice
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/base"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
/*
|
|
模块名:熊猫武馆 练功子系统
|
|
描述:熊猫武馆 主系统 打桩 以及武馆相关数据管理
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Practice)
|
|
return m
|
|
}
|
|
|
|
type Practice struct {
|
|
modules.ModuleBase
|
|
service base.IRPCXService
|
|
friend comm.IFriend
|
|
mail comm.Imail
|
|
atlas comm.IPandaAtlas
|
|
api *apiComp
|
|
configure *configureComp
|
|
modelPandata *modelPandata
|
|
modelQiecuo *modelQiecuo
|
|
}
|
|
|
|
//模块名
|
|
func (this *Practice) GetType() core.M_Modules {
|
|
return comm.ModulePractice
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Practice) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service.(base.IRPCXService)
|
|
return
|
|
}
|
|
func (this *Practice) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleFriend); err != nil {
|
|
return
|
|
}
|
|
this.friend = module.(comm.IFriend)
|
|
if module, err = this.service.GetModule(comm.ModuleMail); err != nil {
|
|
return
|
|
}
|
|
this.mail = module.(comm.Imail)
|
|
if module, err = this.service.GetModule(comm.ModulePandaAtlas); err != nil {
|
|
return
|
|
}
|
|
this.atlas = module.(comm.IPandaAtlas)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Practice) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
this.modelPandata = this.RegisterComp(new(modelPandata)).(*modelPandata)
|
|
this.modelQiecuo = this.RegisterComp(new(modelQiecuo)).(*modelQiecuo)
|
|
}
|
|
|
|
func (this *Practice) AddItems(session comm.IUserSession, items map[string]int32, bPush bool) (code pb.ErrorCode) {
|
|
var (
|
|
err error
|
|
room *pb.DBPracticeRoom
|
|
id []string
|
|
)
|
|
if room, err = this.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
id = make([]string, 0)
|
|
for k, _ := range items {
|
|
room.Knapsack[k] = 0
|
|
id = append(id, k)
|
|
this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), k)
|
|
}
|
|
this.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"knapsack": room.Knapsack,
|
|
})
|
|
session.SendMsg(string(this.GetType()), "jxitem", &pb.PracticeJXItemPush{Id: id})
|
|
return
|
|
}
|
|
|
|
//完成世界任务
|
|
func (this *Practice) TaskComplete(session comm.IUserSession, taskid int32) {
|
|
var (
|
|
configure []*cfg.GamePandamasJsData
|
|
room *pb.DBPracticeRoom
|
|
err error
|
|
)
|
|
if configure, err = this.configure.getGamePandamasJs(); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
if room, err = this.modelPandata.queryUserMartialhall(session.GetUserId()); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
for _, v := range configure {
|
|
if v.UnlockCondition == taskid {
|
|
switch v.Id {
|
|
case 1:
|
|
if !room.Pillar1.Isunlock {
|
|
room.Pillar1.Isunlock = true
|
|
}
|
|
this.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"pillar1": room.Pillar1,
|
|
})
|
|
this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), "1001")
|
|
break
|
|
case 2:
|
|
if !room.Pillar2.Isunlock {
|
|
room.Pillar2.Isunlock = true
|
|
}
|
|
this.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"pillar2": room.Pillar2,
|
|
})
|
|
this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), "1001")
|
|
break
|
|
case 3:
|
|
if !room.Pillar3.Isunlock {
|
|
room.Pillar3.Isunlock = true
|
|
}
|
|
this.modelPandata.Change(session.GetUserId(), map[string]interface{}{
|
|
"pillar3": room.Pillar3,
|
|
})
|
|
this.atlas.CheckActivatePandaAtlasCollect(session.GetUserId(), "1001")
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func (this *Practice) ChallengeResults(bid, red, bule string, winSide int32) {
|
|
var (
|
|
redroom *pb.DBPracticeRoom
|
|
reduser *pb.DBUser
|
|
buleroom *pb.DBPracticeRoom
|
|
buleuser *pb.DBUser
|
|
keep bool
|
|
err error
|
|
)
|
|
|
|
qr := this.modelQiecuo.getQiecuo(red)
|
|
if qr != nil && qr.MatchId == bid {
|
|
this.Debug("清理切磋记录",
|
|
log.Field{Key: "redUid", Value: red},
|
|
log.Field{Key: "matchId", Value: bid})
|
|
//更新时间戳
|
|
update := map[string]interface{}{
|
|
"endTime": configure.Now().Unix(),
|
|
}
|
|
if err = this.modelQiecuo.Change(red, update); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
return
|
|
|
|
}
|
|
|
|
if winSide == 0 {
|
|
return
|
|
}
|
|
reduser = this.ModuleUser.GetUser(red)
|
|
buleuser = this.ModuleUser.GetUser(bule)
|
|
if redroom, err = this.modelPandata.queryUserMartialhall(red); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
if buleroom, err = this.modelPandata.queryUserMartialhall(bule); err != nil {
|
|
this.Errorln(err)
|
|
return
|
|
}
|
|
if winSide == 1 { //红方胜利
|
|
keep = false
|
|
for _, v := range buleroom.Statuers {
|
|
if v.Uid == red {
|
|
v.Create = configure.Now().Unix()
|
|
keep = true
|
|
break
|
|
}
|
|
}
|
|
if !keep {
|
|
buleroom.Statuers = append(buleroom.Statuers, &pb.DBPracticeStatuer{
|
|
Uid: red,
|
|
Figure: reduser.Figure,
|
|
Create: configure.Now().Unix(),
|
|
})
|
|
}
|
|
|
|
for i, v := range redroom.Statuers {
|
|
if v.Uid == bule { //移除雕像
|
|
redroom.Statuers = append(redroom.Statuers[0:i], redroom.Statuers[i+1:]...)
|
|
break
|
|
}
|
|
}
|
|
|
|
} else {
|
|
keep = false
|
|
for _, v := range redroom.Statuers {
|
|
if v.Uid == bule {
|
|
v.Create = configure.Now().Unix()
|
|
keep = true
|
|
break
|
|
}
|
|
}
|
|
if !keep {
|
|
redroom.Statuers = append(redroom.Statuers, &pb.DBPracticeStatuer{
|
|
Uid: bule,
|
|
Figure: buleuser.Figure,
|
|
Create: configure.Now().Unix(),
|
|
})
|
|
}
|
|
for i, v := range buleroom.Statuers {
|
|
if v.Uid == red { //移除雕像
|
|
buleroom.Statuers = append(buleroom.Statuers[0:i], buleroom.Statuers[i+1:]...)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
this.modelPandata.Change(red, map[string]interface{}{
|
|
"statuers": redroom.Statuers,
|
|
})
|
|
this.modelPandata.Change(bule, map[string]interface{}{
|
|
"statuers": buleroom.Statuers,
|
|
})
|
|
}
|