All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
feat(common/cool): 更新GetClient函数支持端口参数 更新GetClient函数签名以接收端口参数,并修改客户端映射键的计算方式, 添加GetClientOnly函数用于仅通过uid获取客户端。 fix(common/rpc): 修复RPC调用中的客户端获取方法 将GetClient调用替换为GetClientOnly,确保正确的客户端获取逻辑。 refactor(logic/controller): 重命名Port字段为UID并优化道具列表处理 将Controller结构体中的Port字段重命名为UID以更好地反映其用途, 优化GetUserItemList函数中道具列表的初始化和填充逻辑。 perf(logic): 调整性能分析web服务启动位置 将PprofWeb服务从全局启动移至调试模式下启动,优化服务配置。 refactor(logic/server): 更新服务器UID生成逻辑 修改Maincontroller的UID字段设置方式,使用服务器ID和端口组合生成唯一标识。 refactor(logic/service/player): 移除未使用的导入并优化怪物生成 移除未使用的service导入,优化怪物生成逻辑中的地图数据访问。 feat(logic/service/space): 添加PitS缓存映射并重构空间初始化 添加新的PitS字段
128 lines
2.4 KiB
Go
128 lines
2.4 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/player/model"
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func (s *ItemService) Exist(itemid uint32) bool {
|
|
|
|
var ttt *model.Item
|
|
s.dbm(s.Model).Where("item_id", itemid).Scan(&ttt)
|
|
|
|
return ttt != nil
|
|
|
|
}
|
|
func (s *ItemService) Get(min, max uint32) []model.Item {
|
|
|
|
var ttt []model.Item
|
|
s.dbm(s.Model).Where(g.Map{
|
|
"item_id <=": max,
|
|
"item_id >=": min,
|
|
}).Where("item_cnt >", 0).Scan(&ttt)
|
|
|
|
return ttt
|
|
|
|
}
|
|
func (s *ItemService) UPDATE(id uint32, count int) {
|
|
if cool.Config.ServerInfo.IsVip != 0 && count < 0 {
|
|
|
|
return
|
|
}
|
|
if id == 0 {
|
|
return
|
|
}
|
|
m := s.dbm(s.Model)
|
|
ok, err := m.Where("item_id", id).Exist()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if ok {
|
|
_, err := s.dbm(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
} else {
|
|
m := s.dbm(s.Model)
|
|
data := g.Map{
|
|
"player_id": s.userid,
|
|
"item_id": id,
|
|
"item_cnt": count,
|
|
"is_vip": cool.Config.ServerInfo.IsVip,
|
|
}
|
|
|
|
m.Data(data).Insert()
|
|
}
|
|
|
|
}
|
|
|
|
// func (s *ItemService) UPDATEM(ids map[uint32]int) {
|
|
// if cool.Config.ServerInfo.IsVip != 0 {
|
|
|
|
// return
|
|
// }
|
|
|
|
// m := s.dbm(s.Model)
|
|
// data := g.List{}
|
|
// for k, v := range ids {
|
|
// data = append(data, g.Map{
|
|
// "player_id": s.userid,
|
|
// "item_id": k,
|
|
// "item_cnt": v,
|
|
// "is_vip": cool.Config.ServerInfo.IsVip,
|
|
// })
|
|
// }
|
|
|
|
// m.Data(data).Insert()
|
|
|
|
// }
|
|
func (s *ItemService) CheakItem(id uint32) int64 {
|
|
var ttt model.Item
|
|
m := s.dbm(s.Model)
|
|
|
|
m.Where("item_id", id).Scan(&ttt)
|
|
return ttt.ItemCnt
|
|
}
|
|
func (s *ItemService) CheakItemM(id ...uint32) []model.Item {
|
|
var ttt []model.Item
|
|
m := s.dbm(s.Model)
|
|
|
|
m.WhereIn("item_id", id).Scan(&ttt)
|
|
return ttt
|
|
}
|
|
|
|
// /添加进来的物品一定是保证存在的
|
|
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": "角色名称不能重复",
|
|
}, PageQueryOp: &cool.QueryOp{
|
|
KeyWordField: []string{"player_id"},
|
|
FieldEQ: []string{"player_id"},
|
|
Where: func(ctx context.Context) [][]interface{} {
|
|
var (
|
|
//admin = cool.GetAdmin(ctx)
|
|
//userId = admin.UserId
|
|
)
|
|
return [][]interface{}{
|
|
// {"player_id", userId, true},
|
|
// {"free", 0, true},
|
|
}
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
|
|
}
|