英雄相关优化 错误码返回
This commit is contained in:
parent
3f11df2200
commit
60f2bbddba
@ -71,8 +71,22 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (e
|
||||
_hero.JuexingLv += 1
|
||||
|
||||
if len(awakenData.Phasebonus) > 0 {
|
||||
this.module.modelHero.resetJuexingProperty(_hero)
|
||||
this.module.modelHero.calFigthValue(_hero)
|
||||
if err = this.module.modelHero.resetJuexingProperty(_hero); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroInitCreat,
|
||||
Title: pb.ErrorCode_HeroInitCreat.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
if _, err = this.module.modelHero.calFigthValue(_hero); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroInitCreat,
|
||||
Title: pb.ErrorCode_HeroInitCreat.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
// 校验 有没有技能
|
||||
if awakenData.Skill != 0 {
|
||||
|
@ -330,15 +330,11 @@ func (this *apiComp) DrawCard(session comm.IUserSession, req *pb.HeroDrawCardReq
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.module.modelDrawRecode.AddDrawRecord(session, req.DrawType, szCards)
|
||||
|
||||
var szHero []*pb.DBHero
|
||||
for _, hero := range add { // 奖励一次性发放
|
||||
if user, err := this.module.GetUserForSession(session); err == nil { // 广播 首次获得英雄
|
||||
HeroConf, _ := this.module.configure.GetHeroConfig(hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, hero, hero.Star, 0, user.Name, hero.HeroID)
|
||||
}
|
||||
szHero = append(szHero, hero)
|
||||
}
|
||||
this.module.HeroLibrary(session, szCards, szHero)
|
||||
this.module.SendTaskMsg(session, szStar, req.DrawCount, req.DrawType, szCards)
|
||||
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "HeroDrawCardReq", atno)
|
||||
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "HeroDrawCardReq", costRes)
|
||||
@ -403,6 +399,10 @@ func (this *apiComp) wishDrawCard(session comm.IUserSession, heroRecord *pb.DBHe
|
||||
atno []*pb.UserAtno
|
||||
update map[string]interface{}
|
||||
rsp *pb.HeroDrawCardResp
|
||||
add []*pb.DBHero
|
||||
err error
|
||||
addres [][]*cfg.Gameatn
|
||||
res []*cfg.Gameatn
|
||||
)
|
||||
rsp = &pb.HeroDrawCardResp{}
|
||||
update = make(map[string]interface{})
|
||||
@ -442,12 +442,22 @@ func (this *apiComp) wishDrawCard(session comm.IUserSession, heroRecord *pb.DBHe
|
||||
}
|
||||
return
|
||||
}
|
||||
var hero *pb.DBHero
|
||||
//var hero *pb.DBHero
|
||||
|
||||
if hero, atno, errdata = this.module.CreateOneHero(session, heroRecord.WishHero); errdata == nil {
|
||||
rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno})
|
||||
if addres, add, err = this.module.modelHero.ImitateHeros(session, []string{heroRecord.WishHero}, false); err == nil {
|
||||
for _, v := range addres {
|
||||
for _, v1 := range v {
|
||||
if v1.A != "hero" { // 不发英雄
|
||||
res = append(res, v1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { //同意发送奖励
|
||||
return
|
||||
}
|
||||
rsp.Data = append(rsp.Data, &pb.AtnoData{Atno: atno})
|
||||
if errdata = this.module.ConsumeRes(session, costRes, true); errdata != nil {
|
||||
return
|
||||
}
|
||||
@ -461,14 +471,8 @@ func (this *apiComp) wishDrawCard(session comm.IUserSession, heroRecord *pb.DBHe
|
||||
session.SendMsg(string(this.module.GetType()), DrawCard, rsp)
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
if user, err := this.module.GetUserForSession(session); err == nil { // 广播 首次获得英雄
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.T == heroRecord.WishHero && v.N == 1 {
|
||||
if HeroConf, err := this.module.configure.GetHeroConfig(heroRecord.WishHero); err == nil {
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, v.T)
|
||||
} else {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
for _, v := range add {
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, v, v.Star, 0, user.Name, v.HeroID)
|
||||
}
|
||||
} else {
|
||||
this.module.Errorln(err)
|
||||
|
@ -81,8 +81,7 @@ func (this *apiComp) SelectCard(session comm.IUserSession, req *pb.HeroSelectCar
|
||||
var szHero []*pb.DBHero
|
||||
for _, hero := range add { // 奖励一次性发放
|
||||
if user, err := this.module.GetUserForSession(session); err == nil { // 广播 首次获得英雄
|
||||
HeroConf, _ := this.module.configure.GetHeroConfig(hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, hero, HeroConf.Star, 0, user.Name, hero.HeroID)
|
||||
this.chat.SendSysChatToWorld(session, comm.ChatSystem13, hero, hero.Star, 0, user.Name, hero.HeroID)
|
||||
}
|
||||
szHero = append(szHero, hero)
|
||||
}
|
||||
@ -126,10 +125,8 @@ func (this *apiComp) SelectCard(session comm.IUserSession, req *pb.HeroSelectCar
|
||||
})
|
||||
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
|
||||
this.module.modelDrawRecode.AddDrawRecord(session, 1, curSzCard)
|
||||
this.module.WriteUserLog(session.GetUserId(), "xinshou", comm.GMResAddType, "HeroSelectCardReq", atno)
|
||||
this.module.HeroLibrary(session, curSzCard, szHero)
|
||||
this.module.SendTaskMsg(session, szStar, 10, 1, curSzCard)
|
||||
})
|
||||
return
|
||||
|
@ -313,40 +313,54 @@ func (this *configureComp) GetHeroConfig(heroCfgId string) (conf *cfg.GameHeroDa
|
||||
}
|
||||
|
||||
// 获取英雄星级配置
|
||||
func (this *configureComp) GetHeroStar(star int32) *cfg.GameHeroStargrowData {
|
||||
|
||||
if v, err := this.GetConfigure(hero_stargrow); err == nil {
|
||||
func (this *configureComp) GetHeroStar(star int32) (conf *cfg.GameHeroStargrowData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = this.GetConfigure(hero_stargrow); err == nil {
|
||||
|
||||
if configure, ok := v.(*cfg.GameHeroStargrow); ok {
|
||||
return configure.Get(star)
|
||||
if conf = configure.Get(star); conf != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
this.module.Errorf(" GetHeroStar err : lv:%d", star)
|
||||
return nil
|
||||
err = comm.NewNotFoundConfErr(moduleName, hero_stargrow, star)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取英雄等级配置
|
||||
func (this *configureComp) GetHeroLv(lv int32) *cfg.GameHeroLevelupData {
|
||||
if v, err := this.GetConfigure(hero_levelup); err == nil {
|
||||
func (this *configureComp) GetHeroLv(lv int32) (conf *cfg.GameHeroLevelupData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = this.GetConfigure(hero_levelup); err == nil {
|
||||
if configure, ok := v.(*cfg.GameHeroLevelup); ok {
|
||||
return configure.Get(lv)
|
||||
if conf = configure.Get(lv); conf != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.module.Errorf(" GetHeroLv err : lv:%d", lv)
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
// 英雄成长配置
|
||||
func (this *configureComp) GetHeroLvgrow(heroId string) *cfg.GameHeroLevelgrowData {
|
||||
if v, err := this.GetConfigure(hero_levelgrow); err == nil {
|
||||
func (this *configureComp) GetHeroLvgrow(heroId string) (conf *cfg.GameHeroLevelgrowData, err error) {
|
||||
var (
|
||||
v interface{}
|
||||
)
|
||||
if v, err = this.GetConfigure(hero_levelgrow); err == nil {
|
||||
if configure, ok := v.(*cfg.GameHeroLevelgrow); ok {
|
||||
return configure.Get(heroId)
|
||||
if conf = configure.Get(heroId); conf != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
this.module.Errorf("cfg.GetHeroLvgrow :id = %s", heroId)
|
||||
return nil
|
||||
err = comm.NewNotFoundConfErr(moduleName, hero_levelgrow, heroId)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取英雄技能升级相关信息
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/lego/sys/redis"
|
||||
"go_dreamfactory/modules"
|
||||
"go_dreamfactory/pb"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
@ -196,17 +198,16 @@ func (this *ModelHero) calFigthValue(hero *pb.DBHero) (addValue int32, err error
|
||||
return
|
||||
}
|
||||
|
||||
//17
|
||||
// 初始化英雄
|
||||
func (this *ModelHero) InitHero(uid string, heroCfgId string) *pb.DBHero {
|
||||
heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId)
|
||||
|
||||
if heroCfg == nil {
|
||||
this.module.Errorf("%v hero not found from config %v", heroCfgId)
|
||||
return nil
|
||||
func (this *ModelHero) InitHero(uid string, heroCfgId string) (newHero *pb.DBHero, err error) {
|
||||
var (
|
||||
heroCfg *cfg.GameHeroData
|
||||
)
|
||||
if heroCfg, err = this.module.configure.GetHeroConfig(heroCfgId); err != nil {
|
||||
return
|
||||
}
|
||||
objId := primitive.NewObjectID().Hex()
|
||||
newHero := &pb.DBHero{
|
||||
newHero = &pb.DBHero{
|
||||
Id: objId,
|
||||
Uid: uid,
|
||||
HeroID: heroCfg.Hid,
|
||||
@ -224,9 +225,9 @@ func (this *ModelHero) InitHero(uid string, heroCfgId string) *pb.DBHero {
|
||||
Fetters: make(map[int32]int32),
|
||||
}
|
||||
this.initHeroSkill(newHero)
|
||||
this.PropertyCompute(newHero)
|
||||
err = this.PropertyCompute(newHero)
|
||||
|
||||
return newHero
|
||||
return
|
||||
}
|
||||
|
||||
// 初始化英雄技能
|
||||
@ -272,14 +273,15 @@ func (this *ModelHero) gmCreateSpecialHero(uid string, heroCfgId string) (hero *
|
||||
return
|
||||
}
|
||||
}
|
||||
hero = this.InitHero(uid, heroCfgId)
|
||||
if hero != nil {
|
||||
hero, err = this.InitHero(uid, heroCfgId)
|
||||
if err == nil {
|
||||
if err = this.AddList(uid, hero.Id, hero); err != nil {
|
||||
this.module.Errorf("%v", err)
|
||||
return
|
||||
}
|
||||
this.module.moduleFetter.AddHeroFetterData(uid, heroCfgId)
|
||||
}
|
||||
this.module.moduleFetter.AddHeroFetterData(uid, heroCfgId)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -309,9 +311,8 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
|
||||
var (
|
||||
model *db.DBModel
|
||||
)
|
||||
hero = this.InitHero(uid, heroCfgId)
|
||||
if hero != nil {
|
||||
|
||||
hero, err = this.InitHero(uid, heroCfgId)
|
||||
if err == nil {
|
||||
if this.module.IsCross() {
|
||||
if model, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
this.module.Errorln(err)
|
||||
@ -332,10 +333,23 @@ func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int
|
||||
|
||||
// 获取一个英雄(参数唯一objID)
|
||||
func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
||||
var (
|
||||
err error
|
||||
model *db.DBModel
|
||||
)
|
||||
hero := &pb.DBHero{}
|
||||
err := this.GetListObj(uid, heroId, hero)
|
||||
if err != nil {
|
||||
return nil
|
||||
if this.module.IsCross() {
|
||||
if model, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
this.module.Errorln(err)
|
||||
} else {
|
||||
if err = model.GetListObj(uid, heroId, hero); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err = this.GetListObj(uid, heroId, hero); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
return hero
|
||||
}
|
||||
@ -366,26 +380,43 @@ func (this *ModelHero) consumeHeroCard(uid string, hero *pb.DBHero) (err error)
|
||||
|
||||
// 获取玩家的英雄列表
|
||||
func (this *ModelHero) getHeroList(uid string) []*pb.DBHero {
|
||||
heroes := make([]*pb.DBHero, 0)
|
||||
err := this.GetList(uid, &heroes)
|
||||
if err != nil {
|
||||
return nil
|
||||
var (
|
||||
err error
|
||||
model *db.DBModel
|
||||
heroes []*pb.DBHero
|
||||
)
|
||||
if this.module.IsCross() {
|
||||
if model, err = this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
this.module.Errorln(err)
|
||||
} else {
|
||||
if err = model.GetList(uid, &heroes); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if err := this.GetList(uid, &heroes); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
return heroes
|
||||
}
|
||||
|
||||
// 重置觉醒属性
|
||||
func (this *ModelHero) resetJuexingProperty(hero *pb.DBHero) {
|
||||
func (this *ModelHero) resetJuexingProperty(hero *pb.DBHero) (err error) {
|
||||
var (
|
||||
awakenData *cfg.GameHeroAwakenData
|
||||
)
|
||||
hero.JuexProperty = make(map[int32]int32)
|
||||
for i := 1; i <= int(hero.JuexingLv); i++ {
|
||||
awakenData, err := this.module.configure.GetHeroAwakenConfig(hero.HeroID, int32(i))
|
||||
if err == nil {
|
||||
if awakenData, err = this.module.configure.GetHeroAwakenConfig(hero.HeroID, int32(i)); err == nil {
|
||||
for _, v := range awakenData.Phasebonus {
|
||||
hero.JuexProperty[v.A] += int32(v.N)
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 设置装备属性
|
||||
@ -444,22 +475,6 @@ func (this *ModelHero) setEquipment(uid string, hero *pb.DBHero) (newHero *pb.DB
|
||||
return
|
||||
}
|
||||
|
||||
// 合并属性即属性值累加 (data 额外加的属性)
|
||||
// func (this *ModelHero) mergeMainProperty(uid string, hero *pb.DBHero, data map[string]int32) (err error) {
|
||||
// for k, v := range hero.Property {
|
||||
// if v1, ok := data[k]; ok {
|
||||
// v += v1
|
||||
// }
|
||||
// }
|
||||
|
||||
// if err = this.ChangeList(uid, hero.Id, map[string]interface{}{
|
||||
// "property": hero.Property,
|
||||
// }); err != nil {
|
||||
// this.module.Errorf("mergeMainProperty err %v", err)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// 合并附加属性
|
||||
func (this *ModelHero) mergeAddProperty(uid string, hero *pb.DBHero, data map[int32]int32, skills []*pb.SkillData) {
|
||||
hero.AddProperty = data
|
||||
@ -474,52 +489,98 @@ func (this *ModelHero) mergeAddProperty(uid string, hero *pb.DBHero, data map[in
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ModelHero) StarAtkAddition(star int32) (addValue float32) {
|
||||
func (this *ModelHero) StarAtkAddition(star int32) (addValue float32, err error) {
|
||||
var (
|
||||
starCfg *cfg.GameHeroStargrowData
|
||||
cfg *cfg.GameHeroLevelupData
|
||||
)
|
||||
for i := 1; i <= int(star); i++ {
|
||||
starCfg := this.module.configure.GetHeroStar(int32(i))
|
||||
cfg := this.module.configure.GetHeroLv(starCfg.Level)
|
||||
addValue += cfg.Atk * starCfg.StarupAtk / 1000.0
|
||||
if starCfg, err = this.module.configure.GetHeroStar(int32(i)); err == nil {
|
||||
if cfg, err = this.module.configure.GetHeroLv(starCfg.Level); err == nil {
|
||||
addValue += cfg.Atk * starCfg.StarupAtk / 1000.0
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
return addValue
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelHero) StarDefAddition(star int32) (addValue float32) {
|
||||
func (this *ModelHero) StarDefAddition(star int32) (addValue float32, err error) {
|
||||
var (
|
||||
starCfg *cfg.GameHeroStargrowData
|
||||
cfg *cfg.GameHeroLevelupData
|
||||
)
|
||||
for i := 1; i <= int(star); i++ {
|
||||
starCfg := this.module.configure.GetHeroStar(int32(i))
|
||||
cfg := this.module.configure.GetHeroLv(starCfg.Level)
|
||||
addValue += cfg.Def * starCfg.StarupDef / 1000.0
|
||||
if starCfg, err = this.module.configure.GetHeroStar(int32(i)); err == nil {
|
||||
if cfg, err = this.module.configure.GetHeroLv(starCfg.Level); err == nil {
|
||||
addValue += cfg.Def * starCfg.StarupDef / 1000.0
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
return addValue
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelHero) StarHpAddition(star int32) (addValue float32) {
|
||||
func (this *ModelHero) StarHpAddition(star int32) (addValue float32, err error) {
|
||||
var (
|
||||
starCfg *cfg.GameHeroStargrowData
|
||||
cfg *cfg.GameHeroLevelupData
|
||||
)
|
||||
for i := 1; i <= int(star); i++ {
|
||||
starCfg := this.module.configure.GetHeroStar(int32(i))
|
||||
cfg := this.module.configure.GetHeroLv(starCfg.Level)
|
||||
|
||||
//this.moduleHero.Debugf("cfg.Atk= %f,starCfg.StarupHp = %f,addValue= %f", cfg.Atk, starCfg.StarupHp, addValue)
|
||||
addValue += cfg.Hp * starCfg.StarupHp / 1000.0
|
||||
if starCfg, err = this.module.configure.GetHeroStar(int32(i)); err == nil {
|
||||
if cfg, err = this.module.configure.GetHeroLv(starCfg.Level); err == nil {
|
||||
addValue += cfg.Hp * starCfg.StarupHp / 1000.0
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
return addValue
|
||||
return
|
||||
}
|
||||
|
||||
// 属性计算 基础属性
|
||||
// 英雄基础属性 + 英雄等级基础属性 * 英雄成长系数 + 英雄星级对应等级属性 * 英雄品质系数
|
||||
func (this *ModelHero) PropertyCompute(hero *pb.DBHero) {
|
||||
growCfg := this.module.configure.GetHeroLvgrow(hero.HeroID)
|
||||
heroCfg, _ := this.module.configure.GetHeroConfig(hero.HeroID)
|
||||
lvCfg := this.module.configure.GetHeroLv(hero.Lv)
|
||||
starCfg := this.module.configure.GetHeroStar(hero.Star)
|
||||
starLvfg := this.module.configure.GetHeroLv(starCfg.Level)
|
||||
|
||||
if growCfg == nil || heroCfg == nil || lvCfg == nil || starCfg == nil || starLvfg == nil {
|
||||
func (this *ModelHero) PropertyCompute(hero *pb.DBHero) (err error) {
|
||||
var (
|
||||
growCfg *cfg.GameHeroLevelgrowData
|
||||
lvCfg *cfg.GameHeroLevelupData
|
||||
atk float32
|
||||
def float32
|
||||
hp float32
|
||||
)
|
||||
growCfg, err = this.module.configure.GetHeroLvgrow(hero.HeroID)
|
||||
if err != nil {
|
||||
this.module.Debugf("hero propertyCompute Configure Info err:heroid :%s, herolv:=%d,heroStar:%d,", hero.HeroID, hero.Lv, hero.Star)
|
||||
return
|
||||
}
|
||||
|
||||
var atk = (this.StarAtkAddition(hero.Star) + lvCfg.Atk + float32(growCfg.Atk)) * (growCfg.Atkgrow / 1000.0)
|
||||
var def = (this.StarDefAddition(hero.Star) + lvCfg.Def + float32(growCfg.Def)) * (growCfg.Defgrow / 1000.0)
|
||||
var hp = (this.StarHpAddition(hero.Star) + lvCfg.Hp + float32(growCfg.Hp)) * (growCfg.Hpgrow / 1000.0)
|
||||
lvCfg, err = this.module.configure.GetHeroLv(hero.Lv)
|
||||
if err != nil {
|
||||
this.module.Debugf("hero propertyCompute Configure Info err:heroid :%s, herolv:=%d,heroStar:%d,", hero.HeroID, hero.Lv, hero.Star)
|
||||
return
|
||||
}
|
||||
atk, err = this.StarAtkAddition(hero.Star)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
def, err = this.StarDefAddition(hero.Star)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
hp, err = this.StarHpAddition(hero.Star)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
atk = (atk + lvCfg.Atk + float32(growCfg.Atk)) * (growCfg.Atkgrow / 1000.0)
|
||||
def = (def + lvCfg.Def + float32(growCfg.Def)) * (growCfg.Defgrow / 1000.0)
|
||||
hp = (hp + lvCfg.Hp + float32(growCfg.Hp)) * (growCfg.Hpgrow / 1000.0)
|
||||
speed := growCfg.Speed
|
||||
hero.Property = map[int32]int32{
|
||||
cfg.GamePropertyType_Base_MaxHp_Base: int32(math.Floor(float64(hp))),
|
||||
@ -543,8 +604,12 @@ func (this *ModelHero) PropertyCompute(hero *pb.DBHero) {
|
||||
this.resetTalentProperty(hero)
|
||||
this.module.moduleHoroscope.ComputeHeroNumeric(hero.Uid, hero)
|
||||
}
|
||||
this.resetJuexingProperty(hero)
|
||||
this.calFigthValue(hero)
|
||||
err = this.resetJuexingProperty(hero)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = this.calFigthValue(hero)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelHero) cleanData(uid string) {
|
||||
@ -617,7 +682,7 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, heros []*pb.DBHero,
|
||||
if maxLv > expConf.HeroLv {
|
||||
maxLv = expConf.HeroLv // 英雄最大等级限制
|
||||
}
|
||||
_data := this.module.configure.GetHeroLv(curLv)
|
||||
_data, _ := this.module.configure.GetHeroLv(curLv)
|
||||
if _data == nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
@ -664,7 +729,7 @@ func (this *ModelHero) AddCardExp(session comm.IUserSession, heros []*pb.DBHero,
|
||||
if upwardconf, err = this.module.configure.GetHeroLvUpWardData(heroconf.Star, curLv); err == nil {
|
||||
upwardconfs = append(upwardconfs, upwardconf)
|
||||
}
|
||||
_data = this.module.configure.GetHeroLv(curLv)
|
||||
_data, _ = this.module.configure.GetHeroLv(curLv)
|
||||
if _data == nil { // 等级加失败了 回到原来的等级
|
||||
fullexp = (curExp - maxExp)
|
||||
curLv -= 1
|
||||
@ -900,155 +965,6 @@ func (this *ModelHero) resetTalentProperty(hero *pb.DBHero) {
|
||||
}
|
||||
}
|
||||
|
||||
// 创建一条英雄信息,如果有这个英雄 则转换成对应的碎片
|
||||
func (this *ModelHero) createHero(session comm.IUserSession, heroCfgId string, count int32) (hero *pb.DBHero, atno []*pb.UserAtno, err error) {
|
||||
heros := make([]*pb.DBHero, 0)
|
||||
uid := session.GetUserId()
|
||||
heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId)
|
||||
bFirst := true
|
||||
if heroCfg == nil {
|
||||
err = errors.New("not found hero configID")
|
||||
this.module.Errorf("not found hero configID:%s", heroCfgId)
|
||||
return
|
||||
}
|
||||
if this.module.IsCross() {
|
||||
if dbModel, err1 := this.module.GetDBModelByUid(uid, this.TableName); err1 == nil {
|
||||
if err = dbModel.GetList(uid, &heros); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
this.module.Errorln(err) // 获取跨服对象失败
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err = this.GetList(uid, &heros); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, obj := range heros {
|
||||
if obj.HeroID == heroCfgId {
|
||||
hero = obj
|
||||
bFirst = false
|
||||
atno = append(atno, &pb.UserAtno{ // 有英雄的时候 数量给0
|
||||
A: "hero",
|
||||
T: hero.HeroID,
|
||||
N: 0,
|
||||
O: hero.Id,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if bFirst { // 没有当前英雄
|
||||
count -= 1
|
||||
hero, err = this.initHeroOverlying(uid, heroCfgId, 1)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: "hero",
|
||||
T: hero.HeroID,
|
||||
N: 1,
|
||||
O: hero.Id,
|
||||
})
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.module.ModuleEntertain.AddXxlCard(session, map[string]int32{hero.HeroID: 1}, true)
|
||||
})
|
||||
}
|
||||
res := make([]*cfg.Gameatn, 0)
|
||||
rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
bChange := false
|
||||
// 转碎片处理
|
||||
for i := 0; int32(i) < count; i++ {
|
||||
bAdd := false
|
||||
//守护之星 获得
|
||||
if heroCfg.Herofragnum > 0 {
|
||||
if v, ok := rst.Herofrag[hero.HeroID]; !ok {
|
||||
rst.Herofrag[hero.HeroID] = 1
|
||||
bAdd = true
|
||||
bChange = true
|
||||
} else if heroCfg.Herofragnum > v {
|
||||
rst.Herofrag[hero.HeroID] += 1
|
||||
bAdd = true
|
||||
bChange = true
|
||||
}
|
||||
}
|
||||
if bAdd {
|
||||
res = append(res, heroCfg.Herofrag...)
|
||||
for _, v := range heroCfg.Herofrag {
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: v.A,
|
||||
T: v.T,
|
||||
N: v.N,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
list := this.module.ModuleTools.GetGlobalConf().Moonshopmoney
|
||||
if list != nil {
|
||||
for pos, v := range list {
|
||||
if int32(pos)+3 == heroCfg.Star && v > 0 {
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "attr",
|
||||
T: "moongold",
|
||||
N: v,
|
||||
})
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: "attr",
|
||||
T: "moongold",
|
||||
N: v,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bAdd = false // 初始化
|
||||
// expitem 获得
|
||||
if heroCfg.Expitemnum > 0 {
|
||||
if v, ok := rst.Expitem[hero.HeroID]; ok {
|
||||
if heroCfg.Expitemnum > v {
|
||||
rst.Expitem[hero.HeroID] += 1
|
||||
bAdd = true
|
||||
bChange = true
|
||||
}
|
||||
} else {
|
||||
rst.Expitem[hero.HeroID] = 1
|
||||
bAdd = true
|
||||
bChange = true
|
||||
}
|
||||
}
|
||||
if bAdd {
|
||||
res = append(res, heroCfg.Expitem...)
|
||||
for _, v := range heroCfg.Expitem {
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: v.A,
|
||||
T: v.T,
|
||||
N: v.N,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if bChange {
|
||||
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
|
||||
"herofrag": rst.Herofrag,
|
||||
"expitem": rst.Expitem,
|
||||
})
|
||||
}
|
||||
if len(res) > 0 { // 资源统一发放
|
||||
this.module.DispenseRes(session, res, true)
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.module.WriteUserLog(session.GetUserId(), heroCfgId, comm.GMResAddType, "create hero", res)
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 校验当前技能是否是满级
|
||||
func (this *ModelHero) checkHeroAllSkillMax(hero *pb.DBHero) bool {
|
||||
for _, v := range hero.NormalSkill {
|
||||
@ -1096,6 +1012,8 @@ func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string, bI
|
||||
var (
|
||||
szCard map[string]int32
|
||||
bChange bool
|
||||
hero *pb.DBHero
|
||||
tasks []*pb.BuriedParam
|
||||
)
|
||||
szCard = make(map[string]int32)
|
||||
heros := make([]*pb.DBHero, 0)
|
||||
@ -1108,15 +1026,19 @@ func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string, bI
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = this.GetList(uid, &heros); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
lock, _ := this.userlock(session.GetUserId())
|
||||
err = lock.Lock()
|
||||
if err != nil {
|
||||
this.module.Error("创建英雄分布式锁失效 err!", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
defer lock.Unlock()
|
||||
heros = this.module.modelHero.getHeroList(uid)
|
||||
for _, heroCfgId := range cids {
|
||||
var (
|
||||
res []*cfg.Gameatn
|
||||
)
|
||||
var hero *pb.DBHero
|
||||
|
||||
heroCfg, _ := this.module.configure.GetHeroConfig(heroCfgId)
|
||||
bFirst := true
|
||||
if heroCfg == nil {
|
||||
@ -1131,7 +1053,7 @@ func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string, bI
|
||||
bFirst = false
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "hero",
|
||||
T: hero.HeroID,
|
||||
T: obj.HeroID,
|
||||
N: 0,
|
||||
})
|
||||
break
|
||||
@ -1211,8 +1133,31 @@ func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string, bI
|
||||
addres = append(addres, res)
|
||||
}
|
||||
if !bImitate {
|
||||
var szAddHero []string
|
||||
for _, v := range add {
|
||||
if cfg, err := this.module.configure.GetHeroConfig(v.HeroID); err == nil {
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype228, cfg.Star))
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype1, 1, utils.ToInt32(v.HeroID)))
|
||||
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype30, v.HeroID, cfg.Color))
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype31, 1, cfg.Color))
|
||||
szAddHero = append(szAddHero, v.HeroID)
|
||||
}
|
||||
|
||||
}
|
||||
if len(add) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: add})
|
||||
}
|
||||
|
||||
if db.IsCross() {
|
||||
go this.module.moduleFetter.SendRpcAddHero(session.GetUserId(), szAddHero, session.GetServiecTag())
|
||||
} else {
|
||||
go this.module.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero)
|
||||
}
|
||||
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.module.ModuleEntertain.AddXxlCard(session, szCard, true)
|
||||
if len(tasks) > 0 {
|
||||
this.module.ModuleBuried.TriggerBuried(session, tasks...)
|
||||
}
|
||||
})
|
||||
if bChange {
|
||||
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
|
||||
@ -1223,3 +1168,8 @@ func (this *ModelHero) ImitateHeros(session comm.IUserSession, cids []string, bI
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 分布式锁
|
||||
func (this *ModelHero) userlock(id string) (result *redis.RedisMutex, err error) {
|
||||
return this.module.modelHero.Redis.NewRedisMutex(fmt.Sprintf("%s-herolock:%s", this.module.modelHero.DBModel.ServiceId, id))
|
||||
}
|
||||
|
@ -93,46 +93,6 @@ func (this *Hero) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建单个叠加英雄
|
||||
func (this *Hero) createRepeatHero(session comm.IUserSession, heroCfgId string, num int32) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) {
|
||||
var (
|
||||
err error
|
||||
tasks []*pb.BuriedParam
|
||||
cfg *cfg.GameHeroData
|
||||
)
|
||||
if cfg, err = this.configure.GetHeroConfig(heroCfgId); err != nil {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_ConfigNoFound,
|
||||
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
hero, atno, err = this.modelHero.createHero(session, heroCfgId, num)
|
||||
if err == nil {
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.N == 1 {
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype228, cfg.Star))
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_HeroCreate,
|
||||
Title: pb.ErrorCode_HeroCreate.ToString(),
|
||||
Message: err.Error(),
|
||||
}
|
||||
return
|
||||
}
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype1, 1, utils.ToInt32(heroCfgId)))
|
||||
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype30, heroCfgId, cfg.Color))
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype31, num, cfg.Color))
|
||||
go this.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.ModuleBuried.TriggerBuried(session, tasks...)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取英雄
|
||||
func (this *Hero) GetHeroByObjID(uid, heroId string) (hero *pb.DBHero, errdata *pb.ErrorData) {
|
||||
hero = this.modelHero.getOneHero(uid, heroId)
|
||||
@ -218,37 +178,34 @@ func (this *Hero) CreateRepeatHeros(session comm.IUserSession, heros map[string]
|
||||
var (
|
||||
szAddHero []string
|
||||
changeList []*pb.DBHero
|
||||
hero *pb.DBHero
|
||||
curSzCard []string
|
||||
err error
|
||||
addres [][]*cfg.Gameatn
|
||||
add []*pb.DBHero
|
||||
res []*cfg.Gameatn
|
||||
)
|
||||
for heroCfgId, num := range heros {
|
||||
if num == 0 { // 数量为0 不做处理
|
||||
continue
|
||||
for k, v := range heros {
|
||||
for i := 0; i < int(v); i++ {
|
||||
curSzCard = append(curSzCard, k)
|
||||
}
|
||||
if hero, atno, errdata = this.createRepeatHero(session, heroCfgId, num); errdata != nil {
|
||||
this.Errorf("create hero %s failed", heroCfgId)
|
||||
continue
|
||||
}
|
||||
if addres, add, err = this.modelHero.ImitateHeros(session, curSzCard, false); err == nil {
|
||||
for _, v := range add {
|
||||
changeList = append(changeList, v)
|
||||
szAddHero = append(szAddHero, v.HeroID)
|
||||
}
|
||||
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.N == 1 {
|
||||
changeList = append(changeList, hero)
|
||||
szAddHero = append(szAddHero, heroCfgId)
|
||||
break
|
||||
}
|
||||
for _, v := range addres {
|
||||
for _, v1 := range v {
|
||||
if v1.A != "hero" {
|
||||
res = append(res, v1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(changeList) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeList})
|
||||
if db.IsCross() {
|
||||
go this.moduleFetter.SendRpcAddHero(session.GetUserId(), szAddHero, session.GetServiecTag())
|
||||
} else {
|
||||
go this.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero)
|
||||
}
|
||||
if errdata, atno = this.DispenseAtno(session, res, true); errdata != nil {
|
||||
return
|
||||
}
|
||||
go this.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
||||
this.ModuleEntertain.AddXxlCard(session, heros, bPush)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -875,7 +832,6 @@ func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp
|
||||
if curAddExp, award, errdata = this.modelHero.AddCardExp(session, heros, exp, model); errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
changeHero = append(changeHero, heros...)
|
||||
}
|
||||
} else {
|
||||
@ -897,32 +853,6 @@ func (this *Hero) AddHerosExp(session comm.IUserSession, heroObjs []string, exp
|
||||
return
|
||||
}
|
||||
|
||||
// 获得一个英雄
|
||||
func (this *Hero) CreateOneHero(session comm.IUserSession, heroCfgId string) (hero *pb.DBHero, atno []*pb.UserAtno, errdata *pb.ErrorData) {
|
||||
var (
|
||||
szAddHero []string
|
||||
changeList []*pb.DBHero
|
||||
)
|
||||
|
||||
if hero, atno, errdata = this.createRepeatHero(session, heroCfgId, 1); errdata != nil {
|
||||
this.Errorf("create hero %s failed", heroCfgId)
|
||||
return
|
||||
}
|
||||
szAddHero = append(szAddHero, heroCfgId)
|
||||
|
||||
for _, v := range atno {
|
||||
if v.A == "hero" && v.N == 1 {
|
||||
changeList = append(changeList, hero)
|
||||
go this.moduleFetter.AddHerosFetterData(session.GetUserId(), szAddHero) // 异步调用
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(changeList) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: changeList})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Hero) GetRandomCardByCardPool(uid string, count int32) (cards []string, err error) {
|
||||
var (
|
||||
drawCount int32 // 抽卡次数
|
||||
@ -1043,30 +973,3 @@ func (this *Hero) GetRandomCardByCardPool(uid string, count int32) (cards []stri
|
||||
err = this.modelRecord.ChangeHeroRecord(uid, update)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Hero) HeroLibrary(session comm.IUserSession, cids []string, addHero []*pb.DBHero) {
|
||||
var (
|
||||
tasks []*pb.BuriedParam
|
||||
add []string
|
||||
)
|
||||
for _, heroCfgId := range cids {
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype1, 1, utils.ToInt32(heroCfgId)))
|
||||
cfg, _ := this.configure.GetHeroConfig(heroCfgId)
|
||||
tasks = append(tasks, comm.GetBuriedParam2(comm.Rtype30, heroCfgId, cfg.Color))
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype31, 1, cfg.Color))
|
||||
}
|
||||
for _, v := range addHero {
|
||||
add = append(add, v.HeroID)
|
||||
}
|
||||
if db.IsCross() {
|
||||
this.moduleFetter.SendRpcAddHero(session.GetUserId(), add, session.GetServiecTag())
|
||||
} else {
|
||||
this.moduleFetter.AddHerosFetterData(session.GetUserId(), add) // 异步调用
|
||||
}
|
||||
|
||||
this.ModuleBuried.TriggerBuried(session, tasks...)
|
||||
if len(addHero) > 0 {
|
||||
session.SendMsg("hero", "change", &pb.HeroChangePush{List: addHero})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -31,7 +31,11 @@ func (this *ModelExpand) Init(service core.IService, module core.IModule, comp c
|
||||
|
||||
// 获取用户通过扩展表
|
||||
func (this *ModelExpand) GetUserExpand(uid string) (result *pb.DBUserExpand, err error) {
|
||||
result = &pb.DBUserExpand{}
|
||||
result = &pb.DBUserExpand{
|
||||
Expitem: map[string]int32{},
|
||||
Race: map[int32]int32{},
|
||||
Herofrag: map[string]int32{},
|
||||
}
|
||||
if db.IsCross() {
|
||||
if model, err := this.module.GetDBModelByUid(uid, this.TableName); err != nil {
|
||||
this.module.Error("Cross GetDBModuleByUid", log.Field{Key: "uid", Value: uid})
|
||||
|
Loading…
Reference in New Issue
Block a user