Anonymous

Template:Disambiguation/doc: Difference between revisions

From Melvor Idle
Updated to omit headers with no results. Now also supports the template: {{EquipmentTableFromList}}
(Updated to include Thieving NPCs)
(Updated to omit headers with no results. Now also supports the template: {{EquipmentTableFromList}})
Line 7: Line 7:
This may result in some duplicates between Icons and Shop Purchases, such as Iron Sieve which is both an Item and Purchase.
This may result in some duplicates between Icons and Shop Purchases, such as Iron Sieve which is both an Item and Purchase.
<syntaxhighlight lang="javascript" line>
<syntaxhighlight lang="javascript" line>
let searchTerm = 'Siren';
// Settings //
let searchTerm = 'Ancient'; // The proper capitalization of the Search Term
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
// End of Settings //
let lcSearchTerm = searchTerm.toLowerCase();
let lcSearchTerm = searchTerm.toLowerCase();
const search = (obj) => obj.name?.toLowerCase().includes(lcSearchTerm);
const search = (obj) => obj.name?.toLowerCase().includes(lcSearchTerm);
const wikiIcon = (obj, icon, extras='') => `*${obj.namespace?.includes('TotH') ? '{{TotH}}' : obj.namespace?.includes('AoD') ? '{{AoD}}' : ''}{{${icon}|${obj.name}${extras}}}`
const wikiIcon = (obj, icon, extras) => {
let results = [`{{Disam}}{{V|${gameVersion.substr(1)}}}`, '', `'''${searchTerm}''' may refer to:`, '===Equipment==='];
if (!returnEquipmentTemplate)
game.items.equipment.filter(x => search(x)).forEach(item => results.push(wikiIcon(item, 'ItemIcon')));
return `*${obj.namespace?.includes('TotH') ? '{{TotH}}' : obj.namespace?.includes('AoD') ? '{{AoD}}' : ''}{{${icon}|${obj.name}${extras}}}`;
results.push(`===Items===`);
else
game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)).forEach(item => results.push(wikiIcon(item, 'ItemIcon')));
return obj.name;
results.push(`===Openables===`);
}
game.items.openables.filter(x => search(x)).forEach(item => results.push(wikiIcon(item, 'ItemIcon')));
const pushResults = (obj) => {
results.push(`===Bones===`);
if (obj.arr.length > 0 && !returnEquipmentTemplate && obj.header !== '')
game.items.bones.filter(x => search(x)).forEach(item => results.push(wikiIcon(item, 'ItemIcon')));
results.push(obj.header);
results.push(`===Food===`);
obj.arr.forEach(item => results.push(wikiIcon(item, obj.iconType, obj.extras || '')));
game.items.food.filter(x => search(x)).forEach(item => results.push(wikiIcon(item, 'ItemIcon')));
}
results.push(`===Combat===`);
let results = [];
game.monsters.filter(x => search(x)).forEach(monster => results.push(wikiIcon(monster, 'MonsterIcon')));
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n{{EquipmentTableFromList`);
game.combatAreas.filter(x => search(x)).forEach(area => results.push(wikiIcon(area, 'ZoneIcon')));
if (!returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}{{Disam}}\n`, `'''${searchTerm}''' may refer to:`);
game.slayerAreas.filter(x => search(x)).forEach(area => results.push(wikiIcon(area, 'ZoneIcon')));
pushResults({arr: game.items.equipment.filter(x => search(x)), header: '===Equipment===', iconType: 'ItemIcon'});
game.dungeons.filter(x => search(x)).forEach(area => results.push(wikiIcon(area, 'ZoneIcon')));
pushResults({arr: game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), header: '===Items===', iconType: 'ItemIcon'});
results.push(`===Spells===`);
pushResults({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
game.standardSpells.filter(x => search(x)).forEach(spell => results.push(wikiIcon(spell, 'SpellIcon'))); // In v1.3, these are
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', iconType: 'ItemIcon'});
game.ancientSpells.filter(x => search(x)).forEach(spell => results.push(wikiIcon(spell, 'SpellIcon'))); // condensed into
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
game.archaicSpells.filter(x => search(x)).forEach(spell => results.push(wikiIcon(spell, 'SpellIcon'))); // game.attackSpells
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
game.curseSpells.filter(x => search(x)).forEach(spell => results.push(wikiIcon(spell, 'SpellIcon')));
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});
game.auroraSpells.filter(x => search(x)).forEach(spell => results.push(wikiIcon(spell, 'SpellIcon')));
pushResults({arr: [...game.combatAreas.allObjects, ...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), header: '', iconType: 'ZoneIcon'});
results.push(`===Purchases===`);
pushResults({arr: [...game.standardSpells.allObjects, ...game.ancientSpells.allObjects, ...game.archaicSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects].filter(x => search(x)), header: '===Spells===', iconType: 'SpellIcon'});
game.shop.purchases.filter(x => search(x)).forEach(purchase => results.push(wikiIcon(purchase, 'UpgradeIcon')));
pushResults({arr: game.shop.purchases.filter(x => search(x)), header: '===Purchases===', iconType: 'UpgradeIcon'});
results.push(`===Prayers===`);
pushResults({arr: game.prayers.filter(x => search(x)), header: '===Prayers===', iconType: 'PrayerIcon'});
game.prayers.filter(x => search(x)).forEach(prayer => results.push(wikiIcon(prayer, 'PrayerIcon')));
pushResults({arr: [...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => search(x)), header: '===Township===', iconType: 'TownshipIcon'});
results.push(`===Township===`);
pushResults({arr: game.skills.filter(x => search(x)), header: '===Others===', iconType: 'Skill'});
game.township.buildings.filter(x => search(x)).forEach(building => results.push(wikiIcon(building, 'TownshipIcon')));
pushResults({arr: game.pets.filter(x => search(x)), header: '', iconType: 'PetIcon'});
game.township.seasons.filter(x => search(x)).forEach(season => results.push(wikiIcon(season, 'TownshipIcon')));
pushResults({arr: game.astrology.actions.filter(x => search(x)), header: '', iconType: 'ConstellationIcon'});
game.township.biomes.filter(x => search(x)).forEach(biome => results.push(wikiIcon(biome, 'TownshipIcon')));
pushResults({arr: game.agility.actions.filter(x => search(x)), header: '', iconType: 'AgilityIcon'});
game.township.resources.filter(x => search(x)).forEach(resource => results.push(wikiIcon(resource, 'TownshipIcon')));
pushResults({arr: game.skills.filter(x => search(x)), header: '', iconType: 'Icon', extras: '|type=thieving'});
results.push(`===Others===`);
game.skills.filter(x => search(x)).forEach(skill => results.push(wikiIcon(skill, 'Skill')));
game.pets.filter(x => search(x)).forEach(pet => results.push(wikiIcon(pet, 'PetIcon')));
game.astrology.actions.filter(x => search(x)).forEach(constellation => results.push(wikiIcon(constellation, 'ConstellationIcon')));
game.agility.actions.filter(x => search(x)).forEach(obstacle => results.push(wikiIcon(obstacle, 'AgilityIcon')));
game.thieving.actions.filter(x => search(x)).forEach(npc => results.push(wikiIcon(npc, 'Icon', '|type=thieving')));
if (cloudManager.hasAoDEntitlementAndIsEnabled)
if (cloudManager.hasAoDEntitlementAndIsEnabled)
game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)).forEach(poi => results.push(wikiIcon(poi, 'POIIcon')));
pushResults({arr: game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), header: '', iconType: 'POIIcon'});
let outputString = ``;
let outputString = ``;
results.forEach((str) => { outputString += `${str}\n` });
results.forEach((str, i) => { outputString += (returnEquipmentTemplate ? i > 0 ? `|${str}` : `${str}` : `${str}\n`) });
console.log(outputString);
if (returnEquipmentTemplate) outputString += '}}';
copy(outputString);console.log(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0)
</syntaxhighlight>
</syntaxhighlight>