package server

import (
	"tinyadventure/internal/model"
	"tinyadventure/internal/rng"
	"tinyadventure/internal/sim"
)

const oddsRuns = 40

func (g *game) threatView() *model.Threat {
	enc, ok := g.encs[g.threat]
	if g.threat == "" || !ok {
		return nil
	}
	r := rng.New(g.state.Seed ^ model.Seed(g.fights+1)*104729)
	o := sim.Forecast(r, g.state.Party.Units, enc.Enemies, oddsRuns)
	t := &model.Threat{Enemies: enc.Enemies, Odds: o.Win, Wounds: o.Wounds, Falls: o.Falls, Worst: o.Worst, WorstUnit: o.WorstUnit, Edge: sim.EdgeOf(g.state.Party.Units, enc.Enemies)}
	if p := g.poi(g.threat); p != nil {
		t.POI, t.Barred = p.ID, !g.bossGate(p)
		if t.Barred {
			t.Needs = g.missingKeys()
		}
	} else {
		t.Band = g.threat
	}
	return t
}
