上传 用户经验满级后处理机制
This commit is contained in:
parent
65312b75a5
commit
4aec88acb9
@ -167,9 +167,9 @@ type (
|
|||||||
//查询用户属性值 例如 金币 经验
|
//查询用户属性值 例如 金币 经验
|
||||||
QueryAttributeValue(uid string, attr string) (value int64)
|
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)
|
// EventUserChanged(session IUserSession)
|
||||||
// EventUserVipChanged(session IUserSession)
|
// EventUserVipChanged(session IUserSession)
|
||||||
|
@ -412,7 +412,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn
|
|||||||
}
|
}
|
||||||
// 真正消耗
|
// 真正消耗
|
||||||
if len(attrs) > 0 {
|
if len(attrs) > 0 {
|
||||||
errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
_, errdata = this.ModuleUser.AddAttributeValues(session, attrs, bPush)
|
||||||
if errdata != nil {
|
if errdata != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -480,7 +480,7 @@ func (this *ModuleBase) DispenseRes(session comm.IUserSession, res []*cfg.Gameat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(attrs) > 0 { //用户属性资源
|
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)
|
this.Debugf("发放用户资源: %v errdata: %v", attrs, errdata)
|
||||||
}
|
}
|
||||||
if len(items) > 0 { //道具资源
|
if len(items) > 0 { //道具资源
|
||||||
@ -702,16 +702,16 @@ func (this *ModuleBase) DispenseAtno(session comm.IUserSession, res []*cfg.Gamea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(attrs) > 0 { //用户属性资源
|
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
|
return
|
||||||
}
|
}
|
||||||
for k, v := range attrs {
|
// for k, v := range attrs {
|
||||||
atno = append(atno, &pb.UserAtno{
|
// atno = append(atno, &pb.UserAtno{
|
||||||
A: comm.AttrType,
|
// A: comm.AttrType,
|
||||||
T: k,
|
// T: k,
|
||||||
N: v,
|
// N: v,
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
this.Debugf("发放用户资源: %v errdata: %v", attrs, errdata)
|
this.Debugf("发放用户资源: %v errdata: %v", attrs, errdata)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,7 @@ const (
|
|||||||
game_equipintensify = "game_equipintensify.json" //装备等级消耗表
|
game_equipintensify = "game_equipintensify.json" //装备等级消耗表
|
||||||
game_equipenchanting = "game_equipenchanting.json" //装备附魔
|
game_equipenchanting = "game_equipenchanting.json" //装备附魔
|
||||||
equip_suit = "game_equipsuit.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"
|
game_pagoda = "game_pagoda.json"
|
||||||
hero_talent = "game_herotalent.json" // 天赋详细数据
|
hero_talent = "game_herotalent.json" // 天赋详细数据
|
||||||
game_playerlv = "game_playerlv.json"
|
game_playerlv = "game_playerlv.json"
|
||||||
@ -32,6 +26,8 @@ const (
|
|||||||
hero_awaken = "game_heroawaken.json"
|
hero_awaken = "game_heroawaken.json"
|
||||||
|
|
||||||
game_horoscope = "game_horoscope.json" //星阵图
|
game_horoscope = "game_horoscope.json" //星阵图
|
||||||
|
|
||||||
|
game_combatlevel = "game_combatlevel.json" //关卡编辑器
|
||||||
)
|
)
|
||||||
|
|
||||||
type configureComp struct {
|
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(game_playerlv, cfg.NewGamePlayerlv, nil)
|
||||||
configure.RegisterConfigure(hero_awaken, cfg.NewGameHeroAwaken, 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_horoscope, cfg.NewGameHoroscope, nil)
|
||||||
|
configure.RegisterConfigure(game_combatlevel, cfg.NewGameCombatLevel, nil)
|
||||||
return
|
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.ModuleShop] = new(ModuleRobot_Shop)
|
||||||
this.modules[comm.ModuleCaravan] = new(ModuleRobot_Caravan)
|
this.modules[comm.ModuleCaravan] = new(ModuleRobot_Caravan)
|
||||||
this.modules[comm.ModuleHoroscope] = new(ModuleRobot_Horoscope)
|
this.modules[comm.ModuleHoroscope] = new(ModuleRobot_Horoscope)
|
||||||
|
this.modules[comm.ModuleCombat] = new(ModuleRobot_Combat)
|
||||||
|
|
||||||
for _, v := range this.modules {
|
for _, v := range this.modules {
|
||||||
v.Init()
|
v.Init()
|
||||||
}
|
}
|
||||||
|
@ -215,45 +215,41 @@ func (this *ModelUser) changeVipExp(change *pb.UserResChangedPush) (lvchange boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// change level
|
// 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 (
|
var (
|
||||||
curLv int32 = change.Lv
|
curLv int32 = change.Lv
|
||||||
nextLvConf *cfg.GamePlayerlvData
|
nextLvConf *cfg.GamePlayerlvData
|
||||||
curExp int64 = change.Exp
|
curExp int64 = change.Exp
|
||||||
res int64
|
res int64
|
||||||
)
|
)
|
||||||
//下一等级配置
|
|
||||||
nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1)
|
for nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1); nextLvConf != nil; {
|
||||||
if nextLvConf == nil {
|
if curExp >= int64(nextLvConf.Exp) {
|
||||||
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) {
|
|
||||||
curExp = curExp - int64(nextLvConf.Exp)
|
curExp = curExp - int64(nextLvConf.Exp)
|
||||||
curLv++
|
curLv++
|
||||||
//叠加奖励
|
//叠加奖励
|
||||||
rewards = append(rewards, nextLvConf.Reward...)
|
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 {
|
if curLv > change.Lv {
|
||||||
lvchange = true
|
lvchange = true
|
||||||
change.Lv = curLv
|
change.Lv = curLv
|
||||||
change.Exp = curExp
|
change.Exp = curExp
|
||||||
} else {
|
|
||||||
if nextLvConf == nil {
|
|
||||||
change.Deposit += res
|
|
||||||
change.Exp = curExp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -381,22 +381,14 @@ func (this *User) QueryAttributeValue(uid string, attr string) (value int64) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *User) change(session comm.IUserSession, attr string, add int32) (change *pb.UserResChangedPush, errdata *pb.ErrorData) {
|
func (this *User) change(session comm.IUserSession, attrs map[string]int32) (atno []*pb.UserAtno, 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
|
|
||||||
}
|
|
||||||
|
|
||||||
uid := session.GetUserId()
|
uid := session.GetUserId()
|
||||||
var (
|
var (
|
||||||
user *pb.DBUser
|
user *pb.DBUser
|
||||||
userEx *pb.DBUserExpand
|
userEx *pb.DBUserExpand
|
||||||
lvexpchange, vipexpchange bool
|
vipexpchange bool
|
||||||
err error
|
temp *pb.UserAtno
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
user, err = this.GetUser(uid)
|
user, err = this.GetUser(uid)
|
||||||
@ -447,224 +439,242 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
|||||||
Integral: user.Integral,
|
Integral: user.Integral,
|
||||||
Profit: user.Profit,
|
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 {
|
||||||
|
if user.Gold+int64(add) < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_GoldNoEnough,
|
||||||
|
Title: pb.ErrorCode_GoldNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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{
|
||||||
|
Code: pb.ErrorCode_UserExpNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserExpNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Exp += int64(add)
|
||||||
|
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 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserExpNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserExpNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Vipexp += int64(add)
|
||||||
|
vipexpchange = true
|
||||||
|
case comm.ResDiamond:
|
||||||
|
if add < 0 {
|
||||||
|
if user.Diamond+int64(add) < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_DiamondNoEnough,
|
||||||
|
Title: pb.ErrorCode_DiamondNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Diamond += int64(add)
|
||||||
|
case comm.Moongold:
|
||||||
|
if add < 0 {
|
||||||
|
if user.Moongold+int32(add) < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserMoongoldNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserMoongoldNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
pb.ErrorCode_PayRenewTimeErr.Enum().Descriptor().ReservedNames()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Moongold += int32(add)
|
||||||
|
case comm.ResFriend:
|
||||||
|
if add < 0 {
|
||||||
|
if userEx.FriendPoint+add < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserFriendNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserFriendNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Friend += add
|
||||||
|
case comm.StarCoin:
|
||||||
|
if add < 0 {
|
||||||
|
if user.Starcoin+int64(add) < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserStarCoinNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserStarCoinNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Starcoin += int64(add)
|
||||||
|
case comm.SociatyCoin:
|
||||||
|
if add < 0 {
|
||||||
|
if userEx.Guildcoin+add < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserSociatyCoinNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserSociatyCoinNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Guildcoin += add
|
||||||
|
case comm.ArenaCoin:
|
||||||
|
if add < 0 {
|
||||||
|
if userEx.Arenacoin+add < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserArenaCoinNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserArenaCoinNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
change.Arenacoin += add
|
||||||
|
case comm.ResPs:
|
||||||
|
ggd := this.ModuleTools.GetGlobalConf()
|
||||||
|
if ggd == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if add < 0 {
|
||||||
|
if user.Ps+add < 0 {
|
||||||
|
errdata = &pb.ErrorData{
|
||||||
|
Code: pb.ErrorCode_UserVitNoEnough,
|
||||||
|
Title: pb.ErrorCode_UserVitNoEnough.ToString(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
change.Ps += add
|
||||||
|
userEx.ConsumPs += -add
|
||||||
|
this.ModuleUiGame.HDPSTodayConsum(session.GetUserId(), userEx.ConsumPs)
|
||||||
|
} else {
|
||||||
|
if change.Ps+add > ggd.PsUl {
|
||||||
|
change.Ps = ggd.PsUl
|
||||||
|
} else {
|
||||||
|
change.Ps += add
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch attr {
|
case comm.Talent1:
|
||||||
case comm.ResGold:
|
if add < 0 {
|
||||||
if add < 0 {
|
if user.Talent1+add < 0 {
|
||||||
if user.Gold+int64(add) < 0 {
|
errdata = &pb.ErrorData{
|
||||||
errdata = &pb.ErrorData{
|
Code: pb.ErrorCode_UserTalent1NoEnough,
|
||||||
Code: pb.ErrorCode_GoldNoEnough,
|
Title: pb.ErrorCode_UserTalent1NoEnough.ToString(),
|
||||||
Title: pb.ErrorCode_GoldNoEnough.ToString(),
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Talent1 += add
|
||||||
change.Gold += int64(add)
|
case comm.Talent2:
|
||||||
case comm.ResExp:
|
if add < 0 {
|
||||||
if add < 0 {
|
if user.Talent2+add < 0 {
|
||||||
if user.Exp+int64(add) < 0 {
|
errdata = &pb.ErrorData{
|
||||||
errdata = &pb.ErrorData{
|
Code: pb.ErrorCode_UserTalent2NoEnough,
|
||||||
Code: pb.ErrorCode_UserExpNoEnough,
|
Title: pb.ErrorCode_UserTalent2NoEnough.ToString(),
|
||||||
Title: pb.ErrorCode_UserExpNoEnough.ToString(),
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Talent2 += add
|
||||||
change.Exp += int64(add)
|
case comm.Talent3:
|
||||||
lvexpchange = true
|
if add < 0 {
|
||||||
case comm.VipExp:
|
if user.Talent3+add < 0 {
|
||||||
if add < 0 {
|
errdata = &pb.ErrorData{
|
||||||
if user.Vipexp+int64(add) < 0 {
|
Code: pb.ErrorCode_UserTalent3NoEnough,
|
||||||
errdata = &pb.ErrorData{
|
Title: pb.ErrorCode_UserTalent3NoEnough.ToString(),
|
||||||
Code: pb.ErrorCode_UserExpNoEnough,
|
}
|
||||||
Title: pb.ErrorCode_UserExpNoEnough.ToString(),
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Talent3 += add
|
||||||
change.Vipexp += int64(add)
|
case comm.Talent4:
|
||||||
vipexpchange = true
|
if add < 0 {
|
||||||
case comm.ResDiamond:
|
if user.Talent4+add < 0 {
|
||||||
if add < 0 {
|
errdata = &pb.ErrorData{
|
||||||
if user.Diamond+int64(add) < 0 {
|
Code: pb.ErrorCode_UserTalent4NoEnough,
|
||||||
errdata = &pb.ErrorData{
|
Title: pb.ErrorCode_UserTalent4NoEnough.ToString(),
|
||||||
Code: pb.ErrorCode_DiamondNoEnough,
|
}
|
||||||
Title: pb.ErrorCode_DiamondNoEnough.ToString(),
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Talent4 += add
|
||||||
change.Diamond += int64(add)
|
case comm.Merchantmoney:
|
||||||
case comm.Moongold:
|
if add < 0 {
|
||||||
if add < 0 {
|
if user.Merchantmoney+add < 0 {
|
||||||
if user.Moongold+int32(add) < 0 {
|
errdata = &pb.ErrorData{
|
||||||
errdata = &pb.ErrorData{
|
Code: pb.ErrorCode_UserMerchantNoEnough,
|
||||||
Code: pb.ErrorCode_UserMoongoldNoEnough,
|
Title: pb.ErrorCode_UserMerchantNoEnough.ToString(),
|
||||||
Title: pb.ErrorCode_UserMoongoldNoEnough.ToString(),
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
pb.ErrorCode_PayRenewTimeErr.Enum().Descriptor().ReservedNames()
|
|
||||||
}
|
}
|
||||||
}
|
change.Merchantmoney += add
|
||||||
change.Moongold += int32(add)
|
case comm.Integral:
|
||||||
case comm.ResFriend:
|
if add < 0 {
|
||||||
if add < 0 {
|
if user.Integral+int64(add) < 0 {
|
||||||
if userEx.FriendPoint+add < 0 {
|
errdata = &pb.ErrorData{
|
||||||
errdata = &pb.ErrorData{
|
Code: pb.ErrorCode_UserMerchantNoEnough,
|
||||||
Code: pb.ErrorCode_UserFriendNoEnough,
|
Title: pb.ErrorCode_UserMerchantNoEnough.ToString(),
|
||||||
Title: pb.ErrorCode_UserFriendNoEnough.ToString(),
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Integral += int64(add)
|
||||||
change.Friend += add
|
case comm.Profit:
|
||||||
case comm.StarCoin:
|
if add < 0 {
|
||||||
if add < 0 {
|
if user.Profit+int64(add) < 0 {
|
||||||
if user.Starcoin+int64(add) < 0 {
|
errdata = &pb.ErrorData{
|
||||||
errdata = &pb.ErrorData{
|
Code: pb.ErrorCode_UserProfitNoEnough,
|
||||||
Code: pb.ErrorCode_UserStarCoinNoEnough,
|
Title: pb.ErrorCode_UserProfitNoEnough.ToString(),
|
||||||
Title: pb.ErrorCode_UserStarCoinNoEnough.ToString(),
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
change.Profit += int64(add)
|
||||||
change.Starcoin += int64(add)
|
default:
|
||||||
case comm.SociatyCoin:
|
err = errors.New(fmt.Sprintf("%s no supported", attr))
|
||||||
if add < 0 {
|
|
||||||
if userEx.Guildcoin+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserSociatyCoinNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserSociatyCoinNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Guildcoin += add
|
|
||||||
case comm.ArenaCoin:
|
|
||||||
if add < 0 {
|
|
||||||
if userEx.Arenacoin+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserArenaCoinNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserArenaCoinNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Arenacoin += add
|
|
||||||
case comm.ResPs:
|
|
||||||
ggd := this.ModuleTools.GetGlobalConf()
|
|
||||||
if ggd == nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if add < 0 {
|
atno = append(atno, temp)
|
||||||
if user.Ps+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserVitNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserVitNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
change.Ps += add
|
|
||||||
userEx.ConsumPs += -add
|
|
||||||
this.ModuleUiGame.HDPSTodayConsum(session.GetUserId(), userEx.ConsumPs)
|
|
||||||
} else {
|
|
||||||
if change.Ps+add > ggd.PsUl {
|
|
||||||
change.Ps = ggd.PsUl
|
|
||||||
} else {
|
|
||||||
change.Ps += add
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case comm.Talent1:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Talent1+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserTalent1NoEnough,
|
|
||||||
Title: pb.ErrorCode_UserTalent1NoEnough.ToString(),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Talent1 += add
|
|
||||||
case comm.Talent2:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Talent2+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserTalent2NoEnough,
|
|
||||||
Title: pb.ErrorCode_UserTalent2NoEnough.ToString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Talent2 += add
|
|
||||||
case comm.Talent3:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Talent3+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserTalent3NoEnough,
|
|
||||||
Title: pb.ErrorCode_UserTalent3NoEnough.ToString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Talent3 += add
|
|
||||||
case comm.Talent4:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Talent4+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserTalent4NoEnough,
|
|
||||||
Title: pb.ErrorCode_UserTalent4NoEnough.ToString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Talent4 += add
|
|
||||||
case comm.Merchantmoney:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Merchantmoney+add < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserMerchantNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserMerchantNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Merchantmoney += add
|
|
||||||
case comm.Integral:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Integral+int64(add) < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserMerchantNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserMerchantNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Integral += int64(add)
|
|
||||||
case comm.Profit:
|
|
||||||
if add < 0 {
|
|
||||||
if user.Profit+int64(add) < 0 {
|
|
||||||
errdata = &pb.ErrorData{
|
|
||||||
Code: pb.ErrorCode_UserProfitNoEnough,
|
|
||||||
Title: pb.ErrorCode_UserProfitNoEnough.ToString(),
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
change.Profit += int64(add)
|
|
||||||
default:
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if vipexpchange {
|
if vipexpchange {
|
||||||
@ -729,37 +739,37 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用户资源
|
// // 用户资源
|
||||||
func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData) {
|
// func (this *User) AddAttributeValue(session comm.IUserSession, attr string, add int32, bPush bool) (errdata *pb.ErrorData) {
|
||||||
var _change *pb.UserResChangedPush
|
// var _change *pb.UserResChangedPush
|
||||||
|
|
||||||
_change, errdata = this.change(session, attr, add)
|
// _change, errdata = this.change(session, attr, add)
|
||||||
if errdata != nil {
|
// if errdata != nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
if _change == nil {
|
// if _change == nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
if bPush { //推送玩家账号信息变化消息
|
// if bPush { //推送玩家账号信息变化消息
|
||||||
session.SendMsg(string(this.GetType()), "reschanged", _change)
|
// session.SendMsg(string(this.GetType()), "reschanged", _change)
|
||||||
}
|
// }
|
||||||
return
|
// 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 (
|
var (
|
||||||
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0)
|
||||||
_change *pb.UserResChangedPush
|
_change *pb.UserResChangedPush
|
||||||
)
|
)
|
||||||
for key, add := range attrs {
|
atno, _change, errdata = this.change(session, attrs)
|
||||||
_change, errdata = this.change(session, key, add)
|
if errdata != nil {
|
||||||
if errdata != nil {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
for key, add := range attrs {
|
||||||
if key == comm.ResPs && add < 0 { //消耗体力
|
if key == comm.ResPs && add < 0 { //消耗体力
|
||||||
tasks = append(tasks, comm.GetBuriedParam(comm.Rtype213, -add))
|
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 := make(map[string]int32, 0)
|
||||||
attrs["exp"] = addExp
|
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