135 lines
3.7 KiB
Go
135 lines
3.7 KiB
Go
package equipment
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"math"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) InscribeCheck(session comm.IUserSession, req *pb.EquipmentInscribeReq) (errdata *pb.ErrorData) {
|
|
if req.Eid == "" || req.Heroid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "ReqParameter is null",
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 铭刻
|
|
func (this *apiComp) Inscribe(session comm.IUserSession, req *pb.EquipmentInscribeReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
equip *pb.DB_Equipment
|
|
hero *pb.DBHero
|
|
conf *cfg.GameEquipData
|
|
heroconf *cfg.GameHeroData
|
|
equipments []*pb.DB_Equipment
|
|
err error
|
|
)
|
|
|
|
if errdata = this.InscribeCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if equip, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), req.Eid); err != nil {
|
|
this.module.Errorf("Equip_Check err:%v", err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EquipmentOnFoundEquipment,
|
|
Title: pb.ErrorCode_EquipmentOnFoundEquipment.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if equip.Inscribe != "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "equie is already Inscribe!",
|
|
}
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.GetEquipmentConfigureById(equip.CId); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if hero, errdata = this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), req.Heroid); errdata != nil {
|
|
return
|
|
}
|
|
if heroconf, err = this.module.ModuleTools.GetHeroConfig(hero.HeroID); errdata != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if !heroconf.Engraving {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Message: "heroconf.Engraving is false!",
|
|
}
|
|
return
|
|
}
|
|
|
|
//消耗
|
|
if errdata = this.module.ConsumeRes(session, conf.EngravingNeed, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
equip.Inscribe = req.Heroid
|
|
equip.Inscribevalue = int32(math.Floor(float64(equip.MainEntry.Value) * float64(conf.EngravingBonus) / float64(1000.0)))
|
|
|
|
if equip.HeroId == hero.Id {
|
|
equipments = make([]*pb.DB_Equipment, 8)
|
|
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 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_EquipmentOnFoundEquipment,
|
|
Title: pb.ErrorCode_EquipmentOnFoundEquipment.ToString(),
|
|
Message: fmt.Sprintf("装备唯一 id:%s", v),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
equipments[i] = equip
|
|
}
|
|
}
|
|
}
|
|
if errdata = this.module.ModuleHero.UpdateEquipment(session, hero, equipments); errdata != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equip.Id, map[string]interface{}{
|
|
"inscribe": equip.Inscribe,
|
|
"inscribevalue": equip.Inscribevalue,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if err = this.module.equipmentsChangePush(session, []*pb.DB_Equipment{equip}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Message: err.Error(),
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "inscribe", &pb.EquipmentInscribeResp{})
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "EquipmentInscribeReq", conf.EngravingNeed)
|
|
})
|
|
return
|
|
}
|