diff --git a/comm/imodule.go b/comm/imodule.go index 57e56775f..45d6af077 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -72,7 +72,7 @@ type ( //获取用户回话 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) // 批量处理 diff --git a/modules/hero/api_strengthenUpSkill.go b/modules/hero/api_strengthenUpSkill.go index 3ef87333c..6524d7ab0 100644 --- a/modules/hero/api_strengthenUpSkill.go +++ b/modules/hero/api_strengthenUpSkill.go @@ -26,7 +26,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt ChangeList []*pb.DBHero // 推送 改变的英雄 mapCostHero map[string]int32 // 消耗的技能卡 mapCostObj map[string]*pb.DBHero // 消耗的技能卡对象 - costGold int32 // 金币消耗 + costGold int64 // 金币消耗 lvUpCount int32 // 技能升级的次数 ) 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) // 消耗多少金币 if expConf != nil { - costGold += expConf.Needgold * v + costGold += int64(expConf.Needgold * v) lvUpCount += expConf.Skilllevelup * v } else { lvUpCount += v // 计算技能升级次数 @@ -115,7 +115,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt _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 { // 金币不足 code = pb.ErrorCode_GoldNoEnough return @@ -124,7 +124,7 @@ func (this *apiComp) StrengthenUpSkill(session comm.IUserSession, req *pb.HeroSt for k, v := range mapCostObj { code = this.module.DelCard(session.GetUserId(), v, mapCostHero[k]) 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 } ChangeList = append(ChangeList, v) diff --git a/modules/hero/api_strengthenUpStar.go b/modules/hero/api_strengthenUpStar.go index 55cc8145d..5e3c4c8c9 100644 --- a/modules/hero/api_strengthenUpStar.go +++ b/modules/hero/api_strengthenUpStar.go @@ -107,7 +107,7 @@ func (this *apiComp) StrengthenUpStar(session comm.IUserSession, req *pb.HeroStr // 金币消耗判断 curGold := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), comm.ResGold) - if curGold < starConf.Gold { // 金币不足 + if curGold < int64(starConf.Gold) { // 金币不足 code = pb.ErrorCode_GoldNoEnough return } diff --git a/modules/hero/api_strengthenUplv.go b/modules/hero/api_strengthenUplv.go index 15d2a45bb..235d177a4 100644 --- a/modules/hero/api_strengthenUplv.go +++ b/modules/hero/api_strengthenUplv.go @@ -28,7 +28,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren var ( addExp int32 // 需要增加的经验 - costGold int32 // 需要消耗的资源 + costGold int64 // 需要消耗的资源 _hero *pb.DBHero // 目标英雄 _costExpHero map[string]*pb.DBHero // 消耗英雄 minAddExp int32 @@ -76,8 +76,8 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren if expConf != nil { addExp += expConf.Heroexp * v } - costGold += expConf.Needgold * v // 需要消耗的金币 - if _expHero.SameCount < v { // 消耗经验卡片数量不足 + costGold += int64(expConf.Needgold * v) // 需要消耗的金币 + if _expHero.SameCount < v { // 消耗经验卡片数量不足 code = pb.ErrorCode_HeroNoEnough return } @@ -111,7 +111,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren } 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 { // 金币不足 code = pb.ErrorCode_GoldNoEnough return @@ -123,7 +123,7 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren if err1 != nil { code = pb.ErrorCode_HeroNoEnough 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 } _changeHero = append(_changeHero, _costExpHero[k]) diff --git a/modules/modulebase.go b/modules/modulebase.go index 90678536a..c54d687f9 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -165,9 +165,6 @@ func (this *ModuleBase) SendMsgToUsers(mainType, subType string, msg proto.Messa // 只校验资源 参数 atn格式 func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) (code pb.ErrorCode) { - var ( - amount int32 - ) source := &comm.ModuleCallSource{ Module: string(this.module.GetType()), @@ -177,7 +174,7 @@ func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) //校验消费资源是否充足 for _, v := range res { 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 this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N) return @@ -187,7 +184,7 @@ func (this *ModuleBase) CheckRes(session comm.IUserSession, res []*cfg.Gameatn) // code = pb.ErrorCode_ConfigurationException // 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 this.Errorf("道具不足:A:%s,T:%s,N:%d", v.A, v.T, v.N) return @@ -223,7 +220,7 @@ func (this *ModuleBase) ConsumeRes(session comm.IUserSession, res []*cfg.Gameatn } // 校验数量 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 this.Errorf("资源不足: A: attr, T: %s, N: %d", k, v) return diff --git a/modules/user/api_figure.go b/modules/user/api_figure.go deleted file mode 100644 index de3eefa38..000000000 --- a/modules/user/api_figure.go +++ /dev/null @@ -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 -} diff --git a/modules/user/api_modifyavatar.go b/modules/user/api_modifyavatar.go new file mode 100644 index 000000000..b78f16bf8 --- /dev/null +++ b/modules/user/api_modifyavatar.go @@ -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 +} diff --git a/modules/user/api_modifybgp.go b/modules/user/api_modifybgp.go new file mode 100644 index 000000000..e0e614c20 --- /dev/null +++ b/modules/user/api_modifybgp.go @@ -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 +} diff --git a/modules/user/api_modifyfigure.go b/modules/user/api_modifyfigure.go new file mode 100644 index 000000000..d4cd6cda6 --- /dev/null +++ b/modules/user/api_modifyfigure.go @@ -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 +} diff --git a/modules/user/api_modifyname.go b/modules/user/api_modifyname.go index 9b7bb927d..41e3cb44d 100644 --- a/modules/user/api_modifyname.go +++ b/modules/user/api_modifyname.go @@ -3,7 +3,6 @@ package user import ( "go_dreamfactory/comm" "go_dreamfactory/pb" - cfg "go_dreamfactory/sys/configure/structs" "strings" "google.golang.org/protobuf/proto" @@ -34,16 +33,15 @@ func (this *apiComp) Modifyname(session comm.IUserSession, req *pb.UserModifynam return } + globalCnf := this.module.configure.GetGlobalAtnConf("hero_name") + if globalCnf == nil { + code = pb.ErrorCode_ConfigNoFound + return + } + //校验名称修改次数 if expand.ModifynameCount <= 0 { - //TODO 从全局配置从读取消耗道具 - if code = this.module.ConsumeRes(session, []*cfg.Gameatn{ - { - A: "attr", - T: "gold", - N: 5000, - }, - }, true); code != pb.ErrorCode_Success { + if code = this.module.ConsumeRes(session, globalCnf.Var, true); code != pb.ErrorCode_Success { return } } diff --git a/modules/user/model_user.go b/modules/user/model_user.go index abebdd3b9..361476666 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -129,28 +129,6 @@ func (this *ModelUser) modifyName(uid string, newName string) (code pb.ErrorCode 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) { if err := this.updateUserAttr(uid, map[string]interface{}{"offlinetime": time.Now().Unix()}); err != nil { this.module.Errorln(err) @@ -170,7 +148,7 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{ curLv := ul.lv //下一等级配置 nextLvConf := this.module.configure.GetPlayerlvConf(curLv + 1) - for nextLvConf != nil && ul.exp >= nextLvConf.Exp { + for nextLvConf != nil && ul.exp >= int64(nextLvConf.Exp) { curLv++ nextLvConf = this.module.configure.GetPlayerlvConf(curLv + 1) } @@ -192,6 +170,6 @@ func (this *ModelUser) ChangeLevel(event interface{}, next func(event interface{ type UserListen struct { event_v2.Event session comm.IUserSession - exp int32 + exp int64 lv int32 } diff --git a/modules/user/module.go b/modules/user/module.go index 50e16af4b..0aab830e1 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -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) if user == nil { return @@ -136,28 +136,28 @@ func (this *User) change(session comm.IUserSession, attr string, add int32) (cha switch attr { case comm.ResGold: if add < 0 { - if user.Gold+add < 0 { + if user.Gold+int64(add) < 0 { code = pb.ErrorCode_GoldNoEnough return } } - change.Gold += add + change.Gold += int64(add) case comm.ResExp: if add < 0 { - if user.Exp+add < 0 { + if user.Exp+int64(add) < 0 { code = pb.ErrorCode_UserExpNoEnough return } } - change.Exp += add + change.Exp += int64(add) case comm.ResDiamond: if add < 0 { - if user.Diamond+add < 0 { + if user.Diamond+int64(add) < 0 { code = pb.ErrorCode_DiamondNoEnough return } } - change.Diamond += add + change.Diamond += int64(add) case comm.ResFriend: if add < 0 { if userEx.FriendPoint+add < 0 { diff --git a/pb/hero_db.pb.go b/pb/hero_db.pb.go index 1ccf64cab..c005dade1 100644 --- a/pb/hero_db.pb.go +++ b/pb/hero_db.pb.go @@ -151,11 +151,11 @@ type DBHero struct { 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"` // 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 练功) - Suite1Star int32 `protobuf:"varint,27,opt,name=suite1Star,proto3" json:"suite1Star" bson:"suite1Star"` // - Suite2Star int32 `protobuf:"varint,28,opt,name=suite2Star,proto3" json:"suite2Star" bson:"suite2Star"` - Suite1Lv int32 `protobuf:"varint,29,opt,name=suite1Lv,proto3" json:"suite1Lv" bson:"suite1Lv"` - Suite2Lv int32 `protobuf:"varint,30,opt,name=suite2Lv,proto3" json:"suite2Lv" bson:"suite2Lv"` + 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"` + Suite2Star int32 `protobuf:"varint,28,opt,name=suite2Star,proto3" json:"suite2Star"` + Suite1Lv int32 `protobuf:"varint,29,opt,name=suite1Lv,proto3" json:"suite1Lv"` + Suite2Lv int32 `protobuf:"varint,30,opt,name=suite2Lv,proto3" json:"suite2Lv"` } func (x *DBHero) Reset() { diff --git a/utils/time.go b/utils/time.go index ff7cb90cc..44847652a 100644 --- a/utils/time.go +++ b/utils/time.go @@ -2,6 +2,7 @@ package utils import ( "fmt" + "math" "time" "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() } -func MatrixingHour(beginTime string) { +// 确定换算规则 现实1H = 虚拟4H +// 计算:根据开服时间为起始时间,计算当前时间与起始时间的差值,计算虚拟当前时间 +func MatrixingHour(beginTime string) (t time.Time) { location, err := time.LoadLocation("Asia/Shanghai") if err != nil { return @@ -50,6 +53,17 @@ func MatrixingHour(beginTime string) { TimeFormats: []string{"2006-01-02 15:04:05"}, } - t, _ := myConfig.Parse(beginTime) - fmt.Println(t) + serverStartTime, _ := myConfig.Parse(beginTime) + + 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 } diff --git a/utils/utils_test.go b/utils/utils_test.go index f064a5f84..e227c398c 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -71,3 +71,7 @@ func BenchmarkInt32ToString(b *testing.B) { cast.ToString(a) } } + +func TestMatrxing(t *testing.T) { + utils.MatrixingHour("2022-10-11 00:00:00") +}