refactor(item): 统一物品操作接口并优化金币处理逻辑
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"` //最后生成的时间记录表
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user