stable
This commit is contained in:
parent
0f1cb2fe6c
commit
129c07183a
51 changed files with 5711 additions and 1122 deletions
|
|
@ -1,4 +1,34 @@
|
|||
"use strict";
|
||||
(function ensureDeterministicHelpers(global) {
|
||||
if (typeof global.deterministicChance === "function" && typeof global.deterministicRange === "function") return;
|
||||
const clamp01 = v => Math.max(0, Math.min(1, Number(v) || 0));
|
||||
const keyPart = value => {
|
||||
if (value == null) return "null";
|
||||
if (typeof value === "number") return Number.isFinite(value) ? value.toFixed(3) : "nan";
|
||||
if (typeof value === "string" || typeof value === "boolean") return String(value);
|
||||
if (typeof value === "object") {
|
||||
const id = value.familyKey || value.id || value.seed || value.liveToken || value.name;
|
||||
if (id) return `${value.type || value.constructor?.name || "entity"}:${id}`;
|
||||
const x = Number.isFinite(value.x) ? value.x.toFixed(1) : "x";
|
||||
const y = Number.isFinite(value.y) ? value.y.toFixed(1) : "y";
|
||||
return `${value.type || value.constructor?.name || "entity"}@${x},${y}`;
|
||||
}
|
||||
return String(value);
|
||||
};
|
||||
const hashUnit = (seed, salt = "") => {
|
||||
const str = `${seed}:${salt}`;
|
||||
let h = 2166136261;
|
||||
for (let i = 0; i < str.length; i++) { h ^= str.charCodeAt(i); h = Math.imul(h, 16777619); }
|
||||
return ((h >>> 0) % 100000) / 100000;
|
||||
};
|
||||
global.deterministicFrame = global.deterministicFrame || ((worldRef = null, hz = 60) => Math.floor((Number(worldRef?.time || 0) || 0) * Math.max(1, Number(hz) || 60) + 1e-6));
|
||||
global.deterministicUnit = global.deterministicUnit || ((worldRef = null, salt = "", ...parts) => hashUnit(String(worldRef?.worldSeed || "tarinai-world"), [salt, global.deterministicFrame(worldRef, 60), Number(worldRef?._deterministicEpoch || 0) || 0, ...parts.map(keyPart)].join("|")));
|
||||
global.deterministicRange = global.deterministicRange || ((worldRef = null, salt = "", min = 0, max = 1, ...parts) => (Number(min) || 0) + global.deterministicUnit(worldRef, salt, ...parts) * ((Number(max) || 0) - (Number(min) || 0)));
|
||||
global.deterministicSigned = global.deterministicSigned || ((worldRef = null, salt = "", ...parts) => global.deterministicUnit(worldRef, salt, ...parts) < 0.5 ? -1 : 1);
|
||||
global.deterministicChance = global.deterministicChance || ((worldRef = null, salt = "", chance = 0, ...parts) => { const p = clamp01(chance); return p >= 1 || (p > 0 && global.deterministicUnit(worldRef, salt, ...parts) < p); });
|
||||
global.deterministicAngle = global.deterministicAngle || ((worldRef = null, salt = "", ...parts) => global.deterministicRange(worldRef, salt, 0, Math.PI * 2, ...parts));
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
|
||||
|
||||
// Layer: entity-runtime/tarinai/update-step
|
||||
// Owns per-frame timers, passive metabolism, disease/effect ticks, colony mood
|
||||
|
|
@ -76,7 +106,7 @@
|
|||
t.defeatedTimer = Math.max(0, t.defeatedTimer - dt);
|
||||
if (wasFighting && t.fightTimer <= 0.04 && t.defeatedById) {
|
||||
const winner = t.world.liveTarinaiById?.(t.defeatedById) || null;
|
||||
t.defeatedTimer = Math.max(t.defeatedTimer, rand(3.4, 5.2));
|
||||
t.defeatedTimer = Math.max(t.defeatedTimer, deterministicRange(t.world, "defeated-recover-timer", 3.4, 5.2, t));
|
||||
t.fearTimer = Math.max(t.fearTimer, 1.0 * t.personalityProfile().fear);
|
||||
t.hurtTimer = Math.max(t.hurtTimer, 1.8);
|
||||
t.fallTimer = Math.max(t.fallTimer, 1.15);
|
||||
|
|
@ -96,27 +126,27 @@
|
|||
&& (t.fallTimer || 0) <= 0.04
|
||||
&& !t.dead
|
||||
&& !["sleep", "fight", "panic", "birth_ritual", "frozen"].includes(String(t.state || ""))
|
||||
&& Math.random() < dt * 0.055) {
|
||||
const dir = Math.random() < 0.5 ? -1 : 1;
|
||||
t.groundStumbleCooldown = rand(8.5, 16.0);
|
||||
t.fallTimer = Math.max(t.fallTimer || 0, rand(0.86, 1.18));
|
||||
&& deterministicChance(t.world, "foot-massage-stumble", dt * 0.055, t)) {
|
||||
const dir = deterministicSigned(t.world, "foot-massage-stumble-dir", t);
|
||||
t.groundStumbleCooldown = deterministicRange(t.world, "foot-massage-stumble-cooldown", 8.5, 16.0, t);
|
||||
t.fallTimer = Math.max(t.fallTimer || 0, deterministicRange(t.world, "foot-massage-stumble-fall", 0.86, 1.18, t));
|
||||
t.fallMax = Math.max(t.fallMax || 1.05, t.fallTimer);
|
||||
t.fallDir = dir;
|
||||
t.vx += dir * rand(26, 52);
|
||||
t.vy += rand(-18, 18);
|
||||
t.vx += dir * deterministicRange(t.world, "foot-massage-stumble-vx", 26, 52, t);
|
||||
t.vy += deterministicRange(t.world, "foot-massage-stumble-vy", -18, 18, t);
|
||||
t.world?.spawnFallEffect?.(t.x, t.y + t.radius * 0.45);
|
||||
t.setActionState?.("idle", { target: null, reason: "足つぼの突起につまづいた。", sleeping: false, clearTarget: false });
|
||||
if ((t.world?.time || 0) >= (t.nextBubbleAt || 0)) t.bubble?.("うっ", 1.6, "rgba(86,70,96,0.78)");
|
||||
}
|
||||
if (t.stress > 92 && t.state !== "sleep" && t.state !== "fight" && t.state !== "eat" && Math.random() < dt * 0.050) {
|
||||
if (t.stress > 92 && t.state !== "sleep" && t.state !== "fight" && t.state !== "eat" && deterministicChance(t.world, "stress-breath-bubble", dt * 0.050, t)) {
|
||||
t.bubble("はっ...はっ...", 3.4, "rgba(58,48,63,0.80)");
|
||||
}
|
||||
if (t.state === "idle" && t.stress < 78 && Math.random() < dt * 0.018) {
|
||||
if (t.state === "idle" && t.stress < 78 && deterministicChance(t.world, "idle-bubble", dt * 0.018, t)) {
|
||||
t.bubble(pick(["はう", "はうぅ", "はうっ", "はぅ"]), 4.2, "rgba(62,84,45,0.76)");
|
||||
}
|
||||
if (t.hurtTimer > 0 && Math.random() < dt * 5.2) {
|
||||
if (t.hurtTimer > 0 && deterministicChance(t.world, "hurt-bleed-effect", dt * 5.2, t)) {
|
||||
const side = t.facingDir();
|
||||
t.world.spawnBleedEffect(t.x - side * t.radius * rand(0.15, 0.42), t.y - t.radius * rand(0.08, 0.34));
|
||||
t.world.spawnBleedEffect(t.x - side * t.radius * deterministicRange(t.world, "hurt-bleed-x", 0.15, 0.42, t), t.y - t.radius * deterministicRange(t.world, "hurt-bleed-y", 0.08, 0.34, t));
|
||||
}
|
||||
|
||||
t.tempTimer += dt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue