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