阵营boss

This commit is contained in:
meixiongfeng 2022-12-19 10:20:08 +08:00
parent 840aae0caf
commit 4893f8496b
16 changed files with 3400 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,102 @@
[
{
"buynum": 1,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 10
}
]
},
{
"buynum": 2,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 20
}
]
},
{
"buynum": 3,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 30
}
]
},
{
"buynum": 4,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 40
}
]
},
{
"buynum": 5,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 50
}
]
},
{
"buynum": 6,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 60
}
]
},
{
"buynum": 7,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 70
}
]
},
{
"buynum": 8,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 80
}
]
},
{
"buynum": 9,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 90
}
]
},
{
"buynum": 10,
"need": [
{
"a": "attr",
"t": "diamond",
"n": 100
}
]
}
]

49
modules/enchant/api.go Normal file
View File

@ -0,0 +1,49 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
const (
HuntingGetListResp = "getlist"
HuntingChallengeResp = "challenge"
HuntingChallengeOverResp = "challengeover"
HuntingSkillLvResp = "skilllv"
HuntingGetRewardResp = "getreward"
HuntingBuyResp = "buy"
HuntingRankListResp = "ranklist"
)
type apiComp struct {
modules.MCompGate
service core.IService
configure *configureComp
module *Hunting
friend comm.IFriend
chat comm.IChat
}
//组件初始化接口
func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompGate.Init(service, module, comp, options)
this.module = module.(*Hunting)
this.service = service
return
}
func (this *apiComp) Start() (err error) {
err = this.MCompGate.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.ModuleChat); err != nil {
return
}
this.chat = module.(comm.IChat)
return
}

137
modules/enchant/api_buy.go Normal file
View File

@ -0,0 +1,137 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.HuntingBuyReq) (code pb.ErrorCode) {
if req.Count <= 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code pb.ErrorCode, data proto.Message) {
var (
curByCount int32
costRes *cfg.Gameatn // 门票atn 类型 只取T
mapData map[string]interface{}
szCostRes []*cfg.Gameatn // 购买累计消耗
curCount int32 // 当前门票数量
addCount int32 //获得数量
)
mapData = make(map[string]interface{}, 0)
code = this.BuyCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
// 校验是不是今天
if !utils.IsToday(list.CTime) {
list.CTime = configure.Now().Unix()
list.BuyCount = 0
mapData["cTime"] = list.CTime
mapData["buyCount"] = list.BuyCount
} else {
curByCount = list.BuyCount
}
curByCount += req.Count // 当前需要购买的数量
if this.configure.GetMaxBuyChallengeCount() < curByCount {
code = pb.ErrorCode_HuntingBuyMaxCount
return
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes = conf.HuntingCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
curCount = amount
if amount < conf.HuntingNum {
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
for { // 计算恢复时间
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
if curCount-amount > 0 {
addCount = curCount - amount
}
} else {
list.RecoveryTime = 0
}
addCount += req.Count
if amount+addCount > conf.VikingNum {
code = pb.ErrorCode_VikingBuyMaxCount
return
}
mapData["recoveryTime"] = list.RecoveryTime
for i := list.BuyCount + 1; i <= curByCount; i++ {
_cfg := this.configure.GetBuyChallengeCount(i)
if _cfg == nil {
code = pb.ErrorCode_HuntingBuyMaxCount
return
}
szCostRes = append(szCostRes, _cfg.Need...)
}
sz := make([]*cfg.Gameatn, 0)
for _, v := range szCostRes {
bFound := false
for _, v1 := range sz {
if v.A == v1.A && v.T == v1.T {
v1.N += v.N
bFound = true
break
}
}
if !bFound {
sz = append(sz, v)
}
}
//消耗
if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success {
return
}
res := &cfg.Gameatn{
A: "item",
T: costRes.T,
N: addCount,
}
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
return
}
list.BuyCount = curByCount
mapData["buyCount"] = curByCount
code = this.module.ModifyHuntingData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), HuntingBuyResp, &pb.HuntingBuyResp{Data: list})
return
}

View File

