aaa
This commit is contained in:
parent
2e90add2e1
commit
db81a509cf
6 changed files with 56 additions and 21 deletions
|
|
@ -267,11 +267,26 @@
|
|||
return structure;
|
||||
}
|
||||
|
||||
function hydrateStructure(structure) {
|
||||
if (!structure || !structure.isStructure) return structure;
|
||||
structure.update = updateStructure;
|
||||
structure.draw = drawStructure;
|
||||
structure.damage = damageStructure;
|
||||
const def = StructureRegistry[structure.type];
|
||||
if (def) {
|
||||
structure.roles = structure.roles || { ...def.roles };
|
||||
structure.needEffects = structure.needEffects || { ...def.needEffects };
|
||||
structure.r = structure.r || (structure.type === "plushie" ? 14 : 28);
|
||||
structure.amount = Math.max(0, structure.hp || structure.amount || 1);
|
||||
}
|
||||
return structure;
|
||||
}
|
||||
|
||||
function consumeGrassMaterial(grass) {
|
||||
if (!grass || grass.dead) return false;
|
||||
grass.amount = Math.max(0, Number(grass.amount || 0) - 34);
|
||||
grass.growth = clamp((grass.growth || 0.5) - 0.24, 0.04, 1.2);
|
||||
if (grass.amount <= 1) grass.dead = true;
|
||||
if (grass.amount <= 1) grass.amount = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -406,8 +421,12 @@
|
|||
const w = world || global.world;
|
||||
const def = StructureRegistry[this.type];
|
||||
def?.onDestroyed?.(this, w, breaker);
|
||||
this.dead = true;
|
||||
this.amount = 0;
|
||||
try {
|
||||
Object.defineProperty(this, "dead", { value: true, configurable: true, writable: true });
|
||||
} catch (_) {
|
||||
// Item.dead is a getter derived from amount; amount=0 is enough for those instances.
|
||||
}
|
||||
w?.markTerrainDirty?.(`structure-destroyed:${this.type}`);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -529,6 +548,7 @@
|
|||
addNeedShock,
|
||||
runNeedDecision,
|
||||
createStructure,
|
||||
hydrateStructure,
|
||||
damageStructure,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue