refactor(fight): 统一战斗系统方法命名规范并优化逻辑 - 将所有下划线命名的方法统一为驼峰命名,如 Turn_Start 改为 TurnStart, Action_end_ex 改为 ActionEndEx,Turn_End 改为 TurnEnd - 新增 IsOwner() 方法用于判断当前精灵是否为场上的当前宠物 - 将硬编码的 CatchTime 比较逻辑替换为 IsOwner() 方法调用 - 在 NewSel408 中实现消除对手能力强化效果的具体逻辑 - 修复 effect_74 中衰弱状态的数值引用,使用枚举类型代替硬编码 - 优化 input/fight.go 中的技能选择逻辑,使用伤害值比较代替权重比较 - 移除 shiny.go 中未使用的 utils 导入和相关逻辑 - 修正 NewSel77 从 Turn_End 重命名为 TurnStart 的方法 - 在 input/fight.go 中添加 Damage 方法的注释说明 ```
106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/common/data"
|
|
"blazing/cool"
|
|
"blazing/modules/config/model"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
)
|
|
|
|
type ShinyService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
func NewShinyService() *ShinyService {
|
|
return &ShinyService{
|
|
&cool.Service{
|
|
Model: model.NewColorfulSkin(),
|
|
InsertParam: func(ctx context.Context) g.MapStrAny {
|
|
admin := cool.GetAdmin(ctx)
|
|
userId := admin.UserId
|
|
return g.MapStrAny{
|
|
"author": userId,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
}
|
|
func (s *ShinyService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
|
var t data.GlowFilter
|
|
|
|
if method == "Delete" {
|
|
return nil
|
|
}
|
|
r := json.Unmarshal([]byte(gconv.String(param["color"])), &t)
|
|
if r != nil {
|
|
return r
|
|
}
|
|
return nil
|
|
}
|
|
func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
|
var ret []model.ColorfulSkin
|
|
|
|
// 执行 Raw SQL 并扫描返回值
|
|
cool.DBM(s.Model).
|
|
Wheref(`bind_elf_ids @> ?::jsonb`, id).
|
|
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").
|
|
Where("is_enabled", 1).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ret)
|
|
|
|
for _, v := range ret {
|
|
//print(v.ID)
|
|
|
|
id := v.ID
|
|
|
|
if grand.Meet(int(v.ElfProbability), 1000) {
|
|
var t data.GlowFilter
|
|
|
|
r := json.Unmarshal([]byte(v.Color), &t)
|
|
if r == nil {
|
|
m := cool.DBM(s.Model).Where("id", id)
|
|
m.Increment("refresh_count", 1)
|
|
return &t
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
|
|
var ret []model.ColorfulSkin
|
|
|
|
// 执行 Raw SQL 并扫描返回值
|
|
cool.DBM(s.Model).
|
|
Wheref(`bind_elf_ids @> ?::jsonb`, id).
|
|
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").
|
|
Where("is_enabled", 1).
|
|
Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ret)
|
|
|
|
v := ret[grand.Intn(len(ret))]
|
|
|
|
var t data.GlowFilter
|
|
|
|
r := json.Unmarshal([]byte(v.Color), &t)
|
|
if r == nil {
|
|
m := cool.DBM(s.Model).Where("id", v.ID)
|
|
m.Increment("usage_count", 1)
|
|
return &t
|
|
}
|
|
|
|
return nil
|
|
}
|