@ -0,0 +1,90 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode) {
if req.BossType <= 0 && req.Difficulty > 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
///挑战主线关卡
func (this *apiComp) Challenge(session comm.IUserSession, req *pb.HuntingChallengeReq) (code pb.ErrorCode, data proto.Message) {
code = this.ChallengeCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
hunting, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.HuntingCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
code = pb.ErrorCode_HuntingNoChallengeCount
return
}
// if hunting.ChallengeCount > this.module.configure.GetGlobalConf().HuntingNum+hunting.BuyCount {
// code = pb.ErrorCode_HuntingMaxChallengeCount
// return
// }
cfgData := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty)
if cfgData == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
value, ok := hunting.Boss[req.BossType]
if !ok { // 类型校验
hunting.Boss[req.BossType] = 0
}
if value < req.Difficulty {
if value+1 != req.Difficulty {
code = pb.ErrorCode_HuntingLvErr
return
}
}
code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{
Ptype: pb.PlayType_hunting,
Title: "",
Format: &pb.BattleFormation{
Leadpos: req.Leadpos,
Format: req.Teamids,
},
Mformat: cfgData.Boss,
})
if code != pb.ErrorCode_Success {
return
}
session.SendMsg(string(this.module.GetType()), HuntingChallengeResp, &pb.HuntingChallengeResp{
Info: &pb.BattleInfo{Id: record.Id, Title: record.Title, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist},
BossType: req.BossType,
Difficulty: req.Difficulty,
})
if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil {
this.chat.SendSysChatToWorld(comm.ChatSystem15, nil, req.BossType, req.Difficulty, user.Name)
} else {
this.module.Errorf("no found userdata uid:%s", session.GetUserId())
}
return
}

View File

@ -0,0 +1,119 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode) {
if req.BossType <= 0 && req.Difficulty > 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
///挑战主线关卡
func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (code pb.ErrorCode, data proto.Message) {
var (
mapData map[string]interface{}
newChallenge bool // 新的关卡
reward []*cfg.Gameatn
bWin bool // 战斗是否胜利
)
mapData = make(map[string]interface{}, 0)
reward = make([]*cfg.Gameatn, 0)
code = this.ChallengeOverCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
hunting, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_PagodaNotFound
return
}
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.HuntingCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success {
code = pb.ErrorCode_HuntingNoChallengeCount
return
}
cfgHunting := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty)
if cfgHunting == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
value, ok := hunting.Boss[req.BossType]
if !ok { // 类型校验
hunting.Boss[req.BossType] = 0
}
if value < req.Difficulty {
if value+1 != req.Difficulty {
code = pb.ErrorCode_HuntingLvErr
return
}
newChallenge = true
}
// 校验门票数量够不够
if code = this.module.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success {
return
}
// check
code, bWin = this.module.battle.CheckBattleReport(session, req.Report)
if code != pb.ErrorCode_Success {
return
}
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
if amount < conf.HuntingNum {
hunting.RecoveryTime = configure.Now().Unix()
mapData["recoveryTime"] = hunting.RecoveryTime
}
if bWin {
this.module.CheckRank(session.GetUserId(), req.BossType, req.Difficulty, hunting, req.Report)
}
// 耗时校验 当前战斗胜利时间消耗小于之前刷新数据
// 发放通关随机奖励
reward = this.module.configure.GetDropReward(cfgHunting.Drop) // 获取掉落奖励
if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success {
return
}
if newChallenge && bWin { // 新关卡挑战通过 发放首通奖励
if code = this.module.DispenseRes(session, cfgHunting.Firstprize, true); code != pb.ErrorCode_Success {
return
}
hunting.Boss[req.BossType] += 1
mapData["boss"] = hunting.Boss
}
for k := range hunting.Boss {
hunting.Boss[k] += 1
}
mapData["challengeTime"] = hunting.BossTime
code = this.module.ModifyHuntingData(session.GetUserId(), mapData)
session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{Data: hunting})
// 随机任务统计
this.module.ModuleRtask.SendToRtask(session, comm.Rtype81, req.Difficulty, req.BossType)
this.module.ModuleRtask.SendToRtask(session, comm.Rtype82, req.BossType)
return
}

View File

