海岛探险代码

This commit is contained in:
liwei1dao 2023-11-02 10:48:17 +08:00
parent 80fa52bbdd
commit 1bdbc69064
9 changed files with 707 additions and 348 deletions

View File

@ -290,6 +290,7 @@ type (
CreateEveBattle(session IUserSession, req *pb.BattleEVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord)
///创建pve战斗
CreatePveBattle(session IUserSession, req *pb.BattlePVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord)
CreateHeroPveBattle(session IUserSession, req *pb.BattleHeroPVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord)
///创建pvb战斗
CreatePvbBattle(session IUserSession, req *pb.BattlePVBReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord)
///创建pvp战斗

View File

@ -715,6 +715,84 @@ func (this *modelBattleComp) createlpve(session comm.IUserSession, conn *db.DBCo
return
}
// 创建pve 战斗记录
func (this *modelBattleComp) createheropve(session comm.IUserSession, conn *db.DBConn, btype pb.BattleType, req *pb.BattleHeroPVEReq, conf *cfg.GameBattleReadyData) (record *pb.DBBattleRecord, errdata *pb.ErrorData) {
var (
captain int32
masters []*pb.BattleRole
)
record = &pb.DBBattleRecord{
Id: primitive.NewObjectID().Hex(),
Title: req.Title,
Btype: btype,
Ptype: req.Ptype,
State: pb.BBattleState_in,
RedCompId: session.GetUserId(),
Redflist: make([]*pb.DBBattleFormt, 1),
BlueCompId: "",
Buleflist: make([]*pb.DBBattleFormt, len(req.Mformat)),
Tasks: conf.BattleEvents,
}
record.Redflist[0] = &pb.DBBattleFormt{
Leadpos: req.Redformat.Leadpos,
Team: make([]*pb.BattleRole, len(req.Redformat.Format)),
}
//自己的英雄阵营
for i, v := range req.Redformat.Format {
if v != nil {
tid := 100 + i
if record.Redflist[0].Team[i], errdata = this.createBattleRole(v, 0, tid, i); errdata != nil {
return
}
} else {
record.Redflist[0].Team[i] = nil
}
}
if conf.DefaultHero != 0 {
if captain, masters, errdata = this.createMasterRoles(1100, 0, conf.DefaultHero); errdata != nil {
return
}
record.Redflist[0].Systeam = masters
if record.Redflist[0].Leadpos == -1 && captain != -1 {
record.Redflist[0].Leadpos = captain
}
}
if conf.RedAssistTeam != 0 {
if captain, masters, errdata = this.createMasterRoles(1200, 0, conf.RedAssistTeam); errdata != nil {
return
}
record.Redflist[0].Backupteam = masters
}
//队长级 弃用
// if ok := this.checkBattlereadyCapskill(req.Format.Leadpos, heros); !ok {
// errdata = &pb.ErrorData{
// Code: pb.ErrorCode_BattleCapskillCheckFailed,
// Title: pb.ErrorCode_BattleCapskillCheckFailed.ToString(),
// }
// return
// }
for i, v := range req.Mformat {
if captain, masters, errdata = this.createMasterRoles(2100, i, v); errdata != nil {
return
}
record.Buleflist[i] = &pb.DBBattleFormt{
Leadpos: captain,
Team: masters,
}
}
if conf.BlueAssistTeam != 0 {
if captain, masters, errdata = this.createMasterRoles(2200, 0, conf.BlueAssistTeam); errdata != nil {
return
}
record.Buleflist[0].Backupteam = masters
}
return
}
func (this *modelBattleComp) createBattleRole(hero *pb.DBHero, vlv int32, tid, pos int) (role *pb.BattleRole, errdata *pb.ErrorData) {
role = &pb.BattleRole{
Tid: int32(tid),

View File

@ -201,6 +201,50 @@ func (this *Battle) CreatePveBattle(session comm.IUserSession, req *pb.BattlePVE
return
}
// 创建连续战斗
func (this *Battle) CreateHeroPveBattle(session comm.IUserSession, req *pb.BattleHeroPVEReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) {
var (
conf *cfg.GameBattleReadyData
conn *db.DBConn
err error
)
if !this.IsCross() {
conn, err = db.Local()
} else {
conn, err = db.ServerDBConn(session.GetServiecTag())
}
if err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
this.Errorf("session:%v err:", session, err)
return
}
if req.Redformat == nil || req.Redformat.Format == nil || len(req.Redformat.Format) != 5 {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
}
return
}
if conf, err = this.configure.GetBattleReady(req.Rulesid); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if record, errdata = this.modelBattle.createheropve(session, conn, pb.BattleType_lpev, req, conf); errdata != nil {
return
}
return
}
// 创建pve战斗
func (this *Battle) CreatePvbBattle(session comm.IUserSession, req *pb.BattlePVBReq) (errdata *pb.ErrorData, record *pb.DBBattleRecord) {
var (

View File

@ -26,10 +26,14 @@ func (this *apiComp) BattleCheck(session comm.IUserSession, req *pb.IsLandBattle
// /获取系统公告
func (this *apiComp) Battle(session comm.IUserSession, req *pb.IsLandBattleReq) (errdata *pb.ErrorData) {
var (
conf *cfg.GamePuggsyEventData
bconf *cfg.GamePuggsyFightData
record *pb.DBBattleRecord
err error
info *pb.DBIsland
conf *cfg.GamePuggsyEventData
bconf *cfg.GamePuggsyFightData
heroids []string
heros []*pb.DBHero
tempHeros []*pb.DBHero
record *pb.DBBattleRecord
err error
)
if errdata = this.BattleCheck(session, req); errdata != nil {
return
@ -50,11 +54,53 @@ func (this *apiComp) Battle(session comm.IUserSession, req *pb.IsLandBattleReq)
}
return
}
if errdata, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
if info, err = this.module.model.getmodel(session.GetUserId()); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
heroids = make([]string, 0)
for _, v := range req.Battle.Format {
if v != "" {
heroids = append(heroids, v)
}
}
if tempHeros, err = this.module.modelhero.getHeros(session.GetUserId(), heroids); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Message: err.Error(),
}
return
}
if err = this.module.model.compute(info, heros); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Message: err.Error(),
}
return
}
heros = make([]*pb.DBHero, 5)
for i, v := range req.Battle.Format {
for _, v1 := range tempHeros {
if v == v1.Id {
heros[i] = v1
}
}
}
if errdata, record = this.module.battle.CreateHeroPveBattle(session, &pb.BattleHeroPVEReq{
Rulesid: bconf.BattleReadyID,
Ptype: pb.PlayType_rtask,
Format: req.Battle,
Mformat: bconf.Boss,
Redformat: &pb.PVPFormation{
Uid: session.GetUserId(),
Leadpos: req.Battle.Leadpos,
Format: heros,
},
}); err != nil {
return
}

