diff --git a/logic/controller/getserver.go b/logic/controller/getserver.go index d9be0b07..80790ae0 100644 --- a/logic/controller/getserver.go +++ b/logic/controller/getserver.go @@ -4,6 +4,7 @@ import ( "blazing/common/rpc" "blazing/common/socket/errorcode" "blazing/logic/service/user" + "blazing/modules/base/service" "golang.org/x/sync/singleflight" @@ -23,7 +24,7 @@ func fetchData() (any, error) { func (h *Controller) COMMEND_ONLINE(data *user.SidInfo, c gnet.Conn) (result *rpc.CommendSvrInfo, err errorcode.ErrorCode) { //这个时候player应该是空的 result = rpc.NewInInfo() - if data.Head.UserID < 100000 { + if service.NewBaseSysUserService().GetPerson(data.Head.UserID).Debug == 1 { result.IsVip = 1 } v, _, _ := sg.Do("GetServerInfoList", fetchData) diff --git a/logic/controller/gold_exp.go b/logic/controller/gold_exp.go index 9fb31363..aee56233 100644 --- a/logic/controller/gold_exp.go +++ b/logic/controller/gold_exp.go @@ -10,7 +10,7 @@ func (h Controller) PlayerGoldCount(data *item.GoldOnlineRemainInboundInfo, c *p return &item.GoldOnlineRemainOutboundInfo{ - GoldNumber: uint32(c.Info.GoldBean) * 100, + GoldNumber: c.User.GetGold(uint(c.Info.UserID)), Coin: c.Info.Coins, }, 0 } diff --git a/logic/controller/item_buy.go b/logic/controller/item_buy.go index 14a95bab..18f47d2f 100644 --- a/logic/controller/item_buy.go +++ b/logic/controller/item_buy.go @@ -62,13 +62,14 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Playe return nil, errorcode.ErrorCodes.ErrSystemError } r1 := c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)}) - if len(r1) == int(data.Count) { - //失败返还 - c.Info.GoldBean += uint32(uint32(data.Count)-uint32(len(r1))) * uint32(gconv.Uint32(r.Price)) - } + isbuycot := len(r1) + + usegold := uint32(uint32(len(r1))) * uint32(gconv.Uint32(r.Price)*100) + c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold) + result = &item.S2C_GoldBuyProductInfo{ - Gold: c.Info.GoldBean, - PayGold: uint32(data.Count) * uint32(gconv.Uint32(r.Price)), + Gold: c.User.GetGold(uint(c.Info.UserID)), + PayGold: uint32(isbuycot) * uint32(gconv.Uint32(r.Price)), Reserved: 0, } diff --git a/logic/controller/item_use.go b/logic/controller/item_use.go index ff82d47d..81f5231d 100644 --- a/logic/controller/item_use.go +++ b/logic/controller/item_use.go @@ -50,18 +50,17 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play //性格随机 case itemID == 300025: - onpet.Nature = uint32(grand.Intn(25)) - case itemID >= 240042 && itemID <= 240056: + onpet.Nature = (onpet.Nature + uint32(grand.Intn(25))) % 25 - if xmlres.ItemsMAP[int(itemID)].Nature != nil { - onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature) - } - if xmlres.ItemsMAP[int(itemID)].NatureSet != nil { + //性格转换 + case itemID >= 300081 && itemID <= 300086: + onpet.Nature = gconv.Uint32(*xmlres.ItemsMAP[int(itemID)].Nature) - rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ") - onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1]) - } + //性格转换 + case (itemID >= 300602 && itemID <= 300605) || itemID == 300119 || itemID == 300120: + rr := strings.Split(*xmlres.ItemsMAP[int(itemID)].NatureSet, " ") + onpet.Nature = gconv.Uint32(rr[grand.Intn(len(rr))-1]) default: // 无效ID处理 return nil, errorcode.ErrorCodes.ErrSystemError diff --git a/logic/controller/login.go b/logic/controller/login.go index 2e71ad76..0c86d65b 100644 --- a/logic/controller/login.go +++ b/logic/controller/login.go @@ -12,6 +12,7 @@ import ( "blazing/logic/service/player" "blazing/logic/service/space" + "blazing/modules/base/service" blservice "blazing/modules/blazing/service" "context" "time" @@ -57,6 +58,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c gnet.Conn) (result *user. return } t.Service = blservice.NewUserService(data.Head.UserID) + t.User = service.NewBaseSysUserService() t.Info = t.Service.Info.Person(data.Head.UserID) if t.Info == nil { defer c.Close() diff --git a/logic/controller/pet.go b/logic/controller/pet.go index a0b8cec1..c7cb0aca 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -77,15 +77,17 @@ func (h *Controller) PET_ROWEI( c.Service.Pet.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { _, _, ok := c.FindPet(data.CatchTime) - + r := xmlres.PetMAP[int(data.ID)].FreeForbidden //如果背包没找到,再放入背包 - if !ok && t.CatchTime != 0 && xmlres.PetMAP[int(data.ID)].FreeForbidden == 0 { + if !ok && t.CatchTime != 0 && r == 0 { t.Free = 1 + } else { + err = errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse } }) - return nil, 0 + return nil, err } diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index 497e48a3..54adf9f0 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -168,6 +168,7 @@ func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode } v1.CatchTime = c.GetInfo().UserID + uint32(i)*1000000 + v1.Cure() in.AllPet = append(in.AllPet, info.CreateBattlePetEntity(v1, f.rand)) } diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 7b97dd6b..f04b75f2 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -12,7 +12,9 @@ import ( "strings" "sync/atomic" + "blazing/modules/base/service" "blazing/modules/blazing/model" + blservice "blazing/modules/blazing/service" "context" "time" @@ -62,6 +64,7 @@ type Player struct { OgreInfo OgreInfo Service *blservice.UserService + User *service.BaseSysUserService // PVP被邀请信息 HavePVPinfo []common.PlayerI monsters [3]int @@ -89,10 +92,10 @@ func (p *Player) UseCoins(t uint32) bool { } func (p *Player) UseGold(t uint32) bool { - if p.Info.GoldBean < t { + if p.User.GetGold(uint(p.Info.UserID)) < t { return false } - p.Info.GoldBean = p.Info.GoldBean - t + //p.Info.GoldBean = p.Info.GoldBean - t return true } @@ -294,7 +297,7 @@ func (p *Player) ItemAdd(t ...model.ItemInfo) (result []model.ItemInfo) { p.Info.ExpPool = p.Info.ExpPool + v.ItemCnt case 5: //金豆ItemAdd - p.Info.GoldBean = p.Info.GoldBean + v.ItemCnt + p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+v.ItemCnt*100)) default: ttt = append(ttt, v) diff --git a/modules/base/controller/admin/base_sys_user.go b/modules/base/controller/admin/base_sys_user.go index 140f3c89..4ca3a76a 100644 --- a/modules/base/controller/admin/base_sys_user.go +++ b/modules/base/controller/admin/base_sys_user.go @@ -58,7 +58,7 @@ func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) } res = &SessionRes{} - t1 := service.NewBaseSysUserService().GetPerson(t.UserId) + t1 := service.NewBaseSysUserService().GetPerson(uint32(t.UserId)) res.Session = retsid diff --git a/modules/base/model/base_sys_user.go b/modules/base/model/base_sys_user.go index 22ba6143..baab8be1 100644 --- a/modules/base/model/base_sys_user.go +++ b/modules/base/model/base_sys_user.go @@ -15,9 +15,11 @@ type BaseSysUser struct { HeadImg *string `gorm:"column:headImg;type:varchar(255)" json:"headImg"` // 头像 - Email *string `gorm:"column:email;type:varchar(255)" json:"email"` // 邮箱 - Status *int32 `gorm:"column:status;not null;default:1" json:"status"` // 状态 0:禁用 1:启用 - Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注 + Email *string `gorm:"column:email;type:varchar(255)" json:"email"` // 邮箱 + Status *int32 `gorm:"column:status;not null;default:1" json:"status"` // 状态 0:禁用 1:启用 + GoldBean float64 `gorm:"column:goldBean;type:decimal;not null;default:0" json:"goldBean"` + Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注 + Debug int32 `gorm:"column:debug;type:int;not null;default:0" json:"debug"` // 是否可以进入2服 } diff --git a/modules/base/service/base_sys_user.go b/modules/base/service/base_sys_user.go index efb8e40c..1f8aab9b 100644 --- a/modules/base/service/base_sys_user.go +++ b/modules/base/service/base_sys_user.go @@ -8,6 +8,7 @@ import ( "blazing/modules/base/model" + "github.com/alpacahq/alpacadecimal" "github.com/gogf/gf/v2/container/garray" "github.com/gogf/gf/v2/container/gset" "github.com/gogf/gf/v2/crypto/gmd5" @@ -38,12 +39,27 @@ func (s *BaseSysUserService) GetSession(email string, password string) (res *mod return } -func (s *BaseSysUserService) GetPerson(userId uint) (res *model.BaseSysUser) { +func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) { m := cool.DBM(s.Model) m.Where("id", userId).FieldsEx("password").Scan(&res) return } +func (s *BaseSysUserService) SetGold(userId uint32, gold uint32) (res *model.BaseSysUser) { + m := cool.DBM(s.Model) + m.Where("id", userId).Scan(&res) + res.GoldBean, _ = alpacadecimal.NewFromFloat(float64(gold)).Div(alpacadecimal.NewFromFloat(100)).Float64() + m.Save(res) + + return +} +func (s *BaseSysUserService) GetGold(userId uint) (res uint32) { + var res1 model.BaseSysUser + m := cool.DBM(s.Model) + m.Where("id", userId).FieldsEx("password").Scan(&res1) + + return uint32(alpacadecimal.NewFromFloat(res1.GoldBean).Mul(alpacadecimal.NewFromFloat(100)).IntPart()) +} func (s *BaseSysUserService) GetEamil(userId string) (res *model.BaseSysUser) { m := cool.DBM(s.Model) m.Where("email", userId).FieldsEx("password").Scan(&res) diff --git a/modules/blazing/model/player.go b/modules/blazing/model/player.go index bf5e13c2..81977733 100644 --- a/modules/blazing/model/player.go +++ b/modules/blazing/model/player.go @@ -67,8 +67,6 @@ func NewPlayerInfo() PlayerInfo { } type PlayerInfo struct { - GoldBean uint32 `struc:"skip" json:"gold_bean"` // 金豆(特殊货币) - ExpPool uint32 `struc:"skip" json:"exp_pool"` // 累计经验池 LastResetTime time.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务 OnlineTime uint32 `struc:"skip" json:"online_time"` //在线分钟数