go_dreamfactory/modules/equipment/api_ench.go
2023-03-27 15:47:17 +08:00

99 lines
3.0 KiB
Go

package equipment
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
cfg "go_dreamfactory/sys/configure/structs"
"math/rand"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) EnchCheck(session comm.IUserSession, req *pb.EquipmentEnchReq) (code pb.ErrorCode) {
if req.Eid == "" {
code = pb.ErrorCode_ReqParameterError
}
return
}
//附魔
func (this *apiComp) Ench(session comm.IUserSession, req *pb.EquipmentEnchReq) (code pb.ErrorCode, data proto.Message) {
var (
equip *pb.DB_Equipment
conf *cfg.GameEquipEnchantingData
hero *pb.DBHero
equipments []*pb.DB_Equipment
need []*cfg.Gameatn
AttrValue int32
err error
)
if code = this.EnchCheck(session, req); code != pb.ErrorCode_Success {
return
}
if conf, err = this.module.configure.getEquipenchanting(req.Itemid); err != nil {
code = pb.ErrorCode_ConfigNoFound
return
}
need = make([]*cfg.Gameatn, 0)
need = append(need, conf.Need...)
need = append(need, &cfg.Gameatn{
A: comm.ItemType,
T: req.Itemid,
N: 1,
})
if code = this.module.ConsumeRes(session, need, true); code != pb.ErrorCode_Success {
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)
code = pb.ErrorCode_SystemError
return
}
if equip.AdverbEntry[req.Index] == nil || equip.AdverbEntry[req.Index].AttrName != conf.Attrkey {
code = pb.ErrorCode_ReqParameterError
return
}
AttrValue = rand.Int31n(conf.AttrMax-conf.AttrMini) + conf.AttrMini
// if AttrValue > equip.AdverbEntry[req.Index].Value {
equip.AdverbEntry[req.Index].EnchValue = AttrValue
// }
if err = this.module.modelEquipment.ChangeList(session.GetUserId(), equip.Id, map[string]interface{}{
"adverbEntry": equip.AdverbEntry,
"isInitialState": false,
}); err != nil {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_SystemError
return
}
if equip.HeroId != "" {
equipments = make([]*pb.DB_Equipment, 8)
if hero, code = this.module.ModuleHero.GetHeroByObjID(session.GetUserId(), equip.HeroId); code != pb.ErrorCode_Success {
this.module.Errorf("Upgrade code:%d", code)
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 {
log.Errorf("Upgrade err:%v", err)
code = pb.ErrorCode_EquipmentOnFoundEquipment
return
}
} else {
equipments[i] = equip
}
}
}
if code = this.module.ModuleHero.UpdateEquipment(session, hero, equipments); code != pb.ErrorCode_Success {
return
}
}
// this.module.ModuleRtask.SendToRtask(session, comm.Rtype94, 1)
go this.module.ModuleRtask.TriggerTask(session.GetUserId(), comm.GettaskParam(comm.Rtype94, 1))
session.SendMsg(string(this.module.GetType()), "ench", &pb.EquipmentEnchResp{Issucc: true, Equipment: equip})
return
}