@ -0,0 +1,95 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) GetList(session comm.IUserSession, req *pb.HuntingGetListReq) (code pb.ErrorCode, data proto.Message) {
var (
mapData map[string]interface{}
curCount int32
)
mapData = make(map[string]interface{}, 0)
code = this.GetListCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
// 校验 是不是当天
if !utils.IsToday(list.CTime) {
list.CTime = configure.Now().Unix()
list.BuyCount = 0
mapData["cTime"] = list.CTime
mapData["buyCount"] = list.BuyCount
}
// 检查恢复时间
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
costRes := conf.HuntingCos
if costRes == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量
curCount = amount
if amount < conf.HuntingNum {
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
for { // 计算恢复时间
if list.RecoveryTime+int64(conf.HuntingRecovery*60) <= configure.Now().Unix() {
curCount++
list.RecoveryTime += int64(conf.HuntingRecovery * 60)
if curCount >= conf.HuntingNum {
list.RecoveryTime = 0
break
}
} else {
break
}
}
addCount := curCount - amount
if addCount > 0 {
res := &cfg.Gameatn{
A: "item",
T: costRes.T,
N: addCount,
}
if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success {
return
}
}
} else {
list.RecoveryTime = 0
}
mapData["recoveryTime"] = list.RecoveryTime
code = this.module.ModifyHuntingData(session.GetUserId(), mapData) //修改内存信息
// 发送难度
for k := range list.Boss {
list.Boss[k] += 1
}
session.SendMsg(string(this.module.GetType()), HuntingGetListResp, &pb.HuntingGetListResp{Data: list})
return
}

View File

@ -0,0 +1,59 @@
package enchant
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/pb"
"strconv"
"github.com/go-redis/redis/v8"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) RankListCheck(session comm.IUserSession, req *pb.HuntingRankListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) RankList(session comm.IUserSession, req *pb.HuntingRankListReq) (code pb.ErrorCode, data proto.Message) {
var (
szRank []*pb.DBHuntingRank
rd *redis.StringSliceCmd
)
code = this.RankListCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
if !req.Friend {
var (
pipe *pipe.RedisPipe = this.module.modelHunting.Redis.RedisPipe(context.TODO())
)
rd = pipe.ZRange("huntingRank"+strconv.Itoa(int(req.BoosType)), 0, -1)
if _, err := pipe.Exec(); err != nil {
this.module.Errorln(err)
return
}
_dataList := rd.Val()
for _, v := range _dataList {
result := &pb.DBHuntingRank{}
if err := this.module.modulerank.GetListObj(session.GetUserId(), v, result); err == nil {
szRank = append(szRank, result)
}
}
} else {
uids := this.friend.GetFriendList(session.GetUserId())
for _, id := range uids {
rankData := this.module.modulerank.getHuntingRankListByBossType(id, req.BoosType)
if rankData != nil {
szRank = append(szRank, rankData)
}
}
}
session.SendMsg(string(this.module.GetType()), HuntingRankListResp, &pb.HuntingRankListResp{Ranks: szRank})
return
}

View File

@ -0,0 +1,112 @@
package enchant
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_huntingboss = "game_huntingboss.json"
game_challenge = "game_huntingchallenge.json"
)
///配置管理基础组件
type configureComp struct {
hlock sync.RWMutex
modules.MCompConfigure
_huntingMap map[int64]*cfg.GameHuntingBossData
}
//组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
this._huntingMap = make(map[int64]*cfg.GameHuntingBossData, 0)
configure.RegisterConfigure(game_huntingboss, cfg.NewGameHuntingBoss, func() {
if v, err := this.GetConfigure(game_huntingboss); err == nil {
if configure, ok := v.(*cfg.GameHuntingBoss); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._huntingMap[int64(value.Type<<16)+int64(value.Difficulty)] = value
}
return
}
} else {
log.Errorf("get game_huntingboss conf err:%v", err)
}
return
})
err = this.LoadConfigure(game_challenge, cfg.NewGameHuntingChallenge)
return
}
// 参数: boss类型 难度
func (this *configureComp) GetHuntingBossConfigData(bossType int32, difficulty int32) (data *cfg.GameHuntingBossData) {
return this._huntingMap[int64(bossType<<16)+int64(difficulty)]
}
//加载多个配置文件
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
for k, v := range confs {
err = configure.RegisterConfigure(k, v, nil)
if err != nil {
log.Errorf("配置文件:%s解析失败!", k)
break
}
}
return
}
//读取配置数据
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name)
}
// get boss Type
func (this *configureComp) GetHuntingBossTypeConfigData() (mapType map[int32]struct{}) {
mapType = make(map[int32]struct{}, 0)
if v, err := this.GetConfigure(game_huntingboss); err == nil {
if configure, ok := v.(*cfg.GameHuntingBoss); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
if _, ok := mapType[value.Type]; !ok {
mapType[value.Type] = struct{}{}
}
}
}
}
return
}
func (this *configureComp) GetBuyChallengeCount(index int32) (data *cfg.GameHuntingChallengeData) {
if v, err := this.GetConfigure(game_challenge); err == nil {
if configure, ok := v.(*cfg.GameHuntingChallenge); ok {
data = configure.Get(index)
return
}
} else {
log.Errorf("get game_challenge conf err:%v", err)
}
return
}
func (this *configureComp) GetMaxBuyChallengeCount() int32 {
if v, err := this.GetConfigure(game_challenge); err == nil {
if configure, ok := v.(*cfg.GameHuntingChallenge); ok {
return int32(len(configure.GetDataList()))
}
} else {
log.Errorf("get game_challenge conf err:%v", err)
}
return 0
}

