玩家信息修改协议
This commit is contained in:
parent
2662294270
commit
e1e6498215
@ -72,7 +72,7 @@ type (
|
|||||||
//获取用户回话
|
//获取用户回话
|
||||||
GetUserSession(uid string) *pb.CacheUser
|
GetUserSession(uid string) *pb.CacheUser
|
||||||
//查询用户属性值 例如 金币 经验
|
//查询用户属性值 例如 金币 经验
|
||||||
QueryAttributeValue(uid string, attr string) (value int32)
|
QueryAttributeValue(uid string, attr string) (value int64)
|
||||||
//添加/减少属性值 第四个参数控制是否推送给前端
|
//添加/减少属性值 第四个参数控制是否推送给前端
|
||||||
AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (code pb.ErrorCode)
|
AddAttributeValue(session IUserSession, attr string, add int32, bPush bool) (code pb.ErrorCode)
|
||||||
// 批量处理
|
// 批量处理
|
||||||
|
@ -26,7 +26,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
ChangeList []*pb.DBHero // 推送 改变的英雄
|
ChangeList []*pb.DBHero // 推送 改变的英雄
|
||||||
mapCostHero map[string]int32 // 消耗的技能卡
|
mapCostHero map[string]int32 // 消耗的技能卡
|
||||||
mapCostObj map[string]*pb.DBHero // 消耗的技能卡对象
|
mapCostObj map[string]*pb.DBHero // 消耗的技能卡对象
|
||||||
costGold int32 // 金币消耗
|
costGold int64 // 金币消耗
|
||||||
lvUpCount int32 // 技能升级的次数
|
lvUpCount int32 // 技能升级的次数
|
||||||
)
|
)
|
||||||
mapCostHero = make(map[string]int32, 0)
|
mapCostHero = make(map[string]int32, 0)
|
||||||
@ -76,7 +76,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
}
|
}
|
||||||
expConf := this.module.configure.GetHeroExp(costHero.HeroID) // 消耗多少金币
|
expConf := this.module.configure.GetHeroExp(costHero.HeroID) // 消耗多少金币
|
||||||
if expConf != nil {
|
if expConf != nil {
|
||||||
costGold += expConf.Needgold * v
|
costGold += int64(expConf.Needgold * v)
|
||||||
lvUpCount += expConf.Skilllevelup * v
|
lvUpCount += expConf.Skilllevelup * v
|
||||||
} else {
|
} else {
|
||||||
lvUpCount += v // 计算技能升级次数
|
lvUpCount += v // 计算技能升级次数
|
||||||
@ -115,7 +115,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
_hero.NormalSkill[szIndex[upSkillPos]].SkillLv += 1
|
_hero.NormalSkill[szIndex[upSkillPos]].SkillLv += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, -costGold, true)
|
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, -int32(costGold), true)
|
||||||
if code != pb.ErrorCode_Success { // 金币不足
|
if code != pb.ErrorCode_Success { // 金币不足
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
return
|
||||||
@ -124,7 +124,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt
|
|||||||
for k, v := range mapCostObj {
|
for k, v := range mapCostObj {
|
||||||
code = this.module.DelCard(session.GetUserId(), v, mapCostHero[k])
|
code = this.module.DelCard(session.GetUserId(), v, mapCostHero[k])
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, costGold, true)
|
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, int32(costGold), true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ChangeList = append(ChangeList, v)
|
ChangeList = append(ChangeList, v)
|
||||||
|
@ -107,7 +107,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr
|
|||||||
|
|
||||||
// 金币消耗判断
|
// 金币消耗判断
|
||||||
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), comm.ResGold)
|
curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), comm.ResGold)
|
||||||
if curGold < starConf.Gold { // 金币不足
|
if curGold < int64(starConf.Gold) { // 金币不足
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
addExp int32 // 需要增加的经验
|
addExp int32 // 需要增加的经验
|
||||||
costGold int32 // 需要消耗的资源
|
costGold int64 // 需要消耗的资源
|
||||||
_hero *pb.DBHero // 目标英雄
|
_hero *pb.DBHero // 目标英雄
|
||||||
_costExpHero map[string]*pb.DBHero // 消耗英雄
|
_costExpHero map[string]*pb.DBHero // 消耗英雄
|
||||||
minAddExp int32
|
minAddExp int32
|
||||||
@ -76,8 +76,8 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
if expConf != nil {
|
if expConf != nil {
|
||||||
addExp += expConf.Heroexp * v
|
addExp += expConf.Heroexp * v
|
||||||
}
|
}
|
||||||
costGold += expConf.Needgold * v // 需要消耗的金币
|
costGold += int64(expConf.Needgold * v) // 需要消耗的金币
|
||||||
if _expHero.SameCount < v { // 消耗经验卡片数量不足
|
if _expHero.SameCount < v { // 消耗经验卡片数量不足
|
||||||
code = pb.ErrorCode_HeroNoEnough
|
code = pb.ErrorCode_HeroNoEnough
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
}
|
}
|
||||||
iLvUp := _hero.Lv - curLv
|
iLvUp := _hero.Lv - curLv
|
||||||
// 消耗金币
|
// 消耗金币
|
||||||
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, -costGold, true)
|
code = this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, -int32(costGold), true)
|
||||||
if code != pb.ErrorCode_Success { // 金币不足
|
if code != pb.ErrorCode_Success { // 金币不足
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
return
|
||||||
@ -123,7 +123,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren
|
|||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
code = pb.ErrorCode_HeroNoEnough
|
code = pb.ErrorCode_HeroNoEnough
|
||||||
this.module.Errorf("delete err failed err:%T!", err1)
|
this.module.Errorf("delete err failed err:%T!", err1)
|
||||||
this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, costGold, true) // 回退金币
|
this.module.ModuleUser.AddAttributeValue(session, comm.ResGold, int32(costGold), true) // 回退金币
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_changeHero = append(_changeHero, _costExpHero[k])
|
_changeHero = append(_changeHero, _costExpHero[k])
|
||||||
|
@ -165,9 +165,6 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa
|
|||||||
|
|
||||||
// 只校验资源 参数 atn格式
|
// 只校验资源 参数 atn格式
|
||||||
func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) (code pb.ErrorCode) {
|
func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) (code pb.ErrorCode) {
|
||||||
var (
|
|
||||||
amount int32
|
|
||||||
)
|
|
||||||
|
|
||||||
source := &comm.ModuleCallSource{
|
source := &comm.ModuleCallSource{
|
||||||
Module: string(this.module.GetType()),
|
Module: string(this.module.GetType()),
|
||||||
@ -177,7 +174,7 @@ func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn)
|
|||||||
//校验消费资源是否充足
|
//校验消费资源是否充足
|
||||||
for _, v := range res {
|
for _, v := range res {
|
||||||
if v.A == comm.AttrType { //用户属性资源
|
if v.A == comm.AttrType { //用户属性资源
|
||||||
if amount = this.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T); amount < v.N {
|
if amount := this.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T); amount < int64(v.N) {
|
||||||
code = pb.ErrorCode_ResNoEnough
|
code = pb.ErrorCode_ResNoEnough
|
||||||
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
||||||
return
|
return
|
||||||
@ -187,7 +184,7 @@ func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn)
|
|||||||
// code = pb.ErrorCode_ConfigurationException
|
// code = pb.ErrorCode_ConfigurationException
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
if amount = int32(this.ModuleItems.QueryItemAmount(source, session.GetUserId(), v.T)); amount < v.N {
|
if amount := this.ModuleItems.QueryItemAmount(source, session.GetUserId(), v.T); amount < uint32(v.N) {
|
||||||
code = pb.ErrorCode_ResNoEnough
|
code = pb.ErrorCode_ResNoEnough
|
||||||
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N)
|
||||||
return
|
return
|
||||||
@ -223,7 +220,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn
|
|||||||
}
|
}
|
||||||
// 校验数量
|
// 校验数量
|
||||||
for k, v := range attrs {
|
for k, v := range attrs {
|
||||||
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -v { // -v 负负得正
|
if this.ModuleUser.QueryAttributeValue(session.GetUserId(), k) < -int64(v) { // -v 负负得正
|
||||||
code = pb.ErrorCode_ResNoEnough
|
code = pb.ErrorCode_ResNoEnough
|
||||||
this.Errorf("资源不足: A: attr, T: %s, N: %d", k, v)
|
this.Errorf("资源不足: A: attr, T: %s, N: %d", k, v)
|
||||||
return
|
return
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
package user
|
|
||||||
|
|
||||||
import (
|
|
||||||
"go_dreamfactory/comm"
|
|
||||||
"go_dreamfactory/pb"
|
|
||||||
"go_dreamfactory/utils"
|
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
|
||||||
)
|
|
||||||
|
|
||||||
// 主角形象设置
|
|
||||||
|
|
||||||
func (this *apiComp) FigureCheck(session comm.IUserSession, req *pb.UserFigureReq) (code pb.ErrorCode) {
|
|
||||||
if req.Preinstall < 1 || req.Preinstall > 5 || req.Action < 0 ||
|
|
||||||
req.Hair == nil || req.Eyes == nil || req.Mouth == nil || req.Body == nil || req.Complexion == nil {
|
|
||||||
code = pb.ErrorCode_ReqParameterError
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *apiComp) Figure(session comm.IUserSession, req *pb.UserFigureReq) (code pb.ErrorCode, data proto.Message) {
|
|
||||||
if code = this.FigureCheck(session, req); code != pb.ErrorCode_Success {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
expand, err := this.module.modelExpand.GetUserExpand(session.GetUserId())
|
|
||||||
if err != nil {
|
|
||||||
code = pb.ErrorCode_DBError
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//当前形象
|
|
||||||
var curFigure *pb.Figure
|
|
||||||
if v, ok := expand.Preinstall[req.Preinstall]; ok {
|
|
||||||
curFigure = v
|
|
||||||
} else {
|
|
||||||
//TODO 设置默认形象
|
|
||||||
curFigure = &pb.Figure{}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rsp := &pb.UserFigureResp{
|
|
||||||
Uid: session.GetUserId(),
|
|
||||||
Action: req.Action,
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Action == 0 {
|
|
||||||
//直接返回预设形象
|
|
||||||
rsp.Figure = curFigure
|
|
||||||
} else {
|
|
||||||
update := make(map[string]interface{})
|
|
||||||
switch req.Action {
|
|
||||||
// 头发
|
|
||||||
case 1:
|
|
||||||
if req.Hair != nil {
|
|
||||||
curFigure.Hair = req.Hair
|
|
||||||
}
|
|
||||||
// 眼睛
|
|
||||||
case 2:
|
|
||||||
if req.Eyes != nil {
|
|
||||||
curFigure.Eyes = req.Eyes
|
|
||||||
}
|
|
||||||
// 嘴巴
|
|
||||||
case 3:
|
|
||||||
if req.Mouth != nil {
|
|
||||||
curFigure.Mouth = req.Mouth
|
|
||||||
}
|
|
||||||
// 体型
|
|
||||||
case 4:
|
|
||||||
if req.Body != nil {
|
|
||||||
curFigure.Body = req.Body
|
|
||||||
}
|
|
||||||
// 肤色
|
|
||||||
case 5:
|
|
||||||
if req.Complexion != nil {
|
|
||||||
curFigure.Complexion = req.Complexion
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
code = pb.ErrorCode_ReqParameterError
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
update = utils.StructToMap(curFigure)
|
|
||||||
|
|
||||||
this.module.modelExpand.ChangeUserExpand(session.GetUserId(), update)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeFigure, rsp); err != nil {
|
|
||||||
code = pb.ErrorCode_SystemError
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
48
modules/user/api_modifyavatar.go
Normal file
48
modules/user/api_modifyavatar.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 修改主角头像
|
||||||
|
|
||||||
|
func (this *apiComp) ModifyavatarCheck(session comm.IUserSession, req *pb.UserModifyavatarReq) (code pb.ErrorCode) {
|
||||||
|
if req.AvatarId == "" {
|
||||||
|
code = pb.ErrorCode_ReqParameterError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *apiComp) Modifyavatar(session comm.IUserSession, req *pb.UserModifyavatarReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
|
if code = this.ModifyavatarCheck(session, req); code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := this.module.GetUser(session.GetUserId())
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
code = pb.ErrorCode_UserSessionNobeing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
update := map[string]interface{}{
|
||||||
|
"avatar": req.AvatarId,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeModifyName, &pb.UserModifyavatarResp{
|
||||||
|
Uid: session.GetUserId(),
|
||||||
|
AvatarId: req.AvatarId,
|
||||||
|
}); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
45
modules/user/api_modifybgp.go
Normal file
45
modules/user/api_modifybgp.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *apiComp) ModifybgpCheck(session comm.IUserSession, req *pb.UserModifybgpReq) (code pb.ErrorCode) {
|
||||||
|
if req.BgpId == 0 {
|
||||||
|
code = pb.ErrorCode_ReqParameterError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *apiComp) Modifybgp(session comm.IUserSession, req *pb.UserModifybgpReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
|
if code = this.ModifybgpCheck(session, req); code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := this.module.GetUser(session.GetUserId())
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
code = pb.ErrorCode_UserSessionNobeing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
update := map[string]interface{}{
|
||||||
|
"bgp": req.BgpId,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeModifyName, &pb.UserModifybgpResp{
|
||||||
|
Uid: session.GetUserId(),
|
||||||
|
BgpId: req.BgpId,
|
||||||
|
}); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
46
modules/user/api_modifyfigure.go
Normal file
46
modules/user/api_modifyfigure.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (this *apiComp) ModifyfigureCheck(session comm.IUserSession, req *pb.UserModifyfigureReq) (code pb.ErrorCode) {
|
||||||
|
if req.FigureId == 0 {
|
||||||
|
code = pb.ErrorCode_ReqParameterError
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *apiComp) Modifyfigure(session comm.IUserSession, req *pb.UserModifyfigureReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
|
if code = this.ModifyfigureCheck(session, req); code != pb.ErrorCode_Success {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := this.module.GetUser(session.GetUserId())
|
||||||
|
|
||||||
|
if user == nil {
|
||||||
|
code = pb.ErrorCode_UserSessionNobeing
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
update := map[string]interface{}{
|
||||||
|
"figure": req.FigureId,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := this.module.modelUser.Change(session.GetUserId(), update); err != nil {
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := session.SendMsg(string(this.module.GetType()), UserSubTypeModifyName, &pb.UserModifyfigureResp{
|
||||||
|
Uid: session.GetUserId(),
|
||||||
|
FigureId: req.FigureId,
|
||||||
|
}); err != nil {
|
||||||
|
code = pb.ErrorCode_SystemError
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
@ -3,7 +3,6 @@ package user
|
|||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
@ -34,16 +33,15 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalCnf := this.module.configure.GetGlobalAtnConf("hero_name")
|
||||||
|
if globalCnf == nil {
|
||||||
|
code = pb.ErrorCode_ConfigNoFound
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
//校验名称修改次数
|
//校验名称修改次数
|
||||||
if expand.ModifynameCount <= 0 {
|
if expand.ModifynameCount <= 0 {
|
||||||
//TODO 从全局配置从读取消耗道具
|
if code = this.module.ConsumeRes(session, globalCnf.Var, true); code != pb.ErrorCode_Success {
|
||||||
if code = this.module.ConsumeRes(session, []*cfg.Gameatn{
|
|
||||||
{
|
|
||||||
A: "attr",
|
|
||||||
T: "gold",
|
|
||||||
N: 5000,
|
|
||||||
},
|
|
||||||
}, true); code != pb.ErrorCode_Success {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,28 +129,6 @@ func (this *ModelUser) modifyName(uid string, newName string) (code pb.ErrorCode
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化玩家形象
|
|
||||||
func (this *ModelUser) InitFigure(uid string) {
|
|
||||||
figureMap := make(map[int32]interface{})
|
|
||||||
for _, v := range this.module.configure.GetPlayerFigureConf() {
|
|
||||||
|
|
||||||
figure := &pb.Figure{
|
|
||||||
Hair: &pb.Hair{Color: v.Figure[0].Color},
|
|
||||||
Eyes: &pb.Eyes{Color: v.Figure[0].Color},
|
|
||||||
Mouth: &pb.Mouth{},
|
|
||||||
Body: &pb.Body{},
|
|
||||||
Complexion: &pb.Complexion{},
|
|
||||||
}
|
|
||||||
|
|
||||||
figureMap[v.Id] = figure
|
|
||||||
}
|
|
||||||
|
|
||||||
update := map[string]interface{}{
|
|
||||||
"preinstall": figureMap,
|
|
||||||
}
|
|
||||||
this.module.modelExpand.ChangeUserExpand(uid, update)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *ModelUser) updateOfflineTime(uid string) {
|
func (this *ModelUser) updateOfflineTime(uid string) {
|
||||||
if err := this.updateUserAttr(uid, map[string]interface{}{"offlinetime": time.Now().Unix()}); err != nil {
|
if err := this.updateUserAttr(uid, map[string]interface{}{"offlinetime": time.Now().Unix()}); err != nil {
|
||||||
this.module.Errorln(err)
|
this.module.Errorln(err)
|
||||||
@ -170,7 +148,7 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{
|
|||||||
curLv := ul.lv
|
curLv := ul.lv
|
||||||
//下一等级配置
|
//下一等级配置
|
||||||
nextLvConf := this.module.configure.GetPlayerlvConf(curLv + 1)
|
nextLvConf := this.module.configure.GetPlayerlvConf(curLv + 1)
|
||||||
for nextLvConf != nil && ul.exp >= nextLvConf.Exp {
|
for nextLvConf != nil && ul.exp >= int64(nextLvConf.Exp) {
|
||||||
curLv++
|
curLv++
|
||||||
nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1)
|
nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1)
|
||||||
}
|
}
|
||||||
@ -192,6 +170,6 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{
|
|||||||
type UserListen struct {
|
type UserListen struct {
|
||||||
event_v2.Event
|
event_v2.Event
|
||||||
session comm.IUserSession
|
session comm.IUserSession
|
||||||
exp int32
|
exp int64
|
||||||
lv int32
|
lv int32
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (this *User) UserOnlineList() ([]*pb.CacheUser, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//查询用户属性值 例如 金币 经验
|
//查询用户属性值 例如 金币 经验
|
||||||
func (this *User) QueryAttributeValue(uid string, attr string) (value int32) {
|
func (this *User) QueryAttributeValue(uid string, attr string) (value int64) {
|
||||||
user := this.modelUser.GetUser(uid)
|
user := this.modelUser.GetUser(uid)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
return
|
return
|
||||||
@ -136,28 +136,28 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha
|
|||||||
switch attr {
|
switch attr {
|
||||||
case comm.ResGold:
|
case comm.ResGold:
|
||||||
if add < 0 {
|
if add < 0 {
|
||||||
if user.Gold+add < 0 {
|
if user.Gold+int64(add) < 0 {
|
||||||
code = pb.ErrorCode_GoldNoEnough
|
code = pb.ErrorCode_GoldNoEnough
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
change.Gold += add
|
change.Gold += int64(add)
|
||||||
case comm.ResExp:
|
case comm.ResExp:
|
||||||
if add < 0 {
|
if add < 0 {
|
||||||
if user.Exp+add < 0 {
|
if user.Exp+int64(add) < 0 {
|
||||||
code = pb.ErrorCode_UserExpNoEnough
|
code = pb.ErrorCode_UserExpNoEnough
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
change.Exp += add
|
change.Exp += int64(add)
|
||||||
case comm.ResDiamond:
|
case comm.ResDiamond:
|
||||||
if add < 0 {
|
if add < 0 {
|
||||||
if user.Diamond+add < 0 {
|
if user.Diamond+int64(add) < 0 {
|
||||||
code = pb.ErrorCode_DiamondNoEnough
|
code = pb.ErrorCode_DiamondNoEnough
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
change.Diamond += add
|
change.Diamond += int64(add)
|
||||||
case comm.ResFriend:
|
case comm.ResFriend:
|
||||||
if add < 0 {
|
if add < 0 {
|
||||||
if userEx.FriendPoint+add < 0 {
|
if userEx.FriendPoint+add < 0 {
|
||||||
|
@ -151,11 +151,11 @@ type DBHero struct {
|
|||||||
IsOverlying bool `protobuf:"varint,23,opt,name=isOverlying,proto3" json:"isOverlying"` // go_tags(`bson:"isOverlying"`) 是否允许叠加 默认true
|
IsOverlying bool `protobuf:"varint,23,opt,name=isOverlying,proto3" json:"isOverlying"` // go_tags(`bson:"isOverlying"`) 是否允许叠加 默认true
|
||||||
EnergyProperty map[string]int32 `protobuf:"bytes,24,rep,name=energyProperty,proto3" json:"energyProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"energyProperty"` //
|
EnergyProperty map[string]int32 `protobuf:"bytes,24,rep,name=energyProperty,proto3" json:"energyProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"energyProperty"` //
|
||||||
JuexProperty map[string]int32 `protobuf:"bytes,25,rep,name=juexProperty,proto3" json:"juexProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"juexProperty"` ////hp
|
JuexProperty map[string]int32 `protobuf:"bytes,25,rep,name=juexProperty,proto3" json:"juexProperty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"juexProperty"` ////hp
|
||||||
Status HeroType `protobuf:"varint,26,opt,name=status,proto3,enum=HeroType" json:"status" bson:"status"` //状态 (1 练功)
|
Status HeroType `protobuf:"varint,26,opt,name=status,proto3,enum=HeroType" json:"status" bson:"heroType"` //状态 (1 练功)
|
||||||
Suite1Star int32 `protobuf:"varint,27,opt,name=suite1Star,proto3" json:"suite1Star" bson:"suite1Star"` //
|
Suite1Star int32 `protobuf:"varint,27,opt,name=suite1Star,proto3" json:"suite1Star"`
|
||||||
Suite2Star int32 `protobuf:"varint,28,opt,name=suite2Star,proto3" json:"suite2Star" bson:"suite2Star"`
|
Suite2Star int32 `protobuf:"varint,28,opt,name=suite2Star,proto3" json:"suite2Star"`
|
||||||
Suite1Lv int32 `protobuf:"varint,29,opt,name=suite1Lv,proto3" json:"suite1Lv" bson:"suite1Lv"`
|
Suite1Lv int32 `protobuf:"varint,29,opt,name=suite1Lv,proto3" json:"suite1Lv"`
|
||||||
Suite2Lv int32 `protobuf:"varint,30,opt,name=suite2Lv,proto3" json:"suite2Lv" bson:"suite2Lv"`
|
Suite2Lv int32 `protobuf:"varint,30,opt,name=suite2Lv,proto3" json:"suite2Lv"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *DBHero) Reset() {
|
func (x *DBHero) Reset() {
|
||||||
|
@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/now"
|
"github.com/jinzhu/now"
|
||||||
@ -39,7 +40,9 @@ func IsYestoday(timestamp int64) bool {
|
|||||||
return tt.Year() == yesTime.Year() && tt.Month() == yesTime.Month() && tt.Day() == yesTime.Day()
|
return tt.Year() == yesTime.Year() && tt.Month() == yesTime.Month() && tt.Day() == yesTime.Day()
|
||||||
}
|
}
|
||||||
|
|
||||||
func MatrixingHour(beginTime string) {
|
// 确定换算规则 现实1H = 虚拟4H
|
||||||
|
// 计算:根据开服时间为起始时间,计算当前时间与起始时间的差值,计算虚拟当前时间
|
||||||
|
func MatrixingHour(beginTime string) (t time.Time) {
|
||||||
location, err := time.LoadLocation("Asia/Shanghai")
|
location, err := time.LoadLocation("Asia/Shanghai")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -50,6 +53,17 @@ func MatrixingHour(beginTime string) {
|
|||||||
TimeFormats: []string{"2006-01-02 15:04:05"},
|
TimeFormats: []string{"2006-01-02 15:04:05"},
|
||||||
}
|
}
|
||||||
|
|
||||||
t, _ := myConfig.Parse(beginTime)
|
serverStartTime, _ := myConfig.Parse(beginTime)
|
||||||
fmt.Println(t)
|
|
||||||
|
n := time.Now()
|
||||||
|
timeSub := n.Sub(serverStartTime)
|
||||||
|
hourSub := timeSub.Hours() * 2
|
||||||
|
|
||||||
|
hh, _ := time.ParseDuration("1h")
|
||||||
|
fmt.Println(hourSub, math.Ceil(hourSub))
|
||||||
|
t2 := serverStartTime.Add(hh * time.Duration(math.Ceil(hourSub)))
|
||||||
|
|
||||||
|
fmt.Println(t2)
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,3 +71,7 @@ func BenchmarkInt32ToString(b *testing.B) {
|
|||||||
cast.ToString(a)
|
cast.ToString(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatrxing(t *testing.T) {
|
||||||
|
utils.MatrixingHour("2022-10-11 00:00:00")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user