diff --git a/lego/sys/log/flieout.go b/lego/sys/log/flieout.go index db40c42d9..2b30065bc 100644 --- a/lego/sys/log/flieout.go +++ b/lego/sys/log/flieout.go @@ -35,6 +35,7 @@ type LogFileOut struct { MaxBackups int `json:"maxbackups" yaml:"maxbackups"` //备份日志的最大数量 LocalTime bool `json:"localtime" yaml:"localtime"` //是使用本地时间还是使用世界标准时间 Compress bool `json:"compress" yaml:"compress"` //是否压缩备份日志 + UniqueLog bool `json:"uniquelog" yaml:"uniquelog"` //是否唯一日志文件 size int64 ctime time.Time file *os.File @@ -79,31 +80,42 @@ func (l *LogFileOut) Write(p []byte) (n int, err error) { return n, err } -func (l *LogFileOut) openExistingOrNew(writeLen int) error { - l.mill() +func (this *LogFileOut) openExistingOrNew(writeLen int) error { + this.mill() - filename := l.filename() + filename := this.filename() info, err := osStat(filename) if os.IsNotExist(err) { - return l.openNew() + return this.openNew() } if err != nil { return fmt.Errorf("error getting log file info: %s", err) } //校验是否需要切割日志 - if info.Size()+int64(writeLen) >= l.max() || (!l.ctime.IsZero() && time.Since(l.ctime) > l.CupTime) { - return l.rotate() + if !this.UniqueLog && (info.Size()+int64(writeLen) >= this.max() || (!this.ctime.IsZero() && time.Since(this.ctime) > this.CupTime)) { + return this.rotate() } - - file, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) - if err != nil { - // if we fail to open the old log file for some reason, just ignore - // it and open a new log file. - return l.openNew() + mode := os.FileMode(0666) + if !this.UniqueLog { + file, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode) + if err != nil { + // if we fail to open the old log file for some reason, just ignore + // it and open a new log file. + return this.openNew() + } + this.file = file + this.size = info.Size() + } else { + //最佳写入 + f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, mode) + if err != nil { + return fmt.Errorf("can't open new logfile: %s", err) + } + this.file = f + this.size = 0 + this.ctime = currentTime() } - l.file = file - l.size = info.Size() return nil } @@ -210,21 +222,21 @@ func (l *LogFileOut) mill() { } //备份老的日志文件创建新的日志文件 -func (l *LogFileOut) openNew() error { - err := os.MkdirAll(l.dir(), 0755) +func (this *LogFileOut) openNew() error { + err := os.MkdirAll(this.dir(), 0755) if err != nil { return fmt.Errorf("can't make directories for new logfile: %s", err) } - name := l.filename() + name := this.filename() mode := os.FileMode(0666) info, err := osStat(name) //备份老的日志文件 - if err == nil { + if !this.UniqueLog && err == nil { // Copy the mode off the old logfile. mode = info.Mode() // move the existing file - newname := backupName(name, l.LocalTime) + newname := backupName(name, this.LocalTime) if err := os.Rename(name, newname); err != nil { return fmt.Errorf("can't rename log file: %s", err) } @@ -235,14 +247,25 @@ func (l *LogFileOut) openNew() error { } } - //创建新的日志文件 - f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode) - if err != nil { - return fmt.Errorf("can't open new logfile: %s", err) + if !this.UniqueLog { + //创建新的日志文件 + f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, mode) + if err != nil { + return fmt.Errorf("can't open new logfile: %s", err) + } + this.file = f + this.size = 0 + this.ctime = currentTime() + } else { + //最佳写入 + f, err := os.OpenFile(name, os.O_APPEND|os.O_CREATE|os.O_WRONLY, mode) + if err != nil { + return fmt.Errorf("can't open new logfile: %s", err) + } + this.file = f + this.size = 0 + this.ctime = currentTime() } - l.file = f - l.size = 0 - l.ctime = currentTime() return nil } diff --git a/lego/sys/log/logger.go b/lego/sys/log/logger.go index f7e5d3da0..453141f28 100644 --- a/lego/sys/log/logger.go +++ b/lego/sys/log/logger.go @@ -17,6 +17,7 @@ func newSys(options *Options) (sys *Logger, err error) { MaxBackups: options.MaxBackups, //最大备份数 MaxSize: options.MaxSize, //最大日志文件大小 LocalTime: true, //使用本地时间 + UniqueLog: options.UniqueLog, //是否唯一文件 } if !options.IsDebug { if err = hook.openNew(); err != nil { diff --git a/lego/sys/log/options.go b/lego/sys/log/options.go index ea07c84ad..2d1296566 100644 --- a/lego/sys/log/options.go +++ b/lego/sys/log/options.go @@ -22,6 +22,7 @@ type Options struct { ReportCaller Loglevel //是否输出堆栈信息 CallerSkip int //堆栈深度 Encoder LogEncoder //日志输出样式 + UniqueLog bool //唯一日志文件(文件不分割 不备份,一直追加日志) CupTimeTime int //日志分割时间 单位 小时 MaxAgeTime int //日志最大保存时间 单位天 MaxBackups int //最大备份日志个数 @@ -75,6 +76,13 @@ func SetEncoder(v LogEncoder) Option { } } +///设置唯一日志 +func SetUniqueLog(v bool) Option { + return func(o *Options) { + o.UniqueLog = v + } +} + ///日志分割时间 单位 小时 func SetRotationTime(v int) Option { return func(o *Options) { diff --git a/modules/friend/model_friend.go b/modules/friend/model_friend.go index e4c2d59b0..f60c12ac2 100644 --- a/modules/friend/model_friend.go +++ b/modules/friend/model_friend.go @@ -10,6 +10,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelFriend struct { @@ -21,6 +22,10 @@ func (this *ModelFriend) Init(service core.IService, module core.IModule, comp c this.TableName = comm.TableFriend err = this.MCompModel.Init(service, module, comp, options) this.moduleFriend = module.(*Friend) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return } diff --git a/modules/gm/api_cmd.go b/modules/gm/api_cmd.go index 32ac4c95b..ad23e8ad0 100644 --- a/modules/gm/api_cmd.go +++ b/modules/gm/api_cmd.go @@ -24,7 +24,7 @@ import ( 9、bingo:season,10 赛季塔层数 10、bingo:viking // 解锁维京所有难度 11、bingo:hunting // 解锁狩猎所有难度 -12、bingo:mainline,11001 // 难度 id +12、bingo:mainline,1100104 // mainstage 关卡ID 13、bingo:moon,1 // 触发月之秘境 14、bingo:arena,100 // 设置竞技场用户积分 15、bingo:sociatyexp,100 // 设置工会经验 @@ -38,7 +38,7 @@ import ( 21、bingo:allequip 21、bingo:chat,1 22、bingo:itemtype,1,1 // 获取某种类型所有道具(道具类型,数量) -18、bingo:viplv,50 +23、bingo:viplv,50 */ //参数校验 func (this *apiComp) CmdCheck(session comm.IUserSession, req *pb.GMCmdReq) (code pb.ErrorCode) { diff --git a/modules/hero/api_awaken.go b/modules/hero/api_awaken.go index a383d7932..d9834ebe6 100644 --- a/modules/hero/api_awaken.go +++ b/modules/hero/api_awaken.go @@ -90,16 +90,11 @@ func (this *apiComp) Awaken(session comm.IUserSession, req *pb.HeroAwakenReq) (c } _heroMap["normalSkill"] = _hero.NormalSkill } else { // 加属性 - value, err := strconv.Atoi(awakenData.Phasebonus[1]) - if err == nil { - if value > 0 { - this.module.modelHero.setJuexingProperty(_hero, awakenData.Phasebonus[0], int32(value)) - _heroMap["juexProperty"] = _hero.JuexProperty - } - } + this.module.modelHero.resetJuexingProperty(_hero) } _hero.JuexingLv += 1 _heroMap["juexingLv"] = _hero.JuexingLv + _heroMap["juexProperty"] = _hero.JuexProperty // 保存数据 err := this.module.modelHero.ChangeList(session.GetUserId(), _hero.Id, _heroMap) if err != nil { diff --git a/modules/hero/api_strengthenUpSkill.go b/modules/hero/api_strengthenUpSkill.go index 55957ea25..a7b103380 100644 --- a/modules/hero/api_strengthenUpSkill.go +++ b/modules/hero/api_strengthenUpSkill.go @@ -159,8 +159,8 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt code = pb.ErrorCode_DBError return } - ///// - this.module.modelHero.ChangeHeroProperty(session, _hero) // 推送属性变化 + + //this.module.modelHero.ChangeHeroProperty(session, _hero) // 推送属性变化 ChangeList = append(ChangeList, _hero) session.SendMsg(string(this.module.GetType()), "change", &pb.HeroChangePush{List: ChangeList}) session.SendMsg(string(this.module.GetType()), StrengthenUpSkill, &pb.HeroStrengthenUpSkillResp{Hero: _hero}) diff --git a/modules/hero/model_hero.go b/modules/hero/model_hero.go index d3fb8a43d..c1508f357 100644 --- a/modules/hero/model_hero.go +++ b/modules/hero/model_hero.go @@ -13,6 +13,7 @@ import ( "math" "math/big" "reflect" + "strconv" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" @@ -252,6 +253,41 @@ func (this *ModelHero) getHeroList(uid string) []*pb.DBHero { return heroes } +// 重置觉醒属性 +func (this *ModelHero) resetJuexingProperty(hero *pb.DBHero) { + hero.JuexProperty = make(map[string]int32) + for i := 1; i <= int(hero.JuexingLv); i++ { + awakenData := this.moduleHero.configure.GetHeroAwakenConfig(hero.HeroID, int32(i)) + if awakenData != nil { + if len(awakenData.Phasebonus) != 2 { + continue + } + key := awakenData.Phasebonus[0] + value, err := strconv.Atoi(awakenData.Phasebonus[1]) + if err != nil { + continue + } + switch key { + case comm.Hp: + hero.JuexProperty[comm.Hp] += int32(value) + case comm.Def: + hero.JuexProperty[comm.Def] += int32(value) + case comm.Atk: + hero.JuexProperty[comm.Atk] += int32(value) + case comm.Speed: + hero.JuexProperty[comm.Speed] += int32(value) + case comm.ResonanceHpPro: + hero.JuexProperty[comm.Hp] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Hp]))) + case comm.ResonanceAtkPro: + hero.JuexProperty[comm.Atk] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Atk]))) + case comm.ResonanceDefPro: + hero.JuexProperty[comm.Def] += int32(math.Floor((float64(value) / 1000) * float64(hero.Property[comm.Def]))) + } + } + } + +} + // 觉醒 func (this *ModelHero) setJuexingProperty(hero *pb.DBHero, key string, value int32) { switch key { @@ -474,9 +510,9 @@ func (this *ModelHero) PropertyCompute(hero *pb.DBHero) { if growCfg == nil || heroCfg == nil || lvCfg == nil || starCfg == nil || starLvfg == nil { return } - var atk = (this.StarAtkAddition(hero.Star) + lvCfg.Atk + float32(growCfg.Atk)) * (growCfg.Atkgrow / 1000.0) * 1.0 - var def = (this.StarDefAddition(hero.Star) + lvCfg.Def + float32(growCfg.Def)) * (growCfg.Defgrow / 1000.0) * 1.0 - var hp = (this.StarHpAddition(hero.Star) + lvCfg.Hp + float32(growCfg.Hp)) * (growCfg.Hpgrow / 1000.0) * 1.0 + var atk = (this.StarAtkAddition(hero.Star) + lvCfg.Atk + float32(growCfg.Atk)) * (growCfg.Atkgrow / 1000.0) + var def = (this.StarDefAddition(hero.Star) + lvCfg.Def + float32(growCfg.Def)) * (growCfg.Defgrow / 1000.0) + var hp = (this.StarHpAddition(hero.Star) + lvCfg.Hp + float32(growCfg.Hp)) * (growCfg.Hpgrow / 1000.0) speed := growCfg.Speed hero.Property = map[string]int32{ comm.Hp: int32(math.Floor(float64(hp))), @@ -492,6 +528,7 @@ func (this *ModelHero) PropertyCompute(hero *pb.DBHero) { if hero.Id != "" { // objID 为空表示是怪物对象 不享受天赋属性加成 this.resetTalentProperty(hero) } + this.resetJuexingProperty(hero) } //重新计算英雄属性 @@ -500,6 +537,7 @@ func (this *ModelHero) ChangeHeroProperty(session comm.IUserSession, hero *pb.DB update := map[string]interface{}{ "property": hero.Property, "talentProperty": hero.TalentProperty, + "juexProperty": hero.JuexProperty, } if err = this.ChangeList(session.GetUserId(), hero.Id, update); err != nil { diff --git a/modules/mline/api_challengeover.go b/modules/mline/api_challengeover.go index c19564aca..f3fdeb987 100644 --- a/modules/mline/api_challengeover.go +++ b/modules/mline/api_challengeover.go @@ -175,7 +175,18 @@ func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChall }) } } - + // 加主角经验 + // if stageConf.Exp > 0 { + // res := make([]*cfg.Gameatn, 0) + // res = append(res, &cfg.Gameatn{ + // A: "attr", + // T: "exp", + // N: stageConf.Exp, + // }) + // if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success { + // this.module.Debugf("Mline Commonaward DispenseRes err:+%v", res) + // } + // } // 加英雄经验 if stageConf.HeroExp > 0 { if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { diff --git a/modules/mline/module.go b/modules/mline/module.go index 54819d6d4..4d044d7c7 100644 --- a/modules/mline/module.go +++ b/modules/mline/module.go @@ -92,6 +92,10 @@ func (this *Mline) CheckPoint(uid string) bool { // 参数 难度 + 章节id func (this *Mline) ModifyMlineDataByNanduID(session comm.IUserSession, id int32) (code pb.ErrorCode) { var del []string + connf := this.configure.GetMainStageConf(id) + if connf == nil { + return + } list, err := this.modelMline.getMainlineList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError @@ -103,10 +107,6 @@ func (this *Mline) ModifyMlineDataByNanduID(session comm.IUserSession, id int32) // 清除 this.modelMline.cleanChapterDataById(session.GetUserId(), del...) - connf := this.configure.GetMainStageConf(id) - if connf == nil { - return - } _data := this.configure.GetAllChapterID() for _, v := range _data { if v <= connf.Chapterid { diff --git a/modules/rtask/model_record.go b/modules/rtask/model_record.go index a758a0056..e016d35b0 100644 --- a/modules/rtask/model_record.go +++ b/modules/rtask/model_record.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" ) type ModelRtaskRecord struct { @@ -22,6 +23,10 @@ func (this *ModelRtaskRecord) Init(service core.IService, module core.IModule, c err = this.MCompModel.Init(service, module, comp, options) this.moduleRtask = module.(*ModuleRtask) this.service = service + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return } diff --git a/modules/sociaty/model_sociaty.go b/modules/sociaty/model_sociaty.go index 92a2806c7..4c39a9244 100644 --- a/modules/sociaty/model_sociaty.go +++ b/modules/sociaty/model_sociaty.go @@ -49,6 +49,9 @@ func (this *ModelSociaty) Init(service core.IService, module core.IModule, comp this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ Keys: bsonx.Doc{{Key: "_id", Value: bsonx.Int32(1)}}, }) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "name", Value: bsonx.Int32(1)}}, + }) this.module = module.(*Sociaty) this.service = service this.EventApp = event_v2.NewApp()