Merge branch 'dev' of http://git.legu.cc/liwei_3d/go_dreamfactory into meixiongfeng

This commit is contained in:
meixiongfeng 2022-12-30 15:23:46 +08:00
commit da9fbe2622
9 changed files with 146 additions and 50 deletions

View File

@ -4,5 +4,5 @@ Website = "http://legu.cc"
Icon = "app.png" Icon = "app.png"
Name = "RobotGUI" Name = "RobotGUI"
ID = "cc.legu.app" ID = "cc.legu.app"
Version = "1.2.3" Version = "1.2.4"
Build = 31 Build = 32

View File

@ -12,6 +12,7 @@ import (
) )
const ( const (
equip_suit = "game_equipsuit.json" //装备套装表
new_hero = "game_hero.json" //英雄 new_hero = "game_hero.json" //英雄
hero_stargrow = "game_herostargrow.json" //英雄品质系数 hero_stargrow = "game_herostargrow.json" //英雄品质系数
hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数 hero_levelgrow = "game_herolevelgrow.json" //英雄成长系数
@ -51,6 +52,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
err = this.MCompConfigure.Init(service, module, comp, options) err = this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*Hero) this.module = module.(*Hero)
err = this.LoadMultiConfigure(map[string]interface{}{ err = this.LoadMultiConfigure(map[string]interface{}{
equip_suit: cfg.NewGameEquipSuit,
new_hero: cfg.NewGameHero, new_hero: cfg.NewGameHero,
hero_stargrow: cfg.NewGameHeroStargrow, hero_stargrow: cfg.NewGameHeroStargrow,
hero_levelgrow: cfg.NewGameHeroLevelgrow, hero_levelgrow: cfg.NewGameHeroLevelgrow,
@ -498,3 +500,19 @@ func (this *configureComp) GetHeroStargrowConfigByStar(star int32) int32 {
return 1 return 1
} }
// 获取英雄升级属性变化相关配置数据
func (this *configureComp) GetEquipsuit(id int32) (configure *cfg.GameEquipSuitData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(equip_suit); err == nil {
if configure, ok = v.(*cfg.GameEquipSuit).GetDataMap()[id]; !ok {
err = fmt.Errorf("%T no is *cfg.GameEquipSuit", v)
return
}
}
return
}

View File

@ -310,22 +310,6 @@ func (this *ModelHero) setEquipProperty(hero *pb.DBHero, equip []*pb.DB_Equipmen
for _, v := range v.AdverbEntry { for _, v := range v.AdverbEntry {
addProperty[v.AttrName] += v.Value + v.EnchValue //附加属性 addProperty[v.AttrName] += v.Value + v.EnchValue //附加属性
} }
for k, v := range addProperty {
switch k {
case comm.AtkPro:
addProperty[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Atk])))
addProperty[comm.AtkPro] = 0
case comm.DefPro:
addProperty[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Def])))
addProperty[comm.DefPro] = 0
case comm.HpPro:
addProperty[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Hp])))
addProperty[comm.HpPro] = 0
case comm.SpeedPro:
addProperty[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Speed])))
addProperty[comm.SpeedPro] = 0
}
}
if v.Adverbskill != nil { if v.Adverbskill != nil {
for _, v := range v.Adverbskill { for _, v := range v.Adverbskill {
equipSkill = append(equipSkill, &pb.SkillData{ equipSkill = append(equipSkill, &pb.SkillData{
@ -335,6 +319,37 @@ func (this *ModelHero) setEquipProperty(hero *pb.DBHero, equip []*pb.DB_Equipmen
} }
} }
} }
if hero.SuiteId != 0 { //套装
if configure, err := this.moduleHero.configure.GetEquipsuit(hero.SuiteId); err != nil {
this.moduleHero.Errorln(err)
} else {
for k, v := range configure.SetBonuses {
addProperty[k] += v
}
}
}
if hero.SuiteExtId != 0 { //套装
if configure, err := this.moduleHero.configure.GetEquipsuit(hero.SuiteExtId); err != nil {
this.moduleHero.Errorln(err)
} else {
for k, v := range configure.SetBonuses {
addProperty[k] += v
}
}
}
for k, v := range addProperty {
switch k {
case comm.AtkPro:
addProperty[comm.Atk] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Atk])))
case comm.DefPro:
addProperty[comm.Def] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Def])))
case comm.HpPro:
addProperty[comm.Hp] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Hp])))
case comm.SpeedPro:
addProperty[comm.Speed] += int32(math.Floor((float64(v) / 1000) * float64(hero.Property[comm.Speed])))
}
}
this.mergeAddProperty(hero.Uid, hero, addProperty, equipSkill) this.mergeAddProperty(hero.Uid, hero, addProperty, equipSkill)
} }

