From d2a3af4dacaf0402aded4f648f7d2e2a9ddee5d3 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 22 Feb 2023 11:03:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=A3=85=E5=A4=87=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8A=A8=E6=80=81=E6=9D=83=E9=87=8D=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/imodule.go | 2 +- modules/equipment/modelEquipment.go | 19 +++++++++++++++---- modules/equipment/module.go | 24 ++++++++++++++---------- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/comm/imodule.go b/comm/imodule.go index 3d7b8026c..1767a9cee 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -159,7 +159,7 @@ type ( pos: 位置(-1 表示随机位置 大于0 表示获得指定位置 ) lv: 装备等级 */ - GetForgeEquip(session IUserSession, suiteId int32, pos int32, lv int32) (eruip *pb.DB_Equipment, code pb.ErrorCode) + GetForgeEquip(session IUserSession, suiteId int32, pos int32, lv int32, dyweight []int32) (eruip *pb.DB_Equipment, code pb.ErrorCode) } IMainline interface { ModifyMainlineDataByNanduID(uid string, nandu, id int32) (code pb.ErrorCode) diff --git a/modules/equipment/modelEquipment.go b/modules/equipment/modelEquipment.go index 00183cf3f..fd8cfaf21 100644 --- a/modules/equipment/modelEquipment.go +++ b/modules/equipment/modelEquipment.go @@ -106,7 +106,7 @@ func (this *modelEquipmentComp) AddEquipments(session comm.IUserSession, cIds ma for k, v := range cIds { if c, ok := configure.GetDataMap()[k]; ok { for i := uint32(0); i < v; i++ { - if equipment, err := this.newEquipment(uId, c); err != nil { + if equipment, err := this.newEquipment(uId, c, nil); err != nil { return nil, err } else { //随机任务 @@ -242,11 +242,12 @@ func (this *modelEquipmentComp) UpdateByHeroId(uid string, equipments ...*pb.DB_ } //创建新的武器对象 -func (this *modelEquipmentComp) newEquipment(uid string, conf *cfg.GameEquipData) (equipment *pb.DB_Equipment, err error) { +func (this *modelEquipmentComp) newEquipment(uid string, conf *cfg.GameEquipData, dyweight []int32) (equipment *pb.DB_Equipment, err error) { var ( mattr []*cfg.GameEquipAttrlibraryData sattr []*cfg.GameEquipAttrlibraryData equipatt *cfg.GameEquipAttributeData + weight []int32 total int satterNum int32 ) @@ -281,12 +282,22 @@ func (this *modelEquipmentComp) newEquipment(uid string, conf *cfg.GameEquipData break } } + weight = make([]int32, len(conf.Addattrnump)) + for i, v := range conf.Addattrnump { + weight[i] = v + } + if dyweight != nil && len(dyweight) >= len(weight) { + for i, _ := range weight { + weight[i] += dyweight[i] + } + } - for _, v := range conf.Addattrnump { + for _, v := range weight { total += int(v) } + n := rand.Intn(total) - for i, v := range conf.Addattrnump { + for i, v := range weight { if int32(n) <= v { satterNum = conf.Addattrnum[i] break diff --git a/modules/equipment/module.go b/modules/equipment/module.go index 3d32570bd..a21a86bde 100644 --- a/modules/equipment/module.go +++ b/modules/equipment/module.go @@ -158,7 +158,7 @@ func (this *Equipment) NewEquipment(uid, cid string) (code pb.ErrorCode, equip * code = pb.ErrorCode_ConfigNoFound return } - if equip, err = this.modelEquipment.newEquipment(uid, conf); err != nil { + if equip, err = this.modelEquipment.newEquipment(uid, conf, nil); err != nil { code = pb.ErrorCode_ConfigNoFound return } @@ -332,11 +332,10 @@ func (this *Equipment) GetActionableSuit(uid string) (code pb.ErrorCode, Suit [] pos: 位置(-1 表示随机位置 大于0 表示获得指定位置 ) lv: 装备等级 */ -func (this *Equipment) GetForgeEquip(session comm.IUserSession, suiteId int32, pos int32, lv int32) (eruip *pb.DB_Equipment, code pb.ErrorCode) { +func (this *Equipment) GetForgeEquip(session comm.IUserSession, suiteId int32, pos int32, lv int32, dyweight []int32) (eruip *pb.DB_Equipment, code pb.ErrorCode) { var ( configures []*cfg.GameEquipData lvs []*cfg.GameEquipData - change []*pb.DB_Equipment err error ) if configures, err = this.configure.GetSuitEquipmentConfigure(suiteId); err != nil { @@ -346,10 +345,14 @@ func (this *Equipment) GetForgeEquip(session comm.IUserSession, suiteId int32, p if pos != -1 { for _, v := range configures { if v.Pos == pos && v.Star == lv { - if change, code = this.AddNewEquipments(session, map[string]uint32{v.Id: 1}, true); code == pb.ErrorCode_Success { - eruip = change[0] + if eruip, err = this.modelEquipment.newEquipment(session.GetUserId(), v, dyweight); err == nil { + code = pb.ErrorCode_Success + this.equipmentsChangePush(session, []*pb.DB_Equipment{eruip}) return } + this.Errorf("err%v", err) + code = pb.ErrorCode_SystemError + return } } code = pb.ErrorCode_ConfigNoFound @@ -363,14 +366,15 @@ func (this *Equipment) GetForgeEquip(session comm.IUserSession, suiteId int32, p } r := rand.New(rand.NewSource(time.Now().Unix())) index := r.Perm(len(lvs))[0] - - if change, code = this.AddNewEquipments(session, map[string]uint32{lvs[index].Id: 1}, true); code == pb.ErrorCode_Success { - eruip = change[0] + if eruip, err = this.modelEquipment.newEquipment(session.GetUserId(), lvs[index], dyweight); err == nil { + code = pb.ErrorCode_Success + this.equipmentsChangePush(session, []*pb.DB_Equipment{eruip}) return } + this.Errorf("err%v", err) + code = pb.ErrorCode_SystemError + return } - - return } //Evens--------------------------------------------------------------------------------------------------------------------------------