212 lines
6.2 KiB
Go
212 lines
6.2 KiB
Go
package stonehenge
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) StoryCheck(session comm.IUserSession, req *pb.StonehengeStoryReq) (errdata *pb.ErrorData) {
|
|
if req.Cid == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.String(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Story(session comm.IUserSession, req *pb.StonehengeStoryReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
stone *pb.DBStonehenge
|
|
err error
|
|
update map[string]interface{}
|
|
newEvent int32
|
|
conf *cfg.GameStoneStoryData
|
|
event []string
|
|
curbuff []int32
|
|
)
|
|
if errdata = this.StoryCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
update = make(map[string]interface{})
|
|
if stone, err = this.module.modelStonehenge.GetStonehengeData(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if v, ok := stone.Rooms.Eventid[req.Eventid]; !ok || v == true { // 不存在该事件
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("req.Eventid err :%d", req.Eventid),
|
|
}
|
|
return
|
|
}
|
|
if req.Cid == -1 {
|
|
stone.Rooms.Story = 0
|
|
stone.Rooms.Eventid[req.Eventid] = true
|
|
|
|
this.module.modelStonehenge.EventOpenRoom(req.Eventid, stone)
|
|
update["rooms"] = stone.Rooms
|
|
this.module.modelStonehenge.ChangeStonehengeData(session.GetUserId(), update)
|
|
session.SendMsg(string(this.module.GetType()), "story", &pb.StonehengeStoryResp{
|
|
Story: stone.Rooms.Story,
|
|
NewEvent: newEvent,
|
|
Room: stone.Rooms,
|
|
})
|
|
return
|
|
} else {
|
|
if conf, err = this.module.configure.GetStoneStoryConf(req.Cid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
this.module.Debugf("GetStoneStoryConf:%v", conf)
|
|
if req.Pos == 0 {
|
|
event = conf.OptionEventIdGroup1
|
|
} else if req.Pos == 1 {
|
|
event = conf.OptionEventIdGroup2
|
|
} else if req.Pos == 2 {
|
|
event = conf.OptionEventIdGroup3
|
|
} else {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
var szW []int32
|
|
if len(event) == 1 {
|
|
arr := strings.Split(event[0], ",")
|
|
if len(arr) != 3 {
|
|
return
|
|
}
|
|
if n, err := strconv.Atoi(arr[2]); err == nil {
|
|
stone.Rooms.Story = int32(n)
|
|
}
|
|
if n, err := strconv.Atoi(arr[0]); err == nil {
|
|
newEvent = int32(n)
|
|
stone.Rooms.Eventid[newEvent] = false
|
|
}
|
|
} else {
|
|
for _, s := range event {
|
|
arr := strings.Split(s, ",")
|
|
if len(arr) != 3 {
|
|
return
|
|
}
|
|
if n, err := strconv.Atoi(arr[1]); err == nil {
|
|
szW = append(szW, int32(n))
|
|
}
|
|
}
|
|
if len(event) > 0 {
|
|
arr := strings.Split(event[comm.GetRandW(szW)], ",")
|
|
if len(arr) != 3 {
|
|
return
|
|
}
|
|
if n, err := strconv.Atoi(arr[2]); err == nil {
|
|
stone.Rooms.Story = int32(n)
|
|
}
|
|
if n, err := strconv.Atoi(arr[0]); err == nil {
|
|
newEvent = int32(n)
|
|
stone.Rooms.Eventid[newEvent] = false
|
|
}
|
|
}
|
|
if eventConf, err := this.module.configure.GetStoneEventDataById(req.Eventid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
} else {
|
|
if eventConf.EventType == EventType23 {
|
|
buff := make(map[int32]struct{}, 0)
|
|
for i := 0; i < int(eventConf.Value1); i++ {
|
|
if eventConf.Value2 == 0 { // 强化所有1级buff
|
|
for _, v := range stone.Userbuff {
|
|
if conf, e := this.module.configure.GetStoneBuffDataById(v); e != nil {
|
|
if conf.BuffLevel == 1 && conf.Type != 5 { // 5是负面buff
|
|
if nextConf, e := this.module.configure.GetStoneBuffDataById(v + 1); e != nil { // 是否有2级
|
|
delete(stone.Userbuff, v)
|
|
stone.Userbuff[nextConf.BuffId] = 1
|
|
buff[nextConf.BuffId] = struct{}{}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if eventConf.Value2 == 1 { // 强化类型 buff
|
|
itype := eventConf.Value3
|
|
for _, v := range stone.Userbuff {
|
|
if conf, e := this.module.configure.GetStoneBuffDataById(v); e != nil {
|
|
if conf.BuffLevel == 1 && conf.Type != itype {
|
|
if nextConf, e := this.module.configure.GetStoneBuffDataById(v + 1); e != nil { // 是否有2级
|
|
delete(stone.Userbuff, v)
|
|
stone.Userbuff[nextConf.BuffId] = 1
|
|
buff[nextConf.BuffId] = struct{}{}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if eventConf.Value2 == 2 { // 强化品质buff
|
|
quility := eventConf.Value3
|
|
for _, v := range stone.Userbuff {
|
|
if conf, e := this.module.configure.GetStoneBuffDataById(v); e != nil {
|
|
if conf.BuffLevel == 1 && conf.Quality == quility && conf.Type != 5 {
|
|
if nextConf, e := this.module.configure.GetStoneBuffDataById(v + 1); e != nil { // 是否有2级
|
|
delete(stone.Userbuff, v)
|
|
stone.Userbuff[nextConf.BuffId] = 1
|
|
buff[nextConf.BuffId] = struct{}{}
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for k := range buff {
|
|
curbuff = append(curbuff, k)
|
|
}
|
|
stone.Rooms.Eventid[newEvent] = true // 直接完成该事件
|
|
newEvent = 0
|
|
if eventConf.Probability >= comm.GetRandNum(0, 1000) { // 命中
|
|
newEvent = eventConf.PostEvent // 直接添加后置事件
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if newEvent != 0 {
|
|
this.module.modelStonehenge.AddNewEvent([]int32{newEvent}, stone)
|
|
}
|
|
update["rooms"] = stone.Rooms
|
|
if err = this.module.modelStonehenge.ChangeStonehengeData(session.GetUserId(), update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.String(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "story", &pb.StonehengeStoryResp{
|
|
Story: stone.Rooms.Story,
|
|
NewEvent: newEvent,
|
|
Room: stone.Rooms,
|
|
Curbuff: curbuff,
|
|
})
|
|
return
|
|
}
|