1package gen 2 3import ( 4 "fmt" 5 6 "tinyadventure/internal/model" 7 "tinyadventure/internal/rng" 8 "tinyadventure/internal/sim" 9) 10 11const ( 12 guardChance = 40 13 mimicChance = 15 14 trapChance = 25 15) 16 17func placeLoot(p *placer, maxDist int, byPower []model.Faction) []model.Band { 18 var bands []model.Band 19 for _, c := range p.take(rng.Between(p.r, 6, 9), 4, func([2]int) bool { return true }) { 20 lv := levelAt(p.origin, maxDist, c[0], c[1]) 21 id := fmt.Sprintf("chest%d", len(p.m.Loot)+1) 22 roll := p.r.IntN(100) 23 bonus := 0 24 node := model.LootNode{ID: id, X: c[0], Y: c[1]} 25 switch { 26 case roll < guardChance: 27 bonus = 1 28 f := factionAt(byPower, p.progress(c, maxDist), p.r.Float64()) 29 bands = append(bands, model.Band{Kind: "guard", Name: "Guards", Faction: f.ID, Level: lv, X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1]}) 30 case roll < guardChance+mimicChance: 31 bonus = 2 32 bands = append(bands, model.Band{Kind: "mimic", Name: "Mimic", Level: lv, X: c[0], Y: c[1], HomeX: c[0], HomeY: c[1]}) 33 case roll < guardChance+mimicChance+trapChance: 34 bonus = 1 35 node.Trap = true 36 } 37 node.Item = sim.RollItem(p.r, lv+2*bonus) 38 p.m.Loot = append(p.m.Loot, node) 39 } 40 return bands 41} 42 43func factionAt(byPower []model.Faction, prog, jitter float64) model.Faction { 44 return byPower[min(len(byPower)-1, int(prog*float64(len(byPower))+jitter*0.8))] 45}