View File

@ -0,0 +1,79 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/mgo"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"strconv"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
type modelHunting struct {
modules.MCompModel
module *Hunting
}
func (this *modelHunting) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = string(comm.TableHunting)
err = this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Hunting)
// uid 创建索引
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *modelHunting) modifyHuntingDataByObjId(uid string, data map[string]interface{}) error {
return this.Change(uid, data)
}
// 获取列表信息
func (this *modelHunting) getHuntingList(uid string) (result *pb.DBHunting, err error) {
result = &pb.DBHunting{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Boss: make(map[int32]int32),
BossTime: make(map[string]int32),
}
if err = this.Get(uid, result); err != nil && mgo.MongodbNil != err {
return
}
if mgo.MongodbNil == err {
if len(result.Boss) == 0 {
_cfg := this.module.configure.GetHuntingBossTypeConfigData()
for k := range _cfg {
result.Boss[k] = 0
str := strconv.Itoa(int(k)) + "_1"
result.BossTime[str] = 0
}
}
this.Add(uid, result)
}
err = nil
return result, err
}
// 红点检测
func (this *modelHunting) checkReddot32(uid string) bool {
conf := this.module.configure.GetGlobalConf()
if conf == nil {
return false
}
costRes := conf.HuntingCos
if costRes == nil {
return false
}
amount := int32(this.module.ModuleItems.QueryItemAmount(uid, costRes.T)) // 获取当前数量
if amount > 0 {
return true
}
return false
}

View File

@ -0,0 +1,82 @@
package enchant
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"github.com/go-redis/redis/v8"
)
type ModelRank struct {
modules.MCompModel
moduleHunting *Hunting
}
func (this *ModelRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableHuntingRecord // 挑战记录
err = this.MCompModel.Init(service, module, comp, options)
this.moduleHunting = module.(*Hunting)
return
}
func (this *ModelRank) AddRankList(uId string, objId string, data *pb.DBHuntingRank) (err error) {
if err = this.AddList(uId, objId, data); err != nil {
return
}
return nil
}
func (this *ModelRank) getHuntingRankList(uid string) []*pb.DBHuntingRank {
ranks := make([]*pb.DBHuntingRank, 0)
err := this.GetList(uid, &ranks)
if err != nil {
return nil
}
return ranks
}
func (this *ModelRank) getHuntingRankListByBossType(uid string, bossType int32) *pb.DBHuntingRank {
ranks := make([]*pb.DBHuntingRank, 0)
err := this.GetList(uid, &ranks)
if err != nil {
return nil
}
for _, v := range ranks {
if v.Bosstype == bossType {
return v
}
}
return nil
}
// 排行数据写跨服
func (this *ModelRank) SetRankListData(tableName string, score int32, uid string) {
if !db.IsCross() {
if conn, err := db.Cross(); err == nil {
var (
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
menbers *redis.Z
)
menbers = &redis.Z{Score: float64(score), Member: uid}
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
dock, err1 := cmd.Result()
if err1 != nil {
this.moduleHunting.Errorln(dock, err1)
}
}
if _, err := pipe.Exec(); err != nil {
this.moduleHunting.Errorln(err)
return
}
}
}
}

181
modules/enchant/module.go Normal file
View File

