246 lines
6.8 KiB
Go
246 lines
6.8 KiB
Go
package smithy
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"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"
|
|
"math/big"
|
|
|
|
"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.Hit = make(map[int32]int32, 0)
|
|
result.Lv = 1
|
|
|
|
result.RecoveTime = 0
|
|
if conf, _ := this.module.configure.GetSmithyStoveConf(result.Lv); conf != nil { // 获取1级炉子温度配置
|
|
result.Temperature = conf.MaxTemperature
|
|
}
|
|
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 cfgData := this.module.configure.GetSmithyProficileData(reelId, index); cfgData != nil {
|
|
if cfgData.Type == comm.SmithyReelType1 {
|
|
t += cfgData.Value1
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 限定 普通打造的时候检查额外概率制造两件装备
|
|
func (this *modelStove) CheckForgetwoEquip(reelId int32, lv int32, addProbability int32) (b bool) {
|
|
var (
|
|
index int32
|
|
value int32
|
|
)
|
|
for index = 1; index <= lv; index++ {
|
|
if cfgData := this.module.configure.GetSmithyProficileData(reelId, index); cfgData != nil {
|
|
if cfgData.Type == comm.SmithyReelType5 {
|
|
value += cfgData.Value1
|
|
}
|
|
}
|
|
}
|
|
value += addProbability
|
|
if value > 0 {
|
|
n, _ := rand.Int(rand.Reader, big.NewInt(1000)) // 千分比
|
|
if value > int32(n.Int64()) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// 检查消耗减少
|
|
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 && cfgData.Value2 != 0 {
|
|
bAdd := false
|
|
strT := strconv.Itoa(int(cfgData.Value1))
|
|
for _, v := range atn {
|
|
if v.T == strT {
|
|
v.N += cfgData.Value2
|
|
bAdd = true
|
|
break
|
|
}
|
|
}
|
|
if !bAdd {
|
|
atn = append(atn, &cfg.Gameatn{
|
|
A: "item",
|
|
T: strT,
|
|
N: cfgData.Value2,
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 计算恢复进度
|
|
func (this *modelStove) calculationRecoveryT(uid string, stove *pb.DBStove) {
|
|
if conf, _ := this.module.configure.GetSmithyStoveConf(stove.Lv); conf != nil {
|
|
if stove.Temperature < conf.MaxTemperature {
|
|
// 小于最高温度就开始恢复
|
|
if addT := (configure.Now().Unix() - stove.RecoveTime) / int64(conf.TemperatureRecovery); addT > 0 {
|
|
stove.Temperature += int32(addT)
|
|
if stove.Temperature > conf.MaxTemperature {
|
|
stove.Temperature = conf.MaxTemperature
|
|
stove.RecoveTime = 0
|
|
} else {
|
|
stove.RecoveTime += addT * int64(conf.TemperatureRecovery)
|
|
}
|
|
update := make(map[string]interface{})
|
|
update["temperature"] = stove.Temperature
|
|
update["recoveTime"] = stove.RecoveTime
|
|
this.module.modelStove.updateSmithyStove(uid, update)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 通过技能获取额外的提升
|
|
func (this *modelStove) StoveToolsQualityProbability(stove *pb.DBStove) int32 {
|
|
if conf := this.module.configure.GetSmithySkill(comm.SmithyToolsSkill1, stove.Skill[comm.SmithyToolsSkill1]); conf != nil {
|
|
return conf.Value
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 所有装备售价提升{0}%
|
|
func (this *modelStove) StoveToolsSellUp(uid string) int32 {
|
|
if stove, err := this.module.modelStove.getSmithyStoveList(uid); err == nil {
|
|
if conf := this.module.configure.GetSmithySkill(comm.SmithyToolsSkill2, stove.Skill[comm.SmithyToolsSkill2]); conf != nil {
|
|
return conf.Value
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 所有图纸炉温消耗减少
|
|
func (this *modelStove) StoveToolsTemperature(stove *pb.DBStove) int32 {
|
|
if conf := this.module.configure.GetSmithySkill(comm.SmithyToolsSkill3, stove.Skill[comm.SmithyToolsSkill3]); conf != nil {
|
|
return conf.Value
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//每日顾客数量提升至{0}人
|
|
func (this *modelStove) StoveSkillAddCustomer(uid string) int32 {
|
|
if stove, err := this.module.modelStove.getSmithyStoveList(uid); err == nil {
|
|
if conf := this.module.configure.GetSmithySkill(comm.SmithyToolsSkill4, stove.Skill[comm.SmithyToolsSkill4]); conf != nil {
|
|
return conf.Value
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//顾客购买装备数量上限提高至{0}件
|
|
func (this *modelStove) StoveSkillBuyEquip(uid string) int32 {
|
|
if stove, err := this.module.modelStove.getSmithyStoveList(uid); err == nil {
|
|
if conf := this.module.configure.GetSmithySkill(comm.SmithyToolsSkill5, stove.Skill[comm.SmithyToolsSkill5]); conf != nil {
|
|
return conf.Value
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (this *modelStove) GetRandEquipLv(sz []int32) int32 {
|
|
|
|
if len(sz) > 0 {
|
|
var _totalW int64 // 总权重
|
|
var _tmpW int64 // 临时权重
|
|
for _, v := range sz {
|
|
_totalW += int64(v)
|
|
}
|
|
// 随机权重
|
|
n, _ := rand.Int(rand.Reader, big.NewInt(_totalW))
|
|
for i, v := range sz {
|
|
_tmpW += int64(v)
|
|
if n.Int64() < _tmpW {
|
|
return int32(i)
|
|
}
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// 解析掉落id
|
|
func (this *modelStove) CheckUnlockSuid(reelId, lv, dropid int32) int32 {
|
|
var index int32
|
|
for index = 1; index <= lv; index++ {
|
|
if conf := this.module.configure.GetSmithyProficileData(reelId, index); conf != nil {
|
|
if conf.Type == comm.SmithyReelType4 && conf.Value1 != 0 {
|
|
dropid *= 100
|
|
dropid += conf.Value1
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return dropid
|
|
}
|
|
func (this *modelStove) checkReddot17108(uid string) int64 {
|
|
list, _ := this.module.modelStove.getSmithyStoveList(uid)
|
|
if list.RecoveTime == 0 {
|
|
return configure.Now().Unix()
|
|
}
|
|
return list.RecoveTime
|
|
}
|