Started equipment; need to rework state system
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//environment variables
|
||||
require('dotenv').config();
|
||||
|
||||
//utilities
|
||||
let { log } = require('../common/utilities.js');
|
||||
|
||||
//the statistics
|
||||
let equipmentStatistics = require('./equipment_statistics.json');
|
||||
|
||||
const statisticsRequest = () => (req, res) => {
|
||||
res.status(200).json(equipmentStatistics);
|
||||
res.end();
|
||||
}
|
||||
|
||||
const listRequest = (connection) => (req, res) => {
|
||||
//verify identity
|
||||
let query = 'SELECT accountId FROM sessions WHERE accountId IN (SELECT id FROM accounts WHERE username = ?) AND token = ?;';
|
||||
connection.query(query, [req.body.username, req.body.token], (err, results) => {
|
||||
if (err) throw err;
|
||||
|
||||
let query = 'SELECT name, quantity, type FROM equipment WHERE accountId = ?;';
|
||||
connection.query(query, [results[0].accountId], (err, results) => {
|
||||
if (err) throw err;
|
||||
|
||||
//transform the results into a sendable array
|
||||
let list = {};
|
||||
|
||||
results.map((record) => {
|
||||
//initialize this type
|
||||
list[record.type] = list[record.type] || {};
|
||||
|
||||
//send the quantity of every type
|
||||
list[record.type][record.name] = record.quantity;
|
||||
});
|
||||
|
||||
res.status(200).json(list);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
statisticsRequest: statisticsRequest,
|
||||
listRequest: listRequest
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
let weapons = [
|
||||
{ name: 'Stick', cost: 50, boost: 0.02, level: 1 },
|
||||
{ name: 'Dagger', cost: 75, boost: 0.03, level: 2 },
|
||||
{ name: 'Sword', cost: 100, boost: 0.04, level: 3 },
|
||||
{ name: 'Longsword', cost: 150, boost: 0.05, level: 4 },
|
||||
{ name: 'Frying Pan', cost: 200, boost: 0.06, level: 5 },
|
||||
];
|
||||
|
||||
let armour = [
|
||||
{ name: 'leather', cost: 75, boost: 0.02, level: 2 },
|
||||
{ name: 'gambeson', cost: 100, boost: 0.03, level: 3 },
|
||||
{ name: 'chainmail', cost: 150, boost: 0.04, level: 4 },
|
||||
{ name: 'platemail', cost: 200, boost: 0.05, level: 5 },
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
weapons: weapons,
|
||||
armour: armour
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Weapons": {
|
||||
"Stick": { "cost": 50, "combatBoost": 0.02, "scientists": 1 },
|
||||
"Dagger": { "cost": 75, "combatBoost": 0.03, "scientists": 2 },
|
||||
"Sword": { "cost": 100, "combatBoost": 0.04, "scientists": 3 },
|
||||
"Longsword": { "cost": 150, "combatBoost": 0.05, "scientists": 4 },
|
||||
"Frying Pan": { "cost": 200, "combatBoost": 0.06, "scientists": 5 }
|
||||
},
|
||||
"Armour": {
|
||||
"Leather": { "cost": 75, "combatBoost": 0.02, "scientists": 2 },
|
||||
"Gambeson": { "cost": 100, "combatBoost": 0.03, "scientists": 3 },
|
||||
"Chainmail": { "cost": 150, "combatBoost": 0.04, "scientists": 4 },
|
||||
"Platemail": { "cost": 200, "combatBoost": 0.05, "scientists": 5 }
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,10 @@ app.post('/attackstatusrequest', combat.attackStatusRequest(connection));
|
||||
app.post('/combatlogrequest', combat.combatLogRequest(connection));
|
||||
combat.runCombatTick(connection);
|
||||
|
||||
let equipment = require('./equipment.js');
|
||||
app.post('/equipmentstatisticsrequest', equipment.statisticsRequest());
|
||||
app.post('/equipmentlistrequest', equipment.listRequest(connection));
|
||||
|
||||
//static directories
|
||||
app.use('/styles', express.static(path.resolve(__dirname + '/../public/styles')) );
|
||||
app.use('/img', express.static(path.resolve(__dirname + '/../public/img')) );
|
||||
|
||||
Reference in New Issue
Block a user