186 lines
5.4 KiB
Go
186 lines
5.4 KiB
Go
package items
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) UseitemCheck(session comm.IUserSession, req *pb.ItemsUseItemReq) (code pb.ErrorCode) {
|
|
if req.GridId == "" || req.Amount <= 0 || req.Select < 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
//使用道具
|
|
func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
err error
|
|
item *pb.DB_UserItemData
|
|
itemcf *cfg.GameItemData
|
|
prop []*cfg.GameDropData
|
|
)
|
|
if code = this.UseitemCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
if itemcf, err = this.module.configure.GetItemConfigure(item.ItemId); err != nil {
|
|
code = pb.ErrorCode_ConfigurationException
|
|
return
|
|
}
|
|
switch itemcf.Usetype {
|
|
case 1: //英雄碎片
|
|
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if itemcf.SynthetizeNum*int32(req.Amount) > int32(item.Amount) { //碎片数量不够
|
|
code = pb.ErrorCode_ItemsNoEnough
|
|
return
|
|
}
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*itemcf.SynthetizeNum*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
sale := RandomProps(prop)
|
|
if code = this.module.ModuleHero.GetSpecifiedHero(session, sale.Prize[0].T, sale.Star, 1, int32(req.Amount)); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
//随机任务
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype22, 1)
|
|
this.module.ModuleRtask.SendToRtask(session, comm.Rtype22, utils.ToInt32(sale.Prize[0].T))
|
|
case 4: //自选宝箱
|
|
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
var sale []*cfg.Gameatn
|
|
for _, v := range prop {
|
|
if v.Id == req.Select {
|
|
for _, v1 := range v.Prize {
|
|
sale = append(sale, &cfg.Gameatn{
|
|
A: v1.A,
|
|
T: v1.T,
|
|
N: v1.N * int32(req.Amount),
|
|
})
|
|
}
|
|
}
|
|
}
|
|
if sale == nil {
|
|
this.module.Errorf("no found target sale:%v", req.Select)
|
|
code = pb.ErrorCode_ReqParameterError
|
|
return
|
|
}
|
|
|
|
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
case 5: //随机宝箱
|
|
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
sale := make([]*cfg.Gameatn, 0)
|
|
for i := uint32(0); i < req.Amount; i++ {
|
|
sale = append(sale, RandomProps(prop).Prize...)
|
|
}
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
case 6: //箱子
|
|
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
sale := make([]*cfg.Gameatn, 0, len(prop))
|
|
for _, v := range prop {
|
|
for _, v1 := range v.Prize {
|
|
sale = append(sale, &cfg.Gameatn{
|
|
A: v1.A,
|
|
T: v1.T,
|
|
N: v1.N * int32(req.Amount),
|
|
})
|
|
}
|
|
}
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
break
|
|
case 8: //觉醒材料合成
|
|
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if itemcf.SynthetizeNum*int32(req.Amount) > int32(item.Amount) { //碎片数量不够
|
|
code = pb.ErrorCode_ItemsNoEnough
|
|
return
|
|
}
|
|
sale := make([]*cfg.Gameatn, 0, len(itemcf.SynthetizeDeplete))
|
|
for _, v := range itemcf.SynthetizeDeplete {
|
|
sale = append(sale, &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * int32(req.Amount),
|
|
})
|
|
}
|
|
if code = this.module.ConsumeRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*itemcf.SynthetizeNum*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
sale = make([]*cfg.Gameatn, 0, len(prop))
|
|
for _, v := range prop {
|
|
for _, v1 := range v.Prize {
|
|
sale = append(sale, &cfg.Gameatn{
|
|
A: v1.A,
|
|
T: v1.T,
|
|
N: v1.N * int32(req.Amount),
|
|
})
|
|
}
|
|
}
|
|
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
case 11: //药剂使用
|
|
sale := make([]*cfg.Gameatn, 0, len(prop))
|
|
for _, v := range itemcf.DecomposeDeplete {
|
|
sale = append(sale, &cfg.Gameatn{
|
|
A: v.A,
|
|
T: v.T,
|
|
N: v.N * int32(req.Amount),
|
|
})
|
|
|
|
}
|
|
if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
break
|
|
default:
|
|
code = pb.ErrorCode_ItemsUseNotSupported
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "useitem", &pb.ItemsUseItemResp{GridId: req.GridId, Amount: req.Amount, Issucc: true})
|
|
return
|
|
}
|