diff --git a/modules/caravan/api_getstory.go b/modules/caravan/api_getstory.go index aa5d5ab8a..96bf89a68 100644 --- a/modules/caravan/api_getstory.go +++ b/modules/caravan/api_getstory.go @@ -16,8 +16,9 @@ func (this *apiComp) GetStoryCheck(session comm.IUserSession, req *pb.CaravanGet func (this *apiComp) GetStory(session comm.IUserSession, req *pb.CaravanGetStoryReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( - resp *pb.CaravanGetStoryResp - update map[string]interface{} + resp *pb.CaravanGetStoryResp + update map[string]interface{} + bAccept bool ) update = make(map[string]interface{}) if code = this.GetStoryCheck(session, req); code != pb.ErrorCode_Success { @@ -39,20 +40,31 @@ func (this *apiComp) GetStory(session comm.IUserSession, req *pb.CaravanGetStory return } if req.Citystory == conf.Citynormal { //接受剧情 - list.Eventid = req.Citystory - list.Task = conf.Worldtask - list.Tasktime = configure.Now().Unix() - update["eventid"] = list.Eventid - update["task"] = list.Task - update["tasktime"] = list.Tasktime - } else { // 拒绝剧情 重置 + module, err := this.service.GetModule(comm.ModuleWorldtask) + if err != nil { + return + } + if wt, ok := module.(comm.IWorldtask); ok { + list.Taskid = wt.GetWorldTaskBy(session.GetUserId(), conf.Worldtask) + if list.Taskid != 0 { // 任务接取成功 + bAccept = true + list.Eventid = req.Citystory + list.Taskid = conf.Worldtask + list.Tasktime = configure.Now().Unix() + update["eventid"] = list.Eventid + update["task"] = list.Taskid + update["tasktime"] = list.Tasktime + } + } + } + if !bAccept { // 拒绝剧情 重置 list.Eventid = 0 - list.Task = 0 + list.Taskid = 0 list.Tasktime = 0 update["eventid"] = list.Eventid - update["task"] = list.Task + update["task"] = list.Taskid update["tasktime"] = list.Tasktime } this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update) diff --git a/modules/caravan/module.go b/modules/caravan/module.go index 145cd1967..896d18fdb 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -17,6 +17,7 @@ type Caravan struct { modelCaravan *modelCaravan api *apiComp configure *configureComp + service core.IService } func NewModule() core.IModule { @@ -29,7 +30,7 @@ func (this *Caravan) GetType() core.M_Modules { func (this *Caravan) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) - + this.service = service return } @@ -219,24 +220,32 @@ func (this *Caravan) refreshCaravanItemInfo(uid string, data *pb.DBCaravan) { // 校验随机事件是否超时 func (this *Caravan) CheckCaravanTask(session comm.IUserSession, data *pb.DBCaravan) { if data.Eventid != 0 { - if even := this.configure.GetCaravanEventById(data.Eventid); even != nil { + if list := this.configure.GetCaravanEventById(data.Eventid); list != nil { // 校验任务是否超时 - if data.Tasktime-configure.Now().Unix() > int64(even.Eventtime) { //TODO 任务超时 通知任务模块处理 并清理相关数据 + if data.Tasktime-configure.Now().Unix() > int64(list.Eventtime) { //TODO 任务超时 通知任务模块处理 并清理相关数据 + module, err := this.service.GetModule(comm.ModuleWorldtask) + if err != nil { + return + } + if wt, ok := module.(comm.IWorldtask); ok { + wt.UpdateTaskStatus(session.GetUserId(), data.Taskid) // 通知任务模块 任务超时 + } + this.CleanCaravanTask(session.GetUserId(), data) //任务超时 清理任务数据 // 任务超时发送任务失败推送 resp := &pb.CaravanTaskCompletePush{} resp.Data = data resp.BSuccess = false - if len(even.Unreword) == 2 && even.Unreword[0] == 1 { + if len(list.Unreword) == 2 && list.Unreword[0] == 1 { // 类型为1 的 直接扣除虚拟币 this.ConsumeRes(session, []*cfg.Gameatn{{ A: "attr", T: "merchantmoney", - N: even.Unreword[1], + N: list.Unreword[1], }}, true) resp.Reward = append(resp.Reward, &pb.UserAssets{ A: "attr", T: "merchantmoney", - N: -even.Unreword[1], + N: -list.Unreword[1], // 扣除虚拟币 }) } session.SendMsg(string(this.GetType()), "taskcomplete", resp) @@ -247,18 +256,18 @@ func (this *Caravan) CheckCaravanTask(session comm.IUserSession, data *pb.DBCara func (this *Caravan) CleanCaravanTask(uid string, data *pb.DBCaravan) { if data.Eventid != 0 { data.Eventid = 0 - data.Task = 0 + data.Taskid = 0 data.Tasktime = 0 update := make(map[string]interface{}) update["eventid"] = data.Eventid - update["task"] = data.Task + update["task"] = data.Taskid update["tasktime"] = data.Tasktime this.modelCaravan.modifyCaravanDataByObjId(uid, update) } } func (this *Caravan) TaskComplete(session comm.IUserSession, taskid int32) { - this.Debug("TaskComplete", + this.Debug("Caravan TaskComplete", log.Field{Key: "session", Value: session.GetUserId()}, log.Field{Key: "taskid", Value: taskid}, ) @@ -269,7 +278,7 @@ func (this *Caravan) TaskComplete(session comm.IUserSession, taskid int32) { if conf := this.configure.GetCaravanEventById(taskid); conf != nil { if list, err := this.modelCaravan.getCaravanList(session.GetUserId()); err != nil { - if list.Eventid == taskid { + if list.Taskid == taskid { this.CleanCaravanTask(session.GetUserId(), list) //任务完成 清理任务数据 resp = &pb.CaravanTaskCompletePush{} resp.Data = list diff --git a/pb/caravan_db.pb.go b/pb/caravan_db.pb.go index d540bd2d1..09c551cf4 100644 --- a/pb/caravan_db.pb.go +++ b/pb/caravan_db.pb.go @@ -232,7 +232,7 @@ type DBCaravan struct { Profit int64 `protobuf:"varint,8,opt,name=profit,proto3" json:"profit"` // 虚拟货利润 Resettime int64 `protobuf:"varint,9,opt,name=resettime,proto3" json:"resettime"` // 最后一次重置时间 Curcity int32 `protobuf:"varint,10,opt,name=curcity,proto3" json:"curcity"` // 当前城市 - Task int32 `protobuf:"varint,11,opt,name=task,proto3" json:"task"` // 对应对应世界任务组 worldtask 210 + Taskid int32 `protobuf:"varint,11,opt,name=taskid,proto3" json:"taskid"` // 对应对应世界任务组 worldtask Eventid int32 `protobuf:"varint,12,opt,name=eventid,proto3" json:"eventid"` // 特殊事件ID(事件配置唯一id) Tasktime int64 `protobuf:"varint,13,opt,name=tasktime,proto3" json:"tasktime"` // 任务触发时间 Baglimit int32 `protobuf:"varint,14,opt,name=baglimit,proto3" json:"baglimit"` // 背包上限 @@ -340,9 +340,9 @@ func (x *DBCaravan) GetCurcity() int32 { return 0 } -func (x *DBCaravan) GetTask() int32 { +func (x *DBCaravan) GetTaskid() int32 { if x != nil { - return x.Task + return x.Taskid } return 0 } @@ -394,7 +394,7 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{ 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, - 0xdd, 0x04, 0x0a, 0x09, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x12, 0x0e, 0x0a, + 0xe1, 0x04, 0x0a, 0x09, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, @@ -413,26 +413,27 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{ 0x74, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x72, 0x65, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x75, 0x72, 0x63, 0x69, 0x74, 0x79, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x63, 0x75, 0x72, 0x63, 0x69, 0x74, 0x79, 0x12, - 0x12, 0x0a, 0x04, 0x74, 0x61, 0x73, 0x6b, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, - 0x61, 0x73, 0x6b, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x64, 0x18, 0x0c, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x69, 0x64, 0x12, 0x1a, 0x0a, - 0x08, 0x74, 0x61, 0x73, 0x6b, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x03, 0x52, - 0x08, 0x74, 0x61, 0x73, 0x6b, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x62, 0x61, 0x67, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x62, 0x61, 0x67, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x1a, 0x42, 0x0a, 0x0a, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x45, 0x6e, - 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, 0x0a, 0x47, 0x6f, 0x6f, - 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1c, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, - 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x42, 0x0a, 0x09, 0x43, - 0x69, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x43, 0x69, 0x74, 0x79, - 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, - 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x69, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x06, 0x74, 0x61, 0x73, 0x6b, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x69, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x69, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1a, 0x0a, + 0x08, 0x62, 0x61, 0x67, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x62, 0x61, 0x67, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x1a, 0x42, 0x0a, 0x0a, 0x49, 0x74, 0x65, + 0x6d, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1e, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x67, 0x49, 0x6e, + 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x40, 0x0a, + 0x0a, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1c, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x47, + 0x6f, 0x6f, 0x64, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, + 0x42, 0x0a, 0x09, 0x43, 0x69, 0x74, 0x79, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1f, + 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x43, 0x69, 0x74, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, + 0x02, 0x38, 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var (