277 lines
8.9 KiB
Go
277 lines
8.9 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) (code pb.ErrorCode) {
|
|
if req.ReelId == 0 || req.Lava < 0 || req.Quality < 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 打造装备
|
|
func (this *apiComp) ForgeEquip(session comm.IUserSession, req *pb.SmithyForgeEquipReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
stove *pb.DBStove
|
|
err error
|
|
update map[string]interface{}
|
|
addProbability int32
|
|
costRes []*cfg.Gameatn
|
|
customLv int32 // 定制装备的等级
|
|
rsp *pb.SmithyForgeEquipResp
|
|
needT int32 // 需要消耗的温度
|
|
maxT int32
|
|
atno []*pb.UserAtno
|
|
)
|
|
// 参数校验
|
|
if req.Count == 0 { // 传0 默认打造意见
|
|
req.Count = 1
|
|
}
|
|
rsp = &pb.SmithyForgeEquipResp{}
|
|
update = make(map[string]interface{})
|
|
code = this.ForgeEquipCheck(session, req)
|
|
if code != pb.ErrorCode_Success {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
stove, err = this.module.modelStove.getSmithyStoveList(session.GetUserId())
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
reelcfg := this.module.configure.GetSmithyReelConfigData(req.ReelId)
|
|
if reelcfg == nil {
|
|
code = pb.ErrorCode_ReqParameterError // 没有找到该类型的图纸信息
|
|
return
|
|
}
|
|
// 校验图纸是否激活
|
|
if _, ok := stove.Data[req.ReelId]; !ok { // 是不是首次打造
|
|
if !this.module.configure.CheckSmithyFirstReelConfigData(reelcfg.Type, req.ReelId) { // 没有激活图纸
|
|
code = pb.ErrorCode_SmithyNoReel
|
|
return
|
|
}
|
|
stove.Data[req.ReelId] = &pb.Mastery{
|
|
Lv: 1,
|
|
Value: 0,
|
|
}
|
|
}
|
|
// 是否是精益打造
|
|
if req.Quality > 0 {
|
|
costRes = append(costRes, reelcfg.RefineCos)
|
|
}
|
|
// 校验是不是装备定制打造
|
|
if req.SuiteId != 0 {
|
|
if req.Position == -1 {
|
|
if code = this.module.CheckRes(session, []*cfg.Gameatn{reelcfg.CustomizedCos1}); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
costRes = append(costRes, reelcfg.CustomizedCos1)
|
|
} else {
|
|
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]
|
|
}
|
|
}
|
|
needT = reelcfg.TemperatureCos * req.Count
|
|
// 熟练度减少的温度
|
|
t := this.module.modelStove.CheckTemperature(req.ReelId, stove.Data[req.ReelId].Lv)
|
|
needT = needT * (1000 - t) / 1000 // 千分比
|
|
// 工具台技能减少
|
|
_s := this.module.modelStove.StoveToolsTemperature(stove)
|
|
if _s != 0 {
|
|
needT *= (1 - _s/1000)
|
|
}
|
|
if req.Lava > 0 { // 熔岩打造
|
|
exemption := this.module.ModuleTools.GetGlobalConf().ExemptionTemperatureCos // 预计消耗温度
|
|
gloabNum := this.module.ModuleTools.GetGlobalConf().ExemptionTemperatureCosNum
|
|
if needT > req.Lava*gloabNum {
|
|
this.module.Errorf("ErrorCode_SmithyLackLava needT:%d,curT:%d,count :%d", needT, req.Count*gloabNum, req.Count)
|
|
code = pb.ErrorCode_SmithyLackLava // 缺少熔岩
|
|
return
|
|
}
|
|
|
|
costRes = append(costRes, exemption)
|
|
} else {
|
|
// 检查炉温 是否够
|
|
if stove.Temperature < needT {
|
|
code = pb.ErrorCode_SmithyNoTemperature // 炉温不够 直接返回
|
|
return
|
|
}
|
|
stove.Temperature -= needT // 消耗温度
|
|
update["temperature"] = stove.Temperature
|
|
}
|
|
|
|
costRes = append(costRes, reelcfg.BasicCos...)
|
|
subAtn := this.module.modelStove.CheckForgeConsume(req.ReelId, stove.Data[req.ReelId].Lv)
|
|
// 异常处理 防止不消耗该道具 但是技能做了该道具的减免
|
|
_costRes := make([]*cfg.Gameatn, len(costRes))
|
|
for i, v := range costRes {
|
|
_costRes[i] = &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * req.Count, // 打造多件装备
|
|
}
|
|
for _, v1 := range subAtn {
|
|
if _costRes[i].A == v1.A && _costRes[i].T == v1.T {
|
|
_costRes[i].N += v1.N * req.Count
|
|
}
|
|
}
|
|
if _costRes[i].N < 0 {
|
|
_costRes[i].N = 0
|
|
}
|
|
}
|
|
|
|
if code = this.module.ConsumeRes(session, _costRes, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
// 玩小游戏增加双倍产出校验
|
|
if req.SuiteId == 0 { // 定制才有
|
|
var (
|
|
hitLen int32
|
|
)
|
|
for k, v := range req.Hit {
|
|
confMake := this.module.configure.GetSmithyMake(k)
|
|
if confMake == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
this.module.Errorf("GetSmithyMake配置没找到:%d", k)
|
|
return
|
|
}
|
|
hitLen += v
|
|
addProbability += v * confMake.Probability
|
|
}
|
|
|
|
// 总次数校验
|
|
maxHitCount := this.module.ModuleTools.GetGlobalConf().GameMakeTunkNum
|
|
if hitLen > maxHitCount {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
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 := this.module.configure.GetSmithyMake(k)
|
|
if confMake == 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); code1 != pb.ErrorCode_Success {
|
|
code = code1
|
|
this.module.Errorf("GetForgeEquip error: %v,req.SuiteId:%d, req.Position:%d, customLv:%d", code, 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)
|
|
res := this.module.configure.GetDropReward(newdrop)
|
|
// 检查是否命中双倍打造
|
|
for i := 0; i < int(req.Count); i++ {
|
|
if ok := this.module.modelStove.CheckForgetwoEquip(req.ReelId, stove.Data[req.ReelId].Lv, addProbability); ok {
|
|
if code, atno = this.module.DispenseAtno(session, res, true); code == pb.ErrorCode_Success {
|
|
for _, v := range atno {
|
|
if eq, err1 := this.module.ModuleEquipment.QueryEquipment(session.GetUserId(), v.O); err1 == pb.ErrorCode_Success {
|
|
rsp.Equip = append(rsp.Equip, eq)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if code, atno = this.module.DispenseAtno(session, res, true); code == pb.ErrorCode_Success {
|
|
for _, v := range atno {
|
|
if eq, err1 := this.module.ModuleEquipment.QueryEquipment(session.GetUserId(), v.O); err1 == pb.ErrorCode_Success {
|
|
rsp.Equip = append(rsp.Equip, eq)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if stoveLvConf := this.module.configure.GetSmithyStoveConf(stove.Lv); stoveLvConf != nil {
|
|
maxT = stoveLvConf.MaxTemperature
|
|
}
|
|
if stove.RecoveTime == 0 && stove.Temperature <= maxT {
|
|
stove.RecoveTime = configure.Now().Unix()
|
|
update["recoveTime"] = stove.RecoveTime
|
|
}
|
|
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,
|
|
}
|
|
}
|
|
// 是否解锁新套装
|
|
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)
|
|
// 更新图鉴信息
|
|
for _, v := range rsp.Equip {
|
|
if equipConf := this.module.configure.GetEquipmentConfigureById(v.CId); equipConf != nil { // 获取装备等级
|
|
go func(cid string, star int32, AdverbEntry int32) {
|
|
this.module.modelAtlas.CheckActivateAtlas(session.GetUserId(), cid, star, AdverbEntry, stove.Forge[req.ReelId])
|
|
}(v.CId, equipConf.Star, int32(len(v.AdverbEntry)+1)) // 品质按副词条数+1 来算
|
|
}
|
|
}
|
|
this.module.SendRdTask(session, atno)
|
|
return
|
|
}
|