Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various updates and bug fixes #106

Merged
merged 6 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions levels/house_ceremony/maps/lovelacehallway.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
"id":25,
"name":"",
"properties":[
{
"name":"interactable",
"type":"bool",
"value":false
},
{
"name":"key",
"type":"string",
Expand Down
62 changes: 35 additions & 27 deletions levels/inside_perimeter/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,9 @@ const LEVEL_STATE = {
keySpellsObtained: [],
hasCredentials: false,
hasKey: false,
openedScrollRoomDoor: false,
hasPledgeScroll: false,
tweenRunning: false,
entities: {
scroll_room_door: {
spell: {
unlock: {
requirements: {
hasKey({ worldState }) {
return worldState.insideCatacombs.hasKey;
},
},
successActions: {
hasKey({ world }) {
world.forEachEntities("scroll_room_door", (door) => {
door.setInteractable(false);
});
},
},
failureActions: {
hasKey({ world }) {
world.showNotification(
"I need the magic key to unlock the Scroll Room. I should activate all the house statues inside these Catacombs before returning."
);
},
},
},
},
},
},
},
};

Expand Down Expand Up @@ -174,6 +148,31 @@ module.exports = async function (event, world) {
npcChecks[event.target.key]();
};

const openScrollRoomDoor = async () => {
if (worldState.insideCatacombs.hasKey) {
if (!event.target.interactable) {
return;
}

worldState.insideCatacombs.openedScrollRoomDoor = true;

world.disablePlayerMovement();
world.useTool("wand");
world.forEachEntities("scroll_room_door", (door) => {
door.setInteractable(false);
});
await world.wait(1000);
openDoor("scroll_room_door");
world.stopUsingTool();
await world.wait(1000);
world.enablePlayerMovement();
} else {
world.showNotification(
"I need the magic key to unlock the Scroll Room. I should activate all the house statues inside these Catacombs before returning."
);
}
};

/*
*
* OBJECTIVE COMPLETE FUNCTION DEFINITIONS
Expand Down Expand Up @@ -376,6 +375,14 @@ module.exports = async function (event, world) {
unhackObject("statue_credentials");
}

if (worldState.insideCatacombs.openedScrollRoomDoor) {
openDoor("scroll_room_door");

world.forEachEntities("scroll_room_door", (door) => {
door.setInteractable(false);
});
}

// Adjust object dimensions
world.forEachEntities(
({ instance }) => instance.layer === "upper",
Expand Down Expand Up @@ -405,6 +412,7 @@ module.exports = async function (event, world) {
if (event.target.notify) runObjectNotification(event);
if (event.target.npc) runNpcChecks(event);
if (event.target.item) runAddItem(event);
if (event.target.key === "scroll_room_door") await openScrollRoomDoor();
}

/*
Expand Down
90 changes: 42 additions & 48 deletions levels/inside_perimeter/maps/catacombs.json

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions levels/lovelace_tower/events.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const merge = require("lodash.merge");
const updateQuestLogWhenComplete = require("../../scripts/updateQuestLogWhenComplete");
const packageInfo = require("../../package.json");
const { LOVELACE_TOWER_STATE_KEY } = require("../../scripts/config");
const handleSpells = require("../../scripts/handleSpells");

Expand Down Expand Up @@ -233,5 +235,15 @@ module.exports = async function (event, world) {
}
}

updateQuestLogWhenComplete({
notification:
'I\'ve completed everything in the <span class="highlight">API Academy House Gauntlet</span> for now!',
log: "I've completed everything in the API Academy House Gauntlet for now!",
event,
world,
worldStateKey: LOVELACE_TOWER_STATE_KEY,
version: packageInfo.version,
});

world.setState(LOVELACE_TOWER_STATE_KEY, worldState);
};
326 changes: 323 additions & 3 deletions levels/lovelace_tower/maps/default.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const assertTestCase = (testFunction) => async (input, expected) => {
assert.strictEqual(
testResult,
expected,
`Expected "${expected}" from input "${input}", but received "${testResult}".`
`Expected "${expected}" but received "${testResult}".`
);
};

Expand Down
6 changes: 4 additions & 2 deletions levels/lovelace_tower/objectives/api-03-fetch/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ul>
<li>Create an "async" function called "getMagicalPhrase".</li>
<li>Use "fetch" to request the magical phrase from the "magic" endpoint.</li>
<li>Parse the text.</li>
<li>Copy and paste the magical phrase into the input.</li>
<li>Once you're done, press <em>HACK</em>.</li>
</ul>
Expand All @@ -18,10 +19,11 @@ Before we get started, let's take a look at an example of fetching data from an

```js
const response = await fetch("some_url");
console.log(response);
const text = await response.text();
console.log(text);
```

The example above uses `fetch` to request data from "some_url", uses `await` to "pause" the code until it's finished fetching, and then prints the response to the console.
The example above uses `fetch` to request data from "some_url" and uses `await` to "pause" the code until it's finished fetching. It then parses the "text" from the response and prints it to the console.

Create a function called "getMagicalPhrase" that uses `fetch` and `await` to request a magical phrase from the "magic" endpoint, then copy and paste it into the input. You may have to `console.log` in order to see it!

Expand Down
8 changes: 6 additions & 2 deletions levels/lovelace_tower/objectives/api-03-fetch/walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ const response = await fetch("some_url", {
method: "GET",
});

// const textData = await response.text();
// const jsonData = await response.json();

console.log(response);
```

Notice the `await` keyword here. The `fetch` function is asynchronous and must be awaited or passed a callback via promise chaining. The example is making a fetch request to a fake URL, but any valid URL would work! Also, pay attention to how we're configuring the request -- the second argument we're passing in is an object and our request uses [the properties](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters:~:text=A%20Request%20object.-,options,-Optional) of that object as the different parts of it's configuration.
Notice the `await` keyword here. The `fetch` function is asynchronous and must be awaited or passed a callback via promise chaining. The example is making a fetch request to a fake URL, but any valid URL would work! Also, pay attention to how we're configuring the request -- the second argument we're passing in is an object and our request uses [the properties](https://developer.mozilla.org/en-US/docs/Web/API/fetch#parameters:~:text=A%20Request%20object.-,options,-Optional) of that object as the different parts of it's configuration. The example also has comments showing two ways you can parse the data received from the response, one for text and another for JSON. How you parse the response depends on the kind of data being sent to you.

```js
const response = await fetch("some_url", {
Expand All @@ -50,8 +53,9 @@ async function getMagicalPhrase() {
const response = await fetch("https://twilio.com/quest/magic", {
method: "GET",
});
const magicalPhrase = await response.text();

console.log(response);
console.log(magicalPhrase);
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
],
"rewards": {
"xp": 100
"xp": 100,
"items": ["spell_lovelace_divination"]
}
}
11 changes: 8 additions & 3 deletions levels/lovelace_tower/objectives/api-05-get-patch/validator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { DIVINATION_API_ENDPOINT } = require("../../../../scripts/config");
const assert = require("assert");

const assertTestCase = (testFunction) => async (input) => {
const assertTestCase = (testFunction, helper) => async (input) => {
await testFunction(input);

const response = await fetch(
// Marvel Johnson [12/14/2022] The fetchOverride method is temporary and used as a workaround to a bug in the endpoint
// utilized for this objective. See the ValidationHelper class in the twilio/twilioquest repo for more info
const response = await helper.fetchOverride(
`${DIVINATION_API_ENDPOINT}?target=lovelace_secret_statue&guid=${input}`
);
let patchedInscription = await response.json();
Expand Down Expand Up @@ -42,7 +44,10 @@ module.exports = async function (helper) {
"The function getAndPatchCorruptedInscription is not defined!"
);

const test = assertTestCase(context.getAndPatchCorruptedInscription);
const test = assertTestCase(
context.getAndPatchCorruptedInscription,
helper
);
const randomID = generateRandomID();
await test(randomID);
} catch (err) {
Expand Down