108 lines
2.8 KiB
Go
108 lines
2.8 KiB
Go
package reputation
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type ModelReputation struct {
|
|
modules.MCompModel
|
|
moduleReputation *Reputation
|
|
service core.IService
|
|
}
|
|
|
|
func (this *ModelReputation) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.TableName = comm.TableReputation
|
|
this.moduleReputation = module.(*Reputation)
|
|
this.service = service
|
|
return
|
|
}
|
|
|
|
func (this *ModelReputation) initCamp(reputation *pb.DBReputation) {
|
|
if reputation != nil && reputation.Camps == nil {
|
|
reputation.Camps = make(map[int32]*pb.Camp)
|
|
}
|
|
}
|
|
|
|
// 获取玩家声望数据
|
|
func (this *ModelReputation) getDBReputation(uid string) *pb.DBReputation {
|
|
reputation := &pb.DBReputation{}
|
|
if err := this.Get(uid, reputation); err != nil {
|
|
if err == mongo.ErrNoDocuments {
|
|
reputation.Uid = uid
|
|
reputation.Camps = make(map[int32]*pb.Camp)
|
|
if err2 := this.Add(uid, reputation); err2 == nil {
|
|
return reputation
|
|
}
|
|
}
|
|
this.moduleReputation.Error("getDBReputation",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "err", Value: err})
|
|
}
|
|
return reputation
|
|
}
|
|
|
|
// 更新声望数据
|
|
func (this *ModelReputation) updateDBReputation(uid string, data map[string]interface{}) error {
|
|
if err := this.Change(uid, data); err != nil {
|
|
this.moduleReputation.Error("updateDBReputation",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "err", Value: err})
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 阵营属性
|
|
func (this *ModelReputation) computeAttr(attr *pb.CampAttr, cfgs []*cfg.Gameatr) *pb.CampAttr {
|
|
if attr == nil {
|
|
attr = &pb.CampAttr{}
|
|
}
|
|
for _, v := range cfgs {
|
|
switch v.A {
|
|
case cfg.GamePropertyType_Base_MaxHp_Base:
|
|
attr.Hp += v.N
|
|
case cfg.GamePropertyType_Base_Atk_Base:
|
|
attr.Attack += v.N
|
|
case cfg.GamePropertyType_Base_Def_Base:
|
|
attr.Defense += v.N
|
|
case cfg.GamePropertyType_Base_MaxHp_Per:
|
|
attr.HpPer += v.N
|
|
}
|
|
}
|
|
return attr
|
|
}
|
|
|
|
// 合计所有阵营的属性
|
|
func (this *ModelReputation) mergeAttrs(camps map[int32]*pb.Camp) *pb.CampAttr {
|
|
totalAttr := &pb.CampAttr{}
|
|
for _, v := range camps {
|
|
if v.CampAttr != nil {
|
|
totalAttr.Hp += v.CampAttr.Hp
|
|
totalAttr.Attack += v.CampAttr.Attack
|
|
totalAttr.Defense += v.CampAttr.Defense
|
|
totalAttr.HpPer += v.CampAttr.HpPer
|
|
}
|
|
}
|
|
return totalAttr
|
|
}
|
|
|
|
// 校验前置节点是否
|
|
func (this *ModelReputation) isReachPreNode(reputation *pb.DBReputation, raceType, preNodeId, preNodeLv int32) bool {
|
|
if camp, ok := reputation.Camps[raceType]; ok {
|
|
for _, n := range camp.Nodes {
|
|
if n.Nid == preNodeId && n.Lv == preNodeLv {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|