@ -0,0 +1,181 @@
package enchant
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"strconv"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type Hunting struct {
modules.ModuleBase
modelHunting *modelHunting
api *apiComp
configure *configureComp
modulerank *ModelRank
battle comm.IBattle
service core.IService
}
func NewModule() core.IModule {
return &Hunting{}
}
func (this *Hunting) GetType() core.M_Modules {
return comm.ModuleHunting
}
func (this *Hunting) 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 *Hunting) Start() (err error) {
err = this.ModuleBase.Start()
var module core.IModule
if module, err = this.service.GetModule(comm.ModuleBattle); err != nil {
return
}
this.battle = module.(comm.IBattle)
return
}
func (this *Hunting) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.modelHunting = this.RegisterComp(new(modelHunting)).(*modelHunting)
this.modulerank = this.RegisterComp(new(ModelRank)).(*ModelRank)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
}
// 接口信息
func (this *Hunting) ModifyHuntingData(uid string, data map[string]interface{}) (code pb.ErrorCode) {
err := this.modelHunting.modifyHuntingDataByObjId(uid, data)
if err != nil {
code = pb.ErrorCode_DBError
}
return
}
func (this *Hunting) CheckUserBaseHuntingInfo(uid string) (data []*pb.DBHuntingRank) {
list, err := this.modelHunting.getHuntingList(uid)
if err != nil {
for k := range list.Boss {
_d := this.modulerank.getHuntingRankListByBossType(uid, k)
if _d != nil {
data = append(data, _d)
}
}
}
return
}
func (this *Hunting) CheckRank(uid string, boosID int32, difficulty int32, hunting *pb.DBHunting, report *pb.BattleReport) {
costTime := report.Costtime
key := strconv.Itoa(int(boosID)) + "_" + strconv.Itoa(int(difficulty))
if hunting.BossTime[key] > costTime || hunting.BossTime[key] == 0 && difficulty >= hunting.Boss[boosID] { // 刷新记录
hunting.BossTime[key] = costTime
szLine := make([]*pb.LineUp, 5)
Leadpos := 0
if report != nil && report.Info != nil && len(report.Info.Redflist) > 0 {
costTime = report.Costtime
Leadpos = int(report.Info.Redflist[0].Leadpos)
for i, v := range report.Info.Redflist[0].Team {
if v != nil {
szLine[i] = &pb.LineUp{
Cid: v.HeroID,
Star: v.Star,
Lv: v.Lv,
}
}
}
}
// 写入排行榜
objID := ""
bFind := false
ranks := this.modulerank.getHuntingRankList(uid)
for _, v := range ranks {
if v.Bosstype == boosID {
mapRankData := make(map[string]interface{}, 0)
mapRankData["difficulty"] = difficulty
mapRankData["bosstype"] = boosID
mapRankData["Leadpos"] = Leadpos
mapRankData["line"] = szLine
mapRankData["costTime"] = costTime
conn_, _ := db.Cross()
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
dbModel.ChangeList(uid, v.Id, mapRankData)
objID = v.Id
bFind = true
break
}
}
if !bFind {
userinfo := this.ModuleUser.GetUser(uid)
new := &pb.DBHuntingRank{
Id: primitive.NewObjectID().Hex(),
Uid: uid,
Difficulty: difficulty,
Bosstype: boosID,
Nickname: userinfo.Name,
Icon: "",
Lv: userinfo.Lv,
Leadpos: int32(Leadpos),
Line: szLine,
CostTime: costTime,
}
objID = new.Id
conn_, _ := db.Cross()
dbModel := db.NewDBModel(comm.TableHuntingRank, time.Hour, conn_)
dbModel.AddList(uid, new.Id, new)
}
this.modulerank.SetRankListData("huntingRank"+strconv.Itoa(int(boosID)), difficulty<<16+costTime, objID)
}
}
//红点查询
func (this *Hunting) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]bool) {
reddot = make(map[comm.ReddotType]bool)
for _, v := range rid {
switch v {
case comm.Reddot32:
reddot[comm.Reddot32] = this.modelHunting.checkReddot32(session.GetUserId())
break
}
}
return
}
// 解锁远征所有难度
func (this *Hunting) CompleteAllLevel(session comm.IUserSession) (code pb.ErrorCode) {
list, err := this.modelHunting.getHuntingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
mapData := make(map[string]interface{}, 0)
// 查配置获取每个Boss的最大难度
for k := range list.Boss {
for i := 1; ; i++ {
conf := this.configure.GetHuntingBossConfigData(k, int32(i))
if conf == nil {
list.Boss[k] = int32(i - 1)
}
}
}
mapData["boss"] = list.Boss
code = this.ModifyHuntingData(session.GetUserId(), mapData)
for k := range list.Boss {
list.Boss[k] += 1
}
session.SendMsg(string(this.GetType()), HuntingGetListResp, &pb.HuntingGetListResp{Data: list})
return
}

