Merge branch 'meixiongfeng' of http://git.legu.cc/liwei_3d/go_dreamfactory into dev

This commit is contained in:
meixiongfeng 2023-01-03 18:15:39 +08:00
commit d89de8a808
5 changed files with 119 additions and 68 deletions

View File

@ -71,6 +71,8 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
ret := this.module.CheckCondition(session.GetUserId()) ret := this.module.CheckCondition(session.GetUserId())
if ret == true { // 命中插入5星英雄 if ret == true { // 命中插入5星英雄
szStar = append(szStar, 5) szStar = append(szStar, 5)
heroRecord.Star5 = 0 // 重置保底
star5Max++ // 记录当前 5星数量
continue continue
} }
// 3,4,5 星权重 // 3,4,5 星权重
@ -95,16 +97,34 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
if heroRecord.Inevitable == 0 && heroRecord.Drawcount > iStart && heroRecord.Drawcount < iEnd && iEnd >= iStart { if heroRecord.Inevitable == 0 && heroRecord.Drawcount > iStart && heroRecord.Drawcount < iEnd && iEnd >= iStart {
n, _ := rand.Int(rand.Reader, big.NewInt(int64(iEnd-iStart))) n, _ := rand.Int(rand.Reader, big.NewInt(int64(iEnd-iStart)))
if n.Int64() < 1 { // 抽中 if n.Int64() < 1 { // 抽中
starIndex = star - 3 starIndex = star
heroRecord.Inevitable = heroRecord.Drawcount heroRecord.Inevitable = heroRecord.Drawcount
update["inevitable"] = heroRecord.Drawcount update["inevitable"] = heroRecord.Drawcount
szStar = append(szStar, star)
if star == 4 {
heroRecord.Star4 = 0
star4Max++
} else if star == 5 {
star5Max++
heroRecord.Star5 = 0
}
continue
} }
} }
// 保底情况 // 保底情况
if heroRecord.Drawcount == iEnd && heroRecord.Inevitable == 0 { if heroRecord.Drawcount == iEnd && heroRecord.Inevitable == 0 {
starIndex = star - 3 starIndex = star
heroRecord.Inevitable = heroRecord.Drawcount heroRecord.Inevitable = heroRecord.Drawcount
update["inevitable"] = heroRecord.Drawcount update["inevitable"] = heroRecord.Drawcount
szStar = append(szStar, star)
if star == 4 {
heroRecord.Star4 = 0
star4Max++
} else if star == 5 {
star5Max++
heroRecord.Star5 = 0
}
continue
} }
} }
} }

View File

@ -55,9 +55,14 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh
} }
} }
// 校验通过 // 校验通过
code, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if code != pb.ErrorCode_Success { if req.Report != nil { // 战斗失败
return code, isWin = this.module.battle.CheckBattleReport(session, req.Report)
if code != pb.ErrorCode_Success {
return
}
} else {
isWin = false
} }
if !isWin { // 战斗失败直接返回 if !isWin { // 战斗失败直接返回
// 返还 // 返还
@ -66,7 +71,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MainlineCh
"ps": 0, "ps": 0,
}) })
if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 扣1点 if code = this.module.DispenseRes(session, node.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力
return return
} }
code = pb.ErrorCode_BattleNoWin code = pb.ErrorCode_BattleNoWin

View File

