克隆英雄对象

This commit is contained in:
meixiongfeng 2022-07-25 18:13:27 +08:00
parent 97beb8c48d
commit 10fb331b52
3 changed files with 23 additions and 24 deletions

View File

@ -97,6 +97,13 @@ func (this *ModelHero) createOneHero(uid string, heroCfgId string) (hero *pb.DBH
return
}
func (this *ModelHero) CloneNewHero(hero *pb.DBHero) (newHero *pb.DBHero) {
temp := *hero
newHero = &temp
newHero.Id = primitive.NewObjectID().Hex()
return
}
//初始化可叠加的英雄
func (this *ModelHero) initHeroOverlying(uid string, heroCfgId string, count int32) (hero *pb.DBHero, err error) {
hero = this.initHero(uid, heroCfgId)
@ -259,18 +266,16 @@ func (this *ModelHero) getHeroList(uid string) []*pb.DBHero {
// 设置装备属性
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
//附加属性
addProperty[v.MainEntry.AttrName] += v.MainEntry.Value //主属性
for _, v := range v.AdverbEntry {
addProperty[v.AttrName] += v.Value
addProperty[v.AttrName] += v.Value //附加属性
}
}
@ -302,11 +307,12 @@ func (this *ModelHero) setEquipment(hero *pb.DBHero) (newHero *pb.DBHero, err er
return
}
//创建新卡
newHero, err = this.createOneHero(hero.Uid, hero.HeroID)
if err != nil {
this.moduleHero.Errorf("%v", err)
return
}
newHero = this.CloneNewHero(hero)
// newHero, err = this.createOneHero(hero.Uid, hero.HeroID)
// if err != nil {
// this.moduleHero.Errorf("%v", err)
// return
// }
update1 := make(map[string]interface{})
update1["sameCount"] = curSameCount

View File

@ -59,14 +59,12 @@ func (this *Hero) GetHeroByObjID(uid, heroId string) (*pb.DBHero, pb.ErrorCode)
//佩戴装备
func (this *Hero) UpdateEquipment(session comm.IUserSession, hero *pb.DBHero, equip []*pb.DB_Equipment) (code pb.ErrorCode) {
var (
tagHero *pb.DBHero // 目标英雄 有可能是创建了新的英雄对象
)
if hero == nil {
code = pb.ErrorCode_HeroNoExist
return
}
tagHero = hero
list := make([]*pb.DBHero, 0)
if newHero, err := this.modelHero.setEquipment(hero); err != nil {
code = pb.ErrorCode_HeroEquipUpdate
@ -74,20 +72,13 @@ func (this *Hero) UpdateEquipment(session comm.IUserSession, hero *pb.DBHero, eq
} else {
if newHero != nil {
list = append(list, newHero)
tagHero = newHero
}
}
list = append(list, hero)
m, err1 := this.modelHero.PushHeroProperty(session, tagHero.Id) // 推送属性变化
if err1 != nil {
code = pb.ErrorCode_Unknown
this.Errorf("PushHeroProperty err!")
}
tagHero.Property = m
this.modelHero.setEquipProperty(hero, equip)
session.SendMsg("hero", "change", &pb.HeroChangePush{List: list})
this.modelHero.setEquipProperty(tagHero, equip)
return
}

View File

@ -40,11 +40,13 @@ func (this *DB_Comp) Start() (err error) {
}
func (this *DB_Comp) run() {
timer := time.NewTimer(time.Second * 2)
defer timer.Stop()
for {
select {
case v := <-this.task:
this.Model_UpdateDBByLog(v)
case <-time.After(time.Second * 2):
case <-timer.C:
this.Model_UpdateDBByLog("")
}
if !this.isInit && this.Model_TotalCount() <= 0 {