From 49b4c8cf2a8c2478084558b79c51ebc20e67fee6 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 16 Dec 2025 06:54:27 +0000 Subject: [PATCH] =?UTF-8?q?refactor(item):=20=E7=BB=9F=E4=B8=80=E7=89=A9?= =?UTF-8?q?=E5=93=81=E6=93=8D=E4=BD=9C=E6=8E=A5=E5=8F=A3=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E9=87=91=E5=B8=81=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/item_buy.go | 2 +- logic/controller/item_sale.go | 4 +++- logic/controller/item_use.go | 4 ++-- logic/service/fight/input.go | 13 +++++++++---- logic/service/fight/loop.go | 14 +++++++------- logic/service/player/pack.go | 7 +++++++ logic/service/player/player.go | 5 +++-- modules/base/model/base_sys_user.go | 2 +- modules/base/service/base_sys_user.go | 18 +++++++++++++----- modules/blazing/service/item.go | 6 +----- 10 files changed, 47 insertions(+), 28 deletions(-) diff --git a/logic/controller/item_buy.go b/logic/controller/item_buy.go index 176319ff2..ffb62c1f3 100644 --- a/logic/controller/item_buy.go +++ b/logic/controller/item_buy.go @@ -64,7 +64,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Playe isbuycot := c.ItemAdd(uint32(gconv.Uint32(r.ItemID)), uint32(data.Count)) if isbuycot { - c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold) + c.User.UpdateGold(c.Info.UserID, -gconv.Float64(usegold)) result = &item.S2C_GoldBuyProductInfo{ Gold: c.User.GetGold(uint(c.Info.UserID)), PayGold: usegold, diff --git a/logic/controller/item_sale.go b/logic/controller/item_sale.go index 8752f6ab4..c2a9960d6 100644 --- a/logic/controller/item_sale.go +++ b/logic/controller/item_sale.go @@ -6,6 +6,8 @@ import ( "blazing/logic/service/fight" "blazing/logic/service/item" "blazing/logic/service/player" + + "github.com/gogf/gf/v2/util/gconv" ) func (h Controller) ITEM_SALE(data *item.C2S_ITEM_SALE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { @@ -17,6 +19,6 @@ func (h Controller) ITEM_SALE(data *item.C2S_ITEM_SALE, c *player.Player) (resul c.Info.Coins += uint32(int64(data.Amount) * int64(xmlres.ItemsMAP[int(data.ItemId)].SellPrice)) } - c.Service.Item.SubItem(data.ItemId, data.Amount) + c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount)) return result, 0 } diff --git a/logic/controller/item_use.go b/logic/controller/item_use.go index b8c1ef84a..23172564e 100644 --- a/logic/controller/item_use.go +++ b/logic/controller/item_use.go @@ -63,7 +63,7 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play } - c.Service.Item.SubItem(data.ItemID, 1) + c.Service.Item.UPDATE(data.ItemID, -1) result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{} onpet.CalculatePetPane(false) copier.Copy(&result, onpet) @@ -82,6 +82,6 @@ func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Playe onpet.Nature = data.Nature onpet.CalculatePetPane(false) - c.Service.Item.SubItem(data.ItemId, 1) + c.Service.Item.UPDATE(data.ItemId, -1) return result, 0 } diff --git a/logic/service/fight/input.go b/logic/service/fight/input.go index ca047e1fd..d25048cea 100644 --- a/logic/service/fight/input.go +++ b/logic/service/fight/input.go @@ -163,17 +163,22 @@ func (f *FightC) initplayer(c common.PlayerI) (*input.Input, errorcode.ErrorCode } in.SortPet() + if len(in.AllPet) == 0 { + return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon + } switch f.Info.Mode { case info.BattleMode.SINGLE_MODE: in.AllPet = in.AllPet[:1] case info.BattleMode.PET_MELEE: in.AllPet = make([]*info.BattlePetEntity, 0) - if len(meetpet) == 0 { - initmeetpet() - } + // if len(meetpet) == 0 { + // initmeetpet() + // } r := service.NewMELEEService().Def() - + if len(r) == 0 { + return nil, errorcode.ErrorCodes.ErrNoEligiblePokemon + } for i, v := range r { if v.Lv == 0 { diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index 2c45dce3b..d09bc0fad 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -173,12 +173,12 @@ func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.Bat if selfinput.CanChange == 2 { selfinput.CanChange = 0 - if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC && pid == 0 { - f.Switch = make(map[uint32]*action.ActiveSwitchAction) - f.Our.Player.SendPackCmd(2407, &ret.Reason) - f.Opp.GetAction() - println("开始执行NPC死切动作") - } + // if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC && pid == 0 { + // f.Switch = make(map[uint32]*action.ActiveSwitchAction) + // f.Our.Player.SendPackCmd(2407, &ret.Reason) + // f.Opp.GetAction() + // println("开始执行NPC死切动作") + // } continue } } @@ -295,7 +295,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) { if r < 1 { return } - f.GetInputByAction(a, false).Player.(*player.Player).Service.Item.SubItem(a.ItemID, 1) + f.GetInputByAction(a, false).Player.(*player.Player).Service.Item.UPDATE(a.ItemID, -1) switch { case gconv.Int(item.Bonus) != 0: diff --git a/logic/service/player/pack.go b/logic/service/player/pack.go index e927bab81..cbad37fd3 100644 --- a/logic/service/player/pack.go +++ b/logic/service/player/pack.go @@ -50,7 +50,14 @@ func getUnderlyingValue(val reflect.Value) (reflect.Value, error) { // 遍历结构体方法并执行RECV_cmd func (h *ClientData) Recv(data common.TomeeHeader) { + defer func() { + if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值 + // 1. 打印错误信息 + cool.Loger.Error(context.TODO(), "panic 错误:", err) + + } + }() cmdlister, ok := cool.CmdCache.Load(data.CMD) if !ok { diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 68b267141..9a1c351bc 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -19,6 +19,7 @@ import ( "github.com/antlabs/timer" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" "github.com/panjf2000/gnet/v2" ) @@ -212,7 +213,7 @@ func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) { return true case 5: //金豆ItemAdd - p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+ItemCnt*100)) + p.User.UpdateGold(p.Info.UserID, gconv.Float64(ItemCnt)) return true default: @@ -240,7 +241,7 @@ func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) { p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样 return false } - p.Service.Item.AddItem(ItemId, ItemCnt) + p.Service.Item.UPDATE(ItemId, gconv.Int(ItemCnt)) return true } diff --git a/modules/base/model/base_sys_user.go b/modules/base/model/base_sys_user.go index 44940607c..875654b4c 100644 --- a/modules/base/model/base_sys_user.go +++ b/modules/base/model/base_sys_user.go @@ -17,7 +17,7 @@ type BaseSysUser struct { 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"` + GoldBean float64 `gorm:"column:goldbean;type:money;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服 测试服 Maxts uint32 `gorm:"column:max_ts;type:int;not null;default:0" json:"max_ts"` //最后生成的时间记录表 diff --git a/modules/base/service/base_sys_user.go b/modules/base/service/base_sys_user.go index 1f8aab9b4..75b6bf18e 100644 --- a/modules/base/service/base_sys_user.go +++ b/modules/base/service/base_sys_user.go @@ -45,11 +45,19 @@ func (s *BaseSysUserService) GetPerson(userId uint32) (res *model.BaseSysUser) { 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) +func (s *BaseSysUserService) UpdateGold(userId uint32, gold float64) { + // updateData := g.Map{ + // "views": &gdb.Counter{ + // Field: "goldbean", + // Value: 1, + // }, + // } + m := cool.DBM(s.Model).Where("id", userId) + m.Increment("goldbean", gold) + // // UPDATE `article` SET `views`=`views`+1 WHERE `id`=1 + // result, err := db.Update("article", updateData, "id", 1) + + //res.GoldBean, _ = alpacadecimal.NewFromFloat(float64(gold)).Div(alpacadecimal.NewFromFloat(100)).Float64() return } diff --git a/modules/blazing/service/item.go b/modules/blazing/service/item.go index ebd3baa29..fbb640512 100644 --- a/modules/blazing/service/item.go +++ b/modules/blazing/service/item.go @@ -20,7 +20,7 @@ func (s *ItemService) Get(min, max uint32) []model.Item { return ttt } -func (s *ItemService) AddItem(id, count uint32) { +func (s *ItemService) UPDATE(id uint32, count int) { if t, _ := s.GModel(s.Model).Where("item_id", id).Count(); t != 0 { _, err := s.GModel(s.Model).Where("item_id", id).Increment("item_cnt", count) if err != nil { @@ -35,11 +35,7 @@ func (s *ItemService) AddItem(id, count uint32) { } } -func (s *ItemService) SubItem(id, count uint32) { - s.GModel(s.Model).Where("item_id", id).Decrement("item_cnt", count) - -} func (s *ItemService) CheakItem(id uint32) uint32 { var ttt model.Item s.GModel(s.Model).Where("item_id", id).Scan(&ttt)