View File

@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
type GameEnchantBoss struct {
_dataMap map[int32]*GameEnchantBossData
_dataList []*GameEnchantBossData
}
func NewGameEnchantBoss(_buf []map[string]interface{}) (*GameEnchantBoss, error) {
_dataList := make([]*GameEnchantBossData, 0, len(_buf))
dataMap := make(map[int32]*GameEnchantBossData)
for _, _ele_ := range _buf {
if _v, err2 := DeserializeGameEnchantBossData(_ele_); err2 != nil {
return nil, err2
} else {
_dataList = append(_dataList, _v)
dataMap[_v.Id] = _v
}
}
return &GameEnchantBoss{_dataList:_dataList, _dataMap:dataMap}, nil
}
func (table *GameEnchantBoss) GetDataMap() map[int32]*GameEnchantBossData {
return table._dataMap
}
func (table *GameEnchantBoss) GetDataList() []*GameEnchantBossData {
return table._dataList
}
func (table *GameEnchantBoss) Get(key int32) *GameEnchantBossData {
return table._dataMap[key]
}

View File

@ -0,0 +1,143 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
import "errors"
type GameEnchantBossData struct {
Id int32
Bossid int32
Name string
Grade string
ScoreLow int32
ScoreUp int32
RewardDrop []int32
Dropshow1 []*Gameatn
Dropshow2 []*Gameatn
Dropshow3 []*Gameatn
Dropshow []int32
Bossmodel int32
MainText string
StrategyText string
BossSkill int32
Boss []int32
}
const TypeId_GameEnchantBossData = -287548876
func (*GameEnchantBossData) GetTypeId() int32 {
return -287548876
}
func (_v *GameEnchantBossData)Deserialize(_buf map[string]interface{}) (err error) {
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["id"].(float64); !_ok_ { err = errors.New("id error"); return }; _v.Id = int32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["bossid"].(float64); !_ok_ { err = errors.New("bossid error"); return }; _v.Bossid = int32(_tempNum_) }
{var _ok_ bool; var __json_text__ map[string]interface{}; if __json_text__, _ok_ = _buf["name"].(map[string]interface{}) ; !_ok_ { err = errors.New("_v.Name error"); return }; { var _ok_ bool; if _, _ok_ = __json_text__["key"].(string); !_ok_ { err = errors.New("key error"); return } }; { var _ok_ bool; if _v.Name, _ok_ = __json_text__["text"].(string); !_ok_ { err = errors.New("text error"); return } } }
{ var _ok_ bool; if _v.Grade, _ok_ = _buf["grade"].(string); !_ok_ { err = errors.New("grade error"); return } }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["score_low"].(float64); !_ok_ { err = errors.New("score_low error"); return }; _v.ScoreLow = int32(_tempNum_) }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["score_up"].(float64); !_ok_ { err = errors.New("score_up error"); return }; _v.ScoreUp = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["reward_drop"].([]interface{}); !_ok_ { err = errors.New("reward_drop error"); return }
_v.RewardDrop = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.RewardDrop = append(_v.RewardDrop, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["dropshow1"].([]interface{}); !_ok_ { err = errors.New("dropshow1 error"); return }
_v.Dropshow1 = make([]*Gameatn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Gameatn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = DeserializeGameatn(_x_); err != nil { return } }
_v.Dropshow1 = append(_v.Dropshow1, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["dropshow2"].([]interface{}); !_ok_ { err = errors.New("dropshow2 error"); return }
_v.Dropshow2 = make([]*Gameatn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Gameatn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = DeserializeGameatn(_x_); err != nil { return } }
_v.Dropshow2 = append(_v.Dropshow2, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["dropshow3"].([]interface{}); !_ok_ { err = errors.New("dropshow3 error"); return }
_v.Dropshow3 = make([]*Gameatn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Gameatn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = DeserializeGameatn(_x_); err != nil { return } }
_v.Dropshow3 = append(_v.Dropshow3, _list_v_)
}
}
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["dropshow"].([]interface{}); !_ok_ { err = errors.New("dropshow error"); return }
_v.Dropshow = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.Dropshow = append(_v.Dropshow, _list_v_)
}
}
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["bossmodel"].(float64); !_ok_ { err = errors.New("bossmodel error"); return }; _v.Bossmodel = int32(_tempNum_) }
{var _ok_ bool; var __json_text__ map[string]interface{}; if __json_text__, _ok_ = _buf["main_text"].(map[string]interface{}) ; !_ok_ { err = errors.New("_v.MainText error"); return }; { var _ok_ bool; if _, _ok_ = __json_text__["key"].(string); !_ok_ { err = errors.New("key error"); return } }; { var _ok_ bool; if _v.MainText, _ok_ = __json_text__["text"].(string); !_ok_ { err = errors.New("text error"); return } } }
{var _ok_ bool; var __json_text__ map[string]interface{}; if __json_text__, _ok_ = _buf["strategy_text"].(map[string]interface{}) ; !_ok_ { err = errors.New("_v.StrategyText error"); return }; { var _ok_ bool; if _, _ok_ = __json_text__["key"].(string); !_ok_ { err = errors.New("key error"); return } }; { var _ok_ bool; if _v.StrategyText, _ok_ = __json_text__["text"].(string); !_ok_ { err = errors.New("text error"); return } } }
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["boss_skill"].(float64); !_ok_ { err = errors.New("boss_skill error"); return }; _v.BossSkill = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["boss"].([]interface{}); !_ok_ { err = errors.New("boss error"); return }
_v.Boss = make([]int32, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
_v.Boss = append(_v.Boss, _list_v_)
}
}
return
}
func DeserializeGameEnchantBossData(_buf map[string]interface{}) (*GameEnchantBossData, error) {
v := &GameEnchantBossData{}
if err := v.Deserialize(_buf); err == nil {
return v, nil
} else {
return nil, err
}
}

