352 lines
11 KiB
Go
352 lines
11 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) ForgeEquipCheck(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (errdata *pb.ErrorData) {
|
|
if req.ReelId == 0 || req.Lava < 0 || req.Quality < 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 打造装备
|
|
func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
stove *pb.DBStove
|
|
err error
|
|
update map[string]interface{}
|
|
addProbability int32
|
|
costRes []*cfg.Gameatn
|
|
customLv int32 // 定制装备的等级
|
|
rsp *pb.SmithyForgeEquipResp
|
|
needT float32 // 需要消耗的温度
|
|
maxT int32
|
|
atno []*pb.UserAtno
|
|
lava *cfg.Gameatn
|
|
bQuality bool // 是否是精炼打造
|
|
preHitCount int32 // 打造之前的次数
|
|
)
|
|
// 参数校验
|
|
if req.Count == 0 { // 传0 默认打造意见
|
|
req.Count = 1
|
|
}
|
|
rsp = &pb.SmithyForgeEquipResp{}
|
|
update = make(map[string]interface{})
|
|
errdata = this.ForgeEquipCheck(session, req)
|
|
if errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
stove, err = this.module.modelStove.getSmithyStoveList(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
reelcfg, err := this.module.configure.GetSmithyReelConfigData(req.ReelId)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
} // 没有找到该类型的图纸信息
|
|
return
|
|
}
|
|
// 校验图纸是否激活
|
|
if _, ok := stove.Data[req.ReelId]; !ok { // 是不是首次打造
|
|
if !this.module.configure.CheckSmithyFirstReelConfigData(reelcfg.Type, req.ReelId) { // 没有激活图纸
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SmithyNoReel,
|
|
Title: pb.ErrorCode_SmithyNoReel.ToString(),
|
|
}
|
|
return
|
|
}
|
|
stove.Data[req.ReelId] = &pb.Mastery{
|
|
Lv: 1,
|
|
Value: 0,
|
|
}
|
|
}
|
|
// 是否是精益打造
|
|
if req.Quality > 0 {
|
|
if len(reelcfg.RefineCos) > 0 {
|
|
costRes = append(costRes, reelcfg.RefineCos...)
|
|
}
|
|
bQuality = true
|
|
}
|
|
// 校验是不是装备定制打造
|
|
if req.SuiteId != 0 {
|
|
if req.Position == -1 {
|
|
if len(reelcfg.CustomizedCos1) > 0 {
|
|
if errdata = this.module.CheckRes(session, reelcfg.CustomizedCos1); errdata != nil {
|
|
return
|
|
}
|
|
costRes = append(costRes, reelcfg.CustomizedCos1...)
|
|
}
|
|
} else {
|
|
if len(reelcfg.CustomizedCos2) > 0 {
|
|
if errdata = this.module.CheckRes(session, reelcfg.CustomizedCos2); errdata != nil {
|
|
return
|
|
}
|
|
costRes = append(costRes, reelcfg.CustomizedCos2...)
|
|
}
|
|
}
|
|
// 随机权重 获取等级
|
|
index := this.module.modelStove.GetRandEquipLv(reelcfg.CustomizedLvDistribution)
|
|
if int32(len(reelcfg.CustomizedLv)) > index {
|
|
customLv = reelcfg.CustomizedLv[index]
|
|
}
|
|
}
|
|
needT = float32(reelcfg.TemperatureCos * req.Count)
|
|
// 熟练度减少的温度
|
|
t := this.module.modelStove.CheckTemperature(req.ReelId, stove.Data[req.ReelId].Lv)
|
|
needT *= float32(1000-t) / 1000 // 千分比
|
|
// 工具台技能减少
|
|
_s := this.module.modelStove.StoveToolsTemperature(stove)
|
|
if _s != 0 {
|
|
needT *= (1 - float32(_s)/1000)
|
|
}
|
|
if req.Lava == 0 {
|
|
// 检查炉温 是否够
|
|
if stove.Temperature < int32(needT) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SmithyNoTemperature,
|
|
Title: pb.ErrorCode_SmithyNoTemperature.ToString(),
|
|
}
|
|
return
|
|
}
|
|
stove.Temperature -= int32(needT) // 消耗温度
|
|
update["temperature"] = stove.Temperature
|
|
} else {
|
|
exemption := this.module.ModuleTools.GetGlobalConf().ExemptionTemperatureCos // 预计消耗温度
|
|
gloabNum := this.module.ModuleTools.GetGlobalConf().ExemptionTemperatureCosNum // 每个消耗的温度
|
|
if gloabNum != 0 {
|
|
req.Lava = int32(needT) / gloabNum
|
|
if int32(needT)%gloabNum != 0 {
|
|
req.Lava += 1
|
|
}
|
|
// 计算
|
|
lava = &cfg.Gameatn{
|
|
A: exemption.A,
|
|
T: exemption.T,
|
|
N: exemption.N * req.Lava,
|
|
}
|
|
if errdata = this.module.CheckRes(session, []*cfg.Gameatn{lava}); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
costRes = append(costRes, reelcfg.BasicCos...)
|
|
subAtn := this.module.modelStove.CheckForgeConsume(req.ReelId, stove.Data[req.ReelId].Lv)
|
|
|
|
_costRes := make([]*cfg.Gameatn, 0)
|
|
for _, v := range costRes {
|
|
_costRes = append(_costRes, &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * req.Count,
|
|
})
|
|
}
|
|
if req.Lava > 0 && lava != nil { // 熔岩打造
|
|
_costRes = append(_costRes, lava)
|
|
}
|
|
if len(subAtn) > 0 {
|
|
_costRes = append(_costRes, subAtn...)
|
|
}
|
|
|
|
if errdata = this.module.ConsumeRes(session, this.module.FormatRes(_costRes), true); errdata != nil {
|
|
return
|
|
}
|
|
// 玩小游戏增加双倍产出校验
|
|
if req.SuiteId == 0 { // 定制才有
|
|
var (
|
|
hitLen int32
|
|
)
|
|
for k, v := range req.Hit {
|
|
confMake, err := this.module.configure.GetSmithyMake(k)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Errorf("GetSmithyMake配置没找到:%d", k)
|
|
|
|
return
|
|
}
|
|
hitLen += v
|
|
addProbability += v * confMake.Probability
|
|
}
|
|
|
|
// 总次数校验
|
|
maxHitCount := this.module.ModuleTools.GetGlobalConf().GameMakeTunkNum
|
|
if hitLen > maxHitCount {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
this.module.Errorf("铁匠铺小游戏打造次数超过上限,当前打造次数:%d, 配置总次数:%d", hitLen, maxHitCount)
|
|
}
|
|
// 校验是否刷新最大记录
|
|
for k, v := range req.Hit {
|
|
if stove.Hit[k] != v {
|
|
var curProbability int32
|
|
for k, v := range stove.Hit {
|
|
confMake, err := this.module.configure.GetSmithyMake(k)
|
|
if err != nil {
|
|
break
|
|
}
|
|
curProbability += v * confMake.Probability
|
|
}
|
|
if curProbability < addProbability {
|
|
stove.Hit = req.Hit
|
|
update["hit"] = stove.Hit
|
|
}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
// 装备资源分发
|
|
if customLv > 0 {
|
|
for i := 0; i < int(req.Count); i++ {
|
|
sz := make([]int32, 4) // 最高 4个品质
|
|
// 获得极品权重
|
|
sz[3] = this.module.modelStove.StoveToolsQualityProbability(stove)
|
|
if equip, code1 := this.module.ModuleEquipment.GetForgeEquip(session, req.SuiteId, req.Position, customLv, sz, bQuality); code1 != nil {
|
|
errdata = code1
|
|
this.module.Errorf("GetForgeEquip error: %v,req.SuiteId:%d, req.Position:%d, customLv:%d", errdata, req.SuiteId, req.Position, customLv)
|
|
return
|
|
} else {
|
|
rsp.Equip = append(rsp.Equip, equip)
|
|
}
|
|
}
|
|
|
|
} else { // 普通打造
|
|
// 获取掉落id
|
|
newdrop := this.module.modelStove.CheckUnlockSuid(req.ReelId, stove.Data[req.ReelId].Lv, reelcfg.BasicDrop)
|
|
// 检查是否命中双倍打造
|
|
for i := 0; i < int(req.Count); i++ {
|
|
res := this.module.configure.GetDropReward(newdrop)
|
|
if ok := this.module.modelStove.CheckForgetwoEquip(req.ReelId, stove.Data[req.ReelId].Lv, addProbability); ok {
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata == nil {
|
|
for _, v := range atno {
|
|
if eq, e := this.module.ModuleEquipment.QueryEquipment(session.GetUserId(), v.O); e == nil {
|
|
rsp.Equip = append(rsp.Equip, eq)
|
|
}
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
|
|
if errdata, atno = this.module.DispenseAtno(session, res, true); errdata == nil {
|
|
for _, v := range atno {
|
|
if eq, err1 := this.module.ModuleEquipment.QueryEquipment(session.GetUserId(), v.O); err1 == nil {
|
|
rsp.Equip = append(rsp.Equip, eq)
|
|
}
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if stoveLvConf, err := this.module.configure.GetSmithyStoveConf(stove.Lv); err == nil {
|
|
maxT = stoveLvConf.MaxTemperature
|
|
}
|
|
if stove.RecoveTime == 0 && stove.Temperature <= maxT {
|
|
stove.RecoveTime = configure.Now().Unix()
|
|
update["recoveTime"] = stove.RecoveTime
|
|
}
|
|
preHitCount = stove.Data[req.ReelId].Value
|
|
stove.Data[req.ReelId].Value += req.Count
|
|
stove.Forge[req.ReelId] += req.Count
|
|
|
|
// 可能存在一次升多级的情况
|
|
// 检查是否提升了熟练度等级
|
|
for {
|
|
nextProficiency := this.module.configure.GetSmithyProficileData(req.ReelId, stove.Data[req.ReelId].Lv+1)
|
|
if nextProficiency != nil && nextProficiency.Proficiency <= stove.Data[req.ReelId].Value { // 提升熟练度
|
|
stove.Data[req.ReelId].Lv += 1
|
|
|
|
// 校验是否解锁了新的图纸
|
|
if nextProficiency.Type == comm.SmithyReelType3 {
|
|
stove.Data[nextProficiency.Value1] = &pb.Mastery{
|
|
Lv: 1,
|
|
Value: 0,
|
|
}
|
|
// 解锁了新的图纸
|
|
var szTask []*pb.BuriedParam
|
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype177, 1))
|
|
szTask = append(szTask, comm.GetBuriedParam(comm.Rtype179, 1, nextProficiency.Value1))
|
|
|
|
this.module.ModuleBuried.TriggerBuried(session.GetUserId(), szTask...)
|
|
}
|
|
// 是否解锁新套装
|
|
if nextProficiency.Type == comm.SmithyReelType4 {
|
|
if rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil {
|
|
rst.SuiteId = append(rst.SuiteId, nextProficiency.Value1)
|
|
|
|
this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{
|
|
"suiteId": rst.SuiteId,
|
|
})
|
|
}
|
|
}
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
|
|
update["data"] = stove.Data
|
|
|
|
update["forge"] = stove.Forge // 打造次数
|
|
this.module.modelStove.updateSmithyStove(session.GetUserId(), update)
|
|
rsp.Data = stove
|
|
session.SendMsg(string(this.module.GetType()), "forgeequip", rsp)
|
|
|
|
// 炉温恢复时间红点推送
|
|
i, err := this.module.service.GetModule(comm.ModuleReddot)
|
|
if err != nil {
|
|
this.module.Error(err.Error())
|
|
return
|
|
}
|
|
if b, y := i.(comm.IReddot); y {
|
|
b.PushReddot(session, &pb.ReddotItem{
|
|
Rid: int32(comm.Reddot17108),
|
|
Nextchanagetime: stove.RecoveTime,
|
|
})
|
|
}
|
|
//session.SendMsg(string(this.GetType()), "change", &pb.ReddotChangePush{Rids: reddot})
|
|
// 校验图鉴信息
|
|
this.module.modelAtlas.CheckActivateEquipAtlas(session.GetUserId(), rsp.Equip, preHitCount)
|
|
var equip map[int32]int32 // key xingji value 数量
|
|
equip = make(map[int32]int32, 0)
|
|
tasks := make([]*pb.BuriedParam, 0)
|
|
for _, v := range rsp.Equip {
|
|
equip[int32(len(v.AdverbEntry))]++
|
|
}
|
|
for k, v := range equip {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype51, v, k))
|
|
}
|
|
// 定制
|
|
if req.SuiteId != 0 {
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype189, req.Count)) // 进行N次定制打造
|
|
}
|
|
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype148, req.Count))
|
|
this.module.ModuleBuried.TriggerBuried(session.GetUserId(), tasks...)
|
|
|
|
return
|
|
}
|