From 8811db5c1b866c017b296d8e9d453e73af8a52ba Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Thu, 20 Apr 2023 16:22:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=81=E7=BB=8A=E5=B1=9E=E6=80=A7=E8=AE=A1?= =?UTF-8?q?=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 ++ modules/hero/model_hero.go | 29 +++++++++++++++++++ modules/hero/module.go | 21 ++++++++++++++ modules/library/api_getreward.go | 17 ++++++++++- modules/library/api_usegift.go | 12 +++++--- modules/library/module.go | 4 +-- .../structs/game.equipAttrlibrary.go | 18 ++++++++---- 7 files changed, 90 insertions(+), 13 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 382b2312d..c30c3bd2e 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -107,6 +107,8 @@ type ( // 跨服查询英雄详细信息 QueryCrossMultipleHeroinfo(oid []string) (hero []*pb.DBHero, err error) + + AddHeroFetterAttribute(session IUserSession, attr map[string][]*cfg.Gameatr) } //玩家 diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index 350f3f13e..1f15f0cde 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -959,3 +959,32 @@ func (this *ModelHero) checkHeroAllSkillMax(hero *pb.DBHero) bool { } return true } +func (this *ModelHero) SetHeroFetterProperty(hero *pb.DBHero, attr []*cfg.Gameatr) { + if hero == nil || len(attr) == 0 { + return + } + if hero.Fetters == nil { + hero.Fetters = make(map[string]int32, 0) + } + for _, key := range attr { + value := key.N + switch key.A { + case comm.Hp: + hero.Fetters[comm.Hp] += int32(value) + case comm.Def: + hero.Fetters[comm.Def] += int32(value) + case comm.Atk: + hero.Fetters[comm.Atk] += int32(value) + case comm.Speed: + hero.Fetters[comm.Speed] += int32(value) + case comm.HpPro: + hero.Fetters[comm.Hp] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Hp]))) + case comm.AtkPro: + hero.Fetters[comm.Atk] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Atk]))) + case comm.DefPro: + hero.Fetters[comm.Def] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Def]))) + default: + this.moduleHero.Errorf("unkonw hero fetter property:%v", key) + } + } +} diff --git a/modules/hero/module.go b/modules/hero/module.go index f8f99f29f..bfa7f0aba 100644 --- a/modules/hero/module.go +++ b/modules/hero/module.go @@ -977,3 +977,24 @@ func (this *Hero) QueryCrossMultipleHeroinfo(oid []string) (hero []*pb.DBHero, e return } + +func (this *Hero) AddHeroFetterAttribute(session comm.IUserSession, attr map[string][]*cfg.Gameatr) { + chanegCard := make([]*pb.DBHero, 0) + heroList := this.GetHeroList(session.GetUserId()) + for _, v := range heroList { + if v1, ok := attr[v.HeroID]; ok { // 找到对应的英雄ID + _heroMap := make(map[string]interface{}, 0) + this.modelHero.SetHeroFetterProperty(v, v1) + _heroMap["fetters"] = v.Fetters + // 保存数据 + err := this.modelHero.ChangeList(session.GetUserId(), v.Id, _heroMap) + if err != nil { + + this.Errorf("SetHeroFetterProperty failed:%v", err) + continue + } + chanegCard = append(chanegCard, v) + } + } + session.SendMsg(string(this.GetType()), "change", &pb.HeroChangePush{List: chanegCard}) +} diff --git a/modules/library/api_getreward.go b/modules/library/api_getreward.go index c33ce3519..265029643 100644 --- a/modules/library/api_getreward.go +++ b/modules/library/api_getreward.go @@ -3,6 +3,7 @@ package library import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 @@ -28,7 +29,8 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.LibraryGetRewa code = pb.ErrorCode_LibraryNoData return } - if conf := this.module.configure.GetFriendData(fetter.Fid, req.Fetterlv); len(conf) == 0 { + conf := this.module.configure.GetFriendData(fetter.Fid, req.Fetterlv) + if len(conf) == 0 { code = pb.ErrorCode_ConfigNoFound return } else { @@ -49,6 +51,19 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.LibraryGetRewa fetter.Prize[req.Fetterlv] = 1 // 发奖 + h := make(map[string][]*cfg.Gameatr, 0) + for _, v := range conf { + var sz []*cfg.Gameatr + for _, v1 := range v.Attribute { + b := &cfg.Gameatr{ + A: v1.A, + N: v1.N, + } + sz = append(sz, b) + } + h[v.Hid] = sz + } + this.module.ModuleHero.AddHeroFetterAttribute(session, h) mapData := make(map[string]interface{}, 0) mapData["prize"] = fetter.Prize this.module.ModifyLibraryData(session.GetUserId(), fetter.Id, mapData) // 更新内存信息 diff --git a/modules/library/api_usegift.go b/modules/library/api_usegift.go index 786ba2af3..17b73ab13 100644 --- a/modules/library/api_usegift.go +++ b/modules/library/api_usegift.go @@ -19,7 +19,6 @@ func (this *apiComp) UseGiftCheck(session comm.IUserSession, req *pb.LibraryUseG func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( res []*cfg.Gameatn - totalExp int32 maxLv int32 // 羁绊最大等级 upLv int32 attenuation map[int32]int32 @@ -97,14 +96,19 @@ func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftRe if code = this.module.CheckRes(session, res); code != pb.ErrorCode_Success { // 道具不够直接返回 return } + itemConf, err1 := this.module.configure.GetItemConfigureData(req.Items) // 获取食物的 + if err1 != nil { + this.module.Errorf("赠送菜品配置没找到:%s", req.Items) + code = pb.ErrorCode_ConfigNoFound + return + } // 100*1 + 100*0.25 + 100*0.5 - totalExp = add - _heroObj.Favorexp += totalExp + _heroObj.Favorexp += add * itemConf.SpecialType / 1000 // 折算出等级 for { if _heroObj.Favorlv >= maxLv { // 达到最大等级不让继续升级 - code = pb.ErrorCode_LibraryMaxLv + _heroObj.Favorexp = 0 break } if _exp[_heroObj.Favorlv] <= _heroObj.Favorexp { diff --git a/modules/library/module.go b/modules/library/module.go index 507842228..00d2a98ac 100644 --- a/modules/library/module.go +++ b/modules/library/module.go @@ -120,7 +120,6 @@ func (this *Library) CheckFetter(uid string, hid string) (dbLibrary []*pb.DBLibr } dbLibrary = append(dbLibrary, tmp) } else { // 有这条羁绊数据 - dbLibrary = append(dbLibrary, list) for _, v := range conf { if _, ok := list.Herofetter[v.Hid]; !ok { if _d := this.CheckHeroFetter(uid, v.Hid); _d == nil { @@ -130,6 +129,7 @@ func (this *Library) CheckFetter(uid string, hid string) (dbLibrary []*pb.DBLibr mapData := make(map[string]interface{}, 0) mapData["herofetter"] = list.Herofetter this.modelLibrary.modifyLibraryDataByObjId(uid, list.Id, mapData) // 更新新的羁绊信息 + dbLibrary = append(dbLibrary, list) } } } @@ -194,7 +194,7 @@ func (this *Library) CheckHeroFetter(uid string, hid string) (obj *pb.DBHeroFett // 创建一条英雄羁绊信息 func (this *Library) createHeroFetter(uid string, heroConfId string) (obj *pb.DBHeroFetter, err error) { - this.modelFetter.getHeroFetterList(uid) + obj = &pb.DBHeroFetter{ Id: primitive.NewObjectID().Hex(), Uid: uid, diff --git a/sys/configure/structs/game.equipAttrlibrary.go b/sys/configure/structs/game.equipAttrlibrary.go index b91463458..968f74f27 100644 --- a/sys/configure/structs/game.equipAttrlibrary.go +++ b/sys/configure/structs/game.equipAttrlibrary.go @@ -9,26 +9,32 @@ package cfg type GameEquipAttrlibrary struct { - _dataList []*GameEquipAttrlibraryData + _dataMap map[int32]*GameEquipAttrlibraryData + _dataList []*GameEquipAttrlibraryData } func NewGameEquipAttrlibrary(_buf []map[string]interface{}) (*GameEquipAttrlibrary, error) { _dataList := make([]*GameEquipAttrlibraryData, 0, len(_buf)) + dataMap := make(map[int32]*GameEquipAttrlibraryData) for _, _ele_ := range _buf { if _v, err2 := DeserializeGameEquipAttrlibraryData(_ele_); err2 != nil { return nil, err2 } else { _dataList = append(_dataList, _v) + dataMap[_v.Key] = _v } } - return &GameEquipAttrlibrary{_dataList:_dataList}, nil + return &GameEquipAttrlibrary{_dataList: _dataList, _dataMap: dataMap}, nil +} + +func (table *GameEquipAttrlibrary) GetDataMap() map[int32]*GameEquipAttrlibraryData { + return table._dataMap } func (table *GameEquipAttrlibrary) GetDataList() []*GameEquipAttrlibraryData { - return table._dataList + return table._dataList } -func (table *GameEquipAttrlibrary) Get(index int) *GameEquipAttrlibraryData { - return table._dataList[index] +func (table *GameEquipAttrlibrary) Get(key int32) *GameEquipAttrlibraryData { + return table._dataMap[key] } -