This commit is contained in:
wh_zcy 2023-02-21 17:48:52 +08:00
commit e60eccfd51
4 changed files with 333 additions and 470 deletions

View File

@ -26,7 +26,9 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq
err error
update map[string]interface{}
costRes []*cfg.Gameatn
costRes []*cfg.Gameatn
customLv int32 // 定制装备的等级
rsp *pb.SmithyForgeEquipResp
)
update = make(map[string]interface{})
code = this.ForgeEquipCheck(session, req)
@ -61,6 +63,25 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq
if req.Quality > 0 {
costRes = append(costRes, reelcfg.RefineCos)
}
// 校验是不是装备定制打造
if req.SuiteId != 0 {
// 检查消耗
if code = this.module.CheckRes(session, []*cfg.Gameatn{reelcfg.CustomizedCos1}); code != pb.ErrorCode_Success {
return
}
costRes = append(costRes, reelcfg.CustomizedCos1)
if req.Position == -1 {
if code = this.module.CheckRes(session, []*cfg.Gameatn{reelcfg.CustomizedCos2}); code != pb.ErrorCode_Success {
return
}
costRes = append(costRes, reelcfg.CustomizedCos2)
}
// 随机权重 获取等级
index := this.module.modelStove.GetRandEquipLv(reelcfg.CustomizedLvDistribution)
if int32(len(reelcfg.CustomizedLv)) > index {
customLv = reelcfg.CustomizedLv[index]
}
}
// 是否是熔岩打造
if req.Lava > 0 {
@ -131,13 +152,25 @@ func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEq
}
// 装备资源分发
res := this.module.configure.GetDropReward(reelcfg.BasicDrop)
this.module.DispenseRes(session, res, true)
if customLv > 0 { //
if equip, code1 := this.module.ModuleEquipment.GetForgeEquip(session, req.SuiteId, req.Position, customLv); code1 != pb.ErrorCode_Success {
rsp.Equip = append(rsp.Equip, equip.CId)
return
}
} else {
res := this.module.configure.GetDropReward(reelcfg.BasicDrop)
this.module.DispenseRes(session, res, true)
for _, v := range res {
rsp.Equip = append(rsp.Equip, v.T)
}
}
stove.RecoveTime = configure.Now().Unix()
update["data"] = stove.Data
update["recoveTime"] = stove.RecoveTime
update["forge"] = stove.Forge // 打造次数
this.module.modelStove.updateSmithyStove(session.GetUserId(), update)
session.SendMsg(string(this.module.GetType()), "forgeequip", &pb.SmithyForgeEquipResp{Data: stove})
rsp.Data = stove
session.SendMsg(string(this.module.GetType()), "forgeequip", rsp)
return
}

View File

@ -1,35 +0,0 @@
package smithy
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) OrderEquipCheck(session comm.IUserSession, req *pb.SmithyOrderEquipReq) (code pb.ErrorCode) {
if req.SuiteId == 0 || req.Position == 0 {
code = pb.ErrorCode_ReqParameterError
return
}
return
}
// 打造装备
func (this *apiComp) OrderEquip(session comm.IUserSession, req *pb.SmithyOrderEquipReq) (code pb.ErrorCode, data proto.Message) {
var ()
code = this.OrderEquipCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
stove, err := this.module.modelStove.getSmithyStoveList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
session.SendMsg(string(this.module.GetType()), "orderequip", &pb.SmithyOrderEquipResp{Data: stove})
return
}

View File

@ -1,6 +1,7 @@
package smithy
import (
"crypto/rand"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/redis"
@ -8,9 +9,9 @@ import (
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"math/big"
"strconv"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
@ -91,8 +92,9 @@ func (this *modelStove) CheckForgetwoEquip(reelId int32, lv int32) (b bool) {
}
}
if value > 0 {
rand.Seed(time.Now().UnixNano())
if value < int32(rand.Intn(100)) {
n, _ := rand.Int(rand.Reader, big.NewInt(100))
if value < int32(n.Int64()) {
return true
}
}
@ -212,3 +214,23 @@ func (this *modelStove) StoveSkillBuyEquip(uid string) int32 {
}
return 0
}
func (this *modelStove) GetRandEquipLv(sz []int32) int32 {
if len(sz) > 0 {
var _totalW int64 // 总权重
var _tmpW int64 // 临时权重
for _, v := range sz {
_totalW += int64(v)
}
// 随机权重
n, _ := rand.Int(rand.Reader, big.NewInt(_totalW))
for i, v := range sz {
_tmpW += int64(v)
if n.Int64() < _tmpW {
return int32(i)
}
}
}
return 0
}

File diff suppressed because it is too large Load Diff