113 lines
3.0 KiB
Go
113 lines
3.0 KiB
Go
package battle
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
)
|
|
|
|
/*
|
|
模块名:战斗模块
|
|
描述:处理游侠战斗相关业务
|
|
开发:李伟
|
|
*/
|
|
func NewModule() core.IModule {
|
|
m := new(Battle)
|
|
return m
|
|
}
|
|
|
|
type Battle struct {
|
|
modules.ModuleBase
|
|
service core.IService
|
|
moonfantasy comm.IMoonFantasy //月之秘境模块
|
|
api_comp *apiComp
|
|
configure *configureComp
|
|
modelBattle *modelBattleComp
|
|
}
|
|
|
|
//模块名
|
|
func (this *Battle) GetType() core.M_Modules {
|
|
return comm.ModuleBattle
|
|
}
|
|
|
|
//模块初始化接口 注册用户创建角色事件
|
|
func (this *Battle) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
|
err = this.ModuleBase.Init(service, module, options)
|
|
this.service = service
|
|
return
|
|
}
|
|
func (this *Battle) Start() (err error) {
|
|
err = this.ModuleBase.Start()
|
|
var module core.IModule
|
|
if module, err = this.service.GetModule(comm.ModuleMoonfantasy); err != nil {
|
|
return
|
|
}
|
|
this.moonfantasy = module.(comm.IMoonFantasy)
|
|
return
|
|
}
|
|
|
|
//装备组件
|
|
func (this *Battle) OnInstallComp() {
|
|
this.ModuleBase.OnInstallComp()
|
|
this.api_comp = this.RegisterComp(new(apiComp)).(*apiComp)
|
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
|
this.modelBattle = this.RegisterComp(new(modelBattleComp)).(*modelBattleComp)
|
|
}
|
|
|
|
//查询战斗记录
|
|
func (this *Battle) QueryBattleRecord(oid string) (code pb.ErrorCode, record *pb.DBBattleRecord) {
|
|
var err error
|
|
if record, err = this.modelBattle.queryrecord(oid); err != nil {
|
|
code = pb.ErrorCode_BattleNoFoundRecord
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve战斗
|
|
func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, record *pb.DBBattleRecord) {
|
|
var conn *db.DBConn
|
|
if this.service.GetTag() == session.GetServiecTag() {
|
|
conn = db.Local()
|
|
} else {
|
|
conn = db.ServerDBConn(session.GetServiecTag())
|
|
}
|
|
if req.Ptype < 0 || req.Ptype > 4 ||
|
|
req.Teamids == nil || len(req.Teamids) != 5 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if record, code = this.modelBattle.createpve(session, conn, pb.BattleType_pve, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//创建pve战斗
|
|
func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVEReq) (code pb.ErrorCode, record *pb.DBBattleRecord) {
|
|
var conn *db.DBConn
|
|
if this.service.GetTag() == session.GetServiecTag() {
|
|
conn = db.Local()
|
|
} else {
|
|
conn = db.ServerDBConn(session.GetServiecTag())
|
|
}
|
|
if req.Ptype < 0 || req.Ptype > 4 ||
|
|
req.Teamids == nil || len(req.Teamids) != 5 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if record, code = this.modelBattle.createpve(session, conn, pb.BattleType_pvb, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
//校验战报是否成功
|
|
func (this *Battle) CheckBattleReport(session comm.IUserSession, report *pb.BattleReport) (code pb.ErrorCode, iswin bool) {
|
|
|
|
this.moonfantasy.Trigger(session, report)
|
|
return pb.ErrorCode_Success, true
|
|
}
|