装备叠卡修改
This commit is contained in:
parent
0099f3d01c
commit
2333b055bb
@ -241,15 +241,58 @@ func (this *ModelHero) getHeroList(uid string) []*pb.DBHero {
|
||||
return heroes
|
||||
}
|
||||
|
||||
//更新装备
|
||||
func (this *ModelHero) setEquipment(uid, heroId string, equipIds []string) error {
|
||||
if len(equipIds) == 0 {
|
||||
// 设置装备属性
|
||||
func (this *ModelHero) setEquipProperty(hero *pb.DBHero, equip []*pb.DB_Equipment) {
|
||||
property := make(map[string]int32) //主属性
|
||||
addProperty := make(map[string]int32) //副属性
|
||||
for i, v := range equip {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
hero.EquipID[i] = v.Id
|
||||
//主属性
|
||||
property[v.MainEntry.AttrName] = v.MainEntry.Value
|
||||
//附加属性
|
||||
for _, v := range v.AdverbEntry {
|
||||
addProperty[v.AttrName] = v.Value
|
||||
}
|
||||
}
|
||||
|
||||
this.mergeMainProperty(hero.Uid, hero.Uid, property)
|
||||
this.mergeAddProperty(hero.Uid, hero.Uid, addProperty)
|
||||
}
|
||||
|
||||
//设置装备
|
||||
func (this *ModelHero) setEquipment(hero *pb.DBHero) (err error) {
|
||||
if len(hero.EquipID) == 0 {
|
||||
return nil
|
||||
}
|
||||
update := map[string]interface{}{
|
||||
"equipID": equipIds,
|
||||
|
||||
update := make(map[string]interface{})
|
||||
if hero.IsOverlying {
|
||||
if hero.SameCount-1 > 0 {
|
||||
update["sameCount"] = hero.SameCount - 1
|
||||
}
|
||||
update["isOverlying"] = false
|
||||
if err = this.modifyHeroData(hero.Uid, hero.Id, update); err != nil {
|
||||
this.moduleHero.Errorf("%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
//创建新卡
|
||||
newHero, err := this.createOneHero(hero.Uid, hero.HeroID)
|
||||
if err != nil {
|
||||
this.moduleHero.Errorf("%v", err)
|
||||
return err
|
||||
}
|
||||
newHero.EquipID = hero.EquipID
|
||||
hero = newHero
|
||||
return this.modifyHeroData(newHero.Uid, newHero.Id, update)
|
||||
} else {
|
||||
update["equipID"] = hero.EquipID
|
||||
}
|
||||
return this.moduleHero.modelHero.modifyHeroData(uid, heroId, update)
|
||||
|
||||
return this.modifyHeroData(hero.Uid, hero.Id, update)
|
||||
}
|
||||
|
||||
//合并属性即属性值累加
|
||||
|
@ -59,28 +59,16 @@ func (this *Hero) GetHero(uid, heroId string) (*pb.DBHero, pb.ErrorCode) {
|
||||
|
||||
//佩戴装备
|
||||
func (this *Hero) UpdateEquipment(hero *pb.DBHero, equip []*pb.DB_Equipment) (code pb.ErrorCode) {
|
||||
equipIds := make([]string, 6)
|
||||
property := make(map[string]int32) //主属性
|
||||
addProperty := make(map[string]int32) //副属性
|
||||
for i, v := range equip {
|
||||
if v == nil {
|
||||
continue
|
||||
}
|
||||
equipIds[i] = v.Id
|
||||
//主属性
|
||||
property[v.MainEntry.AttrName] = v.MainEntry.Value
|
||||
//附加属性
|
||||
for _, v := range v.AdverbEntry {
|
||||
addProperty[v.AttrName] = v.Value
|
||||
}
|
||||
if hero == nil {
|
||||
code = pb.ErrorCode_HeroNoExist
|
||||
return
|
||||
}
|
||||
|
||||
this.modelHero.mergeMainProperty(hero.Uid, hero.Id, property)
|
||||
this.modelHero.mergeAddProperty(hero.Uid, hero.Id, addProperty)
|
||||
if err := this.modelHero.setEquipment(hero.Uid, hero.Id, equipIds); err != nil {
|
||||
if err := this.modelHero.setEquipment(hero); err != nil {
|
||||
code = pb.ErrorCode_HeroEquipUpdate
|
||||
return
|
||||
}
|
||||
this.modelHero.setEquipProperty(hero, equip)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user