package caravan import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 func (this *apiComp) GotoCityCheck(session comm.IUserSession, req *pb.CaravanGotoCityReq) (code pb.ErrorCode) { if req.City == 0 || req.Ticket <= 0 { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) GotoCity(session comm.IUserSession, req *pb.CaravanGotoCityReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( resp *pb.CaravanGotoCityResp res *cfg.Gameatn bNewTask bool ) resp = &pb.CaravanGotoCityResp{} bNewTask = false if code = this.GotoCityCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } list, _ := this.module.modelCaravan.getCaravanList(session.GetUserId()) // 获取事件 if list.Eventid != 0 { if event := this.module.configure.GetCaravanEventById(list.Eventid); event != nil { // 校验任务是否超时 if list.Tasktime-configure.Now().Unix() > int64(event.Eventtime) { //TODO 任务超时 } if event.Eventtype == 1 { code = pb.ErrorCode_TrollTask // 需要完成强制任务 return } else { bNewTask = false } } } if bNewTask { // 到该城市随机一个新的任务 if newCity, e := this.module.configure.GetCaravanCity(req.City); e == nil { ipos := comm.GetRandW(newCity.Cityevent) list.Eventid = newCity.Cityevent[ipos] // 新的任务 // list.Tasktime = configure.Now().Unix() // if event := this.module.configure.GetCaravanEventById(list.Eventid); event != nil { // list.Task = event.Worldtask // 对应世界任务组 // } } else { code = pb.ErrorCode_DataNotFound data.ErrMsg = e.Error() } } if list.Curcity == req.City { code = pb.ErrorCode_TrollCity return } // 校验门票 if d := this.module.configure.GetCaravanLv(list.Lv); d != nil { //d.Tickettop res = &cfg.Gameatn{ A: d.Tickettop.A, T: d.Tickettop.T, N: req.Ticket, } } if code = this.module.ConsumeRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { // 校验门票数量 return } list.Curcity = req.City this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), map[string]interface{}{ "curcity": list.Curcity, "eventid": list.Eventid, }) resp.Data = list resp.Newtask = bNewTask session.SendMsg(string(this.module.GetType()), "gotocity", resp) return }