arx-level-generator
Version:
A tool for creating Arx Fatalis maps
111 lines (106 loc) • 4.22 kB
JavaScript
import { Audio } from '../../Audio.js';
import { Entity } from '../../Entity.js';
import { Script } from '../../Script.js';
import { Texture } from '../../Texture.js';
import { ScriptSubroutine } from '../../scripting/ScriptSubroutine.js';
import { Sound, SoundFlags } from '../../scripting/classes/Sound.js';
import { TweakSkin } from '../../scripting/commands/TweakSkin.js';
import { Label } from '../../scripting/properties/Label.js';
import { Material } from '../../scripting/properties/Material.js';
import { Variable } from '../../scripting/properties/Variable.js';
export class Rune extends Entity {
propRuneName;
propArxTutorialEnabled;
constructor(variant, { arxTutorialEnabled, ...props } = {}) {
super({
src: 'items/magic/rune_aam',
...props,
});
this.withScript();
this.propRuneName = new Variable('string', 'rune_name', variant);
this.script?.properties.push(this.propRuneName);
const system = new Sound(Audio.system.filename, SoundFlags.EmitFromPlayer);
const system2 = new Sound(Audio.system2.filename, SoundFlags.EmitFromPlayer);
const whenRoot = (handler) => {
return () => {
if (!this.script?.isRoot) {
return '';
}
return Script.handlerToString(handler());
};
};
const tutorialMagic = new Variable('global int', 'TUTORIAL_MAGIC', 0, true);
this.script?.on('init', () => {
if (this.script?.isRoot) {
this.propArxTutorialEnabled = new Variable('bool', 'arx_tutorial_enabled', arxTutorialEnabled ?? true);
return [this.propArxTutorialEnabled, tutorialMagic];
}
if (typeof arxTutorialEnabled !== 'undefined') {
this.propArxTutorialEnabled = new Variable('bool', 'arx_tutorial_enabled', arxTutorialEnabled);
return [this.propArxTutorialEnabled];
}
return [];
});
this.script?.on('init', whenRoot(() => {
return [Material.stone, 'set_group provisions', 'set_price 1000', 'set_steal 50', 'set_weight 0'];
}));
this.script?.on('initend', whenRoot(() => {
return [
new Label(`[system_~${this.propRuneName.name}~]`),
`tweak icon rune_~${this.propRuneName.name}~[icon]`,
new TweakSkin(Texture.itemRuneAam, `item_rune_~${this.propRuneName.name}~`),
];
}));
const tutorialFoundRunes = new ScriptSubroutine('tutorial_found_runes', whenRoot(() => {
return `
${system.play()}
herosay [system_tutorial_6]
quest [system_tutorial_6]
`;
}));
const tutorialAddedRunesToBook = new ScriptSubroutine('tutorial_added_runes_to_book', whenRoot(() => {
return `
${system.play()}
herosay [system_tutorial_6bis]
quest [system_tutorial_6bis]
`;
}));
this.script?.subroutines.push(tutorialFoundRunes, tutorialAddedRunesToBook);
this.script?.on('inventoryuse', whenRoot(() => {
return `
${system2.play()}
rune -a ~${this.propRuneName.name}~
if (${this.propArxTutorialEnabled?.name} == 1) {
if (${tutorialMagic.name} < 9) {
inc ${tutorialMagic.name} 3
}
if (${tutorialMagic.name} >= 6) {
set ${tutorialMagic.name} 9
${tutorialAddedRunesToBook.invoke()}
}
}
destroy self
`;
}));
this.script?.on('inventoryin', whenRoot(() => {
return `
if (${this.propArxTutorialEnabled?.name} == 1) {
if (${tutorialMagic.name} > 1) {
accept
}
inc ${tutorialMagic.name} 1
if (${tutorialMagic.name} == 2) {
${tutorialFoundRunes.invoke()}
}
}
`;
}));
}
get variant() {
return this.propRuneName.value;
}
set variant(value) {
this.propRuneName.value = value;
}
}
//# sourceMappingURL=Rune.js.map