修改消卡

This commit is contained in:
zhaocy 2022-07-08 11:25:10 +08:00
parent 83dd0f905f
commit 549be3d0ba
2 changed files with 50 additions and 43 deletions

View File

@ -3,7 +3,6 @@ package hero
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
)
@ -45,32 +44,38 @@ func (this *Hero) CreateHero(uid string, heroCfgId ...int32) error {
}
//消耗英雄卡
func (this *Hero) ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) {
if count <= 0 {
log.Errorf("attr no changed,uid: %s heroCfgId: %s count: %d", uId, heroCfgId, count)
code = pb.ErrorCode_ReqParameterError
return
}
heroes := this.GetHeroList(uId)
var curList []*pb.DBHero
for _, v := range heroes {
if heroCfgId == v.HeroID {
curList = append(curList, v)
}
}
if int32(len(curList)) < count {
return pb.ErrorCode_HeroNoEnough
}
// func (this *Hero) ConsumeCard(uId string, heroCfgId int32, count int32) (code pb.ErrorCode) {
// if count <= 0 {
// log.Errorf("attr no changed,uid: %s heroCfgId: %s count: %d", uId, heroCfgId, count)
// code = pb.ErrorCode_ReqParameterError
// return
// }
for _, v := range curList {
err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
if err != nil {
return pb.ErrorCode_DBError
}
}
// heroCfg := this.configure.GetHero(heroCfgId)
// if heroCfg != nil {
return pb.ErrorCode_Success
}
// }
// heroes := this.GetHeroList(uId)
// var curList []*pb.DBHero
// for _, v := range heroes {
// if heroCfgId == v.HeroID {
// curList = append(curList, v)
// }
// }
// if int32(len(curList)) < count {
// return pb.ErrorCode_HeroNoEnough
// }
// for _, v := range curList {
// err := this.modelHero.consumeOneHeroCard(v.Uid, v.Id, count)
// if err != nil {
// return pb.ErrorCode_DBError
// }
// }
// return pb.ErrorCode_Success
// }
//获取英雄
func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
@ -110,13 +115,13 @@ func (this *Hero) UpdateEquipment(hero *pb.DBHero, equip []*pb.DB_Equipment) (co
//英雄列表
func (this *Hero) GetHeroList(uid string) []*pb.DBHero {
data := []*pb.DBHero{}
// data := []*pb.DBHero{}
heroes := this.modelHero.getHeroList(uid)
for _, h := range heroes {
h.Property = this.modelHero.PropertyCompute(uid, h.Id)
data = append(data, h)
}
return data
// for _, h := range heroes {
// h.Property = this.modelHero.PropertyCompute(uid, h.Id)
// data = append(data, h)
// }
return heroes
}
//查询英雄数量

View File

@ -158,16 +158,17 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
code = pb.ErrorCode_ResNoEnough
return
}
} else if v.A == comm.HeroType { //卡片资源
if resID, err = strconv.Atoi(v.T); err != nil {
code = pb.ErrorCode_ConfigurationException
return
}
if amount = int32(this.ModuleHero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
code = pb.ErrorCode_ResNoEnough
return
}
}
// else if v.A == comm.HeroType { //卡片资源
// if resID, err = strconv.Atoi(v.T); err != nil {
// code = pb.ErrorCode_ConfigurationException
// return
// }
// if amount = int32(this.ModuleHero.QueryHeroAmount(uid, int32(resID))); amount < v.N {
// code = pb.ErrorCode_ResNoEnough
// return
// }
// }
//不存在消耗武器的情况
// } else if v.A == comm.EquipmentType {
// if resID, err = strconv.Atoi(v.T); err != nil {
@ -187,10 +188,11 @@ func (this *ModuleBase) CheckConsumeRes(uid string, res []*cfg.Game_atn) (code p
} else if v.A == comm.ItemType { //道具资源
resID, _ = strconv.Atoi(v.T)
this.ModuleItems.AddItem(source, uid, int32(resID), -1*v.N)
} else if v.A == comm.HeroType { //卡片资源
resID, _ = strconv.Atoi(v.T)
this.ModuleHero.ConsumeCard(uid, int32(resID), -1*v.N)
}
// else if v.A == comm.HeroType { //卡片资源
// resID, _ = strconv.Atoi(v.T)
// this.ModuleHero.ConsumeCard(uid, int32(resID), -1*v.N)
// }
// } else if v.A == comm.EquipmentType {
// resID, _ = strconv.Atoi(v.T)
// equipment.AddNewEquipments(source, uid, resID, -1*v.N)