Spaces:
Sleeping
Sleeping
Update mechanics.js
Browse files- mechanics.js +25 -24
mechanics.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
// LEVEL EVOLUTION β MECHANICS ENGINE (Pure JavaScript ES Module)
|
| 4 |
// ============================================================================
|
| 5 |
|
| 6 |
-
// βββ composition βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 7 |
export const COMPOSITION_ORDER = [ 'ANIMALIA', 'CHITINARIA', 'PLANTAE', 'CNIDARIA', 'MYCELIUM', 'MINERALIS' ];
|
| 8 |
|
| 9 |
export const COMPOSITION_META = {
|
|
@@ -11,7 +11,7 @@ export const COMPOSITION_META = {
|
|
| 11 |
CHITINARIA:{ label: 'Chitinaria', blurb: 'Free ARMOR at β₯30%. Periodic molt window drops defense briefly.', freeStructure: 'ARMOR', accent: '#d97706', glow: '#f59e0b' },
|
| 12 |
PLANTAE: { label: 'Plantae', blurb: 'Passive energy regen in light; free ACID resistance. Neural capped at 4.', accent: '#22c55e', glow: '#4ade80' },
|
| 13 |
CNIDARIA: { label: 'Cnidaria', blurb: 'Free SOFT structure; toxin Features cost less. CONDUCTIVE β vulnerable to Electric.', freeStructure: 'SOFT', accent: '#06b6d4', glow: '#22d3ee' },
|
| 14 |
-
MYCELIUM: { label: 'Mycelium', blurb: 'Free REGEN;
|
| 15 |
MINERALIS: { label: 'Mineralis', blurb: 'Free BRITTLE; zero food need. Immune to TOXIN/ACID. Cannot regenerate.', freeStructure: 'BRITTLE', accent: '#e2e8f0', glow: '#f1f5f9' },
|
| 16 |
};
|
| 17 |
|
|
@@ -26,7 +26,7 @@ export function setCompositionLinked(comps, key, value) {
|
|
| 26 |
const oldSum = others.reduce((s, k) => s + comps[k], 0);
|
| 27 |
const residual = 100 - clamped;
|
| 28 |
const next = { ...comps, [key]: clamped };
|
| 29 |
-
|
| 30 |
if (oldSum === 0) {
|
| 31 |
const each = Math.floor(residual / others.length);
|
| 32 |
others.forEach((k, i) => { next[k] = i === 0 ? residual - each * (others.length - 1) : each; });
|
|
@@ -49,7 +49,7 @@ export function attributeCap(attr, comps) {
|
|
| 49 |
const mycel = comps.MYCELIUM >= 30;
|
| 50 |
const mineral = comps.MINERALIS >= 30;
|
| 51 |
const chitin = comps.CHITINARIA >= 30;
|
| 52 |
-
|
| 53 |
if (attr === 'NEURAL_COMPLEXITY') { if (plant) return 4; if (mycel) return 3; if (mineral) return 2; }
|
| 54 |
if (attr === 'METABOLIC_RATE') { if (mycel) return 4; if (mineral) return 0; }
|
| 55 |
if (attr === 'REGENERATION') { if (mineral) return 0; }
|
|
@@ -77,7 +77,7 @@ export const FEATURE_META = [
|
|
| 77 |
{ type:'GELATINOUS_BODY', label:'Gelatinous Body', category:'Defense', tags:[], baseCost:10, costMult:{CNIDARIA:0}, blurb:'Forces SOFT. Absorbs CRUSH/SONIC; PIERCE/SLASH/TOXIN punish it.' },
|
| 78 |
{ type:'SLIME_COATING', label:'Slime Coating', category:'Defense', tags:[], baseCost:8, requires:{CNIDARIA:15}, blurb:'SLIME modifier β escape chance vs GRAPPLE; small general dodge.' },
|
| 79 |
{ type:'DUST_COATING', label:'Dust Coating', category:'Defense', tags:[], baseCost:9, blurb:'One guaranteed dodge per encounter. Skipped if attacker out-speeds; cleared by SONIC/ACID.' },
|
| 80 |
-
{ type:'REGENERATIVE_FLESH', label:'Regenerative Flesh', category:'Defense', tags:[], baseCost:11, requires:{MYCELIUM:15}, blurb:'REGEN modifier β
|
| 81 |
{ type:'BIOLUMINESCENT_DETERRENT', label:'Bioluminescent Deterrent', category:'Defense', tags:[], baseCost:9, requires:{CNIDARIA:20}, blurb:'Flinch chance to interrupt attacker. Ignored by high Neural Complexity.' },
|
| 82 |
{ type:'SPINY_RIDGE', label:'Spiny Ridge', category:'Defense', tags:[], baseCost:8, requires:{CHITINARIA:20}, blurb:'Reflects chunk of melee CRUSH/SLASH back. Piercing/ranged ignore it.' },
|
| 83 |
{ type:'CAMOUFLAGE_PATTERNS', label:'Camouflage Patterns', category:'Defense', tags:[], baseCost:9, blurb:'Shrinks detection radius; dodge chance vs low-Neural attackers. Costs offense.' },
|
|
@@ -185,35 +185,35 @@ export function getDerivedStats(state, biome) {
|
|
| 185 |
defense += A.BONE_DENSITY * 2;
|
| 186 |
weight += A.BONE_DENSITY * 2.5;
|
| 187 |
speed -= A.BONE_DENSITY * 1.5;
|
| 188 |
-
|
| 189 |
speed += A.METABOLIC_RATE * 2;
|
| 190 |
energyDemand += A.METABOLIC_RATE * 2;
|
| 191 |
heatTolerance += A.METABOLIC_RATE * 3;
|
| 192 |
-
|
| 193 |
hp += A.FAT_RESERVES * 5;
|
| 194 |
weight += A.FAT_RESERVES * 1.5;
|
| 195 |
speed -= A.FAT_RESERVES * 0.5;
|
| 196 |
-
|
| 197 |
energyDemand += A.NEURAL_COMPLEXITY * 1.5;
|
| 198 |
matingSpeed -= A.NEURAL_COMPLEXITY * 0.04;
|
| 199 |
detection += A.NEURAL_COMPLEXITY * 6;
|
| 200 |
-
|
| 201 |
energyDemand += A.REGENERATION * 2;
|
| 202 |
hp -= A.REGENERATION * 1;
|
| 203 |
-
|
| 204 |
coldTolerance += A.INSULATION * 5;
|
| 205 |
heatTolerance -= A.INSULATION * 2;
|
| 206 |
energyDemand += A.INSULATION;
|
| 207 |
speed -= A.INSULATION * 0.3;
|
| 208 |
-
|
| 209 |
weight += A.WATER_RETENTION * 0.5;
|
| 210 |
speed -= A.WATER_RETENTION * 0.2;
|
| 211 |
desiccationRate -= A.WATER_RETENTION * 0.08;
|
| 212 |
-
|
| 213 |
energyDemand += A.THERMAL_REGULATION * 0.8;
|
| 214 |
heatTolerance += A.THERMAL_REGULATION * 3;
|
| 215 |
coldTolerance += A.THERMAL_REGULATION * 3;
|
| 216 |
-
|
| 217 |
offense -= A.CAMOUFLAGE * 0.5;
|
| 218 |
detection -= A.CAMOUFLAGE * 4;
|
| 219 |
defense -= A.BUOYANCY * 0.4;
|
|
@@ -222,7 +222,7 @@ export function getDerivedStats(state, biome) {
|
|
| 222 |
if (state.compositions.PLANTAE >= 30) hp += 20;
|
| 223 |
if (state.compositions.MYCELIUM >= 30) { hp -= 10; matingSpeed += 0.5; }
|
| 224 |
if (state.compositions.MINERALIS >= 30) { energyDemand = 0; weight += 30; speed -= 10; }
|
| 225 |
-
|
| 226 |
const mods = activeModifiers(state);
|
| 227 |
const isAerial = mods.has('AERIAL');
|
| 228 |
const isAquatic = mods.has('AQUATIC');
|
|
@@ -295,7 +295,7 @@ export function resolveCombat(attacker, defender, biome, rng = Math.random) {
|
|
| 295 |
const defMods = activeModifiers(defender);
|
| 296 |
const attMods = activeModifiers(attacker);
|
| 297 |
const notes = [];
|
| 298 |
-
|
| 299 |
let attackerFirst = true;
|
| 300 |
if (defMods.has('LURE') && attacker.attributes.NEURAL_COMPLEXITY < 5) {
|
| 301 |
attackerFirst = false; notes.push('Defender LURE overrides Speed');
|
|
@@ -324,10 +324,10 @@ export function resolveCombat(attacker, defender, biome, rng = Math.random) {
|
|
| 324 |
if (evaded) {
|
| 325 |
return {
|
| 326 |
won: false,
|
| 327 |
-
breakdown: {
|
| 328 |
-
attackerFirst, evasionChance, evaded,
|
| 329 |
effectiveOffense: 0, effectiveDefense: 0,
|
| 330 |
-
winProbability: 0, roll: 0, attackerWon: false,
|
| 331 |
tagsUsed: [], notes: [...notes, 'Evaded before contact'],
|
| 332 |
primaryTag: null, isShatter: false
|
| 333 |
},
|
|
@@ -348,7 +348,8 @@ export function resolveCombat(attacker, defender, biome, rng = Math.random) {
|
|
| 348 |
for (const tag of uniqueTags) {
|
| 349 |
let mult = COUNTER_CHART[tag][defStruct];
|
| 350 |
if (tag === 'TOXIN') {
|
| 351 |
-
if (
|
|
|
|
| 352 |
else if (defMods.has('REGEN')) { mult *= 0.5; notes.push('Defender REGEN halves Toxin'); }
|
| 353 |
}
|
| 354 |
if (tag === 'ELECTRIC') {
|
|
@@ -387,10 +388,10 @@ export function resolveCombat(attacker, defender, biome, rng = Math.random) {
|
|
| 387 |
|
| 388 |
return {
|
| 389 |
won: attackerWon,
|
| 390 |
-
breakdown: {
|
| 391 |
-
attackerFirst, evasionChance, evaded,
|
| 392 |
effectiveOffense: Math.round(bestEffOffense),
|
| 393 |
-
effectiveDefense: Math.round(effDefense),
|
| 394 |
winProbability: Math.round(winProbability * 1000) / 1000,
|
| 395 |
roll: Math.round(roll * 1000) / 1000, attackerWon, tagsUsed: uniqueTags, notes,
|
| 396 |
primaryTag: bestTag, isShatter
|
|
@@ -403,12 +404,12 @@ export function breedOffspring(a, b) {
|
|
| 403 |
const mix = (x, y) => Math.round(((x + y) / 2) * 0.85);
|
| 404 |
const avgComp = {};
|
| 405 |
for (const k of COMPOSITION_ORDER) avgComp[k] = mix(a.compositions[k], b.compositions[k]);
|
| 406 |
-
|
| 407 |
const sum = COMPOSITION_ORDER.reduce((s, k) => s + avgComp[k], 0);
|
| 408 |
if (sum > 0) for (const k of COMPOSITION_ORDER) avgComp[k] = Math.round((avgComp[k] / sum) * 100);
|
| 409 |
const total = COMPOSITION_ORDER.reduce((s, k) => s + avgComp[k], 0);
|
| 410 |
if (total !== 100) avgComp.ANIMALIA = Math.max(0, avgComp.ANIMALIA + (100 - total));
|
| 411 |
-
|
| 412 |
return {
|
| 413 |
compositions: avgComp,
|
| 414 |
attributes: Object.fromEntries(
|
|
|
|
| 3 |
// LEVEL EVOLUTION β MECHANICS ENGINE (Pure JavaScript ES Module)
|
| 4 |
// ============================================================================
|
| 5 |
|
| 6 |
+
// βββ composition βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 7 |
export const COMPOSITION_ORDER = [ 'ANIMALIA', 'CHITINARIA', 'PLANTAE', 'CNIDARIA', 'MYCELIUM', 'MINERALIS' ];
|
| 8 |
|
| 9 |
export const COMPOSITION_META = {
|
|
|
|
| 11 |
CHITINARIA:{ label: 'Chitinaria', blurb: 'Free ARMOR at β₯30%. Periodic molt window drops defense briefly.', freeStructure: 'ARMOR', accent: '#d97706', glow: '#f59e0b' },
|
| 12 |
PLANTAE: { label: 'Plantae', blurb: 'Passive energy regen in light; free ACID resistance. Neural capped at 4.', accent: '#22c55e', glow: '#4ade80' },
|
| 13 |
CNIDARIA: { label: 'Cnidaria', blurb: 'Free SOFT structure; toxin Features cost less. CONDUCTIVE β vulnerable to Electric.', freeStructure: 'SOFT', accent: '#06b6d4', glow: '#22d3ee' },
|
| 14 |
+
MYCELIUM: { label: 'Mycelium', blurb: 'Free REGEN; halves DOT damage. Speed capped at 4. Fragile HP.', accent: '#a855f7', glow: '#c084fc' },
|
| 15 |
MINERALIS: { label: 'Mineralis', blurb: 'Free BRITTLE; zero food need. Immune to TOXIN/ACID. Cannot regenerate.', freeStructure: 'BRITTLE', accent: '#e2e8f0', glow: '#f1f5f9' },
|
| 16 |
};
|
| 17 |
|
|
|
|
| 26 |
const oldSum = others.reduce((s, k) => s + comps[k], 0);
|
| 27 |
const residual = 100 - clamped;
|
| 28 |
const next = { ...comps, [key]: clamped };
|
| 29 |
+
|
| 30 |
if (oldSum === 0) {
|
| 31 |
const each = Math.floor(residual / others.length);
|
| 32 |
others.forEach((k, i) => { next[k] = i === 0 ? residual - each * (others.length - 1) : each; });
|
|
|
|
| 49 |
const mycel = comps.MYCELIUM >= 30;
|
| 50 |
const mineral = comps.MINERALIS >= 30;
|
| 51 |
const chitin = comps.CHITINARIA >= 30;
|
| 52 |
+
|
| 53 |
if (attr === 'NEURAL_COMPLEXITY') { if (plant) return 4; if (mycel) return 3; if (mineral) return 2; }
|
| 54 |
if (attr === 'METABOLIC_RATE') { if (mycel) return 4; if (mineral) return 0; }
|
| 55 |
if (attr === 'REGENERATION') { if (mineral) return 0; }
|
|
|
|
| 77 |
{ type:'GELATINOUS_BODY', label:'Gelatinous Body', category:'Defense', tags:[], baseCost:10, costMult:{CNIDARIA:0}, blurb:'Forces SOFT. Absorbs CRUSH/SONIC; PIERCE/SLASH/TOXIN punish it.' },
|
| 78 |
{ type:'SLIME_COATING', label:'Slime Coating', category:'Defense', tags:[], baseCost:8, requires:{CNIDARIA:15}, blurb:'SLIME modifier β escape chance vs GRAPPLE; small general dodge.' },
|
| 79 |
{ type:'DUST_COATING', label:'Dust Coating', category:'Defense', tags:[], baseCost:9, blurb:'One guaranteed dodge per encounter. Skipped if attacker out-speeds; cleared by SONIC/ACID.' },
|
| 80 |
+
{ type:'REGENERATIVE_FLESH', label:'Regenerative Flesh', category:'Defense', tags:[], baseCost:11, requires:{MYCELIUM:15}, blurb:'REGEN modifier β halves toxin/acid DOT. Useless vs single burst hits.' },
|
| 81 |
{ type:'BIOLUMINESCENT_DETERRENT', label:'Bioluminescent Deterrent', category:'Defense', tags:[], baseCost:9, requires:{CNIDARIA:20}, blurb:'Flinch chance to interrupt attacker. Ignored by high Neural Complexity.' },
|
| 82 |
{ type:'SPINY_RIDGE', label:'Spiny Ridge', category:'Defense', tags:[], baseCost:8, requires:{CHITINARIA:20}, blurb:'Reflects chunk of melee CRUSH/SLASH back. Piercing/ranged ignore it.' },
|
| 83 |
{ type:'CAMOUFLAGE_PATTERNS', label:'Camouflage Patterns', category:'Defense', tags:[], baseCost:9, blurb:'Shrinks detection radius; dodge chance vs low-Neural attackers. Costs offense.' },
|
|
|
|
| 185 |
defense += A.BONE_DENSITY * 2;
|
| 186 |
weight += A.BONE_DENSITY * 2.5;
|
| 187 |
speed -= A.BONE_DENSITY * 1.5;
|
| 188 |
+
|
| 189 |
speed += A.METABOLIC_RATE * 2;
|
| 190 |
energyDemand += A.METABOLIC_RATE * 2;
|
| 191 |
heatTolerance += A.METABOLIC_RATE * 3;
|
| 192 |
+
|
| 193 |
hp += A.FAT_RESERVES * 5;
|
| 194 |
weight += A.FAT_RESERVES * 1.5;
|
| 195 |
speed -= A.FAT_RESERVES * 0.5;
|
| 196 |
+
|
| 197 |
energyDemand += A.NEURAL_COMPLEXITY * 1.5;
|
| 198 |
matingSpeed -= A.NEURAL_COMPLEXITY * 0.04;
|
| 199 |
detection += A.NEURAL_COMPLEXITY * 6;
|
| 200 |
+
|
| 201 |
energyDemand += A.REGENERATION * 2;
|
| 202 |
hp -= A.REGENERATION * 1;
|
| 203 |
+
|
| 204 |
coldTolerance += A.INSULATION * 5;
|
| 205 |
heatTolerance -= A.INSULATION * 2;
|
| 206 |
energyDemand += A.INSULATION;
|
| 207 |
speed -= A.INSULATION * 0.3;
|
| 208 |
+
|
| 209 |
weight += A.WATER_RETENTION * 0.5;
|
| 210 |
speed -= A.WATER_RETENTION * 0.2;
|
| 211 |
desiccationRate -= A.WATER_RETENTION * 0.08;
|
| 212 |
+
|
| 213 |
energyDemand += A.THERMAL_REGULATION * 0.8;
|
| 214 |
heatTolerance += A.THERMAL_REGULATION * 3;
|
| 215 |
coldTolerance += A.THERMAL_REGULATION * 3;
|
| 216 |
+
|
| 217 |
offense -= A.CAMOUFLAGE * 0.5;
|
| 218 |
detection -= A.CAMOUFLAGE * 4;
|
| 219 |
defense -= A.BUOYANCY * 0.4;
|
|
|
|
| 222 |
if (state.compositions.PLANTAE >= 30) hp += 20;
|
| 223 |
if (state.compositions.MYCELIUM >= 30) { hp -= 10; matingSpeed += 0.5; }
|
| 224 |
if (state.compositions.MINERALIS >= 30) { energyDemand = 0; weight += 30; speed -= 10; }
|
| 225 |
+
|
| 226 |
const mods = activeModifiers(state);
|
| 227 |
const isAerial = mods.has('AERIAL');
|
| 228 |
const isAquatic = mods.has('AQUATIC');
|
|
|
|
| 295 |
const defMods = activeModifiers(defender);
|
| 296 |
const attMods = activeModifiers(attacker);
|
| 297 |
const notes = [];
|
| 298 |
+
|
| 299 |
let attackerFirst = true;
|
| 300 |
if (defMods.has('LURE') && attacker.attributes.NEURAL_COMPLEXITY < 5) {
|
| 301 |
attackerFirst = false; notes.push('Defender LURE overrides Speed');
|
|
|
|
| 324 |
if (evaded) {
|
| 325 |
return {
|
| 326 |
won: false,
|
| 327 |
+
breakdown: {
|
| 328 |
+
attackerFirst, evasionChance, evaded,
|
| 329 |
effectiveOffense: 0, effectiveDefense: 0,
|
| 330 |
+
winProbability: 0, roll: 0, attackerWon: false,
|
| 331 |
tagsUsed: [], notes: [...notes, 'Evaded before contact'],
|
| 332 |
primaryTag: null, isShatter: false
|
| 333 |
},
|
|
|
|
| 348 |
for (const tag of uniqueTags) {
|
| 349 |
let mult = COUNTER_CHART[tag][defStruct];
|
| 350 |
if (tag === 'TOXIN') {
|
| 351 |
+
if (defender.compositions.MINERALIS >= 30) { mult = 0; notes.push('Mineralis immune to Toxin'); }
|
| 352 |
+
else if (defMods.has('NUMB')) { mult = 0; notes.push('Defender NUMB β Toxin negated'); }
|
| 353 |
else if (defMods.has('REGEN')) { mult *= 0.5; notes.push('Defender REGEN halves Toxin'); }
|
| 354 |
}
|
| 355 |
if (tag === 'ELECTRIC') {
|
|
|
|
| 388 |
|
| 389 |
return {
|
| 390 |
won: attackerWon,
|
| 391 |
+
breakdown: {
|
| 392 |
+
attackerFirst, evasionChance, evaded,
|
| 393 |
effectiveOffense: Math.round(bestEffOffense),
|
| 394 |
+
effectiveDefense: Math.round(effDefense),
|
| 395 |
winProbability: Math.round(winProbability * 1000) / 1000,
|
| 396 |
roll: Math.round(roll * 1000) / 1000, attackerWon, tagsUsed: uniqueTags, notes,
|
| 397 |
primaryTag: bestTag, isShatter
|
|
|
|
| 404 |
const mix = (x, y) => Math.round(((x + y) / 2) * 0.85);
|
| 405 |
const avgComp = {};
|
| 406 |
for (const k of COMPOSITION_ORDER) avgComp[k] = mix(a.compositions[k], b.compositions[k]);
|
| 407 |
+
|
| 408 |
const sum = COMPOSITION_ORDER.reduce((s, k) => s + avgComp[k], 0);
|
| 409 |
if (sum > 0) for (const k of COMPOSITION_ORDER) avgComp[k] = Math.round((avgComp[k] / sum) * 100);
|
| 410 |
const total = COMPOSITION_ORDER.reduce((s, k) => s + avgComp[k], 0);
|
| 411 |
if (total !== 100) avgComp.ANIMALIA = Math.max(0, avgComp.ANIMALIA + (100 - total));
|
| 412 |
+
|
| 413 |
return {
|
| 414 |
compositions: avgComp,
|
| 415 |
attributes: Object.fromEntries(
|