上传任务道具使用代码
This commit is contained in:
parent
7d3929305a
commit
bd00553832
@ -184,12 +184,12 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
ok bool
|
||||
change bool
|
||||
changes []*pb.ConIProgress
|
||||
|
||||
// completeConIds []int32 //完成id列表
|
||||
err error
|
||||
notify map[string][]*pb.ConIProgress
|
||||
module core.IModule
|
||||
nmodule comm.IBuriedUpdateNotify
|
||||
err error
|
||||
)
|
||||
this.Debug("触发埋点!", log.Field{Key: "burieds", Value: burieds})
|
||||
|
||||
lock, _ := this.modelBuried.userlock(uid)
|
||||
err = lock.Lock()
|
||||
if err != nil {
|
||||
@ -219,6 +219,7 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
return
|
||||
}
|
||||
}
|
||||
notify = make(map[string][]*pb.ConIProgress)
|
||||
changes = make([]*pb.ConIProgress, 0)
|
||||
//处理校验通过埋点数据
|
||||
for buried, conds := range pass {
|
||||
@ -236,43 +237,62 @@ func (this *Buried) trigger(uid string, burieds ...*pb.BuriedParam) {
|
||||
}
|
||||
for _, cond := range conds {
|
||||
this.Debug("更新埋点数据", log.Field{Key: "埋点类型", Value: buried.TaskType}, log.Field{Key: "条件类型", Value: cond.Id})
|
||||
autoActivated := false
|
||||
if cond.Rtype == rtype1 { //创号后入录
|
||||
if change, bitem, err = this.updateAndCheckBuried(bconf, bdata, buried, cond, true); change {
|
||||
changes = append(changes, &pb.ConIProgress{
|
||||
Btype: bdata.Btype,
|
||||
Conid: cond.Id,
|
||||
Value: bitem.Value,
|
||||
Target: cond.Value,
|
||||
State: bitem.Finish,
|
||||
})
|
||||
}
|
||||
autoActivated = true
|
||||
} else if cond.Rtype == rtype2 { //任务接取后才会录入 判断用户埋点数据是否存在 不存在等待任务系统调用接口 ActivationBuried 激活
|
||||
if change, bitem, err = this.updateAndCheckBuried(bconf, bdata, buried, cond, false); change {
|
||||
changes = append(changes, &pb.ConIProgress{
|
||||
Btype: bdata.Btype,
|
||||
Conid: cond.Id,
|
||||
Value: bitem.Value,
|
||||
Target: cond.Value,
|
||||
State: bitem.Finish,
|
||||
})
|
||||
}
|
||||
autoActivated = false
|
||||
} else {
|
||||
this.Error("未知的任务类型", log.Field{Key: "埋点类型", Value: buried.TaskType}, log.Field{Key: "条件Id", Value: cond.Id}, log.Field{Key: "条件类型", Value: cond.Rtype})
|
||||
continue
|
||||
}
|
||||
if change, bitem, err = this.updateAndCheckBuried(bconf, bdata, buried, cond, autoActivated); change {
|
||||
cp := &pb.ConIProgress{
|
||||
Btype: bdata.Btype,
|
||||
Conid: cond.Id,
|
||||
Value: bitem.Value,
|
||||
Target: cond.Value,
|
||||
State: bitem.Finish,
|
||||
}
|
||||
changes = append(changes, cp)
|
||||
if len(cond.Notify) > 0 {
|
||||
for _, mname := range cond.Notify {
|
||||
if _, ok = notify[mname]; !ok {
|
||||
notify[mname] = make([]*pb.ConIProgress, 0)
|
||||
}
|
||||
notify[mname] = append(notify[mname], cp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
change = true
|
||||
}
|
||||
|
||||
if change { //同步数据
|
||||
if len(changes) > 0 { //同步数据
|
||||
if err = this.modelBuried.updateUserBurieds(uid, bdatas); err != nil {
|
||||
this.Error("更新用户埋点数据错误!", log.Field{Key: "err", Value: err.Error()})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(notify) > 0 {
|
||||
for k, v := range notify {
|
||||
if module, err = this.service.GetModule(core.M_Modules(k)); err != nil {
|
||||
this.Error("通知条件变化异常 目标模块未找到!", log.Field{Key: "module", Value: k}, log.Field{Key: "err", Value: err.Error()})
|
||||
continue
|
||||
}
|
||||
if nmodule, ok = module.(comm.IBuriedUpdateNotify); !ok {
|
||||
this.Error("通知条件变化异常 目标模块未实现 IBuriedUpdateNotify 接口 !", log.Field{Key: "module", Value: k})
|
||||
continue
|
||||
}
|
||||
//异步通知指定模块
|
||||
go nmodule.BuriedsNotify(uid, v)
|
||||
}
|
||||
}
|
||||
|
||||
//通知事件
|
||||
if len(changes) > 0 {
|
||||
this.Debug("条件达成通知", log.Field{Key: "ConIds", Value: changes})
|
||||
this.Debug("条件变化通知", log.Field{Key: "ConIds", Value: changes})
|
||||
event.TriggerEvent(comm.EventBuriedComplete, uid, changes)
|
||||
}
|
||||
}
|
||||
|
@ -34,30 +34,24 @@ func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq)
|
||||
return
|
||||
}
|
||||
switch itemcf.Usetype {
|
||||
case comm.UseType1: //英雄碎片
|
||||
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)
|
||||
var res []*cfg.Gameatn
|
||||
res = append(res, &cfg.Gameatn{
|
||||
A: "hero",
|
||||
T: sale.Prize[0].T,
|
||||
N: int32(req.Amount),
|
||||
})
|
||||
if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
case itemuse_exchange: //分解(体力,兑换
|
||||
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),
|
||||
})
|
||||
|
||||
case 4: //自选宝箱
|
||||
}
|
||||
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 itemuse_optionalbox: //自选宝箱
|
||||
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
@ -86,7 +80,7 @@ func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq)
|
||||
if code = this.module.DispenseRes(session, sale, true); code != pb.ErrorCode_Success {
|
||||
return
|
||||
}
|
||||
case 5: //随机宝箱
|
||||
case itemuse_randombox: //宝箱
|
||||
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
@ -101,30 +95,7 @@ func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq)
|
||||
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 comm.UseType8: //觉醒材料合成
|
||||
case itemuse_synthesis: //合成
|
||||
if prop = this.module.configure.GetDropData(itemcf.BoxId); prop == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
@ -161,23 +132,7 @@ func (this *apiComp) Useitem(session comm.IUserSession, req *pb.ItemsUseItemReq)
|
||||
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
|
||||
|
@ -19,6 +19,15 @@ const (
|
||||
Pack_Expiration = -1 //背包缓存数据过期时间
|
||||
)
|
||||
|
||||
const (
|
||||
itemuse_nouse int32 = 1 //不可使用
|
||||
itemuse_jump int32 = 2 //跳转
|
||||
itemuse_exchange int32 = 3 //分解(体力,兑换)
|
||||
itemuse_optionalbox int32 = 4 //自选宝箱
|
||||
itemuse_randombox int32 = 5 //随机宝箱
|
||||
itemuse_synthesis int32 = 6 //合成(英雄,觉醒)
|
||||
)
|
||||
|
||||
var (
|
||||
NoFoundItemConfig = errors.New("no found itemconfig!") //道具配置未找到
|
||||
ItemNotEnoughError = errors.New("item not enough!") //物品不足
|
||||
|
Loading…
Reference in New Issue
Block a user