isBossDefeated,
isChestOpen,
} from './alttp-ram';
+import Logic from './logic';
export const BOOLEAN_STATES = [
'blue-boomerang',
];
export const CONFIG = {
+ bossShuffle: false,
+ glitches: 'none',
+ showMap: 'situational',
+ showCompass: 'situational',
+ showSmall: 'always',
+ showBig: 'always',
wildMap: false,
wildCompass: false,
wildSmall: false,
wildBig: false,
- bossShuffle: false,
+ worldState: 'open',
};
export const DUNGEONS = [
},
];
+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);
+ }
+ return map;
+};
+
+export const shouldShowDungeonItem = (config, which) => {
+ const show = config[`show${which}`] || 'always';
+ const wild = config[`wild${which}`] || false;
+ switch (show) {
+ default:
+ case 'always':
+ return true;
+ case 'situational':
+ return wild;
+ case 'never':
+ return false;
+ }
+};
+
export const toggleBoolean = name => state => ({
...state,
[name]: !state[name],
export const hasClearedLocations = (state, locations) =>
countClearedLocations(state, locations) === locations.length;
+export const getLocationStatus = (name, logic, state) => {
+ if (state[name]) return 'cleared';
+ if (logic[name]) return logic[name];
+ return logic.fallback;
+};
+
+export const getCombinedStatus = statuses => {
+ if (statuses.filter(s => s === 'cleared').length === statuses.length) {
+ return 'cleared';
+ }
+ if (statuses.filter(s => ['available', 'cleared'].includes(s)).length === statuses.length) {
+ return 'available';
+ }
+ if (statuses.filter(s => ['unavailable', 'cleared'].includes(s)).length === statuses.length) {
+ return 'unavailable';
+ }
+ return 'partial';
+};
+
+export const aggregateLocationStatus = (names, logic, state) => {
+ const statuses = names.map(name => getLocationStatus(name, logic, state));
+ return getCombinedStatus(statuses);
+};
+
export const countRemainingLocations = (state, locations) =>
locations.reduce((acc, cur) => state[cur] ? acc : acc + 1, 0);
+export const getGanonCrystals = (state) => state['ganon-crystals'];
+
+export const getGTCrystals = (state) => state['gt-crystals'];
+
+export const getGTBoss = (state, which) => state[`gt-${which}-boss`];
+
export const hasDungeonBoss = (state, dungeon) =>
!dungeon.boss || !!state[`${dungeon.id}-boss-defeated`];
return hasItems && hasBoss && hasPrize;
};
+export const aggregateDungeonStatus = (dungeon, logic, state) => {
+ if (isDungeonCleared(state, dungeon)) {
+ return 'cleared';
+ }
+ if (logic[dungeon.id] === 'unavailable') {
+ return 'unavailable';
+ }
+ const checks = [...dungeon.checks];
+ if (['ct', 'gt'].includes(dungeon.id)) {
+ checks.push(`${dungeon.id}-boss-killable`);
+ }
+ const statuses = checks.map(name => getLocationStatus(name, logic, state));
+ return getCombinedStatus(statuses);
+};
+
export const toggleBossDefeated = dungeon => toggleBoolean(`${dungeon.id}-boss-defeated`);
export const setBossDefeated = (dungeon, defeated) =>
state[`${dungeon.id}-prize`] = 'crystal';
state[`${dungeon.id}-prize-acquired`] = false;
}
+ if (dungeon.id === 'gt') {
+ state['gt-bot-boss'] = 'armos';
+ state['gt-mid-boss'] = 'lanmolas';
+ state['gt-top-boss'] = 'moldorm';
+ }
});
OVERWORLD_LOCATIONS.forEach(location => {
state[location.id] = false;
});
state['mm-medallion'] = null;
state['tr-medallion'] = null;
+ state['gt-crystals'] = 7;
+ state['ganon-crystals'] = 7;
return state;
};
});
};
-export const computeState = (data, prizeMap) => {
+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;
};
return amounts;
};
-export const mergeStates = (config, cur, inc) => {
- const next = { ...cur, ...inc };
- const amounts = getDungeonAmounts(config, inc);
+export const mergeStates = (autoState, manualState) => {
+ const next = { ...autoState };
+ BOOLEAN_STATES.forEach(name => {
+ if (manualState[name]) {
+ next[name] = true;
+ }
+ });
+ INTEGER_STATES.forEach(name => {
+ next[name] = Math.max(autoState[name] || 0, manualState[name] || 0);
+ });
DUNGEONS.forEach(dungeon => {
- next[`${dungeon.id}-checks`] = amounts[dungeon.id];
+ next[`${dungeon.id}-small-key`] += manualState[`${dungeon.id}-small-key`] || 0;
+ next[`${dungeon.id}-checks`] += manualState[`${dungeon.id}-checks`] || 0;
+ if (manualState[`${dungeon.id}-big-key`]) {
+ next[`${dungeon.id}-big-key`] = true;
+ }
+ if (manualState[`${dungeon.id}-compass`]) {
+ next[`${dungeon.id}-compass`] = true;
+ }
+ if (manualState[`${dungeon.id}-map`]) {
+ next[`${dungeon.id}-map`] = true;
+ }
+ if (manualState[`${dungeon.id}-boss-defeated`]) {
+ next[`${dungeon.id}-boss-defeated`] = true;
+ }
+ if (manualState[`${dungeon.id}-prize`] &&
+ manualState[`${dungeon.id}-prize`] !== 'crystal'
+ ) {
+ next[`${dungeon.id}-prize`] = manualState[`${dungeon.id}-prize`];
+ } else if (!next[`${dungeon.id}-prize`]) {
+ next[`${dungeon.id}-prize`] = 'crystal';
+ }
+ if (manualState[`${dungeon.id}-prize-acquired`]) {
+ next[`${dungeon.id}-prize-acquired`] = true;
+ }
+ });
+ OVERWORLD_LOCATIONS.forEach(loc => {
+ if (manualState[loc.id]) {
+ next[loc.id] = true;
+ }
+ });
+ UNDERWORLD_LOCATIONS.forEach(loc => {
+ if (manualState[loc.id]) {
+ next[loc.id] = true;
+ }
});
+ next['mm-medallion'] = manualState['mm-medallion'];
+ next['tr-medallion'] = manualState['tr-medallion'];
+ next['gt-crystals'] = manualState['gt-crystals'];
+ next['ganon-crystals'] = manualState['ganon-crystals'];
+ next['gt-bot-boss'] = manualState['gt-bot-boss'];
+ next['gt-mid-boss'] = manualState['gt-mid-boss'];
+ next['gt-top-boss'] = manualState['gt-top-boss'];
//console.log(next);
return next;
};