feat(fight): 实现精灵切换功能并优化战斗逻辑

- 新增 ChangePet 方法实现精灵切换
- 优化战斗循环逻辑,支持精灵切换
- 修复一些战斗相关的 bug
- 优化代码结构,提高可维护性
This commit is contained in:
2025-09-07 00:23:28 +08:00
parent 6376d94487
commit 9d2de92dd6
12 changed files with 193 additions and 48 deletions

View File

@@ -3,6 +3,7 @@ package model
import (
"blazing/common/data/xmlres"
"blazing/cool"
"math"
"math/rand"
"time"
@@ -23,6 +24,17 @@ type Pet struct {
Data string `gorm:"type:text;not null;comment:'精灵全部数据'" json:"data"`
}
func GetGaussRandomNum(min, max int64) int64 {
σ := (float64(min) + float64(max)) / 2
μ := (float64(max) - σ) / 3
rand.Seed(time.Now().UnixNano())
x := rand.Float64()
x1 := rand.Float64()
a := math.Cos(2*math.Pi*x) * math.Sqrt((-2)*math.Log(x1))
result := a*μ + σ
return int64(result)
}
// RandomInRange 从切片表示的范围中返回对应结果:
// - 切片包含1个元素时返回该元素本身
// - 切片包含2个元素时从[min, max]闭区间随机生成一个整数自动调整min和max顺序
@@ -41,7 +53,8 @@ func RandomInRange(rangeSlice []int) int {
min, max = max, min
}
// 生成 [min, max] 区间的随机整数
return (rand.Intn(int(max-min+1)) + int(min))
return int(GetGaussRandomNum(int64(min), int64(max))) //(rand.Intn(int(max-min+1)) + int(min))
default:
// 其他长度返回0
return 0