Commit cd7c50ed authored by ecnerrolf's avatar ecnerrolf
Browse files

Update script.js suite à l'ajout de Pets.js / Mobs.js / Items.js

parent fe6b071a
import Equipment from "./equipment.js";
import Character from "./character.js";
import Utils from "./utils.js";
import Items from "./items.js";
import Mobs from "./mobs.js";
import Pets from "./pets.js";
(function (window, undef) {
"use strict";
document.addEventListener("DOMContentLoaded", function () {
listenActions();
document.querySelector("#fight").addEventListener("click", plunder);
document.querySelector("#flee").addEventListener("click", leaveRoom);
listenDirections();
Character.init();
displayCharacterAbilities();
});
})(window);
......@@ -19,11 +25,6 @@ let failRisk = 0;
let turns = 0;
let eggTurns = 0;
const listenActions = () => {
document.querySelector("#fight").addEventListener("click", plunder);
document.querySelector("#flee").addEventListener("click", leaveRoom);
}
const listenDirections = () => {
document
.querySelectorAll("#directions > *")
......@@ -47,21 +48,25 @@ const leaveRoom = () => {
};
const plunder = () => {
// vérifier l'état de l'œuf
if (inventory.indexOf("œuf") !== -1) {
console.log(inventory);
// vérifier l'état de l'œuf
if (inventory.find(obj => obj.name === "Oeuf")) {
if (eggTurns === 5) {
// éclosion
Equipment.add(Utils.getRandomListItem(animalDatabase), "pet");
inventory.splice(inventory.indexOf("œuf"), 1);
Equipment.add(Utils.getRandomListItem(Pets.database), "pet");
//inventory.splice(inventory.indexOf("Oeuf"), 1);
inventory.splice(inventory.findIndex(obj => obj.name === "Oeuf"),1);
document.querySelector("#inventory [data-egg]").remove();
eggTurns = 0;
eggTurns = 0;
} else {
eggTurns++;
}
}
// tester si le coffre est piégé
if (testFail()) {
if (testFail()) {
document.querySelector(".actions").remove();
document.querySelector(".state").removeAttribute("hidden");
document.querySelector(".state").classList.add("state--failed");
......@@ -69,27 +74,29 @@ const plunder = () => {
return true;
}
// mettre l'objet dans l'inventaire
const lootItem = Utils.getRandomListItem(lootDatabase);
// mettre l'objet dans l'inventaire
let lootItem = Utils.getRandomListItem(Items.database);
// ne pas avoir deux oeufs dans l'inventaire
if (inventory.find(obj => obj.name === "Oeuf") || Equipment.list.pet !== "") {
while (lootItem.name === "Oeuf"){
lootItem = Utils.getRandomListItem(Items.database);
}
}
// équiper des trucs
if (lootItem === "arme" || lootItem === "armure") {
if (lootItem === "arme") {
if (lootItem.zone === "Main-hand" || lootItem.zone === "Chest") {
if (lootItem.zone === "Main-hand") {
Equipment.add(lootItem, "weapon");
}
if (lootItem === "armure") {
if (lootItem.zone === "Chest") {
Equipment.add(lootItem, "armor");
}
} else {
inventory.push(lootItem);
}
// si on a pioché un œuf, enlever la possibilité dans la base de données
if (lootItem === "œuf") {
lootDatabase.splice(lootDatabase.indexOf("œuf"), 1);
}
// afficher l'inventaire
if (Equipment.justEquiped === null) {
if (inventory.length <= 1) {
......@@ -99,8 +106,8 @@ const plunder = () => {
}
const listElement = document.createElement("li");
listElement.innerHTML = inventory[inventory.length - 1];
if (inventory[inventory.length - 1] === "œuf") {
listElement.innerHTML = inventory[inventory.length - 1].name;
if (inventory[inventory.length - 1].name === "Oeuf") {
listElement.setAttribute("data-egg", "");
}
listElement.classList.add("new");
......@@ -122,7 +129,7 @@ const plunder = () => {
`#equipment .${Equipment.justEquiped}`
);
equipmentElement.innerHTML = Equipment.list[Equipment.justEquiped];
equipmentElement.innerHTML = Equipment.list[Equipment.justEquiped].name;
equipmentElement.classList.add("new");
equipmentElement.addEventListener("animationend", function () {
this.classList.remove("new");
......@@ -153,7 +160,7 @@ const plunder = () => {
leaveRoom();
};
let lootDatabase = [
/*let lootDatabase = [
"armure",
"arme",
"œuf",
......@@ -162,7 +169,7 @@ let lootDatabase = [
"tartiflette",
"marguerite",
"bague",
];
];*/
const checkWinningState = (equipment) =>
equipment.armor !== "" && equipment.weapon !== "";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment