Skip to content

Commit

Permalink
Merge pull request Thaewyn#24 from DevelopThisOfficial/issue_17-skill…
Browse files Browse the repository at this point in the history
…_data_structure

added new data structure for 'software' items, added better logic for…
  • Loading branch information
Thaewyn authored Aug 9, 2022
2 parents 8e1d710 + c0b9cd6 commit 107ad01
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 18 deletions.
33 changes: 33 additions & 0 deletions __test__/controllers/db_controller.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const DBController = require("../../controllers/db_controller.js");
const software_ref = require("../../db/software_ref.json");

describe("DBController", () => {
jest.useFakeTimers();
let dbc;
beforeEach(() => {

dbc = new DBController(); //FIXME: need to mock mysql connection or otherwise mock timers.
})

it("should construct a new DBController instance when initialized", () => {
const dbcInst = new DBController();
expect(dbcInst).toBeInstanceOf(DBController);
});

describe("getSoftwareDetailsById", () => {
it("should accept an id parameter that is a number", () => {

})

it("should return the details for an item if the id is valid", () => {
let sampleId = 2;
let sampleDetails = software_ref[sampleId];

expect(dbc.getSoftwareDetailsById(sampleId)).toEqual(sampleDetails);
})

it("should return an error string if the id provided is not in the database", () => {
expect(dbc.getSoftwareDetailsById(99)).toEqual("ERR: No software with that ID");
})
});
});
18 changes: 18 additions & 0 deletions __test__/controllers/game_controller.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const GameController = require('../../controllers/game_controller.js');

describe("GameController", () => {
let gc
beforeEach(() => {
gc = new GameController();
})
it("should construct a new GameController instance when initialized", () => {

const gameController = new GameController();
Expand Down Expand Up @@ -34,5 +38,19 @@ describe("GameController", () => {



});

describe("generateSoftwareRewards", () => {
it("should (in testing) return an array with [1,4,6]", () => {
expect(gc.generateSoftwareRewards()).toEqual([1,4,6]);
});

it("should return a pseudo-random array of reward ids based on the run seed", () => {

})

it("should not return ids of any items that the player already owns", () => {

})
})
})
13 changes: 13 additions & 0 deletions controllers/db_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const db = require('../db');
const bcrypt = require('bcrypt');
const encounter_ref = require("../db/encounter_ref.json");
const enemy_ref = require("../db/enemy_ref.json");
const software_ref = require("../db/software_ref.json");

//console.log("for the handling of all database things.")

Expand Down Expand Up @@ -132,6 +133,18 @@ class DBController {
validatePassword(existingUserPass, submittedPass) {
return bcrypt.compareSync(submittedPass, existingUserPass);
}

/**
* Grab all software item information from json reference file.
* @param {Number} id
*/
getSoftwareDetailsById(id) {
if(software_ref[id]) {
return software_ref[id];
} else {
return "ERR: No software with that ID";
}
}
}

module.exports = DBController;
31 changes: 31 additions & 0 deletions controllers/game_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ class GameController {
this.handleEnemyAttacks();


/**
* Ability target keywords:
* ALL
* FRONT1
* FRONT2, etc
* BACK1
* BACK2, etc
* SELF
* LOWEST
* HIGHEST
*/

/**
* Ability effect keywords:
* HEAL - heal player
* DAMAGE - damage enemy
* DEFEND - increase player defense
*/

return result_mock;
}
Expand All @@ -114,6 +132,19 @@ class GameController {
handleEnemyAttacks(){
return false;
}

/**
* Generate a list of valid Software item ids based on inputs
* @param {String} seed hex value seed string
* @param {Number} userid unique identifier of the user
*/
generateSoftwareRewards(seed, userid) {
//TODO: generate ids based on seed data and user data.
let list = [1,4,6];

return list;
}

}

module.exports = GameController
71 changes: 71 additions & 0 deletions db/software_ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"1": {
"id": 1,
"name": "ICE Pick",
"icon_url": "",
"desc": "Standard ICE pick spell, breaks down enemy ICE.",
"cooldown": 0,
"targets": "FIRST1",
"power": 10,
"effect": "DAMAGE",
"status": [],
"cost": 10
},
"2": {
"id": 2,
"name": "Fireball",
"icon_url": "",
"desc": "Hits the first 2 enemies for splash damage, and cause burn.",
"cooldown": 2,
"targets": "FIRST2",
"power": 20,
"effect": "DAMAGE",
"status": [2],
"cost": 10
},
"3": {
"id": 3,
"name": "Thumper",
"icon_url": "",
"desc": "Hits all enemies for moderate damage.",
"cooldown": 2,
"targets": "ALL",
"power": 10,
"effect": "DAMAGE",
"status": [],
"cost": 10
},
"4": {
"id": 4,
"name": "Heal",
"desc": "Restore a small amount of health",
"cooldown": 4,
"targets": "SELF",
"power": 5,
"effect": "HEAL",
"status": [],
"cost": 10
},
"5": {
"id": 5,
"name": "Cleanse",
"desc": "Remove burn and poison status effects.",
"cooldown": 2,
"targets": "SELF",
"power": 0,
"effect": "HEAL",
"status": [2,3],
"cost": 10
},
"6": {
"id": 6,
"name": "Firewall",
"desc": "Increase player defense.",
"cooldown": 2,
"targets": "SELF",
"power": 10,
"effect": "DEFEND",
"status": [],
"cost": 10
}
}
28 changes: 10 additions & 18 deletions routes/api_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,16 @@ module.exports = function(app) {
});

app.get("/api/encounter/rewards", function(req,res) {
res.json({ //FIXME: replace with actual item fetching.
items: [
{
type: "hardware",
name: "VR Gloves",
id: 5
},
{
type: "software",
name: "Antivirus",
id: 7
},
{
type: "software",
name: "New attack thingy",
id: 3
},
]
//Right now, fixed item IDs, eventually generate item IDs from seed
let software_rewards = gc.generateSoftwareRewards(req.session.seed, req.session.userid);
let items = [];

for(let i=0; i<software_rewards.length; i++) {
items.push(dbc.getSoftwareDetailsById(software_rewards[i]));
}

res.json({
items
})
});

Expand Down

0 comments on commit 107ad01

Please sign in to comment.