792 lines
24 KiB
Go
792 lines
24 KiB
Go
package stonehenge
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/lego/core"
|
||
"go_dreamfactory/lego/sys/log"
|
||
"go_dreamfactory/modules"
|
||
"go_dreamfactory/pb"
|
||
"go_dreamfactory/sys/configure"
|
||
cfg "go_dreamfactory/sys/configure/structs"
|
||
"sync"
|
||
)
|
||
|
||
const (
|
||
game_bufflottery = "game_bufflottery.json"
|
||
game_eventlottery = "game_eventlottery.json"
|
||
game_roomlottery = "game_roomlottery.json"
|
||
game_roomconf = "game_stoneroom.json"
|
||
game_stageconf = "game_stonestage.json"
|
||
game_buffconf = "game_stonebuff.json"
|
||
game_eventconf = "game_stoneevent.json"
|
||
game_bossconf = "game_stoneboss.json"
|
||
game_battleconf = "game_stonebattle.json"
|
||
game_stonetalent = "game_stonetalent.json"
|
||
game_storeconf = "game_stonestore.json" // 商店配置
|
||
game_stoneillustrated = "game_stoneillustrated.json"
|
||
game_storyconf = "game_stonestory.json" // 剧情表
|
||
game_stoneweek = "game_stoneweek.json" //周长
|
||
game_stonetask = "game_stonetask.json" //任务
|
||
game_stoneprivilege = "game_stoneprivilege.json" //特权
|
||
)
|
||
|
||
///背包配置管理组件
|
||
type configureComp struct {
|
||
modules.MCompConfigure
|
||
module *Stonehenge
|
||
hlock sync.RWMutex
|
||
// stronestage
|
||
stage map[int64]*cfg.GameStoneStageData
|
||
szStage map[int32]int32 // k 关卡ID v 层数
|
||
// buff
|
||
buff map[int32]map[int32]struct{} // key buff 类型 value buffid
|
||
// 房间随机
|
||
// 类型为1 的数据 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组
|
||
_lotteryTypeR map[int32][]*cfg.GameRoomlotteryData // key 大组ID value cid
|
||
// 类型为2 的数据 有多个小组ID
|
||
_lotteryType2R map[int32][]*cfg.GameRoomlotteryData // key 大组ID value 小组ID
|
||
// 小组类型为1
|
||
_groupType1R map[int64][]*cfg.GameRoomlotteryData //value cid
|
||
// 小组类型为2
|
||
_groupType2R map[int64][]*cfg.GameRoomlotteryData //value cid
|
||
//Btype map[int32]int32
|
||
StypeR map[int64]int32 // subtype
|
||
SNumR map[int64]int32 // 小组产出数量
|
||
|
||
// 类型为1 的数据 该大组中的小组为权重掉落,必定从N个小组中随机出1个小组
|
||
_lotteryTypeE map[int32][]*cfg.GameEventlotteryData // key 大组ID value cid
|
||
// 类型为2 的数据 有多个小组ID
|
||
_lotteryType2E map[int32][]*cfg.GameEventlotteryData // key 大组ID value 小组ID
|
||
// 小组类型为1
|
||
_groupType1E map[int64][]*cfg.GameEventlotteryData //value cid
|
||
// 小组类型为2
|
||
_groupType2E map[int64][]*cfg.GameEventlotteryData //value cid
|
||
//Btype map[int32]int32
|
||
StypeE map[int64]int32 // subtype
|
||
SNumE map[int64]int32 // 小组产出数量
|
||
|
||
// buff 随机
|
||
buffLottery map[int32]map[int32]*cfg.GameBufflotteryData
|
||
|
||
story map[int32]*cfg.GameStoneStoryData
|
||
}
|
||
|
||
//组件初始化接口
|
||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||
this.MCompConfigure.Init(service, module, comp, options)
|
||
this.module = module.(*Stonehenge)
|
||
err = this.LoadConfigure(game_bufflottery, cfg.NewGameBufflottery)
|
||
configure.RegisterConfigure(game_bufflottery, cfg.NewGameBufflottery, this.LoadBUffGroupData)
|
||
|
||
err = this.LoadConfigure(game_eventlottery, cfg.NewGameEventlottery)
|
||
configure.RegisterConfigure(game_eventlottery, cfg.NewGameEventlottery, this.LoadEventGroupData)
|
||
|
||
err = this.LoadConfigure(game_roomlottery, cfg.NewGameRoomlottery)
|
||
configure.RegisterConfigure(game_roomlottery, cfg.NewGameRoomlottery, this.LoadRoomGroupData)
|
||
|
||
err = this.LoadConfigure(game_stageconf, cfg.NewGameStoneStage)
|
||
err = this.LoadConfigure(game_buffconf, cfg.NewGameStoneBuff)
|
||
err = this.LoadConfigure(game_eventconf, cfg.NewGameStoneEvent)
|
||
err = this.LoadConfigure(game_roomconf, cfg.NewGameStoneRoom)
|
||
err = this.LoadConfigure(game_bossconf, cfg.NewGameStoneBoss)
|
||
err = this.LoadConfigure(game_battleconf, cfg.NewGameStoneBattle)
|
||
err = this.LoadConfigure(game_stonetalent, cfg.NewGameStoneTalent)
|
||
err = this.LoadConfigure(game_storeconf, cfg.NewGameStoneStore)
|
||
err = this.LoadConfigure(game_stoneweek, cfg.NewGameStoneWeek)
|
||
err = this.LoadConfigure(game_stonetask, cfg.NewGameStoneTask)
|
||
err = this.LoadConfigure(game_stoneprivilege, cfg.NewGameStonePrivilege)
|
||
err = this.LoadConfigure(game_stoneillustrated, cfg.NewGameStoneIllustrated)
|
||
configure.RegisterConfigure(game_stageconf, cfg.NewGameStoneStage, this.LoadGameStoneStage)
|
||
configure.RegisterConfigure(game_buffconf, cfg.NewGameStoneBuff, this.LoadGameStoneBuff)
|
||
configure.RegisterConfigure(game_storyconf, cfg.NewGameStoneStory, this.LoadGameStoneStory)
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) LoadEventGroupData() {
|
||
if v, err := this.GetConfigure(game_eventlottery); err == nil {
|
||
if configure, ok := v.(*cfg.GameEventlottery); ok {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this._lotteryTypeE = make(map[int32][]*cfg.GameEventlotteryData, 0)
|
||
this._lotteryType2E = make(map[int32][]*cfg.GameEventlotteryData, 0)
|
||
this._groupType1E = make(map[int64][]*cfg.GameEventlotteryData, 0)
|
||
this._groupType2E = make(map[int64][]*cfg.GameEventlotteryData, 0)
|
||
//this.Btype = make(map[int32]int32, 0)
|
||
this.StypeE = make(map[int64]int32, 0)
|
||
this.SNumE = make(map[int64]int32, 0)
|
||
var itype int32
|
||
var groupwt int32
|
||
var groupid int32
|
||
for _, value := range configure.GetDataList() {
|
||
if value.SubGroupId == 0 {
|
||
value.SubGroupId = groupid
|
||
} else {
|
||
groupid = value.SubGroupId
|
||
}
|
||
key := int64(value.GroupId)<<31 + int64(value.SubGroupId)
|
||
|
||
if value.GroupType == 0 {
|
||
value.GroupType = itype
|
||
} else {
|
||
itype = value.GroupType
|
||
}
|
||
if value.SubGroupWt == 0 {
|
||
value.SubGroupWt = groupwt
|
||
} else {
|
||
groupwt = value.SubGroupWt
|
||
}
|
||
|
||
if _, ok := this.StypeE[key]; !ok {
|
||
this.StypeE[key] = value.SubGroupType
|
||
}
|
||
if _, ok := this.SNumE[key]; !ok {
|
||
this.SNumE[key] = value.SubGroupNum //value.Groupnum
|
||
}
|
||
|
||
if value.GroupType == 1 {
|
||
this._lotteryTypeE[value.GroupId] = append(this._lotteryTypeE[value.GroupId], value)
|
||
}
|
||
if value.GroupType == 2 {
|
||
this._lotteryType2E[value.GroupId] = append(this._lotteryType2E[value.GroupId], value)
|
||
}
|
||
|
||
if this.StypeE[key] == 1 { // 小组ID为1
|
||
this._groupType1E[key] = append(this._groupType1E[key], value)
|
||
} else if this.StypeE[key] == 2 {
|
||
this._groupType2E[key] = append(this._groupType2E[key], value)
|
||
}
|
||
}
|
||
return
|
||
}
|
||
} else {
|
||
log.Errorf("get LoadGroupData conf err:%v", err)
|
||
}
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) LoadRoomGroupData() {
|
||
if v, err := this.GetConfigure(game_roomlottery); err == nil {
|
||
if configure, ok := v.(*cfg.GameRoomlottery); ok {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this._lotteryTypeR = make(map[int32][]*cfg.GameRoomlotteryData, 0)
|
||
this._lotteryType2R = make(map[int32][]*cfg.GameRoomlotteryData, 0)
|
||
this._groupType1R = make(map[int64][]*cfg.GameRoomlotteryData, 0)
|
||
this._groupType2R = make(map[int64][]*cfg.GameRoomlotteryData, 0)
|
||
//this.Btype = make(map[int32]int32, 0)
|
||
this.StypeR = make(map[int64]int32, 0)
|
||
this.SNumR = make(map[int64]int32, 0)
|
||
var itype int32
|
||
var groupwt int32
|
||
var groupid int32
|
||
for _, value := range configure.GetDataList() {
|
||
if value.SubGroupId == 0 {
|
||
value.SubGroupId = groupid
|
||
} else {
|
||
groupid = value.SubGroupId
|
||
}
|
||
key := int64(value.GroupId)<<31 + int64(value.SubGroupId)
|
||
|
||
if value.GroupType == 0 {
|
||
value.GroupType = itype
|
||
} else {
|
||
itype = value.GroupType
|
||
}
|
||
if value.SubGroupWt == 0 {
|
||
value.SubGroupWt = groupwt
|
||
} else {
|
||
groupwt = value.SubGroupWt
|
||
}
|
||
|
||
if _, ok := this.StypeR[key]; !ok {
|
||
this.StypeR[key] = value.SubGroupType
|
||
}
|
||
if _, ok := this.SNumR[key]; !ok {
|
||
this.SNumR[key] = value.SubGroupNum //value.Groupnum
|
||
}
|
||
|
||
if value.GroupType == 1 {
|
||
this._lotteryTypeR[value.GroupId] = append(this._lotteryTypeR[value.GroupId], value)
|
||
}
|
||
if value.GroupType == 2 {
|
||
this._lotteryType2R[value.GroupId] = append(this._lotteryType2R[value.GroupId], value)
|
||
}
|
||
|
||
if this.StypeR[key] == 1 { // 小组ID为1
|
||
this._groupType1R[key] = append(this._groupType1R[key], value)
|
||
} else if this.StypeR[key] == 2 {
|
||
this._groupType2R[key] = append(this._groupType2R[key], value)
|
||
}
|
||
}
|
||
return
|
||
}
|
||
} else {
|
||
log.Errorf("get LoadGroupData conf err:%v", err)
|
||
}
|
||
return
|
||
}
|
||
|
||
// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具)
|
||
func (this *configureComp) GetRoomGroupDataByLottery(lotteryId int32) (rooms []int32) {
|
||
if _, ok := this._lotteryTypeR[lotteryId]; !ok {
|
||
if _, ok := this._lotteryType2R[lotteryId]; !ok {
|
||
//this.module.Errorf("not found config lotterId:%d", lotteryId)
|
||
return
|
||
}
|
||
}
|
||
// 优先校验大组ID 的类型
|
||
var (
|
||
szW []int32 // 权重数组
|
||
szID []int32 // 小组ID 数组
|
||
groupID int32
|
||
)
|
||
//this.module.Debugf("config lotterId:%d")
|
||
// 随机小组id
|
||
for _, _data := range this._lotteryTypeR[lotteryId] {
|
||
if _data.SubGroupId != 0 {
|
||
szW = append(szW, _data.SubGroupWt)
|
||
szID = append(szID, _data.SubGroupId)
|
||
}
|
||
|
||
}
|
||
if len(szW) > 0 {
|
||
groupID = szID[comm.GetRandW(szW)] // 获得小组ID
|
||
//fmt.Printf("大组类型为1的,获得小组ID :%d,dropID:%d", groupID, lotteryId)
|
||
key := int64(lotteryId)<<31 + int64(groupID)
|
||
// 小组ID 类型判断
|
||
if this.StypeR[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具
|
||
for i := 0; i < int(this.SNumR[key]); i++ {
|
||
sztW := make([]int32, 0)
|
||
sztID := make([]*cfg.GameRoomlotteryData, 0)
|
||
for _, _data := range this._groupType1R[key] {
|
||
sztW = append(sztW, _data.SubGroupWt)
|
||
sztID = append(sztID, _data)
|
||
}
|
||
if len(sztW) == 0 {
|
||
continue
|
||
}
|
||
_data := sztID[comm.GetRandW(sztW)]
|
||
// 随机获得的数量
|
||
rooms = append(rooms, _data.RoomID)
|
||
}
|
||
} else if this.StypeR[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
|
||
for _, _data := range this._groupType2R[key] {
|
||
if _data.RoomWt >= comm.GetRandNum(0, 1000) { // 命中
|
||
rooms = append(rooms, _data.RoomID)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
m := make(map[int64]int32, 0)
|
||
// 每个小组id 都随机取一次
|
||
|
||
for _, _data := range this._lotteryType2R[lotteryId] {
|
||
key := int64(lotteryId)<<31 + int64(_data.SubGroupId)
|
||
if _, ok := m[key]; !ok {
|
||
m[key] = _data.SubGroupWt
|
||
}
|
||
}
|
||
|
||
// 类型为2 可能会同时获得多个组id
|
||
for key, v := range m {
|
||
//fmt.Printf("大组类型为2的,获得小组ID :%d,dropID:%d", k, v.Id)
|
||
if v >= comm.GetRandNum(0, 1000) { // 命中
|
||
if this.StypeR[key] == 1 { // 随机一组数据
|
||
for i := 0; i < int(this.SNumR[key]); i++ {
|
||
sztW := make([]int32, 0)
|
||
sztID := make([]*cfg.GameRoomlotteryData, 0)
|
||
for _, _data := range this._groupType1R[key] {
|
||
sztW = append(sztW, _data.RoomWt)
|
||
sztID = append(sztID, _data)
|
||
}
|
||
if len(sztW) == 0 {
|
||
continue
|
||
}
|
||
_data := sztID[comm.GetRandW(sztW)]
|
||
rooms = append(rooms, _data.RoomID)
|
||
}
|
||
} else if this.StypeR[key] == 2 {
|
||
for _, _data := range this._groupType2R[key] {
|
||
if _data.RoomWt >= comm.GetRandNum(1, 1000) { // 命中
|
||
rooms = append(rooms, _data.RoomID)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.module.Debugf("drop rooms result:%v", rooms)
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) LoadBUffGroupData() {
|
||
if v, err := this.GetConfigure(game_bufflottery); err == nil {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this.buffLottery = make(map[int32]map[int32]*cfg.GameBufflotteryData, 0)
|
||
if configure, ok := v.(*cfg.GameBufflottery); ok {
|
||
for _, v := range configure.GetDataList() {
|
||
if _, ok := this.buffLottery[v.GroupId]; !ok {
|
||
this.buffLottery[v.GroupId] = make(map[int32]*cfg.GameBufflotteryData)
|
||
}
|
||
this.buffLottery[v.GroupId][v.BuffID] = v
|
||
}
|
||
}
|
||
} else {
|
||
log.Errorf("get NewGameBufflottery conf err:%v", err)
|
||
}
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetLotterConfById(id int32) (data *cfg.GameBufflotteryData) {
|
||
if v, err := this.GetConfigure(game_bufflottery); err == nil {
|
||
if configure, ok := v.(*cfg.GameBufflottery); ok {
|
||
return configure.Get(id)
|
||
}
|
||
}
|
||
return
|
||
}
|
||
|
||
// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具)
|
||
func (this *configureComp) GetBuffGroupDataByLottery(lotteryId int32, addType int32, ownerbuff map[int32]struct{}) (buff []int32) {
|
||
var (
|
||
num int32
|
||
szW []int32
|
||
curWt int32 // 是否增加权重
|
||
sz []*cfg.GameBufflotteryData // 这里需要用对象池 稍后处理
|
||
)
|
||
if ownerbuff == nil {
|
||
ownerbuff = make(map[int32]struct{}, 0)
|
||
}
|
||
if v, ok := this.buffLottery[lotteryId]; ok {
|
||
for i := 1; ; i++ {
|
||
szW = make([]int32, 0) // 数组初始化
|
||
sz = make([]*cfg.GameBufflotteryData, 0)
|
||
for k, v1 := range v { // k buffID v1 cfg.GameBufflotteryData
|
||
curWt = 0
|
||
if _, ok := ownerbuff[k]; !ok {
|
||
sz = append(sz, v1)
|
||
if v2, ok := this.buff[addType]; ok {
|
||
if _, ok := v2[k]; ok {
|
||
curWt += v1.TypeWt
|
||
}
|
||
}
|
||
curWt += v1.BuffWt
|
||
szW = append(szW, curWt)
|
||
}
|
||
if num == 0 {
|
||
num = v1.GroupNum
|
||
}
|
||
}
|
||
|
||
getbuffid := sz[comm.GetRandW(szW)].BuffID
|
||
ownerbuff[getbuffid] = struct{}{}
|
||
buff = append(buff, getbuffid)
|
||
if i >= int(num) {
|
||
break
|
||
}
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetStoneRoomDataById(roomid int32) (conf *cfg.GameStoneRoomData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_roomconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneRoom); ok {
|
||
if conf = configure.Get(roomid); conf != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(moduleName, game_roomconf, roomid)
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetStoneBuffDataById(buffid int32) (conf *cfg.GameStoneBuffData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_buffconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneBuff); ok {
|
||
if conf = configure.Get(buffid); conf != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(moduleName, game_buffconf, buffid)
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetStoneEventDataById(eventid int32) (conf *cfg.GameStoneEventData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_eventconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneEvent); ok {
|
||
if conf = configure.Get(eventid); conf != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(moduleName, game_eventconf, eventid)
|
||
return
|
||
}
|
||
|
||
//
|
||
func (this *configureComp) LoadGameStoneStage() {
|
||
|
||
if v, err := this.GetConfigure(game_stageconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneStage); ok {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this.stage = make(map[int64]*cfg.GameStoneStageData, 0)
|
||
this.szStage = make(map[int32]int32, 0)
|
||
for _, v := range configure.GetDataList() {
|
||
key := int64(v.StageId)<<16 + int64(v.RoomId)
|
||
this.stage[key] = v
|
||
this.szStage[v.StageId]++
|
||
}
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
// 参数1 关卡id 参数2 层数id
|
||
func (this *configureComp) GetStageConfByStageid(stgeid int32, roomid int32) (conf *cfg.GameStoneStageData) {
|
||
key := int64(stgeid)<<16 + int64(roomid)
|
||
return this.stage[key]
|
||
}
|
||
|
||
func (this *configureComp) LoadGameStoneBuff() {
|
||
|
||
if v, err := this.GetConfigure(game_buffconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneBuff); ok {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this.buff = make(map[int32]map[int32]struct{}, 0)
|
||
for _, v := range configure.GetDataList() {
|
||
if _, ok := this.buff[v.Type]; !ok {
|
||
this.buff[v.Type] = make(map[int32]struct{})
|
||
}
|
||
this.buff[v.Type][v.BuffId] = struct{}{}
|
||
}
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetGameStoneBuff(addType int32) (m map[int32]struct{}) {
|
||
return this.buff[addType]
|
||
}
|
||
|
||
func (this *configureComp) CheckStage() (bossStage map[int32]*pb.StageData) {
|
||
var (
|
||
boosEvent map[int32]int32 // key stageid value rommid
|
||
)
|
||
bossStage = make(map[int32]*pb.StageData, 0)
|
||
boosEvent = make(map[int32]int32, 0)
|
||
for k, v := range this.szStage {
|
||
if c := this.GetStageConfByStageid(k, v-1); c != nil {
|
||
// 根据传送门组生成传送门
|
||
if rooms := this.GetRoomGroupDataByLottery(c.PortalGroup); len(rooms) > 0 {
|
||
stageData := &pb.StageData{}
|
||
boosEvent[k] = rooms[0]
|
||
if roomconf, err := this.GetStoneRoomDataById(rooms[0]); err == nil {
|
||
|
||
// 生成 我方buff
|
||
if bossConf := this.GetBossConfById(roomconf.BossEvent); bossConf != nil {
|
||
stageData.Mainebuff = this.GetBuffGroupDataByLottery(bossConf.FriendlyBuffGroup, 0, nil)
|
||
stageData.Enemybuff = this.GetBuffGroupDataByLottery(bossConf.EnemyBuffGroup, 0, nil)
|
||
}
|
||
stageData.Roomid = rooms[0]
|
||
|
||
}
|
||
bossStage[k] = stageData
|
||
}
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
func (this *configureComp) GetBossConfById(id int32) (data *cfg.GameStoneBossData) {
|
||
if v, err := this.GetConfigure(game_bossconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneBoss); ok {
|
||
return configure.Get(id)
|
||
}
|
||
}
|
||
return
|
||
}
|
||
|
||
// 通过关卡id 找层数
|
||
func (this *configureComp) GetFloorConfByStageId(stageId int32) int32 {
|
||
return this.szStage[stageId]
|
||
}
|
||
|
||
func (this *configureComp) GetBattleConfById(id int32) (data *cfg.GameStoneBattleData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_battleconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneBattle); ok {
|
||
if data = configure.Get(id); data != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(moduleName, game_battleconf, id)
|
||
return
|
||
}
|
||
|
||
// 获取商店信息
|
||
func (this *configureComp) GetStoneStoreConf(id int32) (data *cfg.GameStoneStoreData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_storeconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneStore); ok {
|
||
if data = configure.Get(id); data != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(moduleName, game_storeconf, id)
|
||
return
|
||
}
|
||
|
||
// 读取任务配置表
|
||
func (this *configureComp) getGameStoneTalentData(id int32) (conf *cfg.GameStoneTalentData, err error) {
|
||
var (
|
||
v interface{}
|
||
ok bool
|
||
)
|
||
if v, err = this.GetConfigure(game_stonetalent); err != nil {
|
||
return
|
||
} else {
|
||
if conf, ok = v.(*cfg.GameStoneTalent).GetDataMap()[id]; !ok {
|
||
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_stonetalent, id)
|
||
this.module.Errorln(err)
|
||
return
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
// 读取任务配置表
|
||
func (this *configureComp) getGameStoneIllustratedDatas() (confs []*cfg.GameStoneIllustratedData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_stoneillustrated); err != nil {
|
||
return
|
||
} else {
|
||
confs = v.(*cfg.GameStoneIllustrated).GetDataList()
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) LoadGameStoneStory() {
|
||
|
||
if v, err := this.GetConfigure(game_storyconf); err == nil {
|
||
if configure, ok := v.(*cfg.GameStoneStory); ok {
|
||
this.hlock.Lock()
|
||
defer this.hlock.Unlock()
|
||
this.story = make(map[int32]*cfg.GameStoneStoryData)
|
||
for _, v := range configure.GetDataList() {
|
||
|
||
this.story[v.Id] = v
|
||
}
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) GetStoneStoryConf(id int32) (data *cfg.GameStoneStoryData, err error) {
|
||
var ok bool
|
||
if data, ok = this.story[id]; ok {
|
||
return
|
||
}
|
||
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_stonetalent, id)
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) getGameStoneWeekData(id int32) (conf *cfg.GameStoneWeekData, err error) {
|
||
var (
|
||
v interface{}
|
||
ok bool
|
||
)
|
||
if v, err = this.GetConfigure(game_stoneweek); err != nil {
|
||
return
|
||
} else {
|
||
if conf, ok = v.(*cfg.GameStoneWeek).GetDataMap()[id]; !ok {
|
||
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_stoneweek, id)
|
||
this.module.Errorln(err)
|
||
return
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) getGameStoneWeekDatas() (confs []*cfg.GameStoneWeekData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_stoneweek); err != nil {
|
||
return
|
||
} else {
|
||
confs = v.(*cfg.GameStoneWeek).GetDataList()
|
||
}
|
||
|
||
return
|
||
}
|
||
func (this *configureComp) getGameStoneTaskData(id int32) (conf *cfg.GameStoneTaskData, err error) {
|
||
var (
|
||
v interface{}
|
||
ok bool
|
||
)
|
||
if v, err = this.GetConfigure(game_stonetask); err != nil {
|
||
return
|
||
} else {
|
||
if conf, ok = v.(*cfg.GameStoneTask).GetDataMap()[id]; !ok {
|
||
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_stonetask, id)
|
||
this.module.Errorln(err)
|
||
return
|
||
}
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *configureComp) getGameStoneTaskDatas() (confs []*cfg.GameStoneTaskData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_stonetask); err != nil {
|
||
return
|
||
} else {
|
||
confs = v.(*cfg.GameStoneTask).GetDataList()
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
// 获取特权信息
|
||
func (this *configureComp) getGameStonePrivilegeData(privilegeId int32) (conf *cfg.GameStonePrivilegeData, err error) {
|
||
var (
|
||
v interface{}
|
||
)
|
||
if v, err = this.GetConfigure(game_stoneprivilege); err == nil {
|
||
if configure, ok := v.(*cfg.GameStonePrivilege); ok {
|
||
if conf = configure.Get(privilegeId); conf != nil {
|
||
return
|
||
}
|
||
}
|
||
}
|
||
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_stonetask, privilegeId)
|
||
this.module.Errorln(err)
|
||
return
|
||
}
|
||
|
||
// 实际掉落逻辑 (传入 掉落组ID vip等级 玩家等级 返回获得的道具)
|
||
func (this *configureComp) GetEventGroupDataByLottery(lotterys ...int32) (event []int32) {
|
||
for _, lotteryId := range lotterys {
|
||
|
||
if _, ok := this._lotteryTypeE[lotteryId]; !ok {
|
||
if _, ok := this._lotteryType2E[lotteryId]; !ok {
|
||
//this.module.Errorf("not found config lotterId:%d", lotteryId)
|
||
return
|
||
}
|
||
}
|
||
// 优先校验大组ID 的类型
|
||
var (
|
||
szW []int32 // 权重数组
|
||
szID []int32 // 小组ID 数组
|
||
groupID int32
|
||
)
|
||
//this.module.Debugf("config lotterId:%d")
|
||
// 随机小组id
|
||
for _, _data := range this._lotteryTypeE[lotteryId] {
|
||
if _data.SubGroupId != 0 {
|
||
szW = append(szW, _data.SubGroupWt)
|
||
szID = append(szID, _data.SubGroupId)
|
||
}
|
||
|
||
}
|
||
if len(szW) > 0 {
|
||
groupID = szID[comm.GetRandW(szW)] // 获得小组ID
|
||
//fmt.Printf("大组类型为1的,获得小组ID :%d,dropID:%d", groupID, lotteryId)
|
||
key := int64(lotteryId)<<31 + int64(groupID)
|
||
// 小组ID 类型判断
|
||
if this.StypeE[key] == 1 { // 该小组的道具为权重掉落,必定从N个道具中随机出1个道具
|
||
for i := 0; i < int(this.SNumE[key]); i++ {
|
||
sztW := make([]int32, 0)
|
||
sztID := make([]*cfg.GameEventlotteryData, 0)
|
||
for _, _data := range this._groupType1E[key] {
|
||
sztW = append(sztW, _data.SubGroupWt)
|
||
sztID = append(sztID, _data)
|
||
}
|
||
if len(sztW) == 0 {
|
||
continue
|
||
}
|
||
_data := sztID[comm.GetRandW(sztW)]
|
||
// 随机获得的数量
|
||
event = append(event, _data.EventID)
|
||
}
|
||
} else if this.StypeE[key] == 2 { // 该小组中的道具为概率掉落,每个道具都会随机一次是否会掉落(单位为千分比)
|
||
for _, _data := range this._groupType2E[key] {
|
||
if _data.EventWt >= comm.GetRandNum(0, 1000) { // 命中
|
||
event = append(event, _data.EventID)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 每个小组id 都随机取一次
|
||
m := make(map[int64]int32, 0)
|
||
for _, _data := range this._lotteryType2E[lotteryId] {
|
||
key := int64(lotteryId)<<31 + int64(_data.SubGroupId)
|
||
if _, ok := m[key]; !ok {
|
||
m[key] = _data.SubGroupWt
|
||
}
|
||
}
|
||
|
||
// 类型为2 可能会同时获得多个组id
|
||
for key, v := range m {
|
||
if v >= comm.GetRandNum(0, 1000) { // 命中
|
||
if this.StypeE[key] == 1 { // 随机一组数据
|
||
for i := 0; i < int(this.SNumE[key]); i++ {
|
||
sztW := make([]int32, 0)
|
||
sztID := make([]*cfg.GameEventlotteryData, 0)
|
||
for _, _data := range this._groupType1E[key] {
|
||
sztW = append(sztW, _data.EventWt)
|
||
sztID = append(sztID, _data)
|
||
}
|
||
if len(sztW) == 0 {
|
||
continue
|
||
}
|
||
_data := sztID[comm.GetRandW(sztW)]
|
||
event = append(event, _data.EventID)
|
||
}
|
||
} else if this.StypeE[key] == 2 {
|
||
for _, _data := range this._groupType2E[key] {
|
||
if _data.EventWt >= comm.GetRandNum(1, 1000) { // 命中
|
||
event = append(event, _data.EventID)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.module.Debugf("drop event result:%v", event)
|
||
return
|
||
}
|