属性计算
This commit is contained in:
parent
47467267b5
commit
69fe11a076
@ -104,7 +104,7 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,12 @@ func (this *apiComp) Chouka(session comm.IUserSession, req *pb.HeroChoukaReq) (c
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
heroCfgIds := req.HeroIds
|
heroCfgIds := req.HeroIds
|
||||||
if err := this.module.hero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil {
|
if err := this.module.modelHero.createMultiHero(session.GetUserId(), heroCfgIds...); err != nil {
|
||||||
code = pb.ErrorCode_HeroCreate
|
code = pb.ErrorCode_HeroCreate
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
heroes, err := this.module.hero.getHeroList(session.GetUserId())
|
heroes, err := this.module.modelHero.getHeroList(session.GetUserId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%v", err)
|
log.Errorf("%v", err)
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
|
@ -24,7 +24,7 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.HeroInfoReq) (code
|
|||||||
utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), HeroSubTypeList, req, rsp)
|
utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), HeroSubTypeList, req, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hero := this.module.hero.getOneHero(session.GetUserId(), req.HeroId)
|
hero := this.module.modelHero.getOneHero(session.GetUserId(), req.HeroId)
|
||||||
if hero == nil {
|
if hero == nil {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ func (this *apiComp) List(session comm.IUserSession, req *pb.HeroListReq) (code
|
|||||||
utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), HeroSubTypeList, req, rsp)
|
utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), HeroSubTypeList, req, rsp)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
list, err := this.module.hero.getHeroList(session.GetUserId())
|
list, err := this.module.modelHero.getHeroList(session.GetUserId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
|
@ -104,7 +104,7 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
|||||||
_heroMap := map[string]interface{}{
|
_heroMap := map[string]interface{}{
|
||||||
"resonateNum": _hero.ResonateNum + resonConfig.Energy,
|
"resonateNum": _hero.ResonateNum + resonConfig.Energy,
|
||||||
}
|
}
|
||||||
err1 = this.module.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("update hero skill failed:%v", err1)
|
log.Errorf("update hero skill failed:%v", err1)
|
||||||
}
|
}
|
||||||
@ -117,11 +117,11 @@ func (this *apiComp) Resonance(session comm.IUserSession, req *pb.HeroResonanceR
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := 0; i < int(v.N); i++ { // 有多少张加多少次
|
for i := 0; i < int(v.N); i++ { // 有多少张加多少次
|
||||||
this.module.hero.createOneHero(session.GetUserId(), int32(value))
|
this.module.modelHero.createOneHero(session.GetUserId(), int32(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
@ -75,13 +75,20 @@ func (this *apiComp) ResonanceReset(session comm.IUserSession, req *pb.HeroReson
|
|||||||
"Energy": _hero.Energy,
|
"Energy": _hero.Energy,
|
||||||
}
|
}
|
||||||
|
|
||||||
err1 = this.module.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("update hero skill failed:%v", err1)
|
log.Errorf("update hero skill failed:%v", err1)
|
||||||
}
|
}
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property := make(map[string]int32, 0)
|
||||||
|
property[comm.HpPro] -= _hero.AddProperty[comm.HpPro]
|
||||||
|
property[comm.AtkPro] -= _hero.AddProperty[comm.AtkPro]
|
||||||
|
property[comm.DefPro] -= _hero.AddProperty[comm.DefPro]
|
||||||
|
this.module.modelHero.mergeMainProperty(session.GetUserId(), _hero.Id, property)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,14 @@ import (
|
|||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"math"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
//参数校验
|
//参数校验
|
||||||
func (this *apiComp) ResonanceUseEnergyCheck(session comm.IUserSession, req *pb.HeroResonanceUseEnergyReq) (code pb.ErrorCode) {
|
func (this *apiComp) ResonanceUseEnergyCheck(session comm.IUserSession, req *pb.HeroResonanceUseEnergyReq) (code pb.ErrorCode) {
|
||||||
if len(req.HeroObjID) == 0 || req.UseEnergy <= 0 || req.UseType < 0 {
|
if len(req.HeroObjID) == 0 || req.UseEnergy <= 0 || req.UseType < 0 || req.UseType > 3 {
|
||||||
code = pb.ErrorCode_ReqParameterError
|
code = pb.ErrorCode_ReqParameterError
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -40,13 +41,30 @@ func (this *apiComp) ResonanceUseEnergy(session comm.IUserSession, req *pb.HeroR
|
|||||||
"Energy": _hero.Energy,
|
"Energy": _hero.Energy,
|
||||||
}
|
}
|
||||||
|
|
||||||
err1 := this.module.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
err1 := this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
log.Errorf("update hero skill failed:%v", err1)
|
log.Errorf("update hero skill failed:%v", err1)
|
||||||
}
|
}
|
||||||
|
// 计算属性
|
||||||
|
resonConfig, errr := this.module.configure.GetHeroResonanceConfig(_hero.HeroID)
|
||||||
|
if errr != nil {
|
||||||
|
code = pb.ErrorCode_ConfigNoFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
property := make(map[string]int32, 0)
|
||||||
|
switch req.UseType {
|
||||||
|
case 1:
|
||||||
|
property[comm.Hp] = int32(math.Floor((1.0 + float64(resonConfig.Hppro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Hp])))
|
||||||
|
case 2:
|
||||||
|
property[comm.Atk] = int32(math.Floor((1.0 + float64(resonConfig.Atkpro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Atk])))
|
||||||
|
case 3:
|
||||||
|
property[comm.Def] = int32(math.Floor((1.0 + float64(resonConfig.Defpro*req.UseEnergy)/1000) * float64(_hero.Property[comm.Def])))
|
||||||
|
}
|
||||||
|
this.module.modelHero.mergeMainProperty(session.GetUserId(), _hero.Id, property)
|
||||||
|
|
||||||
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
_heroMap := map[string]interface{}{
|
_heroMap := map[string]interface{}{
|
||||||
"normalSkill": _hero.NormalSkill,
|
"normalSkill": _hero.NormalSkill,
|
||||||
}
|
}
|
||||||
err1 = this.module.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
err1 = this.module.modelHero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap) // 修改英雄信息
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("update hero skill failed:%v", err)
|
log.Errorf("update hero skill failed:%v", err)
|
||||||
}
|
}
|
||||||
@ -126,7 +126,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,7 @@ func (this *apiComp) StrengthenUpStarCheck(session comm.IUserSession, req *pb.He
|
|||||||
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode, data proto.Message) {
|
func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStrengthenUpStarReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
var (
|
var (
|
||||||
target *cfg.Game_heroStarupData // 配置表目标升星英雄信息
|
target *cfg.Game_heroStarupData // 配置表目标升星英雄信息
|
||||||
raceHero *pb.DBHero // 消耗的阵容英雄
|
|
||||||
costRaceCount int32
|
costRaceCount int32
|
||||||
curGold int32
|
|
||||||
)
|
)
|
||||||
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID)
|
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID)
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -71,7 +69,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
|||||||
}
|
}
|
||||||
// 校验阵容英雄消耗
|
// 校验阵容英雄消耗
|
||||||
for _, v := range req.HeroRace {
|
for _, v := range req.HeroRace {
|
||||||
if raceHero, err = this.module.GetHero(session.GetUserId(), v.CostCardObj); err != pb.ErrorCode_Success {
|
if raceHero, err := this.module.GetHero(session.GetUserId(), v.CostCardObj); err != pb.ErrorCode_Success {
|
||||||
code = pb.ErrorCode_ReqParameterError
|
code = pb.ErrorCode_ReqParameterError
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@ -100,7 +98,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 金币消耗判断
|
// 金币消耗判断
|
||||||
curGold = this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "gold")
|
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), "gold")
|
||||||
if curGold < target.Gold { // 金币不足
|
if curGold < target.Gold { // 金币不足
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
return
|
||||||
@ -131,19 +129,6 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_hero.Star += 1
|
code = this.module.modelHero.HeroStarUp(session, _hero) // 执行升星操作
|
||||||
_heroMap := map[string]interface{}{
|
|
||||||
"star": _hero.Star,
|
|
||||||
}
|
|
||||||
// 保存数据
|
|
||||||
err1 = this.module.hero.modifyHeroData(session.GetUserId(), req.HeroObjID, _heroMap)
|
|
||||||
if err1 != nil {
|
|
||||||
code = pb.ErrorCode_DBError
|
|
||||||
log.Errorf("update hero skill failed:%v", err)
|
|
||||||
}
|
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
|
||||||
if err1 != nil {
|
|
||||||
log.Errorf("PushHeroProperty err!")
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
var (
|
var (
|
||||||
curLv int32
|
curLv int32
|
||||||
curExp int32 // 当前英雄的经验
|
curExp int32 // 当前英雄的经验
|
||||||
costRes int32 // 当前需要消资源的数量
|
costRes map[string]int32 // 当前需要消资源的数量
|
||||||
addExp int32 // 需要增加的经验
|
addExp int32 // 需要增加的经验
|
||||||
curRes int32
|
curRes map[string]int32
|
||||||
atn = map[string]interface{}{}
|
|
||||||
)
|
)
|
||||||
atn = make(map[string]interface{}, 0)
|
curRes = make(map[string]int32, 0)
|
||||||
|
costRes = make(map[string]int32, 0)
|
||||||
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
_hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在
|
||||||
|
|
||||||
if err != pb.ErrorCode_Success {
|
if err != pb.ErrorCode_Success {
|
||||||
@ -91,19 +91,18 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
curLv -= 1
|
curLv -= 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
costRes += _data.Gold[0].N
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, v := range _data.Gold {
|
for _, v := range _data.Gold {
|
||||||
atn["a"] = v.A
|
_curRes := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T)
|
||||||
atn["t"] = v.T
|
if _curRes < v.N {
|
||||||
atn["n"] = v.N
|
|
||||||
}
|
|
||||||
// 资源消耗判断
|
|
||||||
curRes = this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), atn["t"].(string))
|
|
||||||
if curRes < costRes {
|
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
curRes[v.T] = _curRes
|
||||||
|
costRes[v.T] += v.N
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
@ -117,25 +116,28 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroStrengthenUplvResp{Hero: _hero})
|
session.SendMsg(string(this.module.GetType()), StrengthenUplv, &pb.HeroStrengthenUplvResp{Hero: _hero})
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costRes, addExp)
|
log.Debugf("升级后当前等级: %d,经验: %d,需要消耗的金币: %d,增加的经验: %d", curLv, curExp, costRes["gold"], addExp)
|
||||||
// 执行升级逻辑
|
// 执行升级逻辑
|
||||||
code = this.module.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
|
code = this.module.AddCardExp(session.GetUserId(), req.HeroObjID, addExp) // 加经验
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 消耗道具
|
// 消耗道具
|
||||||
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), atn["t"].(string), int32(curRes-costRes)) // 减少金币
|
for k, v := range costRes {
|
||||||
|
|
||||||
|
code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), k, int32(curRes[k]-v)) // 减少金币
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 删除经验卡
|
// 删除经验卡
|
||||||
err1 := this.module.hero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount)
|
err1 := this.module.modelHero.consumeOneHeroCard(session.GetUserId(), req.ExpCardID, req.Amount)
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("delete err failed err:%T!", err)
|
log.Errorf("delete err failed err:%T!", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err1 = this.module.hero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
err1 = this.module.modelHero.PushHeroProperty(session, _hero.Id) // 推送属性变化
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Errorf("PushHeroProperty err!")
|
log.Errorf("PushHeroProperty err!")
|
||||||
}
|
}
|
||||||
|
@ -70,23 +70,23 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
//创建一个英雄s
|
//创建一个英雄s
|
||||||
func TestCreateOneHero(t *testing.T) {
|
func TestCreateOneHero(t *testing.T) {
|
||||||
err := module.hero.createOneHero("u1", 25001)
|
err := module.modelHero.createOneHero("u1", 25001)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取玩家英雄
|
//获取玩家英雄
|
||||||
func TestGetOneHero(t *testing.T) {
|
func TestGetOneHero(t *testing.T) {
|
||||||
d := module.hero.getOneHero("u1", "62b534bebf4745d4117acabe")
|
d := module.modelHero.getOneHero("u1", "62b534bebf4745d4117acabe")
|
||||||
fmt.Printf("%v", d)
|
fmt.Printf("%v", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPropertyCompute(t *testing.T) {
|
func TestPropertyCompute(t *testing.T) {
|
||||||
m := module.hero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
|
m := module.modelHero.PropertyCompute("u1", "62b534bebf4745d4117acabe")
|
||||||
fmt.Println(m)
|
fmt.Println(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHeroList(t *testing.T) {
|
func TestHeroList(t *testing.T) {
|
||||||
heroes, err := module.hero.getHeroList("u1")
|
heroes, err := module.modelHero.getHeroList("u1")
|
||||||
fmt.Printf("%v %v", heroes, err)
|
fmt.Printf("%v %v", heroes, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +95,6 @@ func TestModify(t *testing.T) {
|
|||||||
"lv": 2,
|
"lv": 2,
|
||||||
"exp": 1000,
|
"exp": 1000,
|
||||||
}
|
}
|
||||||
err := module.hero.modifyHeroData("u1", "62b534bebf4745d4117acabe", data)
|
err := module.modelHero.modifyHeroData("u1", "62b534bebf4745d4117acabe", data)
|
||||||
fmt.Printf("%v ", err)
|
fmt.Printf("%v ", err)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ func (this *ModelHero) initHero(uid string, heroCfgId int32) *pb.DBHero {
|
|||||||
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
|
func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
|
||||||
hero := this.initHero(uid, heroCfgId)
|
hero := this.initHero(uid, heroCfgId)
|
||||||
if hero != nil {
|
if hero != nil {
|
||||||
if err = this.moduleHero.hero.AddList(uid, hero.Id, hero); err != nil {
|
if err = this.moduleHero.modelHero.AddList(uid, hero.Id, hero); err != nil {
|
||||||
log.Errorf("%v", err)
|
log.Errorf("%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId int32) (err error) {
|
|||||||
|
|
||||||
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID
|
//创建多个指定的英雄 heroCfgIds可填入多个英雄ID
|
||||||
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
|
func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
|
||||||
heroes, err := this.moduleHero.hero.getHeroList(uid)
|
heroes, err := this.moduleHero.modelHero.getHeroList(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func (this *ModelHero) createMultiHero(uid string, heroCfgIds ...int32) error {
|
|||||||
//获取一个英雄
|
//获取一个英雄
|
||||||
func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
||||||
hero := &pb.DBHero{}
|
hero := &pb.DBHero{}
|
||||||
err := this.moduleHero.hero.GetListObj(uid, heroId, hero)
|
err := this.moduleHero.modelHero.GetListObj(uid, heroId, hero)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ func (this *ModelHero) getOneHero(uid, heroId string) *pb.DBHero {
|
|||||||
//消耗一张英雄卡
|
//消耗一张英雄卡
|
||||||
func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
|
func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err error) {
|
||||||
for i := 0; i < int(count); i++ {
|
for i := 0; i < int(count); i++ {
|
||||||
if err := this.moduleHero.hero.DelListlds(uid, heroId); err != nil {
|
if err := this.moduleHero.modelHero.DelListlds(uid, heroId); err != nil {
|
||||||
log.Errorf("%v", err)
|
log.Errorf("%v", err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -131,7 +131,7 @@ func (this *ModelHero) consumeOneHeroCard(uid, heroId string, count int32) (err
|
|||||||
|
|
||||||
//更新英雄数据
|
//更新英雄数据
|
||||||
func (this *ModelHero) modifyHeroData(uid, heroId string, data map[string]interface{}) error {
|
func (this *ModelHero) modifyHeroData(uid, heroId string, data map[string]interface{}) error {
|
||||||
return this.moduleHero.hero.ChangeList(uid, heroId, data)
|
return this.moduleHero.modelHero.ChangeList(uid, heroId, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取玩家的英雄列表
|
//获取玩家的英雄列表
|
||||||
@ -173,9 +173,9 @@ func (this *ModelHero) mergeAddProperty(uid, heroId string, data map[string]int3
|
|||||||
if hero == nil {
|
if hero == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hero.AddProperty[comm.Hp] += data[comm.Hp]
|
hero.AddProperty[comm.Hp] = data[comm.Hp]
|
||||||
hero.AddProperty[comm.Atk] += data[comm.Atk]
|
hero.AddProperty[comm.Atk] = data[comm.Atk]
|
||||||
hero.AddProperty[comm.Def] += data[comm.Def]
|
hero.AddProperty[comm.Def] = data[comm.Def]
|
||||||
}
|
}
|
||||||
|
|
||||||
//属性计算 - 暂时放在modelHero里实现
|
//属性计算 - 暂时放在modelHero里实现
|
||||||
@ -250,3 +250,37 @@ func (this *ModelHero) PushHeroProperty(session comm.IUserSession, heroId string
|
|||||||
}
|
}
|
||||||
return session.SendMsg("push", "property", &pb.HeroProperty{Property: m})
|
return session.SendMsg("push", "property", &pb.HeroProperty{Property: m})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 英雄升星
|
||||||
|
func (this *ModelHero) HeroStarUp(session comm.IUserSession, hero *pb.DBHero) (code pb.ErrorCode) {
|
||||||
|
|
||||||
|
_heroMap := map[string]interface{}{
|
||||||
|
"star": hero.Star,
|
||||||
|
}
|
||||||
|
// 保存数据
|
||||||
|
err1 := this.modifyHeroData(session.GetUserId(), hero.Id, _heroMap)
|
||||||
|
if err1 != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
log.Errorf("update hero skill failed:%v", err1)
|
||||||
|
}
|
||||||
|
// 计算属性
|
||||||
|
data := make(map[string]int32, 0)
|
||||||
|
newConfig := this.moduleHero.configure.GetHeroStar(hero.Star - 1)
|
||||||
|
if newConfig == nil {
|
||||||
|
code = pb.ErrorCode_ConfigurationException
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data[comm.Hp] = int32(math.Floor((1.0 + float64(newConfig.StarupHp)) * float64(hero.Property[comm.Hp]) / 100))
|
||||||
|
data[comm.Atk] = int32(math.Floor((1.0 + float64(newConfig.StarupAtk)) * float64(hero.Property[comm.Atk]) / 100))
|
||||||
|
data[comm.Def] = int32(math.Floor((1.0 + float64(newConfig.StarupDef)) * float64(hero.Property[comm.Def]) / 100))
|
||||||
|
data[comm.Speed] = int32(math.Floor((1.0 + float64(newConfig.StarupSpeed)) * float64(hero.Property[comm.Speed]) / 100))
|
||||||
|
this.mergeMainProperty(session.GetUserId(), hero.Id, data)
|
||||||
|
|
||||||
|
err1 = this.PushHeroProperty(session, hero.Id) // 推送属性变化
|
||||||
|
if err1 != nil {
|
||||||
|
code = pb.ErrorCode_Unknown
|
||||||
|
log.Errorf("PushHeroProperty err!")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ type Hero struct {
|
|||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
api *apiComp
|
api *apiComp
|
||||||
configure *configureComp
|
configure *configureComp
|
||||||
hero *ModelHero
|
modelHero *ModelHero
|
||||||
items comm.IItems
|
items comm.IItems
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ func (this *Hero) Init(service core.IService, module core.IModule, options core.
|
|||||||
func (this *Hero) OnInstallComp() {
|
func (this *Hero) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
|
||||||
this.hero = this.RegisterComp(new(ModelHero)).(*ModelHero)
|
this.modelHero = this.RegisterComp(new(ModelHero)).(*ModelHero)
|
||||||
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建新英雄
|
//创建新英雄
|
||||||
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
|
func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
|
||||||
return this.hero.createMultiHero(uid, heroCfgId...)
|
return this.modelHero.createMultiHero(uid, heroCfgId...)
|
||||||
}
|
}
|
||||||
|
|
||||||
//消耗英雄卡
|
//消耗英雄卡
|
||||||
@ -58,7 +58,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range curList {
|
for _, v := range curList {
|
||||||
err := this.hero.consumeOneHeroCard(v.Uid, v.Id, count)
|
err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pb.ErrorCode_DBError
|
return pb.ErrorCode_DBError
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func (this *Hero) ChangeCard(uId string, heroCfgId int32, count int32) (code pb.
|
|||||||
|
|
||||||
//获取英雄
|
//获取英雄
|
||||||
func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
|
func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
|
||||||
hero := this.hero.getOneHero(uid, heroId)
|
hero := this.modelHero.getOneHero(uid, heroId)
|
||||||
if hero == nil {
|
if hero == nil {
|
||||||
return nil, pb.ErrorCode_HeroNoExist
|
return nil, pb.ErrorCode_HeroNoExist
|
||||||
}
|
}
|
||||||
@ -91,14 +91,14 @@ func (this *Hero) UpdateEquipment(hero *pb.DBHero, equip []*pb.DB_Equipment) (co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hero.mergeMainProperty(hero.Uid, hero.Id, property)
|
this.modelHero.mergeMainProperty(hero.Uid, hero.Id, property)
|
||||||
this.hero.mergeAddProperty(hero.Uid, hero.Id, addProperty)
|
this.modelHero.mergeAddProperty(hero.Uid, hero.Id, addProperty)
|
||||||
return this.hero.setEquipment(hero.Uid, hero.Id, equipIds)
|
return this.modelHero.setEquipment(hero.Uid, hero.Id, equipIds)
|
||||||
}
|
}
|
||||||
|
|
||||||
//英雄列表
|
//英雄列表
|
||||||
func (this *Hero) GetHeroList(uid string) []*pb.DBHero {
|
func (this *Hero) GetHeroList(uid string) []*pb.DBHero {
|
||||||
list, err := this.hero.getHeroList(uid)
|
list, err := this.modelHero.getHeroList(uid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -159,16 +159,27 @@ func (this *Hero) AddCardExp(uid string, heroId string, exp int32) (code pb.Erro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// _hero.Lv = curLv
|
|
||||||
// _hero.Exp = curExp
|
// 检测等级有变化 推送属性
|
||||||
|
if curLv != _hero.Lv {
|
||||||
|
data := make(map[string]int32, 0)
|
||||||
|
preConfig := this.configure.GetHeroLv(_hero.Lv)
|
||||||
|
nowConfig := this.configure.GetHeroLv(curLv)
|
||||||
|
data["hp"] = int32(nowConfig.Hp - preConfig.Hp)
|
||||||
|
data["atk"] = int32(nowConfig.Atk - preConfig.Atk)
|
||||||
|
data["def"] = int32(nowConfig.Def - preConfig.Def)
|
||||||
|
this.modelHero.mergeMainProperty(uid, heroId, data)
|
||||||
|
}
|
||||||
|
|
||||||
update := map[string]interface{}{
|
update := map[string]interface{}{
|
||||||
"lv": curLv,
|
"lv": curLv,
|
||||||
"exp": curExp,
|
"exp": curExp,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := this.hero.modifyHeroData(uid, heroId, update); err != nil {
|
if err := this.modelHero.modifyHeroData(uid, heroId, update); err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
} // 修改英雄数据
|
} // 修改英雄数据
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
code = pb.ErrorCode_HeroNoExist
|
code = pb.ErrorCode_HeroNoExist
|
||||||
return
|
return
|
||||||
|
@ -29,7 +29,7 @@ message DBHero {
|
|||||||
int32 resonateNum = 18; //@go_tags(`bson:"resonateNum"`) 共鸣次数
|
int32 resonateNum = 18; //@go_tags(`bson:"resonateNum"`) 共鸣次数
|
||||||
int32 distributionResonate =
|
int32 distributionResonate =
|
||||||
19; //@go_tags(`bson:"distributionResonate"`) 分配的共鸣能量
|
19; //@go_tags(`bson:"distributionResonate"`) 分配的共鸣能量
|
||||||
map<int32, int32> energy = 20; // @go_tags(`bson:"energy"`)能量分配到哪里
|
map<int32, int32> energy = 20; // @go_tags(`bson:"energy"`)能量分配到哪里[1,0]
|
||||||
int32 sameCount = 21; // @go_tags(`bson:"sameCount"`) 卡片叠加数量
|
int32 sameCount = 21; // @go_tags(`bson:"sameCount"`) 卡片叠加数量
|
||||||
int32 suiteId = 22; //@go_tags(`bson:"suiteId"`) 套装Id
|
int32 suiteId = 22; //@go_tags(`bson:"suiteId"`) 套装Id
|
||||||
int32 suiteExtId = 23; // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
int32 suiteExtId = 23; // go_tags(`bson:"suiteExtId"`) 扩展套装Id
|
||||||
|
Loading…
Reference in New Issue
Block a user