```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(fight): 新增疲惫状态并优化睡眠状态机制

- 实现疲惫状态(StatusTired),仅限制攻击技能,允许属性技能正常使用
- 重构睡眠状态,改为在被攻击且未miss时立即解除,而非技能使用后
- 修复寄生种子效果触发时机,改为回合开始时触发
- 调整寄生效果的目标为技能施放者而非
This commit is contained in:
昔念
2026-04-13 21:06:45 +08:00
parent ce1a2a3588
commit f95fd49efd
12 changed files with 322 additions and 42 deletions

View File

@@ -2,9 +2,11 @@ package service
import (
"blazing/cool"
"blazing/modules/base/service"
"blazing/modules/config/model"
"context"
"crypto/rand"
"database/sql"
"fmt"
"math/big"
"time"
@@ -170,14 +172,15 @@ type ServerNamingCDKResult struct {
// UseServerNamingCDK 使用服务器冠名类型CDK并原子化更新服务器归属和到期时间。
func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerID, serverID uint32, serverName string) (*ServerNamingCDKResult, error) {
if ctx == nil {
ctx = context.TODO()
execCtx := context.Background()
if ctx != nil && ctx.Err() != nil {
ctx = nil
}
now := time.Now()
serverService := NewServerService()
var updated model.ServerShow
err := g.DB(s.Model.GroupName()).Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
err := g.DB(s.Model.GroupName()).Transaction(execCtx, func(ctx context.Context, tx gdb.TX) error {
var cfg model.CDKConfig
if err := tx.Model(s.Model).Where("cdk_code", code).WhereNot("exchange_remain_count", 0).Scan(&cfg); err != nil {
return err
@@ -185,7 +188,7 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
if cfg.ID == 0 {
return gerror.New("cdk不存在")
}
if cfg.CDKType != CDKTypeServerNaming {
if cfg.Type != CDKTypeServerNaming {
return gerror.New("cdk类型不匹配")
}
if cfg.BindUserId != 0 && cfg.BindUserId != ownerID {
@@ -222,6 +225,11 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
OrderDesc("id").
Limit(1).
Scan(&currentShow); err != nil {
if err == sql.ErrNoRows {
err = nil
}
}
if err != nil {
return err
}
@@ -264,6 +272,7 @@ func (s *CdkService) UseServerNamingCDK(ctx context.Context, code string, ownerI
g.DB(s.Model.GroupName()).GetCore().ClearCache(context.TODO(), s.Model.TableName())
g.DB(model.NewServerList().GroupName()).GetCore().ClearCache(context.TODO(), model.NewServerList().TableName())
g.DB(model.NewServerShow().GroupName()).GetCore().ClearCache(context.TODO(), model.NewServerShow().TableName())
service.NewBaseSysUserService().UpdateGold(updated.Owner, int64(200*100))
return &ServerNamingCDKResult{
ServerID: updated.ServerID,
ServerName: updated.Name,

View File

@@ -35,6 +35,13 @@ type ServerShowInfo struct {
ServerShow *model.ServerShow `json:"servershow,omitempty"`
}
type DonationOwnedServerInfo struct {
ServerID uint32 `json:"server_id"`
ServerName string `json:"server_name"`
Remark string `json:"remark"`
ExpireTime time.Time `json:"expire_time"`
}
func NewServerService() *ServerService {
cf := &ServerService{
Service: &cool.Service{
@@ -188,6 +195,73 @@ func (s *ServerService) GetDonationAvailableServerIDs() []uint32 {
return ids
}
func (s *ServerService) GetOwnerActiveDonationServers(ownerID uint32) []DonationOwnedServerInfo {
if ownerID == 0 {
return []DonationOwnedServerInfo{}
}
now := time.Now()
var shows []model.ServerShow
dbm_nocache_noenable(model.NewServerShow()).Where("owner", ownerID).Scan(&shows)
if len(shows) == 0 {
return []DonationOwnedServerInfo{}
}
serverIDs := make([]uint32, 0, len(shows))
for i := range shows {
if !s.isActiveServerShow(&shows[i], now) {
continue
}
serverIDs = append(serverIDs, shows[i].ServerID)
}
if len(serverIDs) == 0 {
return []DonationOwnedServerInfo{}
}
var servers []model.ServerList
dbm_nocache_noenable(s.Model).WhereIn("online_id", serverIDs).Scan(&servers)
serverMap := make(map[uint32]model.ServerList, len(servers))
for i := range servers {
serverMap[servers[i].OnlineID] = servers[i]
}
items := make([]DonationOwnedServerInfo, 0, len(serverIDs))
for i := range shows {
show := &shows[i]
if !s.isActiveServerShow(show, now) {
continue
}
server, ok := serverMap[show.ServerID]
if !ok || show.ServerID == 0 {
continue
}
serverName := show.Name
if serverName == "" {
serverName = server.Name
}
items = append(items, DonationOwnedServerInfo{
ServerID: show.ServerID,
ServerName: serverName,
Remark: server.Desc,
ExpireTime: show.ExpireTime,
})
}
sort.Slice(items, func(i, j int) bool {
if !items[i].ExpireTime.Equal(items[j].ExpireTime) {
return items[i].ExpireTime.After(items[j].ExpireTime)
}
return items[i].ServerID < items[j].ServerID
})
return items
}
// CanUseDonationName 校验目标服务器在当前时间点是否允许被冠名。
func (s *ServerService) CanUseDonationName(server model.ServerList, ownerID uint32, now time.Time) bool {
return server.OnlineID != 0

View File

@@ -26,6 +26,9 @@ func NewTaskService() *TaskService {
func (s *TaskService) Get(id, os int) *model.TaskConfig {
var res *model.TaskConfig
dbm_enable(s.Model).Where("task_id", id).Where("out_state", os).Scan(&res)
if res == nil {
dbm_notenable(s.Model).Where("task_id", id).Where("out_state", os).Scan(&res)
}
// var res *model.TaskConfig
// for _, v := range item {
// if v.OutState == os {
@@ -41,6 +44,9 @@ func (s *TaskService) Get(id, os int) *model.TaskConfig {
func (s *TaskService) GetDaily() []model.TaskConfig {
var item []model.TaskConfig
dbm_enable(s.Model).Where("task_type", 1).Scan(&item)
if len(item) == 0 {
dbm_notenable(s.Model).Where("task_type", 1).Scan(&item)
}
return item
@@ -48,13 +54,19 @@ func (s *TaskService) GetDaily() []model.TaskConfig {
func (s *TaskService) GetWeek() []model.TaskConfig {
var item []model.TaskConfig
dbm_enable(s.Model).Where("task_type", 2).Scan(&item)
if len(item) == 0 {
dbm_notenable(s.Model).Where("task_type", 2).Scan(&item)
}
return item
}
func (s *TaskService) IsDaily(id, os int) bool {
var item *model.TaskConfig
dbm_enable(s.Model).Where("task_id", id).Where("out_state", os).Scan(item)
dbm_enable(s.Model).Where("task_id", id).Where("out_state", os).Scan(&item)
if item == nil {
dbm_notenable(s.Model).Where("task_id", id).Where("out_state", os).Scan(&item)
}
if item == nil {
return false
}