go_dreamfactory/modules/equipment/api_ench.go
2023-05-31 17:49:01 +08:00

122 lines
3.5 KiB
Go

package equipment
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
)
//参数校验
func (this *apiComp) EnchCheck(session comm.IUserSession, req *pb.EquipmentEnchReq) (code pb.ErrorCode) {
if req.Eid == "" {
code = pb.ErrorCode_ReqParameterError
}
return
}
//附魔
func (this *apiComp) Ench(session comm.IUserSession, req *pb.EquipmentEnchReq) (code pb.ErrorCode, data *pb.ErrorData) {
var (
equip *pb.DB_Equipment
conf *cfg.GameEquipEnchantingData
hero *pb.DBHero
equipments []*pb.DB_Equipment
need []*cfg.Gameatn
AttrValue int32
err error
)
if code = this.EnchCheck(session, req); code != pb.ErrorCode_Success {
return
}
if conf, err = this.module.configure.getEquipenchanting(req.Itemid); err != nil {
code = pb.ErrorCode_ConfigNoFound
data = &pb.ErrorData{
Title: code.ToString(),
Message: err.Error(),
}
return
}
need = make([]*cfg.Gameatn, 0)
need = append(need, conf.Need...)
need = append(need, &cfg.Gameatn{
A: comm.ItemType,
T: req.Itemid,
N: 1,
})
if code = this.module.ConsumeRes(session, need, true); code != pb.ErrorCode_Success {
return
}
if equip, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), req.Eid); err != nil {
this.module.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), req.Eid, err)
code = pb.ErrorCode_SystemError
data = &pb.ErrorData{
Title: code.ToString(),
Message: err.Error(),
}
return
}
if equip.AdverbEntry[req.Index] == nil || equip.AdverbEntry[req.Index].AttrName != conf.Attrkey {
code = pb.ErrorCode_ReqParameterError
data = &pb.ErrorData{
Title: code.ToString(),
Message: req.String(),
}
return
}
AttrValue = rand.Int31n(conf.AttrMax-conf.AttrMini) + conf.AttrMini
// if AttrValue > equip.AdverbEntry[req.Index].Value {
equip.AdverbEntry[req.Index].EnchValue = AttrValue
// }
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equip.Id, map[string]interface{}{
"adverbEntry": equip.AdverbEntry,
"isInitialState": false,
}); err != nil {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_SystemError
data = &pb.ErrorData{
Title: code.ToString(),
Message: err.Error(),
}
return
}
if equip.HeroId != "" {
equipments = make([]*pb.DB_Equipment, 8)
if hero, code = this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), equip.HeroId); code != pb.ErrorCode_Success {
this.module.Errorf("Upgrade code:%d", code)
data = &pb.ErrorData{
Title: code.ToString(),
Message: fmt.Sprintf("英雄唯一 id:%s", equip.HeroId),
}
return
}
for i, v := range hero.EquipID {
if v != "" {
if v != equip.Id {
if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_EquipmentOnFoundEquipment
data = &pb.ErrorData{
Title: code.ToString(),
Message: fmt.Sprintf("装备唯一 id:%s", v),
}
return
}
} else {
equipments[i] = equip
}
}
}
if code = this.module.ModuleHero.UpdateEquipment(session, hero, equipments); code != pb.ErrorCode_Success {
return
}
}
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype94, 1)
go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), comm.GetBuriedParam(comm.Rtype94, 1))
session.SendMsg(string(this.module.GetType()), "ench", &pb.EquipmentEnchResp{Issucc: true, Equipment: equip})
return
}