上传 用户经验满级后处理机制
This commit is contained in:
parent
65312b75a5
commit
4aec88acb9
@ -167,9 +167,9 @@ type (
|
||||
//查询用户属性值 例如 金币 经验
|
||||
QueryAttributeValue(uid string, attr string) (value int64)
|
||||
//添加/减少属性值 第四个参数控制是否推送给前端
|
||||
AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData)
|
||||
// AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData)
|
||||
// 批量处理
|
||||
AddAttributeValues(session IUserSession, attrs map[string]int32, bPush bool) (errdata *pb.ErrorData)
|
||||
AddAttributeValues(session IUserSession, attrs map[string]int32, bPush bool) (atno []*pb.UserAtno, errdata *pb.ErrorData)
|
||||
//用户改变事件
|
||||
// EventUserChanged(session IUserSession)
|
||||
// EventUserVipChanged(session IUserSession)
|
||||
|
@ -412,7 +412,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn
|
||||
}
|
||||
// 真正消耗
|
||||
if len(attrs) > 0 {
|
||||
errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
_, errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
if errdata != nil {
|
||||
return
|
||||
}
|
||||
@ -480,7 +480,7 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
|
||||
}
|
||||
|
||||
if len(attrs) > 0 { //用户属性资源
|
||||
errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
_, errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||
this.Debugf("发放用户资源: %v errdata: %v", attrs, errdata)
|
||||
}
|
||||
if len(items) > 0 { //道具资源
|
||||
@ -702,16 +702,16 @@ func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gamea
|
||||
}
|
||||
|
||||
if len(attrs) > 0 { //用户属性资源
|
||||
if errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush); errdata != nil {
|
||||
if atno, errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush); errdata != nil {
|
||||
return
|
||||
}
|
||||
for k, v := range attrs {
|
||||
atno = append(atno, &pb.UserAtno{
|
||||
A: comm.AttrType,
|
||||
T: k,
|
||||
N: v,
|
||||
})
|
||||
}
|
||||
// for k, v := range attrs {
|
||||
// atno = append(atno, &pb.UserAtno{
|
||||
// A: comm.AttrType,
|
||||
// T: k,
|
||||
// N: v,
|
||||
// })
|
||||
// }
|
||||
this.Debugf("发放用户资源: %v errdata: %v", attrs, errdata)
|
||||
|
||||
}
|
||||
|
@ -18,13 +18,7 @@ const (
|
||||
game_equipintensify = "game_equipintensify.json" //装备等级消耗表
|
||||
game_equipenchanting = "game_equipenchanting.json" //装备附魔
|
||||
equip_suit = "game_equipsuit.json" //装备套装表
|
||||
// gameWorldAll = "game_worldall.json"
|
||||
// gameburiedCond = "game_buriedcondi.json"
|
||||
// gamerdtasknpc = "game_rdtasknpc.json"
|
||||
// gamesearchitemall = "game_searchitemall.json"
|
||||
// gamesearchitembox = "game_searchitembox.json"
|
||||
// game_worlddeal = "game_worlddeal.json"
|
||||
// game_worldrd = "game_worldrd.json"
|
||||
|
||||
game_pagoda = "game_pagoda.json"
|
||||
hero_talent = "game_herotalent.json" // 天赋详细数据
|
||||
game_playerlv = "game_playerlv.json"
|
||||
@ -32,6 +26,8 @@ const (
|
||||
hero_awaken = "game_heroawaken.json"
|
||||
|
||||
game_horoscope = "game_horoscope.json" //星阵图
|
||||
|
||||
game_combatlevel = "game_combatlevel.json" //关卡编辑器
|
||||
)
|
||||
|
||||
type configureComp struct {
|
||||
@ -54,6 +50,8 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
|
||||
configure.RegisterConfigure(game_playerlv, cfg.NewGamePlayerlv, nil)
|
||||
configure.RegisterConfigure(hero_awaken, cfg.NewGameHeroAwaken, nil) // 觉醒
|
||||
configure.RegisterConfigure(game_horoscope, cfg.NewGameHoroscope, nil)
|
||||
configure.RegisterConfigure(game_horoscope, cfg.NewGameHoroscope, nil)
|
||||
configure.RegisterConfigure(game_combatlevel, cfg.NewGameCombatLevel, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
64
modules/robot/modulerobot_combat.go
Normal file
64
modules/robot/modulerobot_combat.go
Normal file
@ -0,0 +1,64 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/sys/configure"
|
||||
cfg "go_dreamfactory/sys/configure/structs"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
//用户模块 机器人
|
||||
type ModuleRobot_Combat struct {
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Combat) Init() (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//接收到消息
|
||||
func (this *ModuleRobot_Combat) Receive(robot IRobot, stype string, message proto.Message) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Combat) OncePipeline(robot IRobot) (err error) {
|
||||
var (
|
||||
errdata *pb.ErrorData
|
||||
conf *cfg.GameCombatLevelData
|
||||
)
|
||||
conf = this.GetCombatLevelData()[0]
|
||||
if _, errdata = robot.SendMessage("combat", "ask", &pb.CombatAskReq{Level: conf.Id}); errdata != nil {
|
||||
err = errors.New(fmt.Sprintf("code:%d message:%s", errdata.Code, errdata.Message))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//机器人执行流
|
||||
func (this *ModuleRobot_Combat) DoPipeline(robot IRobot) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//做任务
|
||||
func (this *ModuleRobot_Combat) DoTask(robot IRobot, taskconf *cfg.GameWorldTaskData, condconf *cfg.GameBuriedCondiData) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModuleRobot_Combat) GetCombatLevelData() (data []*cfg.GameCombatLevelData) {
|
||||
data = make([]*cfg.GameCombatLevelData, 0)
|
||||
if v, err := configure.GetConfigure(game_combatlevel); err == nil {
|
||||
if _configure, ok := v.(*cfg.GameCombatLevel); ok {
|
||||
for _, v := range _configure.GetDataList() {
|
||||
data = append(data, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
@ -77,6 +77,8 @@ func (this *Robot) Init(addr string, client IClient) (err error) {
|
||||
this.modules[comm.ModuleShop] = new(ModuleRobot_Shop)
|
||||
this.modules[comm.ModuleCaravan] = new(ModuleRobot_Caravan)
|
||||
this.modules[comm.ModuleHoroscope] = new(ModuleRobot_Horoscope)
|
||||
this.modules[comm.ModuleCombat] = new(ModuleRobot_Combat)
|
||||
|
||||
for _, v := range this.modules {
|
||||
v.Init()
|
||||
}
|
||||
|
@ -215,45 +215,41 @@ func (this *ModelUser) changeVipExp(change *pb.UserResChangedPush) (lvchange boo
|
||||
}
|
||||
|
||||
// change level
|
||||
func (this *ModelUser) computeLevel(change *pb.UserResChangedPush) (lvchange bool, rewards []*cfg.Gameatn) {
|
||||
func (this *ModelUser) computeLevel(change *pb.UserResChangedPush) (lvchange bool, loseexp int32, rewards []*cfg.Gameatn) {
|
||||
var (
|
||||
curLv int32 = change.Lv
|
||||
nextLvConf *cfg.GamePlayerlvData
|
||||
curExp int64 = change.Exp
|
||||
res int64
|
||||
)
|
||||
//下一等级配置
|
||||
nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1)
|
||||
if nextLvConf == nil {
|
||||
curLvConf := this.module.configure.GetPlayerlvConf(curLv)
|
||||
reward := this.module.globalConf.OverexpReward
|
||||
if curExp < int64(curLvConf.Exp) {
|
||||
res = curExp * int64(reward.N)
|
||||
} else {
|
||||
yu := int32(curExp) - curLvConf.Exp
|
||||
res = int64(yu * reward.N)
|
||||
}
|
||||
curExp = int64(curLvConf.Exp)
|
||||
} else {
|
||||
for nextLvConf != nil && curExp >= int64(nextLvConf.Exp) {
|
||||
|
||||
for nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1); nextLvConf != nil; {
|
||||
if curExp >= int64(nextLvConf.Exp) {
|
||||
curExp = curExp - int64(nextLvConf.Exp)
|
||||
curLv++
|
||||
//叠加奖励
|
||||
rewards = append(rewards, nextLvConf.Reward...)
|
||||
nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if nextLvConf == nil { //满级了
|
||||
curLvConf := this.module.configure.GetPlayerlvConf(curLv)
|
||||
reward := this.module.globalConf.OverexpReward
|
||||
if curExp > int64(curLvConf.Exp) {
|
||||
loseexp = int32(curExp) - curLvConf.Exp
|
||||
res = int64(loseexp * reward.N)
|
||||
curExp = int64(curLvConf.Exp)
|
||||
change.Deposit += res
|
||||
change.Exp = curExp
|
||||
}
|
||||
}
|
||||
// 等级有递增时再更新
|
||||
if curLv > change.Lv {
|
||||
lvchange = true
|
||||
change.Lv = curLv
|
||||
change.Exp = curExp
|
||||
} else {
|
||||
if nextLvConf == nil {
|
||||
change.Deposit += res
|
||||
change.Exp = curExp
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -381,21 +381,13 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int64) {
|
||||
return
|
||||
}
|
||||
|
||||
func (this *User) change(session comm.IUserSession, attr string, add int32) (change *pb.UserResChangedPush, errdata *pb.ErrorData) {
|
||||
if add == 0 {
|
||||
log.Warn("attr no changed",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "attr", Value: attr},
|
||||
log.Field{Key: "add", Value: add},
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atno []*pb.UserAtno, change *pb.UserResChangedPush, errdata *pb.ErrorData) {
|
||||
uid := session.GetUserId()
|
||||
var (
|
||||
user *pb.DBUser
|
||||
userEx *pb.DBUserExpand
|
||||
lvexpchange, vipexpchange bool
|
||||
vipexpchange bool
|
||||
temp *pb.UserAtno
|
||||
err error
|
||||
)
|
||||
|
||||
@ -447,7 +439,21 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
Integral: user.Integral,
|
||||
Profit: user.Profit,
|
||||
}
|
||||
|
||||
atno = make([]*pb.UserAtno, 0, len(attrs))
|
||||
for attr, add := range attrs {
|
||||
if add == 0 {
|
||||
log.Warn("attr no changed",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "attr", Value: attr},
|
||||
log.Field{Key: "add", Value: add},
|
||||
)
|
||||
continue
|
||||
}
|
||||
temp = &pb.UserAtno{
|
||||
A: comm.AttrType,
|
||||
T: attr,
|
||||
N: add,
|
||||
}
|
||||
switch attr {
|
||||
case comm.ResGold:
|
||||
if add < 0 {
|
||||
@ -461,6 +467,11 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
}
|
||||
change.Gold += int64(add)
|
||||
case comm.ResExp:
|
||||
var (
|
||||
lvchange bool
|
||||
loseexp int32
|
||||
rewards []*cfg.Gameatn
|
||||
)
|
||||
if add < 0 {
|
||||
if user.Exp+int64(add) < 0 {
|
||||
errdata = &pb.ErrorData{
|
||||
@ -471,7 +482,10 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
}
|
||||
}
|
||||
change.Exp += int64(add)
|
||||
lvexpchange = true
|
||||
if lvchange, loseexp, rewards = this.modelUser.computeLevel(change); lvchange {
|
||||
go this.modelUser.changelv(session.Clone(), change.Lv, change.Exp, user.Name, rewards)
|
||||
}
|
||||
temp.N = temp.N - loseexp
|
||||
case comm.VipExp:
|
||||
if add < 0 {
|
||||
if user.Vipexp+int64(add) < 0 {
|
||||
@ -660,11 +674,7 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
err = errors.New(fmt.Sprintf("%s no supported", attr))
|
||||
return
|
||||
}
|
||||
|
||||
if lvexpchange {
|
||||
if ok, rewards := this.modelUser.computeLevel(change); ok {
|
||||
go this.modelUser.changelv(session.Clone(), change.Lv, change.Exp, user.Name, rewards)
|
||||
}
|
||||
atno = append(atno, temp)
|
||||
}
|
||||
|
||||
if vipexpchange {
|
||||
@ -729,37 +739,37 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
||||
return
|
||||
}
|
||||
|
||||
// 用户资源
|
||||
func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData) {
|
||||
var _change *pb.UserResChangedPush
|
||||
// // 用户资源
|
||||
// func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData) {
|
||||
// var _change *pb.UserResChangedPush
|
||||
|
||||
_change, errdata = this.change(session, attr, add)
|
||||
if errdata != nil {
|
||||
return
|
||||
}
|
||||
// _change, errdata = this.change(session, attr, add)
|
||||
// if errdata != nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
if _change == nil {
|
||||
return
|
||||
}
|
||||
// if _change == nil {
|
||||
// return
|
||||
// }
|
||||
|
||||
if bPush { //推送玩家账号信息变化消息
|
||||
session.SendMsg(string(this.GetType()), "reschanged", _change)
|
||||
}
|
||||
return
|
||||
}
|
||||
// if bPush { //推送玩家账号信息变化消息
|
||||
// session.SendMsg(string(this.GetType()), "reschanged", _change)
|
||||
// }
|
||||
// return
|
||||
// }
|
||||
|
||||
// 用户资源
|
||||
func (this *User) AddAttributeValues(session comm.IUserSession, attrs map[string]int32, bPush bool) (errdata *pb.ErrorData) {
|
||||
func (this *User) AddAttributeValues(session comm.IUserSession, attrs map[string]int32, bPush bool) (atno []*pb.UserAtno, errdata *pb.ErrorData) {
|
||||
var (
|
||||
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
||||
_change *pb.UserResChangedPush
|
||||
)
|
||||
for key, add := range attrs {
|
||||
_change, errdata = this.change(session, key, add)
|
||||
atno, _change, errdata = this.change(session, attrs)
|
||||
if errdata != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for key, add := range attrs {
|
||||
if key == comm.ResPs && add < 0 { //消耗体力
|
||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype213, -add))
|
||||
}
|
||||
@ -1219,7 +1229,8 @@ func (this *User) ConsumePsAddExp(session comm.IUserSession, ps int32) (addExp i
|
||||
attrs := make(map[string]int32, 0)
|
||||
attrs["exp"] = addExp
|
||||
|
||||
return addExp, this.AddAttributeValues(session, attrs, true)
|
||||
_, errdata = this.AddAttributeValues(session, attrs, true)
|
||||
return
|
||||
}
|
||||
|
||||
// 剩余体力
|
||||
|
Loading…
Reference in New Issue
Block a user