122 lines
3.7 KiB
Go
122 lines
3.7 KiB
Go
package equipment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) EquipCheck(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
///英雄挂在装备 code 错误码信息 data 错误附加数据
|
|
func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
err error
|
|
confs []*cfg.Game_equipData
|
|
equipment *pb.DB_Equipment
|
|
equipments []*pb.DB_Equipment
|
|
updatequipment []*pb.DB_Equipment
|
|
hero *pb.DBHero
|
|
)
|
|
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
session.SendMsg(string(this.module.GetType()), "equip", &pb.EquipmentEquipResp{Equipments: equipments})
|
|
}
|
|
}()
|
|
//校验数据
|
|
confs = make([]*cfg.Game_equipData, len(req.EquipmentId))
|
|
equipments = make([]*pb.DB_Equipment, len(req.EquipmentId))
|
|
for i, v := range req.EquipmentId {
|
|
if v != "" {
|
|
if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
|
|
log.Errorf("Equip_Check err:%v", err)
|
|
code = pb.ErrorCode_EquipmentOnFoundEquipment
|
|
return
|
|
}
|
|
if confs[i], err = this.module.configure.GetEquipmentConfigureById(equipments[i].CId); err != nil {
|
|
log.Errorf("Equip_Check err:%v", err)
|
|
code = pb.ErrorCode_EquipmentOnFoundEquipment
|
|
return
|
|
}
|
|
}
|
|
}
|
|
//获取英雄数据
|
|
if hero, code = this.module.hero.GetHero(session.GetUserId(), req.HeroCardId); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
//读取英雄原装备
|
|
for i, v := range hero.EquipID {
|
|
if v != "" {
|
|
if equipments[i] != nil && v != equipments[i].Id {
|
|
if equipment, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
|
|
log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
equipment.HeroId = ""
|
|
equipments[i].HeroId = hero.Id
|
|
updatequipment = append(updatequipment, equipment, equipments[i])
|
|
} else if equipments[i] == nil {
|
|
if equipment, err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
|
|
log.Errorf("Equip reader uid:%s equipment:%s err:%v", session.GetUserId(), v, err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
equipment.HeroId = ""
|
|
updatequipment = append(updatequipment, equipment)
|
|
}
|
|
} else {
|
|
if equipments[i] != nil {
|
|
equipments[i].HeroId = hero.Id
|
|
updatequipment = append(updatequipment, equipments[i])
|
|
}
|
|
}
|
|
}
|
|
msuit := true
|
|
subsit := true
|
|
for i, v := range equipments { //校验装备位置
|
|
if v != nil {
|
|
if i != int(confs[i].Pos) {
|
|
log.Errorf("Equip conf:%v Target:%d Incorrect range!", confs[i], i)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
} else {
|
|
if i < 4 {
|
|
msuit = false //主套装没有
|
|
} else {
|
|
subsit = false //辅套装没有
|
|
}
|
|
}
|
|
}
|
|
|
|
if msuit { //前4个位置都有装备 判断是否存在套装
|
|
if confs[0].Suittype == confs[1].Suittype &&
|
|
confs[1].Suittype == confs[2].Suittype &&
|
|
confs[2].Suittype == confs[3].Suittype {
|
|
hero.SuiteId = confs[0].Suittype
|
|
}
|
|
}
|
|
if subsit { //后2个位置都有装备 判断是否存在套装
|
|
if confs[4].Suittype == confs[5].Suittype {
|
|
hero.SuiteExtId = confs[4].Suittype
|
|
}
|
|
}
|
|
//更新装备数据加成
|
|
if code = this.module.hero.UpdateEquipment(hero, equipments); code == pb.ErrorCode_Success {
|
|
if err = this.module.modelEquipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
|
|
log.Errorf("Equip err%v", err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|