feat(game): 动物自然生成(草面/白天/限频)与繁殖冷却/成长;村民交易表数据驱动(含测试)
This commit is contained in:
@@ -34,10 +34,11 @@ type Session struct {
|
||||
Entities *entity.Manager
|
||||
BlockEntities map[[3]int32]*blockentity.Entity
|
||||
|
||||
// 自然生成计时(僵尸与敌对生物.md §5:夜晚/黑暗处刷怪)
|
||||
spawnTimer float64
|
||||
damageIn float64 // 玩家受击冷却
|
||||
rng *rand.Rand
|
||||
// 自然生成计时(僵尸与敌对生物.md §5、动物体系.md §6)
|
||||
spawnTimer float64
|
||||
animalTimer float64
|
||||
damageIn float64 // 玩家受击冷却
|
||||
rng *rand.Rand
|
||||
|
||||
// 破坏进度状态(方块交互与动画.md §3)
|
||||
breakTarget raycast.Hit
|
||||
@@ -84,6 +85,8 @@ func (s *Session) Tick(dt float64) {
|
||||
}
|
||||
// 夜间刷僵尸(僵尸与敌对生物.md §5:黑暗处、距玩家 24 格、限频)
|
||||
s.spawnZombies(dt)
|
||||
// 白天刷动物(动物体系.md §6:草面、亮度≥9、距玩家 16–32、限频)
|
||||
s.spawnAnimals(dt)
|
||||
// 僵尸近身伤害(僵尸与敌对生物.md §3:3 点/秒)
|
||||
s.applyZombieDamage(dt)
|
||||
// 相机跟随玩家眼睛
|
||||
@@ -278,6 +281,49 @@ func (s *Session) spawnZombies(dt float64) {
|
||||
}
|
||||
}
|
||||
|
||||
// spawnAnimals 白天刷动物(动物体系.md §6:草面、天空光 ≥9、距玩家 16–32、每 10 秒一只)。
|
||||
func (s *Session) spawnAnimals(dt float64) {
|
||||
s.animalTimer -= dt
|
||||
if s.animalTimer > 0 {
|
||||
return
|
||||
}
|
||||
s.animalTimer = 10.0
|
||||
for i := 0; i < 16; i++ {
|
||||
ang := s.rng.Float64() * 2 * math.Pi
|
||||
dist := 16 + s.rng.Float64()*16
|
||||
x := int32(s.Player.Pos[0] + math.Cos(ang)*dist)
|
||||
z := int32(s.Player.Pos[2] + math.Sin(ang)*dist)
|
||||
var y int32
|
||||
for y = 255; y > 0; y-- {
|
||||
if s.World.Block(x, y, z) != block.Air {
|
||||
break
|
||||
}
|
||||
}
|
||||
if s.World.Block(x, y+1, z) != block.Air {
|
||||
continue
|
||||
}
|
||||
// 只在草面上且白天(天空光 ≥9)
|
||||
if s.World.Block(x, y, z).ID() != s.grassID() {
|
||||
continue
|
||||
}
|
||||
if s.World.SkyLight(x, y+1, z) < 9 {
|
||||
continue
|
||||
}
|
||||
e := s.Entities.Spawn(entity.KindAnimal, float64(x)+0.5, float64(y+1), float64(z)+0.5)
|
||||
e.Data = &entity.Animal{}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// grassID 草方块 ID(注册表查询缓存值)。
|
||||
func (s *Session) grassID() uint16 {
|
||||
id, ok := s.Reg.ID("grass_block")
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// applyZombieDamage 僵尸近身伤害(僵尸与敌对生物.md §3:约 3 点/秒)。
|
||||
func (s *Session) applyZombieDamage(dt float64) {
|
||||
if s.Health <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user