View File

@ -1,7 +1,6 @@
package island
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
@ -16,10 +15,10 @@ func (this *apiComp) UpgradeCheck(session comm.IUserSession, req *pb.IsLandUpgra
// /获取自己的排行榜信息
func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.IsLandUpgradeReq) (errdata *pb.ErrorData) {
var (
info *pb.DBIsland
conf *cfg.GamePuggsySkillData
ok bool
err error
info *pb.DBIsland
conf *cfg.GamePuggsySkillData
front *cfg.GamePuggsySkillData
err error
)
if errdata = this.UpgradeCheck(session, req); errdata != nil {
return
@ -40,18 +39,39 @@ func (this *apiComp) Upgrade(session comm.IUserSession, req *pb.IsLandUpgradeReq
}
return
}
if _, ok = info.Nodes[conf.Id]; ok {
if conf.CostItem != nil && len(conf.CostItem) > 0 { //可有升级
for _, _front := range conf.Front {
if _front > 0 {
if front, err = this.module.configure.getGamePuggsySkillData(_front); err != nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ConfigNoFound,
Title: pb.ErrorCode_ConfigNoFound.ToString(),
Message: err.Error(),
}
return
}
if v, ok := info.Nodes[front.NodeId]; !ok || v < front.Lv {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: "node Front no complete",
}
return
}
}
}
} else {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_ReqParameterError,
Title: pb.ErrorCode_ReqParameterError.ToString(),
Message: fmt.Sprintf("%d Unlocked!", conf.Id),
Message: "The level has reached the upper limit",
}
return
}
if errdata = this.module.ConsumeRes(session, conf.CostItem, true); errdata != nil {
return
}
info.Nodes[conf.Id] = 1
info.Nodes[conf.NodeId] = conf.Lv + 1
this.module.model.Change(session.GetUserId(), map[string]interface{}{
"nodes": info.Nodes,
})

View File

@ -92,6 +92,25 @@ func (this *ConfigureComp) getGamePuggsySkillData(id int32) (configure *cfg.Game
return
}
//技能节点
func (this *ConfigureComp) getGamePuggsySkilllvData(nid, lv int32) (conf *cfg.GamePuggsySkillData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_puggsyskill); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
for _, v := range v.(*cfg.GamePuggsySkill).GetDataList() {
if v.NodeId == nid && v.Lv == lv {
conf = v
return
}
}
}
return
}
// 获取伤害对应的评分组
func (this *ConfigureComp) getGamePuggsyScoreData(harm int32) (results *cfg.GamePuggsyScoreData, err error) {
var (

View File

@ -6,6 +6,8 @@ import (
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
@ -48,3 +50,39 @@ func (this *modelComp) getmodel(uid string) (result *pb.DBIsland, err error) {
err = nil
return
}
//计算属性
func (this *modelComp) compute(info *pb.DBIsland, heros []*pb.DBHero) (err error) {
var (
node *cfg.GamePuggsySkillData
property map[string]int32 = make(map[string]int32)
)
for k, v := range info.Nodes {
if node, err = this.module.configure.getGamePuggsySkilllvData(k, v); err != nil {
this.module.Errorln(err)
return
}
for _, v := range node.Upgrade {
property[v.A] += v.N
}
}
for _, hero := range heros {
for k, v := range property {
hero.Property[k] += v
}
for k, v := range hero.Property {
switch k {
case comm.AtkPro:
hero.Property[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Atk])))
case comm.DefPro:
hero.Property[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Def])))
case comm.HpPro:
hero.Property[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Hp])))
case comm.SpeedPro:
hero.Property[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Speed])))
}
}
}
return
}

View File

@ -33,6 +33,13 @@ func (this *modelHeroComp) getHeroList(uid string) (heros []*pb.DBHero, err erro
return
}
// 获取玩家的英雄
func (this *modelHeroComp) getHeros(uid string, ids []string) (heros []*pb.DBHero, err error) {
heros = make([]*pb.DBHero, 0)
err = this.GetListObjs(uid, ids, &heros)
return
}
func (this *modelHeroComp) addheros(heros *pb.DBHero) (err error) {
return
}

File diff suppressed because it is too large Load Diff