2025-09-21 14:56:37 +00:00
|
|
|
package info
|
|
|
|
|
|
2026-03-28 21:57:22 +08:00
|
|
|
import "github.com/gogf/gf/v2/util/grand"
|
2025-09-21 14:56:37 +00:00
|
|
|
|
|
|
|
|
// PlayerCaptureContext 用户捕捉上下文(每次登录创建)
|
|
|
|
|
type PlayerCaptureContext struct {
|
|
|
|
|
Denominator int // 统一分母=1000
|
|
|
|
|
DecayFactor float64 // 衰减系数
|
|
|
|
|
MinDecayNum int // 衰减分子最小值
|
|
|
|
|
Guarantees map[int]int // 按分母分组的保底分子 map[denominator]numerator
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 01:28:55 +08:00
|
|
|
func NewPlayerCaptureContext() *PlayerCaptureContext {
|
|
|
|
|
return &PlayerCaptureContext{
|
|
|
|
|
Denominator: 1000,
|
|
|
|
|
DecayFactor: 0.10,
|
|
|
|
|
MinDecayNum: 1,
|
|
|
|
|
Guarantees: make(map[int]int),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-14 04:55:29 +08:00
|
|
|
// Roll 通用概率判定(带共享保底) 返回成功,基础,保底
|
2025-09-21 14:56:37 +00:00
|
|
|
func (c *PlayerCaptureContext) Roll(numerator, denominator int) (bool, float64, float64) {
|
|
|
|
|
if denominator <= 0 {
|
|
|
|
|
return false, 0, 0
|
|
|
|
|
}
|
2026-04-08 01:28:55 +08:00
|
|
|
if c == nil {
|
|
|
|
|
c = NewPlayerCaptureContext()
|
|
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
|
|
|
|
|
base := float64(numerator) / float64(denominator)
|
2026-03-28 21:57:22 +08:00
|
|
|
bonusNumerator := c.getGuaranteeNumerator(denominator)
|
|
|
|
|
bonus := float64(bonusNumerator) / float64(denominator)
|
2025-09-21 14:56:37 +00:00
|
|
|
total := base + bonus
|
|
|
|
|
if total > 1.0 {
|
|
|
|
|
total = 1.0
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 21:57:22 +08:00
|
|
|
totalNumerator := numerator + bonusNumerator
|
|
|
|
|
if totalNumerator > denominator {
|
|
|
|
|
totalNumerator = denominator
|
|
|
|
|
}
|
|
|
|
|
success := grand.Intn(denominator) < totalNumerator
|
2025-09-21 14:56:37 +00:00
|
|
|
|
|
|
|
|
if success {
|
|
|
|
|
c.resetGuarantee(denominator)
|
|
|
|
|
} else {
|
|
|
|
|
c.increaseGuarantee(denominator)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success, base * 100, bonus * 100
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保底操作
|
|
|
|
|
func (c *PlayerCaptureContext) getGuaranteeNumerator(denominator int) int {
|
2026-04-08 01:28:55 +08:00
|
|
|
if c == nil || c.Guarantees == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
if num, ok := c.Guarantees[denominator]; ok {
|
|
|
|
|
return num
|
|
|
|
|
}
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
func (c *PlayerCaptureContext) increaseGuarantee(denominator int) {
|
2026-04-08 01:28:55 +08:00
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if c.Guarantees == nil {
|
|
|
|
|
c.Guarantees = make(map[int]int)
|
|
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
c.Guarantees[denominator]++
|
|
|
|
|
}
|
|
|
|
|
func (c *PlayerCaptureContext) resetGuarantee(denominator int) {
|
2026-04-08 01:28:55 +08:00
|
|
|
if c == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if c.Guarantees == nil {
|
|
|
|
|
c.Guarantees = make(map[int]int)
|
|
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
c.Guarantees[denominator] = 0
|
|
|
|
|
}
|