go_dreamfactory/modules/reputation/module.go
2023-04-19 19:29:25 +08:00

114 lines
2.7 KiB
Go

package reputation
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
cfg "go_dreamfactory/sys/configure/structs"
)
var _ comm.IReputation = (*Reputation)(nil)
type Reputation struct {
modules.ModuleBase
api *apiComp
service base.IRPCXService
configure *configureComp
modelReputation *ModelReputation
}
func NewModule() core.IModule {
return &Reputation{}
}
func (this *Reputation) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
func (this *Reputation) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.api = this.RegisterComp(new(apiComp)).(*apiComp)
this.configure = this.RegisterComp(new(configureComp)).(*configureComp)
this.modelReputation = this.RegisterComp(new(ModelReputation)).(*ModelReputation)
}
func (this *Reputation) GetType() core.M_Modules {
return comm.ModuleReputation
}
func (this *Reputation) Start() (err error) {
err = this.ModuleBase.Start()
return
}
// 获取阵营最大等级
// raceType 阵营类型
func (this *Reputation) getCampLvMax(raceType int32) (maxLv int32) {
campLvConf, err := this.configure.getCampLvCfg()
if err != nil {
return
}
arr := campLvConf.GetDataList()
n := len(arr)
if n > 0 {
maxLv = arr[n-1].ReputationLv
} else {
maxLv = -1
}
return
}
// 声望升级
// raceType 阵营 fv 阵营好感度累计值
func (this *Reputation) Upgrade(session comm.IUserSession, raceType int32, fv int32) (lv int32) {
uid := session.GetUserId()
reputation := this.modelReputation.getDBReputation(uid)
if reputation == nil {
return
}
c, ok := reputation.Camps[raceType]
if !ok {
this.Error("阵营不存在",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "raceType", Value: raceType})
return
}
maxLv := this.getCampLvMax(raceType)
if c.ReputationLv == maxLv {
this.Debug("已达到声望最大等级",
log.Field{Key: "uid", Value: uid},
log.Field{Key: "maxLv", Value: c.ReputationLv})
return c.ReputationLv
}
campLvConf, err := this.configure.getCampLvCfg()
if err != nil {
return
}
for _, conf := range campLvConf.GetDataList() {
if conf.RaceType == raceType && conf.ReputationLv == c.ReputationLv {
if fv >= conf.ReputationExp {
//更新等级
c.ReputationLv = c.ReputationLv + 1
update := map[string]interface{}{
"camps": reputation.Camps,
}
this.modelReputation.updateDBReputation(uid, update)
//发放天赋点奖励
this.DispenseRes(session, []*cfg.Gameatn{conf.Reward}, false)
break
}
}
}
return
}