From 2333b055bb79b0d8a5c5ad9a4255360f9f8d5576 Mon Sep 17 00:00:00 2001 From: zhaocy Date: Tue, 19 Jul 2022 19:04:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E5=A4=87=E5=8F=A0=E5=8D=A1=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/model_hero.go | 55 +++++++++++++++++++++++++++++++++----- modules/hero/module.go | 22 ++++----------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 86424b06b..325103cc7 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -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) } //合并属性即属性值累加 diff --git a/modules/hero/module.go b/modules/hero/module.go index ea47442c1..f546402fa 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -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 }