200 lines
6.9 KiB
Go
200 lines
6.9 KiB
Go
package equipment
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
"math"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) EquipCheck(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode) {
|
|
if len(req.EquipmentId) != 8 || req.HeroCardId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///英雄挂在装备 code 错误码信息 data 错误附加数据
|
|
func (this *apiComp) Equip(session comm.IUserSession, req *pb.EquipmentEquipReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
var (
|
|
err error
|
|
confs []*cfg.GameEquipData
|
|
equipment *pb.DB_Equipment
|
|
equipments []*pb.DB_Equipment
|
|
updatequipment []*pb.DB_Equipment
|
|
equipNum int32
|
|
equipStr map[int32]int32 = make(map[int32]int32)
|
|
equipLv map[int32]int32 = make(map[int32]int32)
|
|
hero *pb.DBHero
|
|
suite1Str, suite1Lv, suite2Str, suite2Lv int32 = math.MaxInt32, math.MaxInt32, math.MaxInt32, math.MaxInt32
|
|
tasks []*comm.TaskParam = make([]*comm.TaskParam, 0)
|
|
)
|
|
|
|
if code = this.EquipCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
//校验数据
|
|
confs = make([]*cfg.GameEquipData, len(req.EquipmentId))
|
|
equipments = make([]*pb.DB_Equipment, len(req.EquipmentId))
|
|
|
|
//获取英雄数据
|
|
if hero, code = this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), req.HeroCardId); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
for i, v := range req.EquipmentId {
|
|
if v != "" {
|
|
equipNum++
|
|
if equipments[i], err = this.module.modelEquipment.QueryUserEquipmentsById(session.GetUserId(), v); err != nil {
|
|
this.module.Errorf("Equip_Check err:%v", err)
|
|
code = pb.ErrorCode_EquipmentOnFoundEquipment
|
|
return
|
|
}
|
|
if equipments[i].HeroId != "" && hero.Id != equipments[i].HeroId { //装备已经有宿主了
|
|
code = pb.ErrorCode_EquipmentIsWorn
|
|
return
|
|
}
|
|
equipLv[equipments[i].Lv]++
|
|
if confs[i], err = this.module.configure.GetEquipmentConfigureById(equipments[i].CId); err != nil {
|
|
this.module.Errorf("Equip_Check err:%v", err)
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
equipStr[confs[i].Star]++
|
|
|
|
if i < 4 {
|
|
if confs[i].Star < suite1Str {
|
|
suite1Str = confs[i].Star
|
|
}
|
|
if equipments[i].Lv < suite1Lv {
|
|
suite1Lv = equipments[i].Lv
|
|
}
|
|
} else if i < 6 {
|
|
if confs[i].Star < suite2Str {
|
|
suite2Str = confs[i].Star
|
|
}
|
|
if equipments[i].Lv < suite2Lv {
|
|
suite2Lv = equipments[i].Lv
|
|
}
|
|
}
|
|
} else {
|
|
equipments[i] = nil
|
|
}
|
|
}
|
|
|
|
//读取英雄原装备
|
|
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 {
|
|
this.module.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 {
|
|
this.module.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) {
|
|
this.module.Errorf("Equip conf:%+v Target:%d Incorrect range!", confs[i], i)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
hero.EquipID[i] = v.Id
|
|
} else {
|
|
if i < 4 {
|
|
msuit = false //主套装没有
|
|
} else if i < 6 {
|
|
subsit = false //辅套装没有
|
|
}
|
|
hero.EquipID[i] = ""
|
|
}
|
|
}
|
|
|
|
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
|
|
hero.Suite1Star = suite1Str
|
|
hero.Suite1Lv = suite1Lv
|
|
}
|
|
} else {
|
|
hero.SuiteId = 0
|
|
hero.Suite1Star = 0
|
|
hero.Suite1Lv = 0
|
|
}
|
|
if subsit { //后2个位置都有装备 判断是否存在套装
|
|
if confs[4].Suittype == confs[5].Suittype {
|
|
hero.SuiteExtId = confs[4].Suittype
|
|
hero.Suite2Star = suite2Str
|
|
hero.Suite2Lv = suite2Lv
|
|
}
|
|
} else {
|
|
hero.SuiteExtId = 0
|
|
hero.Suite2Star = 0
|
|
hero.Suite2Lv = 0
|
|
}
|
|
//更新装备数据加成
|
|
if code = this.module.ModuleHero.UpdateEquipment(session, hero, equipments); code != pb.ErrorCode_Success {
|
|
this.module.Errorf("Equip ModuleHero UpdateEquipment code%v", code)
|
|
return
|
|
}
|
|
//同步数据
|
|
if err = this.module.modelEquipment.UpdateByHeroId(session.GetUserId(), updatequipment...); err != nil {
|
|
this.module.Errorf("Equip err%v", err)
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype5, 1, equipNum, utils.ToInt32(hero.HeroID)))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype5, utils.ToInt32(hero.HeroID), equipNum)
|
|
for k, v := range equipStr {
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype41, 1, utils.ToInt32(hero.HeroID), v, k))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype41, utils.ToInt32(hero.HeroID), v, k)
|
|
}
|
|
for k, v := range equipLv {
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype42, 1, utils.ToInt32(hero.HeroID), v, k))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype42, utils.ToInt32(hero.HeroID), v, k)
|
|
}
|
|
if hero.SuiteId != 0 {
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype49, 1, hero.Suite1Star, hero.Suite1Lv))
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype98, 1, hero.Suite1Lv))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype49, 1, hero.Suite1Star, hero.Suite1Lv)
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype98, 1, hero.Suite1Lv)
|
|
}
|
|
if hero.SuiteExtId != 0 {
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype48, 1, hero.Suite2Star, hero.Suite2Lv))
|
|
tasks = append(tasks, comm.GettaskParam(comm.Rtype98, 1, hero.Suite1Lv))
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype48, 1, hero.Suite2Star, hero.Suite2Lv)
|
|
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype98, 1, hero.Suite1Lv)
|
|
}
|
|
|
|
if len(tasks) > 0 {
|
|
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), tasks...)
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "equip", &pb.EquipmentEquipResp{Equipments: updatequipment})
|
|
return
|
|
}
|