X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2Ftracker.js;h=c4b685c5b9ced45af45281b71e0728bae7aac022;hb=90922f8595a8d4fd7780a0b137eed66eaf7d6c49;hp=4f44d3c50d3b4fac23f28a157fe5f662004fd4e9;hpb=69d9cc4f72b11616642a364827c096ed80e666c7;p=alttp.git diff --git a/resources/js/helpers/tracker.js b/resources/js/helpers/tracker.js index 4f44d3c..c4b685c 100644 --- a/resources/js/helpers/tracker.js +++ b/resources/js/helpers/tracker.js @@ -43,7 +43,10 @@ export const BOOLEAN_STATES = [ ]; export const INTEGER_STATES = [ - 'bottle', + 'bottle-1', + 'bottle-2', + 'bottle-3', + 'bottle-4', 'heart-piece', 'lift', 'mail', @@ -55,6 +58,17 @@ export const INITIAL = { mail: 1, }; +export const BOTTLE_CONTENTS = [ + 'mushroom', + 'bottle', + 'red-potion', + 'green-potion', + 'blue-potion', + 'fairy', + 'bottle-bee', + 'bottle-good-bee', +]; + export const BOSSES = [ 'armos', 'lanmolas', @@ -70,7 +84,9 @@ export const BOSSES = [ export const CONFIG = { bossShuffle: false, + checkCalculation: 'room-data', glitches: 'none', + mapLayout: 'horizontal', showMap: 'situational', showCompass: 'situational', showSmall: 'always', @@ -1559,11 +1575,38 @@ export const UNDERWORLD_LOCATIONS = [ }, ]; +export const getConfigValue = (config, name, fallback) => + Object.prototype.hasOwnProperty.call(config, name) ? config[name] : fallback; + +export const configureDungeons = config => DUNGEONS.map(dungeon => { + const newDungeon = JSON.parse(JSON.stringify(dungeon)); + if (config.wildMap && dungeon.map) { + ++newDungeon.items; + } + if (config.wildCompass && dungeon.compass) { + ++newDungeon.items; + } + if (config.wildSmall) { + newDungeon.items += dungeon.sk; + } + if (config.wildBig && dungeon.bk && !dungeon.dropBk) { + ++newDungeon.items; + } + if (dungeon.boss) { + newDungeon.bosses = config.bossShuffle ? BOSSES : [dungeon.boss]; + } + return newDungeon; +}); + export const applyLogic = (config, dungeons, state) => { const logic = Logic[config.worldState]; const map = {}; for (const name in logic) { - map[name] = logic[name](config, dungeons, state); + try { + map[name] = logic[name](config, dungeons, state); + } catch (e) { + console.error('error evaluating', name, e); + } } return map; }; @@ -1576,7 +1619,7 @@ export const shouldShowDungeonItem = (config, which) => { case 'always': return true; case 'situational': - return wild; + return wild || (which === 'Compass' && config.bossShuffle); case 'never': return false; } @@ -1661,9 +1704,9 @@ export const aggregateLocationStatus = (names, logic, state) => { export const countRemainingLocations = (state, locations) => locations.reduce((acc, cur) => state[cur] ? acc : acc + 1, 0); -export const getGanonCrystals = (state) => state['ganon-crystals']; +export const getGanonCrystals = (config) => getConfigValue(config, 'ganon-crystals', 7); -export const getGTCrystals = (state) => state['gt-crystals']; +export const getGTCrystals = (config) => getConfigValue(config, 'gt-crystals', 7); export const getGTBoss = (state, which) => state[`gt-${which}-boss`]; @@ -1671,7 +1714,9 @@ export const hasDungeonBoss = (state, dungeon) => !dungeon.boss || !!state[`${dungeon.id}-boss-defeated`]; export const getDungeonBoss = (state, dungeon) => - state[`${dungeon.id}-boss`] || dungeon.boss || null; + dungeon.bosses.length > 1 + ? state[`${dungeon.id}-boss`] || dungeon.boss || null + : dungeon.bosses[0]; export const hasDungeonPrize = (state, dungeon) => !dungeon.prize || !!state[`${dungeon.id}-prize-acquired`]; @@ -1762,8 +1807,6 @@ export const makeEmptyState = () => { }); state['mm-medallion'] = null; state['tr-medallion'] = null; - state['gt-crystals'] = 7; - state['ganon-crystals'] = 7; return state; }; @@ -1789,19 +1832,10 @@ const collectInventory = (state, data, prizeMap) => { state.duck = !!(data[INV_ADDR.RANDO_FLUTE] & 0x01); state.bugnet = !!data[INV_ADDR.BUGNET]; state.book = !!data[INV_ADDR.BOOK]; - state.bottle = 0; - if (data[INV_ADDR.BOTTLE_1]) { - ++state.bottle; - } - if (data[INV_ADDR.BOTTLE_2]) { - ++state.bottle; - } - if (data[INV_ADDR.BOTTLE_3]) { - ++state.bottle; - } - if (data[INV_ADDR.BOTTLE_4]) { - ++state.bottle; - } + state['bottle-1'] = data[INV_ADDR.BOTTLE_1]; + state['bottle-2'] = data[INV_ADDR.BOTTLE_2]; + state['bottle-3'] = data[INV_ADDR.BOTTLE_3]; + state['bottle-4'] = data[INV_ADDR.BOTTLE_4]; state.somaria = !!data[INV_ADDR.SOMARIA]; state.byrna = !!data[INV_ADDR.BYRNA]; state.cape = !!data[INV_ADDR.CAPE]; @@ -1824,10 +1858,26 @@ const collectInventory = (state, data, prizeMap) => { state[`${dungeon.id}-compass`] = !!(compass & dungeon.mask); state[`${dungeon.id}-small-key`] = data[INV_ADDR.RANDO_KEY_START + dungeon.offset]; state[`${dungeon.id}-big-key`] = !!(bigKey & dungeon.mask); + state[`${dungeon.id}-checks-collected`] = + data[INV_ADDR.RANDO_CHECKS_START + dungeon.offset]; if (dungeon.prize) { const isCrystal = prizeMap[dungeon.offset].isCrystal; const prizeFlags = data[isCrystal ? INV_ADDR.CRYSTALS : INV_ADDR.PENDANTS]; - state[`${dungeon.id}-prize-acquired`] = !!(prizeFlags & prizeMap[dungeon.offset].mask); + const prizeAcquired = !!(prizeFlags & prizeMap[dungeon.offset].mask); + state[`${dungeon.id}-prize-acquired`] = prizeAcquired; + if (prizeAcquired) { + if (!isCrystal) { + if (prizeMap[dungeon.offset].mask === 1) { + state[`${dungeon.id}-prize`] = 'red-pendant'; + } else if (prizeMap[dungeon.offset].mask === 2) { + state[`${dungeon.id}-prize`] = 'blue-pendant'; + } else if (prizeMap[dungeon.offset].mask === 4) { + state[`${dungeon.id}-prize`] = 'green-pendant'; + } + } else { + state[`${dungeon.id}-prize`] = 'crystal'; + } + } } }); }; @@ -1847,28 +1897,20 @@ const collectUnderworld = (state, data) => { }); }; -export const computeState = (config, data, prizeMap) => { - const state = {}; - collectInventory(state, data.slice(SRAM_ADDR.INV_START), prizeMap); - collectOverworld(state, data); - collectUnderworld(state, data.slice(SRAM_ADDR.ROOM_DATA_START)); - const amounts = getDungeonAmounts(config, state); - DUNGEONS.forEach(dungeon => { - state[`${dungeon.id}-checks`] = amounts[dungeon.id]; - }); - return state; -}; - const getDungeonAmounts = (config, state) => { const amounts = {}; DUNGEONS.forEach(dungeon => { let amount = 0; let total = dungeon.checks.length; - dungeon.checks.forEach(check => { - if (state[check]) { - ++amount; - } - }); + if (config.checkCalculation === 'inventory') { + amount = state[`${dungeon.id}-checks-collected`]; + } else { + dungeon.checks.forEach(check => { + if (state[check]) { + ++amount; + } + }); + } if (!config.wildMap && state[`${dungeon.id}-map`]) { --amount; --total; @@ -1890,6 +1932,18 @@ const getDungeonAmounts = (config, state) => { return amounts; }; +export const computeState = (config, data, prizeMap) => { + const state = {}; + collectInventory(state, data.slice(SRAM_ADDR.INV_START), prizeMap); + collectOverworld(state, data); + collectUnderworld(state, data.slice(SRAM_ADDR.ROOM_DATA_START)); + const amounts = getDungeonAmounts(config, state); + DUNGEONS.forEach(dungeon => { + state[`${dungeon.id}-checks`] = amounts[dungeon.id]; + }); + return state; +}; + export const mergeStates = (autoState, manualState) => { const next = { ...autoState }; BOOLEAN_STATES.forEach(name => { @@ -1912,6 +1966,9 @@ export const mergeStates = (autoState, manualState) => { if (manualState[`${dungeon.id}-map`]) { next[`${dungeon.id}-map`] = true; } + if (manualState[`${dungeon.id}-boss`]) { + next[`${dungeon.id}-boss`] = manualState[`${dungeon.id}-boss`]; + } if (manualState[`${dungeon.id}-boss-defeated`]) { next[`${dungeon.id}-boss-defeated`] = true; } @@ -1936,6 +1993,12 @@ export const mergeStates = (autoState, manualState) => { next[loc.id] = true; } }); + // prefer auto + next['bottle-1'] = autoState['bottle-1'] || manualState['bottle-1'] || 0; + next['bottle-2'] = autoState['bottle-2'] || manualState['bottle-2'] || 0; + next['bottle-3'] = autoState['bottle-3'] || manualState['bottle-3'] || 0; + next['bottle-4'] = autoState['bottle-4'] || manualState['bottle-4'] || 0; + // force manual next['mm-medallion'] = manualState['mm-medallion']; next['tr-medallion'] = manualState['tr-medallion']; next['gt-crystals'] = manualState['gt-crystals'];