1
This commit is contained in:
@@ -33,7 +33,7 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
|
||||
cacheKey := strings.Join(gconv.Strings(Material1[:]), ":")
|
||||
println(cacheKey, "获取融合id")
|
||||
fusions := service.DictInfoServiceS.GetData("fusion")
|
||||
fusions := service.NewDictInfoService().GetData("fusion")
|
||||
|
||||
for _, v := range Material1 {
|
||||
// if v < 10000 {
|
||||
@@ -57,12 +57,12 @@ func (s *PetFusionMaterialService) Data(Material1 [4]uint32) uint32 {
|
||||
"material4": Material1[3],
|
||||
"is_enable": 1,
|
||||
}
|
||||
m.Where(condition) .Scan(&effect)
|
||||
m.Where(condition).Scan(&effect)
|
||||
//这时候有可能效果是空的,那么这时候就再次查询默认的特性,保证每次必会生成一个数据库有的特性
|
||||
//也许这个时候的特性配方就是随机从数据库中查找一个特性
|
||||
|
||||
if effect == nil {
|
||||
effect2s := service.DictInfoServiceS.GetData("effect")
|
||||
effect2s := service.NewDictInfoService().GetData("effect")
|
||||
for _, v := range effect2s {
|
||||
return gconv.Uint32(v.Value)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func init() {
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/dict/info",
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.DictInfoServiceS,
|
||||
Service: service.NewDictInfoService(),
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
@@ -34,7 +34,7 @@ type DictInfoDataReq struct {
|
||||
|
||||
// Data 方法 获得字典数据
|
||||
func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) {
|
||||
service := service.DictInfoServiceS
|
||||
service := service.NewDictInfoService()
|
||||
data, err := service.Data(ctx, req.Types)
|
||||
res = cool.Ok(data)
|
||||
return
|
||||
|
||||
@@ -11,7 +11,7 @@ type DictInfo struct {
|
||||
*cool.Model
|
||||
TypeID int32 `gorm:"column:typeId;type:int;not null" json:"typeId"` // 类型ID
|
||||
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
|
||||
ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序
|
||||
Ordernum int32 `gorm:"column:ordernum;type:int;not null" json:"ordernum"` // 排序
|
||||
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
|
||||
Value int32 `gorm:"column:value;type:int;not null" json:"value"`
|
||||
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
|
||||
|
||||
@@ -87,11 +87,27 @@ func (s *DictInfoService) GetData(types string) (data map[uint32]model.DictInfo)
|
||||
})
|
||||
return fusions
|
||||
|
||||
}
|
||||
func (s *DictInfoService) GetMax(value uint32) (max uint32) {
|
||||
|
||||
m := cool.DBM(s.Model)
|
||||
var ress *model.DictInfo
|
||||
m.Where("value", value).Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&ress)
|
||||
if ress == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return uint32(ress.Ordernum)
|
||||
|
||||
}
|
||||
|
||||
// ModifyAfter 修改后
|
||||
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
||||
|
||||
defer s.Service.ModifyAfter(ctx, method, param)
|
||||
if method == "Delete" {
|
||||
// 删除后,同时删除子节点
|
||||
ids, ok := param["ids"]
|
||||
@@ -128,8 +144,6 @@ func delChildDict(id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var DictInfoServiceS = NewDictInfoService()
|
||||
|
||||
// NewDictInfoService 初始化 DictInfoService
|
||||
func NewDictInfoService() *DictInfoService {
|
||||
return &DictInfoService{
|
||||
|
||||
@@ -3,19 +3,34 @@ package model
|
||||
import (
|
||||
"blazing/cool"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tnnmigga/enum"
|
||||
)
|
||||
|
||||
var MilestoneEnum = enum.New[struct {
|
||||
CollectElfCount EnumMilestone `enum:"3515"` // 收集精灵数量
|
||||
DailyTaskCount EnumMilestone `enum:"3510"` // 日常任务次数
|
||||
MaxLevelCount EnumMilestone `enum:"3511"` // 满级数量
|
||||
SingleAttrCount EnumMilestone `enum:"3512"` // 单属性数量
|
||||
DoubleAttrCount EnumMilestone `enum:"3513"` // 双属性数量
|
||||
Arena EnumMilestone `enum:"3508"` // 擂台
|
||||
Brawl EnumMilestone `enum:"3504"` // 乱斗
|
||||
ElfKing EnumMilestone `enum:"3503"` // 精灵王
|
||||
BaseVisit EnumMilestone `enum:"3506"` // 基地拜访
|
||||
BaseVisitedCount EnumMilestone `enum:"3520"` // 基地被拜访次数
|
||||
WinSPTType EnumMilestone `enum:"3521"` // 战胜spt种类
|
||||
CollectElfType EnumMilestone `enum:"3522"` // 收集精灵种类
|
||||
DefeatWildElfCount EnumMilestone `enum:"3523"` // 击败野生精灵次数
|
||||
}]()
|
||||
|
||||
type EnumMilestone int
|
||||
|
||||
var MilestoneMode = enum.New[struct {
|
||||
BOSS EnumMilestone //boss类 地图ID->BOSSID ,胜利次数 mapid bossid petid,防止换boss后数据不可用
|
||||
ITEM EnumMilestone //物品类 物品ID 使用精灵
|
||||
Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数
|
||||
Moster EnumMilestone //野怪统计 地图ID->怪物ID
|
||||
Task EnumMilestone
|
||||
}]()
|
||||
// var MilestoneMode = enum.New[struct {
|
||||
// BOSS EnumMilestone //boss类 地图ID->BOSSID ,胜利次数 mapid bossid petid,防止换boss后数据不可用
|
||||
// ITEM EnumMilestone //物品类 物品ID 使用精灵
|
||||
// Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数
|
||||
// Moster EnumMilestone //野怪统计 地图ID->怪物ID
|
||||
// Task EnumMilestone
|
||||
// }]()
|
||||
|
||||
const TableNameMilestone = "player_milestone"
|
||||
|
||||
@@ -30,31 +45,31 @@ type Milestone struct {
|
||||
Count uint32 `gorm:"not null;comment:'里程碑完成次数'" json:"count"`
|
||||
}
|
||||
|
||||
// MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作
|
||||
type MilestoneEX struct {
|
||||
Milestone
|
||||
Args []uint32 // 解析后的里程碑详细数据
|
||||
Results []uint32 `json:"results"` // 解析后的里程碑详细数据
|
||||
}
|
||||
// // MilestoneEX 里程碑扩展结构体,用于业务层解析后的数据操作
|
||||
// type MilestoneEX struct {
|
||||
// Milestone
|
||||
// Args []uint32 // 解析后的里程碑详细数据
|
||||
// Results []uint32 `json:"results"` // 解析后的里程碑详细数据
|
||||
// }
|
||||
|
||||
// 检查是否触发过,成功返回触发的次数,失败返回0
|
||||
func (m *MilestoneEX) CheakNoNumber(count uint32) bool {
|
||||
// if v.DoneType == model.MilestoneMode.BOSS && IsPrefixBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count {
|
||||
// // 检查是否触发过,成功返回触发的次数,失败返回0
|
||||
// func (m *MilestoneEX) CheakNoNumber(count uint32) bool {
|
||||
// // if v.DoneType == model.MilestoneMode.BOSS && IsPrefixBasicSlice(v.Args, []uint32{mapid, bossid}) && v.Count == count {
|
||||
|
||||
_, ok := lo.Find(m.Results, func(v1 uint32) bool { //寻找是否触发过
|
||||
//大于触发值就触发,然后1的返回false,因为没有奖励,这样就可以一直触发
|
||||
return v1 == count //大于等于就触发
|
||||
})
|
||||
//没找到且次数满足才能返回真
|
||||
if !ok && m.Count >= count {
|
||||
return true
|
||||
}
|
||||
// _, ok := lo.Find(m.Results, func(v1 uint32) bool { //寻找是否触发过
|
||||
// //大于触发值就触发,然后1的返回false,因为没有奖励,这样就可以一直触发
|
||||
// return v1 == count //大于等于就触发
|
||||
// })
|
||||
// //没找到且次数满足才能返回真
|
||||
// if !ok && m.Count >= count {
|
||||
// return true
|
||||
// }
|
||||
|
||||
//已经触发过
|
||||
return false
|
||||
// //已经触发过
|
||||
// return false
|
||||
|
||||
// }
|
||||
}
|
||||
// // }
|
||||
// }
|
||||
|
||||
// TableName 返回表名
|
||||
func (*Milestone) TableName() string {
|
||||
|
||||
@@ -3,49 +3,45 @@ package service
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type DoneService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
arss := strings.Join(gconv.Strings(id), "-")
|
||||
m := s.PModel(s.Model).Where("done_type", data).Where("args", arss)
|
||||
var tt *model.MilestoneEX
|
||||
m.Scan(&tt)
|
||||
if tt == nil {
|
||||
tt = &model.MilestoneEX{
|
||||
Milestone: model.Milestone{
|
||||
DoneType: data,
|
||||
Args: strings.Join(gconv.Strings(id), "-"),
|
||||
//Count: 1,
|
||||
},
|
||||
}
|
||||
}
|
||||
// func (s *DoneService) Exec(data model.EnumMilestone, id []uint32, fn func(*model.MilestoneEX) bool) {
|
||||
// if cool.Config.ServerInfo.IsVip != 0 {
|
||||
// cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
// return
|
||||
// }
|
||||
// arss := strings.Join(gconv.Strings(id), "-")
|
||||
// m := s.PModel(s.Model).Where("done_type", data).Where("args", arss)
|
||||
// var tt *model.MilestoneEX
|
||||
// m.Scan(&tt)
|
||||
// if tt == nil {
|
||||
// tt = &model.MilestoneEX{
|
||||
// Milestone: model.Milestone{
|
||||
// DoneType: data,
|
||||
// Args: strings.Join(gconv.Strings(id), "-"),
|
||||
// //Count: 1,
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
tt.Args = id
|
||||
ook := fn(tt)
|
||||
if !ook { //不需要保存
|
||||
return
|
||||
}
|
||||
tt.PlayerID = uint64(s.userid)
|
||||
tt.Milestone.Args = strings.Join(gconv.Strings(id), "-")
|
||||
// tt.Args = id
|
||||
// ook := fn(tt)
|
||||
// if !ook { //不需要保存
|
||||
// return
|
||||
// }
|
||||
// tt.PlayerID = uint64(s.userid)
|
||||
// tt.Milestone.Args = strings.Join(gconv.Strings(id), "-")
|
||||
|
||||
_, err := m.Save(tt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// _, err := m.Save(tt)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
func NewDoneService(id uint32) *DoneService {
|
||||
return &DoneService{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user