View File

@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
type GameEnchantShop struct {
_dataMap map[int32]*GameEnchantShopData
_dataList []*GameEnchantShopData
}
func NewGameEnchantShop(_buf []map[string]interface{}) (*GameEnchantShop, error) {
_dataList := make([]*GameEnchantShopData, 0, len(_buf))
dataMap := make(map[int32]*GameEnchantShopData)
for _, _ele_ := range _buf {
if _v, err2 := DeserializeGameEnchantShopData(_ele_); err2 != nil {
return nil, err2
} else {
_dataList = append(_dataList, _v)
dataMap[_v.Buynum] = _v
}
}
return &GameEnchantShop{_dataList:_dataList, _dataMap:dataMap}, nil
}
func (table *GameEnchantShop) GetDataMap() map[int32]*GameEnchantShopData {
return table._dataMap
}
func (table *GameEnchantShop) GetDataList() []*GameEnchantShopData {
return table._dataList
}
func (table *GameEnchantShop) Get(key int32) *GameEnchantShopData {
return table._dataMap[key]
}

View File

@ -0,0 +1,50 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
package cfg
import "errors"
type GameEnchantShopData struct {
Buynum int32
Need []*Gameatn
}
const TypeId_GameEnchantShopData = 1535577405
func (*GameEnchantShopData) GetTypeId() int32 {
return 1535577405
}
func (_v *GameEnchantShopData)Deserialize(_buf map[string]interface{}) (err error) {
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["buynum"].(float64); !_ok_ { err = errors.New("buynum error"); return }; _v.Buynum = int32(_tempNum_) }
{
var _arr_ []interface{}
var _ok_ bool
if _arr_, _ok_ = _buf["need"].([]interface{}); !_ok_ { err = errors.New("need error"); return }
_v.Need = make([]*Gameatn, 0, len(_arr_))
for _, _e_ := range _arr_ {
var _list_v_ *Gameatn
{ var _ok_ bool; var _x_ map[string]interface{}; if _x_, _ok_ = _e_.(map[string]interface{}); !_ok_ { err = errors.New("_list_v_ error"); return }; if _list_v_, err = DeserializeGameatn(_x_); err != nil { return } }
_v.Need = append(_v.Need, _list_v_)
}
}
return
}
func DeserializeGameEnchantShopData(_buf map[string]interface{}) (*GameEnchantShopData, error) {
v := &GameEnchantShopData{}
if err := v.Deserialize(_buf); err == nil {
return v, nil
} else {
return nil, err
}
}