File size: 2,970 Bytes
c04dd6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Shared helpers for boss modules of any game (load before the game's bosses/*.js).
// pick() = PlayMaker SendRandomEventV3: an event past its repeat cap is re-rolled, an event missed missMax times in a
// row is forced; with probability (1 - entropy) the choice is a fixed cycle instead (spec select.policy entropy_cycle).
(function (g) {
  var BB = g.BB;
  BB.bossKit = function (P, SPEC, ROLE) {
    P.spec = SPEC;
    P.role = function () { return ROLE[this.st] || 'idle'; };
    P.tele = function (c, base) {
      var tm = SPEC.timing.telegraph, t = base * this.k[tm.knob];
      if (tm.jitter && this.k[tm.jitter] > 0) t += c.rng.uniform(-this.k[tm.jitter], this.k[tm.jitter]);
      return Math.max(tm.min || 0, t);
    };
    P.rec = function (base) { return base * this.k[SPEC.timing.recovery.knob]; };
    P.spd = function () { return this.k[SPEC.locomotion.knob]; };
    P.face = function (c) { var hx = c.body.x; if (hx > this.x + 1e-6) this.f = 1; else if (hx < this.x - 1e-6) this.f = -1; };
    P.go = function (c, st, timer, move) {
      if (move !== undefined) this.move = move;
      this.st = st; this.timer = timer == null ? 0 : timer; this.stT = 0;
      if (ROLE[st] === 'telegraph' && SPEC.announce && this.move) { this.stamp = (this.stamp || 0) + 1; this.lastActive = null; c.emit(SPEC.announce.telegraph.replace('{move}', this.move)); }
      else if (ROLE[st] === 'active' && SPEC.announce && this.move && this.lastActive !== this.move + this.stamp) {
        this.lastActive = this.move + this.stamp; c.emit(SPEC.announce.active.replace('{move}', this.move));
      }
    };
    P.pick = function (c, key, evs, w, maxRep, missMax) {
      var tr = this.track || (this.track = {}), i, n = evs.length, ev = null;
      evs.forEach(function (e) { if (!tr[key + e]) tr[key + e] = { ct: 0, ms: 0 }; });
      if (c.rng.random() < this.k[SPEC.select.knob]) {
        if (missMax) for (i = 0; i < n && ev === null; i++) if (tr[key + evs[i]].ms >= missMax[i]) ev = evs[i];
        for (var guard = 0; ev === null && guard < 64; guard++) {
          var j = c.rng.pick(w);
          if (w[j] > 0 && (!maxRep || tr[key + evs[j]].ct < maxRep[j])) ev = evs[j];
        }
        if (ev === null) ev = evs[0];
      } else {
        var cy = this.cycle || (this.cycle = {}), live = evs.filter(function (e, i2) { return w[i2] > 0; });
        cy[key] = (cy[key] || 0) + 1; ev = live[(cy[key] - 1) % live.length];
      }
      evs.forEach(function (e) { var t = tr[key + e]; if (e === ev) { t.ct++; t.ms = 0; } else { t.ct = 0; t.ms++; } });
      return ev;
    };
    P.flash = function (dt) { if (this.hitFlash > 0) this.hitFlash = Math.max(0, this.hitFlash - dt); };
  };
  BB.clamp = function (v, lo, hi) { return v < lo ? lo : v > hi ? hi : v; };
  // per-tick exponential factor: "multiply by f every `step` seconds"
  BB.perTick = function (f, step) { return Math.pow(f, BB.DT / step); };
})(typeof window !== 'undefined' ? window : globalThis);