118 lines
3.2 KiB
Go
118 lines
3.2 KiB
Go
package smithy
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"strconv"
|
|
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
|
)
|
|
|
|
type modelStove struct {
|
|
modules.MCompModel
|
|
module *Smithy
|
|
}
|
|
|
|
func (this *modelStove) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = string(comm.TableStove)
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Smithy)
|
|
// uid 创建索引
|
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
|
})
|
|
return
|
|
}
|
|
|
|
// 获取铁匠铺信息
|
|
func (this *modelStove) getSmithyStoveList(uid string) (result *pb.DBStove, err error) {
|
|
result = &pb.DBStove{}
|
|
if err = this.Get(uid, result); err != nil {
|
|
if redis.RedisNil != err { // 没有数据直接创建新的数据
|
|
result.Id = primitive.NewObjectID().Hex()
|
|
result.Uid = uid
|
|
result.Data = make(map[int32]*pb.Mastery, 0)
|
|
result.Skill = make(map[int32]int32, 0)
|
|
result.Forge = make(map[int32]int32, 0)
|
|
result.Lv = 1
|
|
result.Temperature = 20000 // 配置
|
|
result.RecoveTime = 0
|
|
|
|
if err = this.Add(uid, result); err != nil {
|
|
this.module.Errorf("err:%v", err)
|
|
err = nil
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
err = nil
|
|
return result, err
|
|
}
|
|
|
|
func (this *modelStove) updateSmithyStove(uid string, update map[string]interface{}) (err error) {
|
|
err = this.Change(uid, update)
|
|
return err
|
|
}
|
|
|
|
// 图纸属性 炉温消耗减少
|
|
func (this *modelStove) CheckTemperature(reelId int32, lv int32) (t int32) {
|
|
var index int32
|
|
for index = 1; index <= lv; index++ {
|
|
if cfg := this.module.configure.GetSmithyProficileData(reelId, index); cfg != nil {
|
|
if cfg.Type == comm.SmithyReelType1 {
|
|
t += cfg.Value1
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 检查消耗减少
|
|
func (this *modelStove) CheckForgeConsume(reelId int32, lv int32) (atn []*cfg.Gameatn) {
|
|
var index int32
|
|
for index = 1; index <= lv; index++ {
|
|
if cfgData := this.module.configure.GetSmithyProficileData(reelId, index); cfgData != nil {
|
|
if cfgData.Type == comm.SmithyReelType2 {
|
|
atn = append(atn, &cfg.Gameatn{
|
|
A: "item",
|
|
T: strconv.Itoa(int(cfgData.Value1)),
|
|
N: cfgData.Value2,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 计算恢复进度
|
|
func (this *modelStove) calculationRecoveryT(uid string, stove *pb.DBStove) {
|
|
|
|
conf := this.module.configure.GetSmithyStoveConf(stove.Lv)
|
|
if conf == nil {
|
|
return
|
|
}
|
|
if stove.Temperature < conf.MaxTemperature {
|
|
update := make(map[string]interface{})
|
|
// 小于最高温度就开始恢复
|
|
addT := (configure.Now().Unix() - stove.RecoveTime) / int64(conf.TemperatureRecovery)
|
|
stove.Temperature += int32(addT)
|
|
if stove.Temperature > conf.MaxTemperature {
|
|
stove.Temperature = conf.MaxTemperature
|
|
stove.RecoveTime = 0
|
|
} else {
|
|
stove.RecoveTime += addT * int64(conf.TemperatureRecovery)
|
|
}
|
|
update["temperature"] = stove.Temperature
|
|
update["recoveTime"] = stove.RecoveTime
|
|
this.module.modelStove.updateSmithyStove(uid, update)
|
|
}
|
|
}
|