Files
bl/modules/blazing/service/task.go
昔念 77f3d153c6 ```
fix(monster): 调整闪光宠物生成概率并修复时间种子问题

将闪光宠物的生成条件从 `grand.Meet(1, 100)` 修改为 `grand.Meet(30, 100)`,
同时为 `RandSHiny` 方法增加时间偏移参数以提升随机性。

此外,修正了登录任务判断逻辑中的索引范围错误,字段命名优化以及部分冗余代码清理。
```
2025-12-14 23:28:28 +08:00

87 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"time"
"github.com/gogf/gf/v2/os/gtime"
)
// func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
// //todo待测试
// var player T
// m1 := cool.DBM(s.Model).Where("player_id", userid)
// m1.Scan(&player)
// // 方法2使用反射获取
// // 获取反射值对象
// ttt := player
// //fmt.Println(dataField.Interface().(string))
// var tt F
// err := json.Unmarshal([]byte(ttt.GetData()), &tt)
// if err != nil {
// panic(err)
// }
// tt1 := processFunc(tt)
// tmep, err := json.Marshal(tt1)
// if err != nil {
// panic(err)
// }
// ttt.SetData(string(tmep))
// m1.Save(player)
// return false
// }
// 获取任务信息
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
var gg model.TaskEX
m1 := s.GModel(s.Model).Where("task_id", id)
m1.Scan(&gg)
tre := t(&gg)
if !tre { //不需要更新
return
}
gg.PlayerID = uint64(s.userid)
gg.TaskID = id
_, err := m1.Save(gg)
if err != nil {
panic(err)
}
}
// IsToday 判断给定时间是否是今天
func IsToday(t1 *gtime.Time) bool {
if t1 == nil {
return false
}
t := t1.Time
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
type TaskService struct {
BaseService
}
func NewTaskService(id uint32) *TaskService {
return &TaskService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewTask()},
},
}
}