提交信息

This commit is contained in:
1
2025-08-27 20:52:15 +00:00
parent fc2f88f14a
commit b36ff6d0f1
10 changed files with 283 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ import (
"blazing/logic/service/maps"
"blazing/logic/service/space"
mservice "blazing/modules/blazing/service"
"math/rand"
"time"
)
@@ -31,7 +32,15 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps
// 启动刷怪协程
go func(stopChan chan struct{}, currentMap int) {
ticker := time.NewTicker(5 * time.Second)
time.After(5 * time.Second)
// 首次刷新
if !c.IsFighting && c.MapId != 0 {
spawnMonsters(c)
}
//循环刷新怪物
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
for {
@@ -103,29 +112,24 @@ func spawnMonsters(c *entity.Player) {
// 创建数据包
tt := handler.NewTomeeHeader(2004, c.UserID)
t1 := genMonster(c.MapId)
t1 := genMonster(c.MapId, generateThreeUniqueNumbers())
c.SendPack(tt.Pack(&t1))
}
func genMonster(id uint32) maps.OgreInfo {
// 应该根据怪物信息决定后端生成
func genMonster(mapid uint32, wz [3]int) maps.OgreInfo {
// 设置怪物信息
t1 := maps.OgreInfo{}
var localMenu = make([]int, 0)
for i := 7; i <= 448; i++ {
if bitsCount(i) == 3 {
localMenu = append(localMenu, i)
}
}
for i := 0; i < 3; i++ {
ttt := maps.OgrePetInfo{}
ttt.Id = mservice.NewMonsterService().GetId(id)
ttt.Id = mservice.NewMonsterService().GetId(mapid) //待修改成xml获取
ttt.Shiny = uint32(i + 1)
ttt.Shiny = uint32(i + 1) //异色概率,待实现自定义
//t1.Data[i] = mservice.NewMonsterService().GetId(c.MapId)
t1.Data[i] = ttt
t1.Data[wz[i]] = ttt
}
return t1
@@ -140,3 +144,50 @@ func bitsCount(n int) int {
}
return count
}
// 生成0-9之间三个不重复的随机数 进地图5s
func generateThreeUniqueNumbers() [3]int {
rand.Seed(time.Now().UnixNano())
selected := make(map[int]bool)
var result [3]int
index := 0
for index < 3 {
num := rand.Intn(10)
if !selected[num] {
selected[num] = true
result[index] = num
index++
}
}
return result
}
// 从三个数字中移除一个并从剩余6个数字中选一个补充 10s
func replaceOneNumber(original [3]int) ([3]int, int, int) {
// 随机选择要移除的索引0-2
removeIndex := rand.Intn(3)
removedNum := original[removeIndex]
// 找出所有不在原始数组中的数字(候选数字)
candidates := []int{}
originalMap := make(map[int]bool)
for _, num := range original {
originalMap[num] = true
}
for i := 0; i < 10; i++ {
if !originalMap[i] {
candidates = append(candidates, i)
}
}
// 从候选数字中随机选择一个
newNum := candidates[rand.Intn(len(candidates))]
// 创建新数组并替换数字
newNumbers := original
newNumbers[removeIndex] = newNum
return newNumbers, removedNum, newNum
}