View File

@ -45,6 +45,7 @@ func (this *apiComp) BuyPhysical(session comm.IUserSession, req *pb.ItemsBuyPhys
if req.Amount+uint32(user.Physicalbuynum) > uint32(len(needs)) { if req.Amount+uint32(user.Physicalbuynum) > uint32(len(needs)) {
code = pb.ErrorCode_ItemsBuyPsUpperLimit code = pb.ErrorCode_ItemsBuyPsUpperLimit
return
} }
haveneeds = make([]*cfg.Gameatn, 0) haveneeds = make([]*cfg.Gameatn, 0)

View File

@ -9,7 +9,7 @@ import (
) )
//参数校验 //参数校验
func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode) { func (this *apiComp) DecomposeCheck(session comm.IUserSession, req *pb.ItemsDecomposeReq) (code pb.ErrorCode) {
if req.GridId == "" || req.Amount <= 0 { if req.GridId == "" || req.Amount <= 0 {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }
@ -17,14 +17,14 @@ func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellI
} }
//出售道具 //出售道具
func (this *apiComp) SellItem(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) Decompose(session comm.IUserSession, req *pb.ItemsDecomposeReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error err error
item *pb.DB_UserItemData item *pb.DB_UserItemData
itemcf *cfg.GameItemData itemcf *cfg.GameItemData
sale []*cfg.Gameatn sale []*cfg.Gameatn
) )
if code = this.SellItemCheck(session, req); code != pb.ErrorCode_Success { if code = this.DecomposeCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil { if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil {
@ -73,6 +73,6 @@ func (this *apiComp) SellItem(session comm.IUserSession, req *pb.ItemsSellItemRe
if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success { if code = this.module.AddItemforGrid(session, req.GridId, -1*int32(req.Amount), true); code != pb.ErrorCode_Success {
return return
} }
session.SendMsg(string(this.module.GetType()), "sellitem", &pb.ItemsSellItemResp{GridId: req.GridId, Amount: req.Amount, Issucc: true}) session.SendMsg(string(this.module.GetType()), "decompose", &pb.ItemsDecomposeResp{GridId: req.GridId, Amount: req.Amount, Issucc: true})
return return
} }

View File

@ -9,22 +9,22 @@ import (
) )
//参数校验 //参数校验
func (this *apiComp) DecomposeCheck(session comm.IUserSession, req *pb.ItemsDecomposeReq) (code pb.ErrorCode) { func (this *apiComp) SellItemCheck(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode) {
if req.GridId == "" || req.Amount <= 0 { if req.GridId == "" || req.Amount <= 0 {
code = pb.ErrorCode_ReqParameterError code = pb.ErrorCode_ReqParameterError
} }
return return
} }
//出售道具 //分解道具
func (this *apiComp) Decompose(session comm.IUserSession, req *pb.ItemsDecomposeReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) SellItem(session comm.IUserSession, req *pb.ItemsSellItemReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
err error err error
item *pb.DB_UserItemData item *pb.DB_UserItemData
itemcf *cfg.GameItemData itemcf *cfg.GameItemData
sale []*cfg.Gameatn sale []*cfg.Gameatn
) )
if code = this.DecomposeCheck(session, req); code != pb.ErrorCode_Success { if code = this.SellItemCheck(session, req); code != pb.ErrorCode_Success {
return return
} }
if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil { if item, err = this.module.modelItems.QueryUserPackByGridId(session.GetUserId(), req.GridId); err != nil {
@ -44,7 +44,7 @@ func (this *apiComp) Decompose(session comm.IUserSession, req *pb.ItemsDecompose
this.module.Errorf("SellItemCheck over all amount:[%d:%d]", req.Amount, item.Amount) this.module.Errorf("SellItemCheck over all amount:[%d:%d]", req.Amount, item.Amount)
return return
} }
sale = make([]*cfg.Gameatn, len(itemcf.Sale)) sale = make([]*cfg.Gameatn, len(itemcf.DecomposeDeplete))
for i, v := range itemcf.Sale { for i, v := range itemcf.Sale {
temp := *v temp := *v
sale[i] = &temp sale[i] = &temp

View File

@ -12,6 +12,7 @@ import (
"go_dreamfactory/sys/db" "go_dreamfactory/sys/db"
"go_dreamfactory/utils" "go_dreamfactory/utils"
"strings" "strings"
"sync"
"time" "time"
"go_dreamfactory/lego/base" "go_dreamfactory/lego/base"
@ -55,6 +56,8 @@ type User struct {
configure *configureComp configure *configureComp
globalConf *cfg.GameGlobalData globalConf *cfg.GameGlobalData
modelSign *ModelSign // 签到 modelSign *ModelSign // 签到
timerLock sync.Mutex
timerMap map[string]*time.Ticker
} }
func (this *User) GetType() core.M_Modules { func (this *User) GetType() core.M_Modules {
@ -64,6 +67,7 @@ func (this *User) GetType() core.M_Modules {
func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { func (this *User) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options) err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService) this.service = service.(base.IRPCXService)
this.timerMap = make(map[string]*time.Ticker)
return return
} }
@ -78,6 +82,7 @@ func (this *User) Start() (err error) {
if this.globalConf == nil { if this.globalConf == nil {
err = errors.New("global config not found") err = errors.New("global config not found")
} }
this.ResetSession()
return return
} }
@ -132,8 +137,20 @@ func (this *User) GetUserSession(uid string) *pb.CacheUser {
return this.modelSession.getUserSession(uid) return this.modelSession.getUserSession(uid)
} }
func (this *User) ResetSession() {
us, err := this.UserOnlineList()
if err != nil {
return
}
for _, v := range us {
this.modelSession.DelListlds(comm.RDS_EMPTY, v.Uid)
}
}
// 清除session // 清除session
func (this *User) CleanSession(session comm.IUserSession) { func (this *User) CleanSession(session comm.IUserSession) {
this.stopTicker(session.GetUserId())
if !this.IsCross() { if !this.IsCross() {
this.modelUser.updateOfflineTime(session.GetUserId()) this.modelUser.updateOfflineTime(session.GetUserId())
} }
@ -615,9 +632,29 @@ func (this *User) BingoSetUserLv(session comm.IUserSession, lv int32) error {
return nil return nil
} }
func (this *User) Update() {
if this.IsCross() {
return
}
cu, err := this.UserOnlineList()
if err != nil {
return
}
for _, v := range cu {
if isession, ok := this.ModuleBase.GetUserSession(v.Uid); ok {
//del session
log.Debug("del session", log.Field{Key: "uid", Value: v.Uid}, log.Field{Key: "isLogin", Value: isession.IsLogin()})
}
}
}
func (this *User) RecoverUserVitStart(uid string) { func (this *User) RecoverUserVitStart(uid string) {
go func(uid string) { go func(uid string) {
timeSec := time.NewTicker(time.Second * 30) timeSec := time.NewTicker(time.Second * 30)
this.timerLock.Lock()
this.timerMap[uid] = timeSec
this.timerLock.Unlock()
for { for {
select { select {
case <-timeSec.C: case <-timeSec.C:
@ -627,6 +664,15 @@ func (this *User) RecoverUserVitStart(uid string) {
}(uid) }(uid)
} }
func (this *User) stopTicker(uid string) {
if t, ok := this.timerMap[uid]; ok {
if t != nil {
t.Stop()
delete(this.timerMap, uid)
}
}
}
// 玩家体力恢复 // 玩家体力恢复
func (this *User) recoverUserVit(uid string) { func (this *User) recoverUserVit(uid string) {
if this.IsCross() { if this.IsCross() {
@ -642,7 +688,11 @@ func (this *User) recoverUserVit(uid string) {
return return
} }
var yu int32 var (
yu int32
add int32
changed int32
)
cur := time.Now().Unix() cur := time.Now().Unix()
if u.LastRecoverVitSec == 0 { if u.LastRecoverVitSec == 0 {
update := map[string]interface{}{ update := map[string]interface{}{
@ -660,19 +710,31 @@ func (this *User) recoverUserVit(uid string) {
if pconf == nil { if pconf == nil {
return return
} }
total := u.Ps + yu if u.Ps < pconf.PsCeiling {
if total <= pconf.PsCeiling { total := u.Ps + yu
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok { if total > pconf.PsCeiling {
if code := this.AddAttributeValue(isession, comm.ResPs, yu, false); code == pb.ErrorCode_Success { add = pconf.PsCeiling - u.Ps
update := map[string]interface{}{ changed = pconf.PsCeiling
"lastRecoverVitSec": cur, } else {
} add = yu
if err := this.modelUser.Change(u.Uid, update); err == nil { changed = total
}
} else {
add = 0
}
if isession, ok := this.ModuleBase.GetUserSession(u.Uid); ok {
if code := this.AddAttributeValue(isession, comm.ResPs, add, false); code == pb.ErrorCode_Success {
update := map[string]interface{}{
"lastRecoverVitSec": cur,
}
if err := this.modelUser.Change(u.Uid, update); err == nil {
if changed > 0 {
if err := this.SendMsgToUser(string(this.GetType()), "vitchanged", if err := this.SendMsgToUser(string(this.GetType()), "vitchanged",
&pb.UserVitChangedPush{Ps: total}, u.Uid); err != nil { &pb.UserVitChangedPush{Ps: changed}, u.Uid); err != nil {
this.Error("玩家体力变化 UserVitChangedPush推送失败", this.Error("玩家体力变化 UserVitChangedPush推送失败",
log.Field{Key: "uid", Value: u.Uid}, log.Field{Key: "uid", Value: u.Uid},
log.Field{Key: comm.ResPs, Value: total}, log.Field{Key: comm.ResPs, Value: changed},
) )
} }
} }

View File

@ -16,7 +16,7 @@ type GameEquipSuitData struct {
Skill int32 Skill int32
Skillname string Skillname string
Skillintr string Skillintr string
SetBonuses map[string]float32 SetBonuses map[string]int32
} }
const TypeId_GameEquipSuitData = -1986764885 const TypeId_GameEquipSuitData = -1986764885
@ -36,15 +36,15 @@ func (_v *GameEquipSuitData)Deserialize(_buf map[string]interface{}) (err error)
var _ok_ bool var _ok_ bool
if _arr_, _ok_ = _buf["SetBonuses"].([]interface{}); !_ok_ { err = errors.New("SetBonuses error"); return } if _arr_, _ok_ = _buf["SetBonuses"].([]interface{}); !_ok_ { err = errors.New("SetBonuses error"); return }
_v.SetBonuses = make(map[string]float32) _v.SetBonuses = make(map[string]int32)
for _, _e_ := range _arr_ { for _, _e_ := range _arr_ {
var _kv_ []interface{} var _kv_ []interface{}
if _kv_, _ok_ = _e_.([]interface{}); !_ok_ || len(_kv_) != 2 { err = errors.New("SetBonuses error"); return } if _kv_, _ok_ = _e_.([]interface{}); !_ok_ || len(_kv_) != 2 { err = errors.New("SetBonuses error"); return }
var _key_ string var _key_ string
{ if _key_, _ok_ = _kv_[0].(string); !_ok_ { err = errors.New("_key_ error"); return } } { if _key_, _ok_ = _kv_[0].(string); !_ok_ { err = errors.New("_key_ error"); return } }
var _value_ float32 var _value_ int32
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _kv_[1].(float64); !_ok_ { err = errors.New("_value_ error"); return }; _value_ = float32(_x_) } { var _ok_ bool; var _x_ float64; if _x_, _ok_ = _kv_[1].(float64); !_ok_ { err = errors.New("_value_ error"); return }; _value_ = int32(_x_) }
_v.SetBonuses[_key_] = _value_ _v.SetBonuses[_key_] = _value_
} }
} }

View File

@ -77,18 +77,18 @@ func TestMatrxing(t *testing.T) {
utils.MatrixingHour("2022-10-11 00:00:00") utils.MatrixingHour("2022-10-11 00:00:00")
} }
func TestCompre(t *testing.T){ func TestCompre(t *testing.T) {
a:=[]int32{1,2,4,5} a := []int32{1, 2, 4, 5}
b:=[]int32{1,2,4} b := []int32{1, 2, 4}
fmt.Println(utils.ForContainer(a,b)) fmt.Println(utils.ForContainer(a, b))
} }
func TestDeletex(t *testing.T){ func TestDeletex(t *testing.T) {
a:=[]int32{1,2,3,4} a := []int32{1, 2, 3, 4}
c:=utils.Deletex(a, 2) c := utils.Deletex(a, 2)
fmt.Println(c) fmt.Println(c)
} }
func TestDiffDays(t *testing.T){ func TestDiffDays(t *testing.T) {
fmt.Println(utils.DiffDays(1614527999, 1614614400)) fmt.Println(utils.DiffDays(1614527999, 1614614400))
} }