187 lines
5.3 KiB
Go
187 lines
5.3 KiB
Go
package stonehenge
|
||
|
||
import (
|
||
"go_dreamfactory/comm"
|
||
"go_dreamfactory/lego/core"
|
||
"go_dreamfactory/lego/sys/event"
|
||
"go_dreamfactory/lego/sys/mgo"
|
||
"go_dreamfactory/modules"
|
||
"go_dreamfactory/pb"
|
||
"go_dreamfactory/sys/configure"
|
||
"go_dreamfactory/utils"
|
||
"sync"
|
||
|
||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||
"go.mongodb.org/mongo-driver/mongo"
|
||
"go.mongodb.org/mongo-driver/x/bsonx"
|
||
)
|
||
|
||
const (
|
||
StoneBossKey = "StoneBossKey"
|
||
)
|
||
|
||
// 石阵秘境
|
||
type MStonehenge struct {
|
||
modules.MCompModel
|
||
module *Stonehenge
|
||
|
||
lock sync.RWMutex
|
||
bossStage map[int32]*pb.StageData
|
||
}
|
||
|
||
//组件初始化接口
|
||
func (this *MStonehenge) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||
this.TableName = comm.TableStonehenge
|
||
this.MCompModel.Init(service, module, comp, opt)
|
||
this.module = module.(*Stonehenge)
|
||
this.bossStage = make(map[int32]*pb.StageData)
|
||
//创建uid索引
|
||
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||
})
|
||
return
|
||
}
|
||
func (this *MStonehenge) Start() (err error) {
|
||
err = this.MCompModel.Start()
|
||
|
||
event.RegisterGO(core.Event_ServiceStartEnd, func() {
|
||
err = this.reLoadStoneBoos()
|
||
})
|
||
|
||
return
|
||
}
|
||
|
||
func (this *MStonehenge) GetStonehengeData(uid string) (info *pb.DBStonehenge, err error) {
|
||
info = &pb.DBStonehenge{}
|
||
if err = this.Get(uid, info); err != nil && mgo.MongodbNil != err { // 创建一条初始的数据
|
||
return
|
||
}
|
||
if mgo.MongodbNil == err {
|
||
info = &pb.DBStonehenge{
|
||
Id: primitive.NewObjectID().Hex(),
|
||
Uid: uid,
|
||
Rooms: nil,
|
||
Userbuff: make(map[int32]int32),
|
||
Reward: make(map[int32]bool),
|
||
Addweight: make(map[int32]int32),
|
||
Etime: utils.WeekIntervalTime(configure.Now().Unix()),
|
||
Hero: make(map[string]*pb.BattleRole),
|
||
Talent: make(map[int32]bool),
|
||
Talentproperty: make(map[int32]int32),
|
||
Privilege: make([]pb.StonehengePrivilege, 0),
|
||
Task: make(map[int32]bool),
|
||
Privilegeevent: make(map[int32]int32),
|
||
Weeklyreward: make(map[int32]bool),
|
||
}
|
||
err = this.Add(uid, info)
|
||
}
|
||
return
|
||
}
|
||
|
||
// 修改石阵信息
|
||
func (this *MStonehenge) ChangeStonehengeData(uid string, update map[string]interface{}) (err error) {
|
||
|
||
return this.Change(uid, update)
|
||
}
|
||
|
||
func (this *MStonehenge) reLoadStoneBoos() (err error) {
|
||
if this.module.ModuleTools == nil {
|
||
return
|
||
}
|
||
s := &pb.DBStoneBoss{}
|
||
this.module.ModuleTools.GetGlobalData(StoneBossKey, s)
|
||
this.lock.Lock()
|
||
this.bossStage = this.module.configure.CheckStage()
|
||
this.lock.Unlock()
|
||
if len(s.Bossstage) != len(this.bossStage) || utils.WeekIntervalTime(configure.Now().Unix()) != s.Rtime {
|
||
this.module.ModuleTools.UpdateGlobalData(StoneBossKey, map[string]interface{}{
|
||
"BossStage": this.bossStage,
|
||
"rtime": utils.WeekIntervalTime(configure.Now().Unix()),
|
||
})
|
||
} else {
|
||
this.lock.Lock()
|
||
this.bossStage = s.Bossstage
|
||
this.lock.Unlock()
|
||
}
|
||
|
||
return
|
||
}
|
||
|
||
func (this *MStonehenge) GetStoneBoosData(id int32) (bossstage *pb.StageData) {
|
||
return this.bossStage[id]
|
||
}
|
||
func (this *MStonehenge) GetAllStoneBoosData() (bossstage map[int32]*pb.StageData) {
|
||
return this.bossStage
|
||
}
|
||
|
||
// 获得新的事件
|
||
func (this *MStonehenge) AddNewEvent(event []int32, stone *pb.DBStonehenge) {
|
||
for _, newEvent := range event {
|
||
stone.Rooms.Eventid[newEvent] = false //
|
||
newEventConf, err := this.module.configure.GetStoneEventDataById(newEvent)
|
||
if err != nil {
|
||
continue
|
||
}
|
||
|
||
switch newEventConf.EventType {
|
||
case EventType25: // buff是3选1
|
||
var addtype int32
|
||
for key := range stone.Addweight { // 这个map 目前只会存在一条数据
|
||
addtype = key
|
||
break
|
||
}
|
||
ownerbuff := make(map[int32]struct{}, 0)
|
||
for k := range stone.Userbuff {
|
||
ownerbuff[k] = struct{}{}
|
||
}
|
||
stone.Rooms.Selectbuff = this.module.configure.GetBuffGroupDataByLottery(newEventConf.Value1, addtype, ownerbuff)
|
||
stone.Rooms.Resetcount = 0 // 重置buff 三选一次数
|
||
//}
|
||
case EventType10: // 宝箱事件
|
||
if _, ok := stone.Rooms.Box[newEventConf.EventId]; !ok {
|
||
stone.Rooms.Box[newEventConf.EventId] = 0
|
||
}
|
||
case EventType30: // 下场战斗,扣除敌方血量
|
||
if _, ok := stone.Rooms.Passive[newEventConf.EventId]; !ok {
|
||
stone.Rooms.Box[newEventConf.EventId] = 1
|
||
}
|
||
case EventType31: // 持续N场战斗,战斗开始时扣除我方当前血量(千分比)
|
||
if _, ok := stone.Rooms.Passive[newEventConf.EventId]; !ok {
|
||
stone.Rooms.Box[newEventConf.EventId] = newEventConf.Value1
|
||
}
|
||
case EventType22: //随机三个buff
|
||
stone.Rooms.Selectbuff = make([]int32, 0)
|
||
for k := range stone.Userbuff {
|
||
stone.Rooms.Selectbuff = append(stone.Rooms.Selectbuff, k)
|
||
if len(stone.Rooms.Selectbuff) >= 3 {
|
||
break
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
// 完成事件 开启传送门
|
||
func (this *MStonehenge) EventOpenRoom(event int32, stone *pb.DBStonehenge) {
|
||
stone.Rooms.Complete = true
|
||
if roomConf, err := this.module.configure.GetStoneRoomDataById(stone.Rooms.Roomid); err == nil {
|
||
for _, v := range roomConf.Condition {
|
||
for k, ok := range stone.Rooms.Eventid {
|
||
if !ok {
|
||
if eventConf, err := this.module.configure.GetStoneEventDataById(k); err == nil {
|
||
if eventConf.EventType == v {
|
||
stone.Rooms.Complete = false
|
||
break
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if !stone.Rooms.Complete {
|
||
break
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|