feat(capture): 重构捕捉系统,实现状态倍率计算和保底机制
This commit is contained in:
129
logic/service/fight/input/Capture.go
Normal file
129
logic/service/fight/input/Capture.go
Normal file
@@ -0,0 +1,129 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// 异常状态常量定义(对应数组索引)
|
||||
const (
|
||||
StatusParalysis = 0 // 麻痹
|
||||
StatusPoison = 1 // 中毒
|
||||
StatusSleep = 8 // 睡眠
|
||||
StatusFreeze = 3 // 冰冻
|
||||
// 预留其他状态到19
|
||||
)
|
||||
|
||||
// getItemBonus 获取道具倍率
|
||||
func getItemBonus(itemID uint32) float64 {
|
||||
if bonus, ok := xmlres.ItemsMAP[int(itemID)]; ok {
|
||||
return gconv.Float64(bonus.Bonus)
|
||||
}
|
||||
return 1.0
|
||||
}
|
||||
|
||||
// CaptureDetails 捕捉详情
|
||||
type CaptureDetails struct {
|
||||
Success bool
|
||||
Mode string
|
||||
BaseRate float64
|
||||
ModifiedRate float64
|
||||
GuaranteeBonus float64 // 百分比
|
||||
StatusBonus float64 // 状态倍率
|
||||
Details string
|
||||
}
|
||||
|
||||
// func main() {
|
||||
// ctx := NewPlayerCaptureContext()
|
||||
// fmt.Println("=== 精灵捕捉系统测试(状态数组版) ===")
|
||||
|
||||
// // 测试1:不同异常状态组合
|
||||
// fmt.Println("\n--- 异常状态测试 ---")
|
||||
// // 无异常状态
|
||||
// var noStatus [20]byte
|
||||
// // 中毒状态
|
||||
// var poisonStatus [20]byte
|
||||
// poisonStatus[StatusPoison] = 1
|
||||
// // 睡眠+冰冻状态(取最高倍率2.0)
|
||||
// var multipleStatus [20]byte
|
||||
// multipleStatus[StatusSleep] = 1
|
||||
// multipleStatus[StatusFreeze] = 1
|
||||
|
||||
// statusTests := []struct {
|
||||
// name string
|
||||
// status [20]byte
|
||||
// }{
|
||||
// {"无异常状态", noStatus},
|
||||
// {"中毒状态", poisonStatus},
|
||||
// {"睡眠+冰冻状态", multipleStatus},
|
||||
// }
|
||||
|
||||
// for _, test := range statusTests {
|
||||
// params := CaptureParams{
|
||||
// PetID: 1001,
|
||||
// MaxHP: 100,
|
||||
// CurrentHP: 10,
|
||||
// CatchRate: 50,
|
||||
// CatchDenom: 100,
|
||||
// ItemID: 300001,
|
||||
// Statuses: test.status,
|
||||
// OwnedCount: -1,
|
||||
// }
|
||||
// _, details := ctx.Capture(params)
|
||||
// fmt.Printf("%s: 状态倍率=%.1f | 基础成功率=%.2f%%\n",
|
||||
// test.name, details.StatusBonus, details.BaseRate)
|
||||
// }
|
||||
|
||||
// // 测试2:无敌胶囊
|
||||
// fmt.Println("\n--- 无敌胶囊测试 ---")
|
||||
// invincibleParams := CaptureParams{
|
||||
// PetID: 9999,
|
||||
// MaxHP: 1000,
|
||||
// CurrentHP: 1000,
|
||||
// CatchRate: 1,
|
||||
// CatchDenom: 1000,
|
||||
// ItemID: 300006,
|
||||
// Statuses: noStatus,
|
||||
// OwnedCount: -1,
|
||||
// }
|
||||
// success, details := ctx.Capture(invincibleParams)
|
||||
// fmt.Printf("捕捉结果: %v | 模式: %s | 成功率: %.2f%%\n",
|
||||
// success, details.Mode, details.ModifiedRate)
|
||||
|
||||
// // 测试3:锁定模式
|
||||
// fmt.Println("\n--- 锁定模式测试 ---")
|
||||
// lockParams := CaptureParams{
|
||||
// PetID: 1002,
|
||||
// MaxHP: 50,
|
||||
// CurrentHP: 1,
|
||||
// CatchRate: 100,
|
||||
// CatchDenom: 100,
|
||||
// ItemID: 300003,
|
||||
// Statuses: poisonStatus,
|
||||
// OwnedCount: 0,
|
||||
// }
|
||||
// success, details = ctx.Capture(lockParams)
|
||||
// fmt.Printf("捕捉结果: %v | 模式: %s | 成功率: %.2f%%\n",
|
||||
// success, details.Mode, details.ModifiedRate)
|
||||
|
||||
// // 测试4:衰减模式
|
||||
// fmt.Println("\n--- 衰减模式测试 ---")
|
||||
// decayParams := CaptureParams{
|
||||
// PetID: 1003,
|
||||
// MaxHP: 100,
|
||||
// CurrentHP: 10,
|
||||
// CatchRate: 50,
|
||||
// CatchDenom: 100,
|
||||
// ItemID: 300002,
|
||||
// Statuses: multipleStatus,
|
||||
// OwnedCount: 1,
|
||||
// }
|
||||
|
||||
// for i := 1; i <= 5; i++ {
|
||||
// decayParams.OwnedCount = i
|
||||
// success, details := ctx.Capture(decayParams)
|
||||
// fmt.Printf("拥有%d只 - 结果: %v | 基础成功率: %.2f%% | 实际成功率: %.2f%%\n",
|
||||
// i, success, details.BaseRate, details.ModifiedRate)
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user