diff --git a/app/functions/get_creature.py b/app/functions/get_creature.py new file mode 100644 index 0000000..2948204 --- /dev/null +++ b/app/functions/get_creature.py @@ -0,0 +1,6 @@ +from app.tables.creature import Creatures + + +def get_creature(creature_id): + creature = Creatures() + return creature.get_creature(creature_id) diff --git a/app/routes/encounter.py b/app/routes/encounter.py index 655b632..f262a3d 100644 --- a/app/routes/encounter.py +++ b/app/routes/encounter.py @@ -1,5 +1,7 @@ from flask import request from flask_restx import Resource, Namespace, reqparse + +from app.functions.get_creature import get_creature from app.functions.roll_encounter import roll_encounter namespace = Namespace('gameplay', description='Gamma World Game Play') @@ -18,7 +20,13 @@ class RollEncounter(Resource): valid_terrains = ["clear", "mountains", "forest", "desert", "watery", "ruins", "deathlands"] if terrain: if terrain.lower() in valid_terrains: - return roll_encounter(terrain.lower()), 200 + details = dict() + encounter = roll_encounter(terrain.lower()) + details["name"] = encounter["encounter"] + creature_stats = get_creature(encounter["encounter"]) + if creature_stats is not None: + details.update(creature_stats) + return details, 200 else: return { 'error': 'Invalid terrain type provided.', diff --git a/app/tables/creatures.json b/app/tables/creatures.json index 9d86e7e..78fb2d3 100644 --- a/app/tables/creatures.json +++ b/app/tables/creatures.json @@ -367,5 +367,26 @@ "mutations": ["Death Field Generation", "Life Leach", "Manipulative Vines", "Mobility", "Molecular Disruption", "Symbiotic Attachment"], "description": "[Red Crep | Pink Crep] Creps come in 2 varieties: the Water Crep (also called the Pink Crep) and the Land Crep (also called the Red Crep). Water Creps live totally submerged and Land Creps grow under a mat of other foliage. Both are carnivorous, using their broad flat leaves to feed by Life Leaching those with whom they come into contact. Leaves that have been used to feed drop off once the victim escapes or dies, eventually sprouting new plants. [HOUSE NOTE: Players snared by a Crep Plant must make a Dex Check to escape. Life Leach attacks continue for each round the Dex Check fails. - GMG]" + }, + "fen": { + "number": [1, 10, 0], + "morale": [1, 6, 4], + "hit dice": [10, 6, 0], + "armour": 7, + "environ": ["land","water", "air"], + "land speed": [0, 300, 6], + "water speed": [6, 1800, 36], + "air speed": [0, 1800, 36], + "ms": [1, 10, 2], + "in": [1, 10, 8], + "dx": [1, 10, 2], + "ch": [1, 8, 1], + "cn": [1, 12, 4], + "ps": [1, 10, 8], + "attacks": {"Tail Slap": [6,6,0]}, + "mutations": ["Shape change"], + "description": "[Man Fish] These intelligent Humanoids are adapted for living both on land and in water, having fish-like tails, stubby legs, and both lungs and gills. They can remain out of water for only 24 hours at a time. They are not affected by attacks involving heat or lasers during the first 5 action turns these attacks are used against them in a combat. Fens can shape-change into the form of a bird of their own size. They carry Tech Level I weapons (usually clubs) and wear Fishkin Armour (similar to fiber armour)." } + + } \ No newline at end of file diff --git a/app/tables/encounters.py b/app/tables/encounters.py index 6b005ea..9473f53 100644 --- a/app/tables/encounters.py +++ b/app/tables/encounters.py @@ -9,18 +9,18 @@ class EncounterTable: 'centisteed', 'rakox', 'rakox', 'brutorz', 'hoop', 'hawkoid', 'hopper', 'hopper', None, None], 'mountains': ['hisser', 'blight', 'parn', 'zarn', 'manta', 'orlen', 'zeethh', 'sep', 'arn', 'yexil', 'herp', 'wardent', 'kep plant', 'crep plant', 'cal then', 'ark', 'hawkoid', 'podog', 'carrin', None], - 'forest': ['hisser', 'sep', 'blaash', 'blackun', 'terl', 'winseen', 'pineto', 'perth', 'obb', 'kailin', - 'grens', 'badder', 'arn', 'lil', 'blood bird', 'horl choo', 'soul besh', 'dabber', 'centisteed', + 'forest': ['hisser', 'sep', 'blaash', 'blackun', 'terl', 'win seen', 'pineto', 'perth', 'obb', 'kailin', + 'gren', 'badder', 'arn', 'lil', 'blood bird', 'horl choo', 'soul besh', 'dabber', 'centisteed', None], 'desert': ['serf', 'kamodo', 'blight', 'perth', 'parn', 'zarn', 'yexil', 'hisser', 'sep', 'calthen', 'manta', 'kep plant', 'carrin', 'podog', None, None, None, None, None, None], - 'watery': ['winseen', 'crep plant', 'seroon loo', 'terl', 'ert telden', 'barl nep', 'ert', 'fleshin', - 'keeshin', 'narlep', 'menarl', 'herkel', 'berlep', 'crentosh', 'fen', 'gator', None, None, None, + 'watery': ['win seen', 'crep plant', 'seroon lou', 'terl', 'ert telden', 'barl nep', 'ert', 'fleshin', + 'keeshin', 'narl ep', 'menarl', 'herkel', 'ber lep', 'cren tosh', 'fen', 'gator', None, None, None, None], 'ruins': ['arn', 'obb', 'hoop', 'android', 'badder', 'serf', 'blaash', 'yexil', 'manta', 'ark', 'orlen', 'dabber', 'sleeth', 'carrin', 'squeeker', 'squeeker', 'squeeker', None, None, None], 'deathlands': ['android', 'hisser', 'blight', 'zarn', 'perth', 'blaash', 'serf', 'parn', 'squeeker', - 'squeekr', None, None, None, None, None, None, None, None, None, None] + 'squeeker', None, None, None, None, None, None, None, None, None, None] } self.table_dataframe = pd.DataFrame(self.table) self.table_dataframe.index = np.arange(1, len(self.table_dataframe) + 1) diff --git a/web/encounter.html b/web/encounter.html index 5521f98..2338148 100644 --- a/web/encounter.html +++ b/web/encounter.html @@ -2,6 +2,7 @@ + Gamma World Encounter Check diff --git a/web/encounter.js b/web/encounter.js index 9d3fb89..d5fea07 100644 --- a/web/encounter.js +++ b/web/encounter.js @@ -1,6 +1,6 @@ document.getElementById('terrainForm').addEventListener('submit', function (event) { event.preventDefault(); - var terrain = document.getElementById('terrainType').value; + const terrain = document.getElementById('terrainType').value; const queryParams = new URLSearchParams({ terrain: terrain, }); @@ -17,30 +17,89 @@ document.getElementById('terrainForm').addEventListener('submit', function (even imgElement.style.marginRight = 'auto'; resultSection.appendChild(imgElement); - fetch(`${window.BASE_URL}/gameplay/encounter?${queryParams}`) - .then((response) => { - if (!response.ok) { - throw response; - } - return response.json(); // we only get here if there is no error - }) - .then((json) => { - // Handle null encounter - let encounterText = json.encounter ? json.encounter : 'No Encounter'; - - // Change the src attribute of the image after fetch resolves - setTimeout(() => { - imgElement.src = './img/' + encounterText + ".jpg"; - }, 1000); + setTimeout(() => { + fetch(`${window.BASE_URL}/gameplay/encounter?${queryParams}`) + .then((response) => { + if (!response.ok) { + throw response; + } + return response.json(); // we only get here if there is no error + }) + .then((json) => { + resultSection.innerHTML = ''; // Clear previous content + if (Object.keys(json).length === 1) { // Short version of response + let name = json.name !== null ? json.name : 'No Encounter'; + console.log(name); + setResultImage(name); + } else { // Long version of the response + setResultTable(json); + } + }) + .catch((err) => { + err.text().then((errorMessage) => { + imgElement.src = './img/404.jpg'; + }); + }); + function setResultImage(name) { + let imgElement = document.createElement('img'); + imgElement.src = './img/' + name + ".jpg"; + console.log(imgElement.src); imgElement.onerror = function () { this.onerror = null; this.src = './img/404.jpg'; }; - }) - .catch((err) => { - err.text().then((errorMessage) => { - imgElement.src = './img/404.jpg'; - }); - }); + resultSection.appendChild(imgElement); + } + + function setResultTable(data) { + let table = document.createElement('table'); + for (let key in data) { + let tr = document.createElement('tr'); + let tdKey = document.createElement('td'); + let tdValue = document.createElement('td'); + + tdKey.innerText = key.toUpperCase(); + + // Make the key names bold: + tdKey.style.fontWeight = 'bold'; + + if (Array.isArray(data[key])) { + if (key === 'environ' || key === 'mutations') { + tdValue.innerText = data[key].join(', '); + } else if (key === 'land speed' || key === 'water speed' || key === 'air speed') { + tdValue.innerText = `${data[key][0]}/${data[key][1]}/${data[key][2]}`; + } else { + tdValue.innerText = `${data[key][0]}d${data[key][1]}${data[key][2] === 0 ? "" : "+" + data[key][2]}`; + } + } else if (key === 'attacks' && typeof data[key] === 'object') { + let attacksTable = document.createElement('table'); + for (let attack in data[key]) { + let tr = document.createElement('tr'); + let tdKey = document.createElement('td'); + let tdValue = document.createElement('td'); + tdKey.innerText = attack; + + if (data[key][attack].join() === "0,0,0") { + tdValue.innerText = "See notes below"; + } else { + tdValue.innerText = `${data[key][attack][0]}d${data[key][attack][1]}${data[key][attack][2] === 0 ? "" : "+" + data[key][attack][2]}`; + } + + tr.appendChild(tdKey); + tr.appendChild(tdValue); + attacksTable.appendChild(tr); + } + tdValue.appendChild(attacksTable); + } else { + tdValue.innerText = data[key]; + } + + tr.appendChild(tdKey); + tr.appendChild(tdValue); + table.appendChild(tr); + } + resultSection.appendChild(table); + } + }, 1000); }); \ No newline at end of file diff --git a/web/img/berlep.jpg b/web/img/ber lep.jpg similarity index 100% rename from web/img/berlep.jpg rename to web/img/ber lep.jpg diff --git a/web/img/crentosh.jpg b/web/img/cren tosh.jpg similarity index 100% rename from web/img/crentosh.jpg rename to web/img/cren tosh.jpg diff --git a/web/img/grens.jpg b/web/img/gren.jpg similarity index 100% rename from web/img/grens.jpg rename to web/img/gren.jpg diff --git a/web/img/narlep.jpg b/web/img/narl ep.jpg similarity index 100% rename from web/img/narlep.jpg rename to web/img/narl ep.jpg diff --git a/web/img/seroon loo.jpg b/web/img/seroon lou.jpg similarity index 100% rename from web/img/seroon loo.jpg rename to web/img/seroon lou.jpg diff --git a/web/img/squeekr.jpg b/web/img/squeekr.jpg deleted file mode 100644 index dc0cae7..0000000 Binary files a/web/img/squeekr.jpg and /dev/null differ diff --git a/web/img/winseen.jpg b/web/img/win seen.jpg similarity index 100% rename from web/img/winseen.jpg rename to web/img/win seen.jpg