@ -91,6 +91,7 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
code = pb.ErrorCode_BattleNoWin code = pb.ErrorCode_BattleNoWin
return return
} }
key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty))
if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励
viking.Boss[req.BossId]++ viking.Boss[req.BossId]++
@ -99,8 +100,12 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
return return
} }
} }
if viking.BossTime[key] > req.Report.Costtime || viking.BossTime[key] == 0 && req.Difficulty >= viking.Boss[req.BossId] {
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, viking, req.Report) viking.BossTime[key] = req.Report.Costtime
mapData["bossTime"] = viking.BossTime // 更新时间
userinfo := this.module.ModuleUser.GetUser(session.GetUserId())
this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report, userinfo)
}
reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励 reward = this.module.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
if code, atno = this.module.DispenseAtno(session, reward, true); code != pb.ErrorCode_Success { if code, atno = this.module.DispenseAtno(session, reward, true); code != pb.ErrorCode_Success {
return return
@ -119,7 +124,6 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChal
if len(del) > 0 { // 自动出售 if len(del) > 0 { // 自动出售
this.equip.SellEquipments(session, del) this.equip.SellEquipments(session, del)
} }
mapData["bossTime"] = viking.BossTime // 更新时间
// if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { // if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 {
// for _, v := range req.Report.Info.Redflist[0].Team { // for _, v := range req.Report.Info.Redflist[0].Team {

View File

@ -55,7 +55,7 @@ func (this *ModelRank) getVikingRankListByBossType(uid string, bossType int32) *
} }
// 排行数据写跨服 // 排行数据写跨服
func (this *ModelRank) SetRankListData(tableName string, score int64, uid string) { func (this *ModelRank) SetRankListData(tableName string, score int64, objId string) {
if !db.IsCross() { if !db.IsCross() {
if conn, err := db.Cross(); err == nil { if conn, err := db.Cross(); err == nil {
var ( var (
@ -63,7 +63,7 @@ func (this *ModelRank) SetRankListData(tableName string, score int64, uid string
menbers *redis.Z menbers *redis.Z
) )
menbers = &redis.Z{Score: float64(score), Member: uid} menbers = &redis.Z{Score: float64(score), Member: objId}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil { if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {

View File

@ -6,8 +6,10 @@
package viking package viking
import ( import (
"context"
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
@ -17,6 +19,7 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/bson/primitive"
) )
@ -84,67 +87,86 @@ func (this *Viking) CheckUserBaseVikingInfo(uid string) (data []*pb.DBVikingRank
return return
} }
func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, viking *pb.DBViking, report *pb.BattleReport) { // 记录数据存在跨服
costTime := report.Costtime func (this *Viking) CheckRank(uid string, boosID int32, difficulty int32, report *pb.BattleReport, userinfo *pb.DBUser) {
key := strconv.Itoa(int(boosID)) + "_" + strconv.Itoa(int(difficulty)) conn_, _ := db.Cross() // 获取跨服数据库对象
if viking.BossTime[key] > costTime || viking.BossTime[key] == 0 && difficulty >= viking.Boss[boosID] { // 刷新记录 model := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
viking.BossTime[key] = costTime
szLine := make([]*pb.LineUp, 5) costTime := report.Costtime
Leadpos := 0 szLine := make([]*pb.LineUp, 5)
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 { Leadpos := 0
costTime = report.Costtime if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
Leadpos = int(report.Info.Redflist[0].Leadpos) costTime = report.Costtime
for i, v := range report.Info.Redflist[0].Team { Leadpos = int(report.Info.Redflist[0].Leadpos)
if v != nil { for i, v := range report.Info.Redflist[0].Team {
szLine[i] = &pb.LineUp{ if v != nil {
Cid: v.HeroID, szLine[i] = &pb.LineUp{
Star: v.Star, Cid: v.HeroID,
Lv: v.Lv, Star: v.Star,
} Lv: v.Lv,
} }
} }
} }
// 写入排行榜 }
objID := "" // 写入排行榜
bFind := false objID := ""
ranks := this.modulerank.getVikingRankList(uid) bFind := false
for _, v := range ranks { ranks := make([]*pb.DBVikingRank, 0)
if v.Bosstype == boosID { model.GetList(uid, &ranks)
mapRankData := make(map[string]interface{}, 0) for _, v := range ranks {
mapRankData["difficulty"] = difficulty if v.Bosstype == boosID {
mapRankData["bosstype"] = boosID mapRankData := make(map[string]interface{}, 0)
mapRankData["Leadpos"] = Leadpos mapRankData["difficulty"] = difficulty
mapRankData["line"] = szLine mapRankData["bosstype"] = boosID
mapRankData["costTime"] = costTime mapRankData["Leadpos"] = Leadpos
conn_, _ := db.Cross() mapRankData["line"] = szLine
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_) mapRankData["costTime"] = costTime
dbModel.ChangeList(uid, v.Id, mapRankData)
objID = v.Id model.ChangeList(uid, v.Id, mapRankData)
bFind = true objID = v.Id
break bFind = true
} break
} }
if !bFind { }
userinfo := this.ModuleUser.GetUser(uid) if !bFind {
new := &pb.DBVikingRank{
Id: primitive.NewObjectID().Hex(), new := &pb.DBVikingRank{
Uid: uid, Id: primitive.NewObjectID().Hex(),
Difficulty: difficulty, Uid: uid,
Bosstype: boosID, Difficulty: difficulty,
Nickname: userinfo.Name, Bosstype: boosID,
Icon: "", Nickname: userinfo.Name,
Lv: userinfo.Lv, Icon: "",
Leadpos: int32(Leadpos), Lv: userinfo.Lv,
Line: szLine, Leadpos: int32(Leadpos),
CostTime: costTime, Line: szLine,
} CostTime: costTime,
objID = new.Id
conn_, _ := db.Cross()
dbModel := db.NewDBModel(comm.TableVikingRank, time.Hour, conn_)
dbModel.AddList(uid, new.Id, new)
} }
this.modulerank.SetRankListData("vikingRank"+strconv.Itoa(int(boosID)), int64(difficulty<<31)+int64(math.MaxInt32-costTime), objID) objID = new.Id
model.AddList(uid, new.Id, new)
}
var (
pipe *pipe.RedisPipe = conn_.Redis.RedisPipe(context.TODO())
menbers *redis.Z
tableName string
score int64
)
score = int64(difficulty<<31) + int64(math.MaxInt32-costTime)
tableName = "vikingRank" + strconv.Itoa(int(boosID))
menbers = &redis.Z{Score: float64(score), Member: objID}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
dock, err1 := cmd.Result()
if err1 != nil {
this.Errorln(dock, err1)
}
}
if _, err := pipe.Exec(); err != nil {
this.Errorln(err)
return
} }
} }
@ -282,8 +304,8 @@ func (this *Viking) AutoBattleOver(session comm.IUserSession, Report *pb.BattleR
return return
} }
} }
userinfo := this.ModuleUser.GetUser(session.GetUserId())
this.CheckRank(session.GetUserId(), bossId, difficulty, viking, Report) this.CheckRank(session.GetUserId(), bossId, difficulty, Report, userinfo)
reward := this.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励 reward := this.configure.GetDropReward(vikingCfg.Drop) // 获取掉落奖励
if c, res1 := this.DispenseAtno(session, reward, true); c == pb.ErrorCode_Success { if c, res1 := this.DispenseAtno(session, reward, true); c == pb.ErrorCode_Success {
atno = append(atno, res1...) atno = append(atno, res1...)