stable
This commit is contained in:
parent
fbdac9ebf1
commit
86226ccc94
97 changed files with 5790 additions and 2307 deletions
52
js/tarinai_local_environment_system.js
Normal file
52
js/tarinai_local_environment_system.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
"use strict";
|
||||
|
||||
// Layer: entity-runtime/tarinai/update-system
|
||||
// Owns local family/friend/grass/nest comfort environment effects.
|
||||
(function (global) {
|
||||
function legacyMethod(dt) {
|
||||
const parent = this.parentToFollow ? this.parentToFollow() : null;
|
||||
if (parent && dist(this, parent) < 96) {
|
||||
applyNeedRelief(this, { social: -dt * 4, safety: -dt * 2 });
|
||||
this.loneliness = clamp(this.loneliness - dt * 0.32, 0, 110);
|
||||
this.adjustPersonality("sociability", dt * 0.004 * this.sociabilityFriendScale(), "after staying near family.");
|
||||
}
|
||||
const friend = this.bestFriendLive ? this.bestFriendLive(FRIEND_AFFINITY_THRESHOLD, 92) : null;
|
||||
const friendCount = this.currentFriendCount ? this.currentFriendCount(FRIEND_AFFINITY_THRESHOLD, true) : 0;
|
||||
if (friend) {
|
||||
applyNeedRelief(this, { social: -dt * 3, fulfill: -dt * 1 });
|
||||
this.adjustPersonality("sociability", dt * 0.004 * this.sociabilityFriendScale(), "after staying near friends.");
|
||||
} else if (friendCount <= 0 && this.loneliness > 72 && this.age > 8) {
|
||||
this.adjustPersonality("sociability", -dt * 0.0018, "after having no friends.");
|
||||
}
|
||||
let grassComfort = 0;
|
||||
for (const it of this.world.nearbyItems(this.x, this.y, 105)) {
|
||||
if (it.type !== "grass" || it.dead) continue;
|
||||
const d = distXY(this.x, this.y, it.x, it.y);
|
||||
const lush = clamp((it.growth ?? it.amount / 120) * (it.health ?? 1), 0, 1.2);
|
||||
grassComfort += clamp(1 - d / 105, 0, 1) * lush;
|
||||
}
|
||||
let nestComfort = 0;
|
||||
for (const it of this.world.nearbyItems(this.x, this.y, 120)) {
|
||||
if (!it || it.dead || it.type !== "nest_box") continue;
|
||||
nestComfort += clamp(1 - distXY(this.x, this.y, it.x, it.y) / 120, 0, 1);
|
||||
}
|
||||
if (nestComfort > 0) applyNeedRelief(this, { sleep: -dt * Math.min(4, nestComfort * 3), safety: -dt * Math.min(5, nestComfort * 4) });
|
||||
if (grassComfort > 0) {
|
||||
applyNeedRelief(this, { fulfill: -dt * Math.min(2, grassComfort * 0.5), safety: -dt * Math.min(1.5, grassComfort * 0.4) });
|
||||
if (this.state === "panic") this.fearTimer = Math.max(0, this.fearTimer - dt * Math.min(0.22, grassComfort * 0.06));
|
||||
if (this.shouldApplyPersonalityBehavior("neuroticism", 1)) this.affection += dt * Math.min(0.06, grassComfort * 0.012);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function updateOne(tarinai, dt) {
|
||||
if (!tarinai || tarinai.dead) return false;
|
||||
legacyMethod.call(tarinai, dt);
|
||||
return true;
|
||||
}
|
||||
|
||||
global.TarinaiLocalEnvironmentSystem = Object.freeze({
|
||||
legacyMethod,
|
||||
updateOne,
|
||||
});
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
Loading…
Add table
Add a link
Reference in a new issue