随机触发事件
This commit is contained in:
parent
d45353e82b
commit
ce736c1a19
@ -33,6 +33,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
|
||||
this.module.refreshCaravanCityInfo(session.GetUserId(), list)
|
||||
// 更新货物信息
|
||||
this.module.refreshCaravanItemInfo(session.GetUserId(), list)
|
||||
this.module.CheckCaravanTask(session.GetUserId(), list)
|
||||
resp.Data = list
|
||||
session.SendMsg(string(this.module.GetType()), "getlist", resp)
|
||||
return
|
||||
|
63
modules/caravan/api_getstory.go
Normal file
63
modules/caravan/api_getstory.go
Normal file
@ -0,0 +1,63 @@
|
||||
package caravan
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
)
|
||||
|
||||
//参数校验
|
||||
func (this *apiComp) GetStoryCheck(session comm.IUserSession, req *pb.CaravanGetStoryReq) (code pb.ErrorCode) {
|
||||
if req.Cid == 0 || req.Citystory == 0 {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *apiComp) GetStory(session comm.IUserSession, req *pb.CaravanGetStoryReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
||||
var (
|
||||
resp *pb.CaravanGetStoryResp
|
||||
update map[string]interface{}
|
||||
)
|
||||
update = make(map[string]interface{})
|
||||
if code = this.GetStoryCheck(session, req); code != pb.ErrorCode_Success {
|
||||
return // 参数校验失败直接返回
|
||||
}
|
||||
list, err := this.module.api.module.modelCaravan.getCaravanList(session.GetUserId())
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
conf := this.module.configure.GetCaravanEventById(req.Cid)
|
||||
if conf == nil {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
return
|
||||
}
|
||||
if list.Eventid != req.Cid {
|
||||
code = pb.ErrorCode_ReqParameterError
|
||||
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 { // 拒绝剧情 重置
|
||||
list.Eventid = 0
|
||||
list.Task = 0
|
||||
list.Tasktime = 0
|
||||
|
||||
update["eventid"] = list.Eventid
|
||||
update["task"] = list.Task
|
||||
update["tasktime"] = list.Tasktime
|
||||
}
|
||||
this.module.modelCaravan.modifyCaravanDataByObjId(session.GetUserId(), update)
|
||||
|
||||
resp.Data = list
|
||||
session.SendMsg(string(this.module.GetType()), "getstory", resp)
|
||||
return
|
||||
}
|
@ -117,14 +117,14 @@ func (this *configureComp) GetAllCaravanItem() (data []*cfg.Gameitinerant_thingD
|
||||
}
|
||||
|
||||
// 获取随机事件
|
||||
func (this *configureComp) GetAllCaravanEvent(id int32) (data *cfg.Gameitinerant_eventData) {
|
||||
func (this *configureComp) GetCaravanEventById(id int32) (data *cfg.Gameitinerant_eventData) {
|
||||
if v, err := this.GetConfigure(game_itinerant_event); err == nil {
|
||||
if configure, ok := v.(*cfg.Gameitinerant_event); ok {
|
||||
data = configure.Get(id)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
log.Errorf("get GetAllCaravanEvent conf err:%v", err)
|
||||
log.Errorf("get GetCaravanEventById conf err:%v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ func (this *Caravan) refreshCaravanItemInfo(uid string, data *pb.DBCaravan) {
|
||||
bChange bool
|
||||
update map[string]interface{}
|
||||
)
|
||||
update = make(map[string]interface{})
|
||||
for k, v := range data.Goods {
|
||||
if c := this.configure.GetCaravanGoods(k); c != nil {
|
||||
if configure.Now().Unix()-v.Time > int64(c.Changetime) {
|
||||
@ -213,3 +214,34 @@ func (this *Caravan) refreshCaravanItemInfo(uid string, data *pb.DBCaravan) {
|
||||
this.modelCaravan.modifyCaravanDataByObjId(uid, update)
|
||||
}
|
||||
}
|
||||
|
||||
// 校验随机事件是否超时
|
||||
func (this *Caravan) CheckCaravanTask(uid string, data *pb.DBCaravan) {
|
||||
if data.Eventid != 0 {
|
||||
if even := this.configure.GetCaravanEventById(data.Eventid); even != nil {
|
||||
// 校验任务是否超时
|
||||
if data.Tasktime-configure.Now().Unix() > int64(even.Eventtime) { //TODO 任务超时 通知任务模块处理 并清理相关数据
|
||||
data.Eventid = 0
|
||||
data.Task = 0
|
||||
data.Tasktime = 0
|
||||
update := make(map[string]interface{})
|
||||
update["eventid"] = data.Eventid
|
||||
update["task"] = data.Task
|
||||
update["tasktime"] = data.Tasktime
|
||||
this.modelCaravan.modifyCaravanDataByObjId(uid, update)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func (this *Caravan) CleanCaravanTask(uid string, data *pb.DBCaravan) {
|
||||
if data.Eventid != 0 {
|
||||
data.Eventid = 0
|
||||
data.Task = 0
|
||||
data.Tasktime = 0
|
||||
update := make(map[string]interface{})
|
||||
update["eventid"] = data.Eventid
|
||||
update["task"] = data.Task
|
||||
update["tasktime"] = data.Tasktime
|
||||
this.modelCaravan.modifyCaravanDataByObjId(uid, update)
|
||||
}
|
||||
}
|
||||
|
@ -232,10 +232,10 @@ 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"`
|
||||
Eventid int32 `protobuf:"varint,12,opt,name=eventid,proto3" json:"eventid"` // 特殊事件ID
|
||||
Tasktime int64 `protobuf:"varint,13,opt,name=tasktime,proto3" json:"tasktime"` // 任务触发时间
|
||||
Baglimit int32 `protobuf:"varint,14,opt,name=baglimit,proto3" json:"baglimit"` // 背包上限
|
||||
Task int32 `protobuf:"varint,11,opt,name=task,proto3" json:"task"` // 对应对应世界任务组 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"` // 背包上限
|
||||
}
|
||||
|
||||
func (x *DBCaravan) Reset() {
|
||||
|
@ -328,6 +328,109 @@ func (x *CaravanGotoCityResp) GetNewtask() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// 剧情任务
|
||||
type CaravanGetStoryReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Cid int32 `protobuf:"varint,1,opt,name=cid,proto3" json:"cid"`
|
||||
Citystory int32 `protobuf:"varint,2,opt,name=citystory,proto3" json:"citystory"` // 抵达城市触发的剧情
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryReq) Reset() {
|
||||
*x = CaravanGetStoryReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_caravan_caravan_msg_proto_msgTypes[6]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CaravanGetStoryReq) ProtoMessage() {}
|
||||
|
||||
func (x *CaravanGetStoryReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_caravan_caravan_msg_proto_msgTypes[6]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CaravanGetStoryReq.ProtoReflect.Descriptor instead.
|
||||
func (*CaravanGetStoryReq) Descriptor() ([]byte, []int) {
|
||||
return file_caravan_caravan_msg_proto_rawDescGZIP(), []int{6}
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryReq) GetCid() int32 {
|
||||
if x != nil {
|
||||
return x.Cid
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryReq) GetCitystory() int32 {
|
||||
if x != nil {
|
||||
return x.Citystory
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type CaravanGetStoryResp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Data *DBCaravan `protobuf:"bytes,1,opt,name=data,proto3" json:"data"`
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryResp) Reset() {
|
||||
*x = CaravanGetStoryResp{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_caravan_caravan_msg_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryResp) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CaravanGetStoryResp) ProtoMessage() {}
|
||||
|
||||
func (x *CaravanGetStoryResp) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_caravan_caravan_msg_proto_msgTypes[7]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CaravanGetStoryResp.ProtoReflect.Descriptor instead.
|
||||
func (*CaravanGetStoryResp) Descriptor() ([]byte, []int) {
|
||||
return file_caravan_caravan_msg_proto_rawDescGZIP(), []int{7}
|
||||
}
|
||||
|
||||
func (x *CaravanGetStoryResp) GetData() *DBCaravan {
|
||||
if x != nil {
|
||||
return x.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_caravan_caravan_msg_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_caravan_caravan_msg_proto_rawDesc = []byte{
|
||||
@ -362,8 +465,16 @@ var file_caravan_caravan_msg_proto_rawDesc = []byte{
|
||||
0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x04,
|
||||
0x64, 0x61, 0x74, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x6e, 0x65, 0x77, 0x74, 0x61, 0x73, 0x6b, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6e, 0x65, 0x77, 0x74, 0x61, 0x73, 0x6b, 0x42, 0x06,
|
||||
0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6e, 0x65, 0x77, 0x74, 0x61, 0x73, 0x6b, 0x22, 0x44,
|
||||
0x0a, 0x12, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x47, 0x65, 0x74, 0x53, 0x74, 0x6f, 0x72,
|
||||
0x79, 0x52, 0x65, 0x71, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x05, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x69, 0x74, 0x79, 0x73, 0x74,
|
||||
0x6f, 0x72, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x69, 0x74, 0x79, 0x73,
|
||||
0x74, 0x6f, 0x72, 0x79, 0x22, 0x35, 0x0a, 0x13, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x47,
|
||||
0x65, 0x74, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64,
|
||||
0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x44, 0x42, 0x43, 0x61,
|
||||
0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x06, 0x5a, 0x04, 0x2e,
|
||||
0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -378,7 +489,7 @@ func file_caravan_caravan_msg_proto_rawDescGZIP() []byte {
|
||||
return file_caravan_caravan_msg_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_caravan_caravan_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
|
||||
var file_caravan_caravan_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||
var file_caravan_caravan_msg_proto_goTypes = []interface{}{
|
||||
(*CaravanGetListReq)(nil), // 0: CaravanGetListReq
|
||||
(*CaravanGetListResp)(nil), // 1: CaravanGetListResp
|
||||
@ -386,19 +497,22 @@ var file_caravan_caravan_msg_proto_goTypes = []interface{}{
|
||||
(*CaravanBuyOrSellResp)(nil), // 3: CaravanBuyOrSellResp
|
||||
(*CaravanGotoCityReq)(nil), // 4: CaravanGotoCityReq
|
||||
(*CaravanGotoCityResp)(nil), // 5: CaravanGotoCityResp
|
||||
nil, // 6: CaravanBuyOrSellReq.ItemsEntry
|
||||
(*DBCaravan)(nil), // 7: DBCaravan
|
||||
(*CaravanGetStoryReq)(nil), // 6: CaravanGetStoryReq
|
||||
(*CaravanGetStoryResp)(nil), // 7: CaravanGetStoryResp
|
||||
nil, // 8: CaravanBuyOrSellReq.ItemsEntry
|
||||
(*DBCaravan)(nil), // 9: DBCaravan
|
||||
}
|
||||
var file_caravan_caravan_msg_proto_depIdxs = []int32{
|
||||
7, // 0: CaravanGetListResp.data:type_name -> DBCaravan
|
||||
6, // 1: CaravanBuyOrSellReq.items:type_name -> CaravanBuyOrSellReq.ItemsEntry
|
||||
7, // 2: CaravanBuyOrSellResp.data:type_name -> DBCaravan
|
||||
7, // 3: CaravanGotoCityResp.data:type_name -> DBCaravan
|
||||
4, // [4:4] is the sub-list for method output_type
|
||||
4, // [4:4] is the sub-list for method input_type
|
||||
4, // [4:4] is the sub-list for extension type_name
|
||||
4, // [4:4] is the sub-list for extension extendee
|
||||
0, // [0:4] is the sub-list for field type_name
|
||||
9, // 0: CaravanGetListResp.data:type_name -> DBCaravan
|
||||
8, // 1: CaravanBuyOrSellReq.items:type_name -> CaravanBuyOrSellReq.ItemsEntry
|
||||
9, // 2: CaravanBuyOrSellResp.data:type_name -> DBCaravan
|
||||
9, // 3: CaravanGotoCityResp.data:type_name -> DBCaravan
|
||||
9, // 4: CaravanGetStoryResp.data:type_name -> DBCaravan
|
||||
5, // [5:5] is the sub-list for method output_type
|
||||
5, // [5:5] is the sub-list for method input_type
|
||||
5, // [5:5] is the sub-list for extension type_name
|
||||
5, // [5:5] is the sub-list for extension extendee
|
||||
0, // [0:5] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_caravan_caravan_msg_proto_init() }
|
||||
@ -480,6 +594,30 @@ func file_caravan_caravan_msg_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_caravan_caravan_msg_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CaravanGetStoryReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_caravan_caravan_msg_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CaravanGetStoryResp); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
@ -487,7 +625,7 @@ func file_caravan_caravan_msg_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_caravan_caravan_msg_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 7,
|
||||
NumMessages: 9,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user