110 lines
3.3 KiB
Go
110 lines
3.3 KiB
Go
package equipment
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) WashConfirmCheck(session comm.IUserSession, req *pb.EquipmentWashConfirmReq) (errdata *pb.ErrorData) {
|
|
if req.Eid == "" || req.Pids == nil || len(req.Pids) == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 锻造
|
|
func (this *apiComp) WashConfirm(session comm.IUserSession, req *pb.EquipmentWashConfirmReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
equip *pb.DB_Equipment
|
|
attrlibrary *cfg.GameEquipAttrlibrarySData
|
|
hero *pb.DBHero
|
|
equipments []*pb.DB_Equipment
|
|
err error
|
|
)
|
|
if errdata = this.WashConfirmCheck(session, req); errdata != nil {
|
|
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)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Title: pb.ErrorCode_SystemError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if len(equip.AdverbEntry) != len(req.Pids) {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
for i, v := range equip.AdverbEntry {
|
|
if attrlibrary, err = this.module.configure.GetEquipmentAttrlibraryConfigureByKey(req.Pids[i]); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Title: pb.ErrorCode_SystemError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
equip.AdverbEntry[i] = &pb.EquipmentAttributeEntry{
|
|
Id: attrlibrary.Key,
|
|
Libraryid: attrlibrary.Libraryid,
|
|
Lv: v.Lv,
|
|
AttrName: attrlibrary.Attr.A,
|
|
BaseValue: attrlibrary.Attr.N,
|
|
Value: attrlibrary.Attr.N + int32(float64(attrlibrary.Addition[equip.AdverbEntry[i].Lv-1])/1000.0*float64(attrlibrary.Attr.N)),
|
|
}
|
|
}
|
|
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equip.Id, map[string]interface{}{
|
|
"adverbEntry": equip.AdverbEntry,
|
|
}); err != nil {
|
|
log.Errorf("Upgrade err:%v", err)
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_SystemError,
|
|
Title: pb.ErrorCode_SystemError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if equip.HeroId != "" {
|
|
equipments = make([]*pb.DB_Equipment, 8)
|
|
if hero, errdata = this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), equip.HeroId); errdata != nil {
|
|
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 {
|
|
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
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "washconfirm", &pb.EquipmentWashConfirmResp{Issucc: true})
|
|
return
|
|
}
|