131 lines
3.9 KiB
Go
131 lines
3.9 KiB
Go
package equipment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) EquipCheck(session comm.IUserSession, req *pb.EquipmentEquipReq) (result map[string]interface{}, code comm.ErrorCode) {
|
|
var (
|
|
err error
|
|
errorCode pb.ErrorCode
|
|
confs []*cfg.Game_equipData
|
|
equipments []*pb.DB_Equipment
|
|
hero *pb.DBHero
|
|
)
|
|
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.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.Code = pb.ErrorCode_EquipmentOnFoundEquipment
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
if hero, errorCode = this.module.hero.GetHero(session.GetUserId(), req.HeroCardId); errorCode != pb.ErrorCode_Success {
|
|
code.Code = errorCode
|
|
return
|
|
}
|
|
result = map[string]interface{}{
|
|
"confs": confs,
|
|
"equipments": equipments,
|
|
"hero": hero,
|
|
}
|
|
return
|
|
}
|
|
|
|
///英雄挂在装备
|
|
func (this *apiComp) Equip(session comm.IUserSession, agrs map[string]interface{}, req *pb.EquipmentEquipReq) (code pb.ErrorCode) {
|
|
var (
|
|
err error
|
|
confs []*cfg.Game_equipData
|
|
equipment *pb.DB_Equipment
|
|
equipments []*pb.DB_Equipment
|
|
updatequipment []*pb.DB_Equipment
|
|
hero *pb.DBHero
|
|
)
|
|
|
|
confs = agrs["conf"].([]*cfg.Game_equipData)
|
|
equipments = agrs["equipment"].([]*pb.DB_Equipment)
|
|
updatequipment = make([]*pb.DB_Equipment, 0)
|
|
hero = agrs["hero"].(*pb.DBHero)
|
|
|
|
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
|
|
}
|