fix(fight): 修复战斗逻辑中的一些潜在问题 - 在 `fight_leitai.go` 中增加玩家是否可以战斗的判断,避免非法挑战 - 注释掉部分冗余的日志打印与广播调用,并调整了擂台状态更新逻辑 - 修正 `effect_62.go` 中镇魂歌效果持续时间的处理方式,引入独立计数器 `duy` - 优化随机精灵生成逻辑,确保 CatchTime 正确设置 - 增加对数据库操作错误的 panic 处理,提高代码健壮性 - 调整部分结构体指针传递,统一返回结构体指针以避免拷贝问题 - 移除未使用的导入包和调试日志,清理无用代码 ```
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/blazing/model"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func (s *ItemService) Get(min, max uint32) []model.Item {
|
|
|
|
//todo待测试
|
|
var ttt []model.Item
|
|
s.GModel(s.Model).Where(g.Map{
|
|
"item_id <=": max,
|
|
"item_id >=": min,
|
|
}).Scan(&ttt)
|
|
|
|
return ttt
|
|
|
|
}
|
|
func (s *ItemService) AddItem(id, count uint32) {
|
|
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 {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
s.GModel(s.Model).Data(g.Map{
|
|
"player_id": s.userid,
|
|
"item_id": id,
|
|
"item_cnt": count,
|
|
}).Insert()
|
|
}
|
|
|
|
}
|
|
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)
|
|
return ttt.ItemCnt
|
|
}
|
|
|
|
// /添加进来的物品一定是保证存在的
|
|
type ItemService struct {
|
|
BaseService
|
|
}
|
|
|
|
func NewItemService(id uint32) *ItemService {
|
|
return &ItemService{
|
|
|
|
BaseService: BaseService{userid: id,
|
|
|
|
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
|
|
"player_id": "角色名称不能重复",
|
|
}},
|
|
},
|
|
}
|
|
|
|
}
|