go_dreamfactory/modules/smithy/module.go

329 lines
8.2 KiB
Go

/*
模块名:Smithy
描述:美食家模块
开发:梅雄风
*/
package smithy
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"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"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
var _ comm.ISmithy = (*Smithy)(nil)
type Smithy struct {
modules.ModuleBase
service base.IRPCXService
modelTrade *modelTrade
api *apiComp
configure *configureComp
modelStove *modelStove
modelAtlas *modelAtlas
modelTask *modelTask
}
func NewModule() core.IModule {
return &Smithy{}
}
func (this *Smithy) GetType() core.M_Modules {
return comm.ModuleSmithy
}
func (this *Smithy) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
if err = this.ModuleBase.Init(service, module, options); err != nil {
return
}
this.service = service.(base.IRPCXService)
return
}
func (this *Smithy) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelTrade = this.RegisterComp(new(modelTrade)).(*modelTrade)
this.modelStove = this.RegisterComp(new(modelStove)).(*modelStove)
this.modelAtlas = this.RegisterComp(new(modelAtlas)).(*modelAtlas)
this.modelTask = this.RegisterComp(new(modelTask)).(*modelTask)
}
func (this *Smithy) CheckActivateAtlasCollect(uid string, id string) {
atlasConf, err := this.configure.GetSmithyAtlasConf(id)
if err != nil || atlasConf.TypeId != 2 {
return
}
if this.IsCross() {
atlas := &pb.DBAtlas{}
if model, err := this.GetDBModelByUid(uid, this.modelAtlas.TableName); err == nil {
if err := model.Get(uid, atlas); err != nil { // 防止数据没有初始化情况
if mongo.ErrNoDocuments == err {
atlas.Id = primitive.NewObjectID().Hex()
atlas.Uid = uid
atlas.Atlas = make(map[string]*pb.ForgeList, 0)
atlas.Collect = make(map[string]*pb.CollectData, 0)
atlas.Award = 1 // 初始1级
atlas.Collect[id] = &pb.CollectData{
Id: id,
Score: atlasConf.AtlasScore,
Time: configure.Now().Unix(),
Activate: false,
}
update := make(map[string]interface{}, 0)
update["collect"] = atlas.Collect
if err := model.Add(uid, update); err != nil {
this.Errorf("err:%v", err)
}
return
} else {
this.Errorf("err:%v", err)
return
}
}
if _, ok := atlas.Collect[id]; !ok {
atlas.Collect[id] = &pb.CollectData{
Id: id,
Score: atlasConf.AtlasScore,
Time: configure.Now().Unix(),
Activate: false,
}
update := make(map[string]interface{}, 0)
update["collect"] = atlas.Collect
if err := model.Change(uid, update); err != nil {
this.Errorf("err:%v", err)
return
}
}
}
} else {
if list, err := this.modelAtlas.getSmithyAtlasList(uid); err == nil {
if _, ok := list.Collect[id]; !ok {
list.Collect[id] = &pb.CollectData{
Id: id,
Score: atlasConf.AtlasScore,
Time: configure.Now().Unix(),
Activate: false,
}
update := make(map[string]interface{}, 0)
update["collect"] = list.Collect
this.modelAtlas.modifySmithyAtlasList(uid, update) // 更新信息
return
}
}
}
return
}
func (this *Smithy) Reddot(session comm.IUserSession, rid ...comm.ReddotType) (reddot map[comm.ReddotType]*pb.ReddotItem) {
reddot = make(map[comm.ReddotType]*pb.ReddotItem)
for _, v := range rid {
switch v {
case comm.Reddot17102: // 铁匠铺手册台
reddot[comm.Reddot17102] = &pb.ReddotItem{
Rid: int32(comm.Reddot17102),
Activated: this.modelAtlas.checkReddot17102(session.GetUserId()),
}
break
case comm.Reddot17107: // 铁匠铺手册台收藏家奖励按钮上
reddot[comm.Reddot17107] = &pb.ReddotItem{
Rid: int32(comm.Reddot17107),
Activated: this.modelTask.checkReddot17107(session.GetUserId()),
}
break
case comm.Reddot17108: // 铁匠铺炉温恢复
reddot[comm.Reddot17108] = &pb.ReddotItem{
Rid: int32(comm.Reddot17108),
Nextchanagetime: this.modelStove.checkReddot17108(session.GetUserId()),
}
break
}
}
return
}
func (this *Smithy) BuriedsNotify(session comm.IUserSession, conds []*pb.ConIProgress) {
this.Debug("铁匠铺任务通知", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "conds", Value: conds})
confList, err := this.configure.GetSmithyTasks()
if err != nil {
this.Error(err.Error())
return
}
condMap := make(map[int32]*pb.ConIProgress)
for _, conf := range confList {
for _, cond := range conds {
if cond.Conid == conf.TypeId {
condMap[conf.Key] = cond
}
}
}
update := make(map[string]interface{})
dt, err := this.modelTask.getTaskRecord(session.GetUserId())
if err != nil {
if err == mongo.ErrNoDocuments {
for k, v := range condMap {
tt := &pb.TujianTask{
TaskId: k,
Cond: v,
}
if v.State == pb.BuriedItemFinishState_buried_finish {
tt.Received = 1
i, err := this.service.GetModule(comm.ModuleReddot)
if err != nil {
this.Error(err.Error())
return
}
if b, y := i.(comm.IReddot); y {
b.PushReddot(session, &pb.ReddotItem{
Rid: int32(comm.Reddot17107),
Activated: true,
Nextchanagetime: 0,
})
}
}
dt.Tasks = append(dt.Tasks, tt)
if err := this.modelTask.Add(session.GetUserId(), dt); err != nil {
this.Error(err.Error())
return
}
return
}
} else {
this.Error(err.Error())
return
}
}
if dt.Tasks == nil {
for k, v := range condMap {
tt := &pb.TujianTask{
TaskId: k,
Cond: v,
}
if v.State == pb.BuriedItemFinishState_buried_finish {
tt.Received = 1
}
dt.Tasks = append(dt.Tasks, tt)
}
update["tasks"] = dt.Tasks
if err := this.modelTask.Change(session.GetUserId(), update); err != nil {
this.Error(err.Error())
return
}
return
}
var newTask []*pb.TujianTask
existTaskMap := make(map[int32]*pb.TujianTask)
for _, task := range dt.Tasks {
existTaskMap[task.TaskId] = task
}
for k, v := range condMap {
if task, ok := existTaskMap[k]; ok {
task.Cond = v
if v.State == pb.BuriedItemFinishState_buried_finish {
task.Received = 1
}
} else {
nt := &pb.TujianTask{
TaskId: k,
Cond: v,
}
if v.State == pb.BuriedItemFinishState_buried_finish {
nt.Received = 1
}
newTask = append(newTask, nt)
}
}
dt.Tasks = append(dt.Tasks, newTask...)
update["tasks"] = dt.Tasks
if len(update) > 0 {
if err := this.modelTask.Change(session.GetUserId(), update); err != nil {
this.Error(err.Error())
return
}
}
}
// gm 不管性能
func (this *Smithy) GmProficiency(uid string) {
stove, err := this.modelStove.getSmithyStoveList(uid)
if err != nil {
return
}
conf := this.configure.GmGetProficileData()
for k, v := range conf {
if c := this.configure.GetSmithyProficileData(k, v); c != nil {
stove.Data[k] = &pb.Mastery{
Lv: v,
Value: c.Proficiency,
}
}
}
update := make(map[string]interface{})
update["data"] = stove.Data
this.modelStove.updateSmithyStove(uid, update)
}
// gm 新增图鉴信息
func (this *Smithy) GmSmithyAtlas(session comm.IUserSession) {
var (
res []*cfg.Gameatn
szLibrary []string
)
conf := this.configure.GmGetAllAtlasConf()
for _, v := range conf {
if v.TypeId == 1 {
for _, v1 := range this.configure.GetAllEquipmentConfigure() {
if v1.AtlasId == v.Id {
res = append(res, &cfg.Gameatn{
A: "equi",
T: v1.Id,
N: 1,
})
break
}
}
} else if v.TypeId == 2 {
szLibrary = append(szLibrary, v.Id)
}
}
if errdata, atno := this.DispenseAtno(session, res, true); errdata == nil {
ids := make([]string, 0)
for _, v := range atno {
ids = append(ids, v.O)
}
if equip, errdata := this.ModuleEquipment.QueryEquipment(session.GetUserId(), ids...); errdata == nil {
this.modelAtlas.CheckActivateEquipAtlas(session.GetUserId(), equip, 1)
}
}
if len(szLibrary) > 0 {
for _, v := range szLibrary {
this.CheckActivateAtlasCollect(session.GetUserId(), v)
}
}
}