Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const constants = require('dotaconstants');
const utility = require('./utility');
const playerWon = utility.playerWon;
// all items that cost at least 2000
const itemCost = 2000;
const dotaItems = Object.keys(constants.items).map(k => [constants.items[k], k]).filter(x => x[0].cost >= itemCost).map(x => x[1]);
const timings = [7.5, 10, 12, 15, 20, 25, 30].map(x => x * 60);
const gameDurationBucket = [15, 30, 45, 60, 90].map(x => x * 60);
const negativeWords = ['ff', 'report', 'gg', 'end', 'noob'];
const positiveWords = ['gl', 'glhf', 'hf', 'good luck', 'have fun'];
const teamScenariosQueryParams = [
'pos_chat_1min',
'neg_chat_1min',
'courier_kill',
'first_blood',
];
function buildTeamScenario(scenario, isRadiant, match) {
return [{
scenario,
unused_item(m, pm)
{
const result = [];
if (pm.purchase)
{
for (const key in pm.purchase)
{
if (pm.purchase[key] && getGroupedItemUses(key) < 1 && constants.items[key] && isActiveItem(key))
{
// if item has cooldown, consider it usable
result.push(`<img src="${constants.items[key].img}" class="item img-sm" title="${key}">`);
}
}
}
function getGroupedItemUses(key)
{
let total = 0;
for (const key2 in pm.item_uses)
{
if (key === key2 || constants.item_groups.some((g) => {
return (key in g) && (key2 in g);
}))
{
unused_item(m, pm)
{
const result = [];
if (pm.purchase)
{
for (const key in pm.purchase)
{
if (pm.purchase[key] && getGroupedItemUses(key) < 1 && constants.items[key] && isActiveItem(key))
{
// if item has cooldown, consider it usable
result.push(`<img src="${constants.items[key].img}" class="item img-sm" title="${key}">`);
}
}
}
function getGroupedItemUses(key)
{
let total = 0;
for (const key2 in pm.item_uses)
{
if (key === key2 || constants.item_groups.some((g) => {
return (key in g) && (key2 in g);
}))
{
total += pm.item_uses[key];
}
}
const Chance = require('chance');
const express = require('express');
const matches = express.Router();
const constants = require('dotaconstants');
const matchPages = constants.match_pages;
const playerSlots = [0, 1, 2, 3, 4, 128, 129, 130, 131, 132];
const item_ids = Object.keys(constants.items);
const hero_ids = Object.keys(constants.heroes);
module.exports = function (db)
{
matches.get('/:player_id/:match_id/:info?', (req, res, cb) => {
console.time('hyperopia generate match');
db.first('personaname')
.from('players')
.where({
account_id: req.params.player_id,
})
.asCallback((err, p) => {
if (err)
{
return cb(err);
}
function isActiveItem(key)
{
const whitelist = {
branches: 1,
bloodstone: 1,
radiance: 1,
};
return (constants.items[key].desc.indexOf('Active: ') > -1 && !(key in whitelist));
}
}
lastXP = 0;
for (var j = 0; j < times.length; j++) {
gold.push(lastGold);
lh.push(lastLH);
xp.push(lastXP);
lastGold = mChance.natural({ min: lastGold, max: 100000 });
lastLH = mChance.natural({ min: lastLH, max: player.last_hits });
lastXP = mChance.natural({ min: lastXP, max: 100000 });
}
player.gold_t = gold;
player.lh_t = lh;
player.xp_t = xp;
for (j = 0; j < mChance.weighted([0, 1, 2, 3, 4, 5, 6], [0.01, 0.04, 0.5, 0.1, 0.2, 0.3, 0.3]); j++) {
player[`item_${j}`] = constants.items[mChance.pickone(item_ids)].id;
}
player.obs_log = generateWards();
player.sen_log = generateWards();
player.purchase_log = generateItemTimeline();
player.kills_log = [];
player.buyback_log = [];
player.lane_pos = {};
player.obs = {};
player.sen = {};
player.actions = {};
player.pings = mChance.natural({ max: 1000 });
player.purchase = {};
player.gold_reasons = {};
player.xp_reasons = {};
player.killed = {};
function generateItemTimeline()
{
const items = [];
let lastTime = -60;
for (let j = 0; j < mChance.natural({ max: 40 }); j++) {
lastTime = mChance.integer({ min: lastTime, max: match.duration });
items.push({
time: lastTime,
key: mChance.pickone(Object.keys(constants.items)),
});
}
}