refactor: 重构战斗属性和特效应用逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -3,6 +3,9 @@ package admin
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/service"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type SignRecordController struct {
|
||||
@@ -18,3 +21,16 @@ func init() {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type ResetAllReq struct {
|
||||
g.Meta `path:"/resetAll" method:"POST"`
|
||||
Authorization string `json:"Authorization" in:"header"`
|
||||
}
|
||||
|
||||
func (c *SignRecordController) ResetAll(ctx context.Context, req *ResetAllReq) (res *cool.BaseRes, err error) {
|
||||
result, err := service.NewSignService(0).ResetAll()
|
||||
if err != nil {
|
||||
return cool.Fail(err.Error()), nil
|
||||
}
|
||||
return cool.Ok(result), nil
|
||||
}
|
||||
|
||||
@@ -383,6 +383,13 @@ func (pet *PetInfo) RnadEffect() {
|
||||
// 7 :繁殖加成
|
||||
// 8 :体力提升加成
|
||||
|
||||
const (
|
||||
maxHPUpEffectIdx uint16 = 60000
|
||||
maxHPUpEffectStatus byte = 8
|
||||
maxHPUpEffectEID uint16 = 26
|
||||
maxHPUpEffectCap = 20
|
||||
)
|
||||
|
||||
// 繁殖加成,体力提升加成 ,这里是防止和其他重复所以定义不同类别,但是实际上,能量珠那些事调用不同id的effect实现
|
||||
// <!-- Stat: 精灵特效Stat: 0: 无效(默认值), 1: 永久, 2: 有`有效次数'的特效 3: 爆发特效 4: 异能精灵特质,5特训,6魂印-->
|
||||
func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) {
|
||||
@@ -393,6 +400,47 @@ func (pet *PetInfo) GetEffect(ptype int) (int, *PetEffectInfo, bool) {
|
||||
|
||||
}
|
||||
|
||||
func (pet *PetInfo) AddMaxHPUpEffect(itemID uint32, value int) bool {
|
||||
if pet == nil || value <= 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, eff, ok := pet.GetEffect(int(maxHPUpEffectStatus)); ok {
|
||||
current := 0
|
||||
if len(eff.Args) >= 2 && eff.Args[0] == 0 && eff.Args[1] > 0 {
|
||||
current = eff.Args[1]
|
||||
}
|
||||
if current >= maxHPUpEffectCap {
|
||||
return false
|
||||
}
|
||||
|
||||
next := current + value
|
||||
if next > maxHPUpEffectCap {
|
||||
next = maxHPUpEffectCap
|
||||
}
|
||||
|
||||
eff.ItemID = itemID
|
||||
eff.Idx = maxHPUpEffectIdx
|
||||
eff.Status = maxHPUpEffectStatus
|
||||
eff.EID = maxHPUpEffectEID
|
||||
eff.Args = []int{0, next}
|
||||
return next > current
|
||||
}
|
||||
|
||||
if value > maxHPUpEffectCap {
|
||||
value = maxHPUpEffectCap
|
||||
}
|
||||
|
||||
pet.EffectInfo = append(pet.EffectInfo, PetEffectInfo{
|
||||
ItemID: itemID,
|
||||
Idx: maxHPUpEffectIdx,
|
||||
Status: maxHPUpEffectStatus,
|
||||
EID: maxHPUpEffectEID,
|
||||
Args: []int{0, value},
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
func (pet *PetInfo) Downgrade(level uint32) {
|
||||
|
||||
for pet.Level > uint32(level) {
|
||||
|
||||
@@ -53,6 +53,13 @@ type SignClaimResult struct {
|
||||
Rewards []SignRewardResult `json:"rewards,omitempty"`
|
||||
}
|
||||
|
||||
// SignResetResult 表示管理端执行的签到重置结果。
|
||||
type SignResetResult struct {
|
||||
SignRecordRows int64 `json:"sign_record_rows"`
|
||||
CdkLogRows int64 `json:"cdk_log_rows"`
|
||||
ResetCdkIDs []uint32 `json:"reset_cdk_ids"`
|
||||
}
|
||||
|
||||
// SignService 管理玩家签到进度。
|
||||
type SignService struct {
|
||||
BaseService
|
||||
@@ -117,6 +124,46 @@ func (s *SignService) Claim() (*SignClaimResult, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SignService) ResetAll() (*SignResetResult, error) {
|
||||
result := &SignResetResult{}
|
||||
|
||||
signRes, err := cool.DBM(model.NewSignInRecord()).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if signRes != nil {
|
||||
result.SignRecordRows, _ = signRes.RowsAffected()
|
||||
}
|
||||
|
||||
configs := configservice.NewSignInService().GetEnabled()
|
||||
cdkIDs := make([]uint32, 0, len(configs))
|
||||
seen := make(map[uint32]struct{}, len(configs))
|
||||
for _, cfg := range configs {
|
||||
if cfg.CdkID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[cfg.CdkID]; ok {
|
||||
continue
|
||||
}
|
||||
seen[cfg.CdkID] = struct{}{}
|
||||
cdkIDs = append(cdkIDs, cfg.CdkID)
|
||||
}
|
||||
sort.Slice(cdkIDs, func(i, j int) bool { return cdkIDs[i] < cdkIDs[j] })
|
||||
result.ResetCdkIDs = cdkIDs
|
||||
|
||||
if len(cdkIDs) > 0 {
|
||||
cdkRes, err := cool.DBM(model.NewCdkLog()).WhereIn("code_id", cdkIDs).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cdkRes != nil {
|
||||
result.CdkLogRows, _ = cdkRes.RowsAffected()
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *SignService) grantReachedStageRewards(record *model.SignInRecord) ([]SignRewardResult, error) {
|
||||
configs := configservice.NewSignInService().GetEnabled()
|
||||
if len(configs) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user