feat(fight): 新增疲惫状态并优化睡眠状态机制 - 实现疲惫状态(StatusTired),仅限制攻击技能,允许属性技能正常使用 - 重构睡眠状态,改为在被攻击且未miss时立即解除,而非技能使用后 - 修复寄生种子效果触发时机,改为回合开始时触发 - 调整寄生效果的目标为技能施放者而非
This commit is contained in:
@@ -16,7 +16,7 @@ type CDKConfig struct {
|
||||
|
||||
// 核心字段
|
||||
CDKCode string `gorm:"not null;size:16;uniqueIndex;comment:'CDK编号(唯一标识,用于玩家兑换)'" json:"cdk_code" description:"CDK编号"`
|
||||
CDKType uint32 `gorm:"column:type;not null;default:0;comment:'CDK类型:0普通奖励,1服务器冠名'" json:"type" description:"CDK类型"`
|
||||
Type uint32 `gorm:"column:type;not null;default:0;comment:'CDK类型:0普通奖励,1服务器冠名'" json:"type" description:"CDK类型"`
|
||||
|
||||
//cdk可兑换次数,where不等于0
|
||||
ExchangeRemainCount int64 `gorm:"not null;default:1;comment:'CDK剩余可兑换次数(不能为0才允许兑换,支持查询where !=0)'" json:"exchange_remain_count" description:"剩余可兑换次数"`
|
||||
|
||||
@@ -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(¤tShow); 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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ type DonationServerListReq struct {
|
||||
g.Meta `path:"/donation/serverIds" method:"GET"`
|
||||
}
|
||||
|
||||
type DonationCurrentReq struct {
|
||||
g.Meta `path:"/donation/current" method:"GET"`
|
||||
}
|
||||
|
||||
type DonationServerInfoReq struct {
|
||||
g.Meta `path:"/donation/serverInfo" method:"GET"`
|
||||
ServerID uint32 `json:"server_id" v:"required|min:1#服务器ID不能为空|服务器ID非法"`
|
||||
@@ -68,6 +72,18 @@ func (c *CdkController) DonationServerIDs(ctx context.Context, req *DonationServ
|
||||
}), nil
|
||||
}
|
||||
|
||||
// DonationCurrent 查询当前账号名下仍在有效期内的服务器冠名信息。
|
||||
func (c *CdkController) DonationCurrent(ctx context.Context, req *DonationCurrentReq) (res *cool.BaseRes, err error) {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
if admin == nil || admin.UserId == 0 {
|
||||
return cool.Fail("未登录或登录已失效"), nil
|
||||
}
|
||||
|
||||
return cool.Ok(g.Map{
|
||||
"list": configservice.NewServerService().GetOwnerActiveDonationServers(uint32(admin.UserId)),
|
||||
}), nil
|
||||
}
|
||||
|
||||
// DonationServerInfo 查询冠名兑换前展示的服务器名称与备注。
|
||||
func (c *CdkController) DonationServerInfo(ctx context.Context, req *DonationServerInfoReq) (res *cool.BaseRes, err error) {
|
||||
if err = g.Validator().Data(req).Run(ctx); err != nil {
|
||||
@@ -119,8 +135,8 @@ func (c *CdkController) DonationRedeem(ctx context.Context, req *DonationRedeemR
|
||||
if cdkInfo == nil {
|
||||
return cool.Fail("CDK不存在或已被使用"), nil
|
||||
}
|
||||
if cdkInfo.CDKType != configservice.CDKTypeServerNaming {
|
||||
return cool.Fail("CDK类型不匹配"), nil
|
||||
if cdkInfo.Type != configservice.CDKTypeServerNaming {
|
||||
return cool.Fail("当前页面仅支持服务器冠名CDK,请确认输入的是服务器冠名类型"), nil
|
||||
}
|
||||
if cdkInfo.BindUserId != 0 && cdkInfo.BindUserId != ownerID {
|
||||
return cool.Fail("CDK已绑定其他用户"), nil
|
||||
|
||||
Reference in New Issue
Block a user