feat(capture): 重构捕捉系统,实现状态倍率计算和保底机制

This commit is contained in:
1
2025-09-21 14:56:37 +00:00
parent bb9b0510ce
commit 691cfc878b
17 changed files with 563 additions and 539 deletions

View File

@@ -0,0 +1,50 @@
package info
import "math/rand"
// PlayerCaptureContext 用户捕捉上下文(每次登录创建)
type PlayerCaptureContext struct {
Random *rand.Rand
Denominator int // 统一分母=1000
DecayFactor float64 // 衰减系数
MinDecayNum int // 衰减分子最小值
Guarantees map[int]int // 按分母分组的保底分子 map[denominator]numerator
}
// Roll 通用概率判定(带共享保底)
func (c *PlayerCaptureContext) Roll(numerator, denominator int) (bool, float64, float64) {
if denominator <= 0 {
return false, 0, 0
}
base := float64(numerator) / float64(denominator)
bonus := float64(c.getGuaranteeNumerator(denominator)) / float64(denominator)
total := base + bonus
if total > 1.0 {
total = 1.0
}
success := c.Random.Float64() < total
if success {
c.resetGuarantee(denominator)
} else {
c.increaseGuarantee(denominator)
}
return success, base * 100, bonus * 100
}
// 保底操作
func (c *PlayerCaptureContext) getGuaranteeNumerator(denominator int) int {
if num, ok := c.Guarantees[denominator]; ok {
return num
}
return 0
}
func (c *PlayerCaptureContext) increaseGuarantee(denominator int) {
c.Guarantees[denominator]++
}
func (c *PlayerCaptureContext) resetGuarantee(denominator int) {
c.Guarantees[denominator] = 0
}